Search in sources :

Example 1 with ResourceWithVolumes

use of com.linbit.linstor.api.model.ResourceWithVolumes in project cloudstack by apache.

the class LinstorStorageAdaptor method getPhysicalDisk.

@Override
public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool) {
    s_logger.debug("Linstor: getPhysicalDisk for " + name);
    if (name == null) {
        return null;
    }
    final DevelopersApi api = getLinstorAPI(pool);
    try {
        final String rscName = getLinstorRscName(name);
        List<VolumeDefinition> volumeDefs = api.volumeDefinitionList(rscName, null, null);
        final long size = volumeDefs.isEmpty() ? 0 : volumeDefs.get(0).getSizeKib() * 1024;
        List<ResourceWithVolumes> resources = api.viewResources(Collections.emptyList(), Collections.singletonList(rscName), Collections.emptyList(), null, null, null);
        if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) {
            final String devPath = resources.get(0).getVolumes().get(0).getDevicePath();
            final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool);
            kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
            kvmDisk.setSize(size);
            kvmDisk.setVirtualSize(size);
            return kvmDisk;
        } else {
            s_logger.error("Linstor: viewResources didn't return resources or volumes for " + rscName);
            throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
        }
    } catch (ApiException apiEx) {
        s_logger.error(apiEx);
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : VolumeDefinition(com.linbit.linstor.api.model.VolumeDefinition) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) ApiException(com.linbit.linstor.api.ApiException)

Example 2 with ResourceWithVolumes

use of com.linbit.linstor.api.model.ResourceWithVolumes in project cloudstack by apache.

the class LinstorStorageAdaptor method createPhysicalDisk.

@Override
public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, QemuImg.PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
    final String rscName = getLinstorRscName(name);
    LinstorStoragePool lpool = (LinstorStoragePool) pool;
    final DevelopersApi api = getLinstorAPI(pool);
    try {
        List<ResourceDefinition> definitionList = api.resourceDefinitionList(Collections.singletonList(rscName), null, null, null);
        if (definitionList.isEmpty()) {
            ResourceGroupSpawn rgSpawn = new ResourceGroupSpawn();
            rgSpawn.setResourceDefinitionName(rscName);
            // linstor uses KiB
            rgSpawn.addVolumeSizesItem(size / 1024);
            s_logger.debug("Linstor: Spawn resource " + rscName);
            ApiCallRcList answers = api.resourceGroupSpawn(lpool.getResourceGroup(), rgSpawn);
            handleLinstorApiAnswers(answers, "Linstor: Unable to spawn resource.");
        }
        // query linstor for the device path
        List<ResourceWithVolumes> resources = api.viewResources(Collections.emptyList(), Collections.singletonList(rscName), Collections.emptyList(), null, null, null);
        if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) {
            final String devPath = resources.get(0).getVolumes().get(0).getDevicePath();
            s_logger.info("Linstor: Created drbd device: " + devPath);
            final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool);
            kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
            return kvmDisk;
        } else {
            s_logger.error("Linstor: viewResources didn't return resources or volumes.");
            throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
        }
    } catch (ApiException apiEx) {
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) ApiException(com.linbit.linstor.api.ApiException)

Example 3 with ResourceWithVolumes

use of com.linbit.linstor.api.model.ResourceWithVolumes in project cloudstack by apache.

the class LinstorStorageAdaptor method disconnectPhysicalDiskByPath.

/**
 * disconnectPhysicalDiskByPath is called after e.g. a live migration.
 * The problem is we have no idea just from the path to which linstor-controller
 * this resource would belong to. But as it should be highly unlikely that someone
 * uses more than one linstor-controller to manage resource on the same kvm host.
 * We will just take the first stored storagepool.
 */
@Override
public boolean disconnectPhysicalDiskByPath(String localPath) {
    // get first storage pool from the map, as we don't know any better:
    if (!MapStorageUuidToStoragePool.isEmpty()) {
        s_logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath);
        String firstKey = MapStorageUuidToStoragePool.keySet().stream().findFirst().get();
        final KVMStoragePool pool = MapStorageUuidToStoragePool.get(firstKey);
        s_logger.debug("Linstor: Using storpool: " + pool.getUuid());
        final DevelopersApi api = getLinstorAPI(pool);
        try {
            List<ResourceWithVolumes> resources = api.viewResources(Collections.singletonList(localNodeName), null, null, null, null, null);
            Optional<ResourceWithVolumes> rsc = getResourceByPath(resources, localPath);
            if (rsc.isPresent()) {
                ResourceDefinitionModify rdm = new ResourceDefinitionModify();
                rdm.deleteProps(Collections.singletonList("DrbdOptions/Net/allow-two-primaries"));
                ApiCallRcList answers = api.resourceDefinitionModify(rsc.get().getName(), rdm);
                if (answers.hasError()) {
                    s_logger.error("Failed to remove 'allow-two-primaries' on " + rsc.get().getName());
                    throw new CloudRuntimeException(answers.get(0).getMessage());
                }
                return true;
            }
            s_logger.warn("Linstor: Couldn't find resource for this path: " + localPath);
        } catch (ApiException apiEx) {
            s_logger.error(apiEx);
            throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
        }
    }
    return false;
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceDefinitionModify(com.linbit.linstor.api.model.ResourceDefinitionModify) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ApiException (com.linbit.linstor.api.ApiException)3 DevelopersApi (com.linbit.linstor.api.DevelopersApi)3 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)3 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)2 ResourceDefinition (com.linbit.linstor.api.model.ResourceDefinition)1 ResourceDefinitionModify (com.linbit.linstor.api.model.ResourceDefinitionModify)1 ResourceGroupSpawn (com.linbit.linstor.api.model.ResourceGroupSpawn)1 VolumeDefinition (com.linbit.linstor.api.model.VolumeDefinition)1