Search in sources :

Example 1 with ResourceGroupSpawn

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

the class LinstorPrimaryDataStoreDriverImpl method createResource.

private String createResource(VolumeInfo vol, StoragePoolVO storagePoolVO) {
    DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
    final String rscGrp = storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ? storagePoolVO.getUserInfo() : "DfltRscGrp";
    ResourceGroupSpawn rscGrpSpawn = new ResourceGroupSpawn();
    final String rscName = LinstorUtil.RSC_PREFIX + vol.getUuid();
    rscGrpSpawn.setResourceDefinitionName(rscName);
    rscGrpSpawn.addVolumeSizesItem(vol.getSize() / 1024);
    try {
        s_logger.debug("Linstor: Spawn resource " + rscName);
        ApiCallRcList answers = linstorApi.resourceGroupSpawn(rscGrp, rscGrpSpawn);
        checkLinstorAnswersThrow(answers);
        return getDeviceName(linstorApi, rscName);
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) ApiException(com.linbit.linstor.api.ApiException)

Example 2 with ResourceGroupSpawn

use of com.linbit.linstor.api.model.ResourceGroupSpawn 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)

Aggregations

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