Search in sources :

Example 11 with DevelopersApi

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

the class LinstorPrimaryDataStoreDriverImpl method deleteSnapshot.

private void deleteSnapshot(@Nonnull DataStore dataStore, @Nonnull String rscDefName, @Nonnull String snapshotName) {
    StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
    DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePool.getHostAddress());
    try {
        ApiCallRcList answers = linstorApi.resourceSnapshotDelete(rscDefName, snapshotName);
        if (answers.hasError()) {
            for (ApiCallRc answer : answers) {
                s_logger.error(answer.getMessage());
            }
            throw new CloudRuntimeException("Linstor: Unable to delete snapshot: " + rscDefName);
        }
    } 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) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiCallRc(com.linbit.linstor.api.model.ApiCallRc) ApiException(com.linbit.linstor.api.ApiException)

Example 12 with DevelopersApi

use of com.linbit.linstor.api.DevelopersApi 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 13 with DevelopersApi

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

the class LinstorStorageAdaptor method getUsed.

public long getUsed(LinstorStoragePool pool) {
    DevelopersApi linstorApi = getLinstorAPI(pool);
    final String rscGroupName = pool.getResourceGroup();
    try {
        List<ResourceGroup> rscGrps = linstorApi.resourceGroupList(Collections.singletonList(rscGroupName), null, null, null);
        if (rscGrps.isEmpty()) {
            final String errMsg = String.format("Linstor: Resource group '%s' not found", rscGroupName);
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        List<StoragePool> storagePools = linstorApi.viewStoragePools(Collections.emptyList(), rscGrps.get(0).getSelectFilter().getStoragePoolList(), null, null, null);
        final long used = storagePools.stream().filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS).mapToLong(sp -> sp.getTotalCapacity() - sp.getFreeCapacity()).sum() * // linstor uses Kib
        1024;
        s_logger.debug("Linstor: getUsed() -> " + used);
        return used;
    } catch (ApiException apiEx) {
        s_logger.error(apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiCallRc(com.linbit.linstor.api.model.ApiCallRc) QemuImgFile(org.apache.cloudstack.utils.qemu.QemuImgFile) HashMap(java.util.HashMap) StoragePool(com.linbit.linstor.api.model.StoragePool) Configuration(com.linbit.linstor.api.Configuration) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) QemuImg(org.apache.cloudstack.utils.qemu.QemuImg) LibvirtException(org.libvirt.LibvirtException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Logger(org.apache.log4j.Logger) ProviderKind(com.linbit.linstor.api.model.ProviderKind) Map(java.util.Map) Properties(com.linbit.linstor.api.model.Properties) VolumeDefinition(com.linbit.linstor.api.model.VolumeDefinition) Storage(com.cloud.storage.Storage) Nonnull(javax.annotation.Nonnull) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) QemuImgException(org.apache.cloudstack.utils.qemu.QemuImgException) ResourceMakeAvailable(com.linbit.linstor.api.model.ResourceMakeAvailable) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException) List(java.util.List) ApiClient(com.linbit.linstor.api.ApiClient) ResourceDefinitionModify(com.linbit.linstor.api.model.ResourceDefinitionModify) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) StringJoiner(java.util.StringJoiner) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) StoragePool(com.linbit.linstor.api.model.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) ApiException(com.linbit.linstor.api.ApiException)

Example 14 with DevelopersApi

use of com.linbit.linstor.api.DevelopersApi 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 15 with DevelopersApi

use of com.linbit.linstor.api.DevelopersApi 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

DevelopersApi (com.linbit.linstor.api.DevelopersApi)18 ApiException (com.linbit.linstor.api.ApiException)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)13 ApiClient (com.linbit.linstor.api.ApiClient)6 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)6 ResourceDefinition (com.linbit.linstor.api.model.ResourceDefinition)5 ResourceDefinitionModify (com.linbit.linstor.api.model.ResourceDefinitionModify)5 ResourceGroupSpawn (com.linbit.linstor.api.model.ResourceGroupSpawn)5 Configuration (com.linbit.linstor.api.Configuration)4 ApiCallRc (com.linbit.linstor.api.model.ApiCallRc)4 Properties (com.linbit.linstor.api.model.Properties)4 ProviderKind (com.linbit.linstor.api.model.ProviderKind)4 ResourceGroup (com.linbit.linstor.api.model.ResourceGroup)4 ResourceMakeAvailable (com.linbit.linstor.api.model.ResourceMakeAvailable)4 StoragePool (com.linbit.linstor.api.model.StoragePool)4 VolumeDefinition (com.linbit.linstor.api.model.VolumeDefinition)4 Collections (java.util.Collections)4 List (java.util.List)4 Logger (org.apache.log4j.Logger)4