Search in sources :

Example 1 with DevelopersApi

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

the class LinstorStorageAdaptor method connectPhysicalDisk.

@Override
public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<String, String> details) {
    s_logger.debug(String.format("Linstor: connectPhysicalDisk %s:%s -> %s", pool.getUuid(), volumePath, details));
    if (volumePath == null) {
        s_logger.warn("volumePath is null, ignoring");
        return false;
    }
    final DevelopersApi api = getLinstorAPI(pool);
    try {
        final String rscName = getLinstorRscName(volumePath);
        ResourceMakeAvailable rma = new ResourceMakeAvailable();
        ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, localNodeName, rma);
        checkLinstorAnswersThrow(answers);
        // allow 2 primaries for live migration, should be removed by disconnect on the other end
        ResourceDefinitionModify rdm = new ResourceDefinitionModify();
        Properties props = new Properties();
        props.put("DrbdOptions/Net/allow-two-primaries", "yes");
        rdm.setOverrideProps(props);
        answers = api.resourceDefinitionModify(rscName, rdm);
        if (answers.hasError()) {
            s_logger.error("Unable to set 'allow-two-primaries' on " + rscName);
            throw new CloudRuntimeException(answers.get(0).getMessage());
        }
    } catch (ApiException apiEx) {
        s_logger.error(apiEx);
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
    return true;
}
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) ResourceMakeAvailable(com.linbit.linstor.api.model.ResourceMakeAvailable) Properties(com.linbit.linstor.api.model.Properties) ApiException(com.linbit.linstor.api.ApiException)

Example 2 with DevelopersApi

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

the class LinstorStorageAdaptor method deletePhysicalDisk.

@Override
public boolean deletePhysicalDisk(String name, KVMStoragePool pool, Storage.ImageFormat format) {
    s_logger.debug("Linstor: deletePhysicalDisk " + name);
    final DevelopersApi api = getLinstorAPI(pool);
    try {
        final String rscName = getLinstorRscName(name);
        s_logger.debug("Linstor: delete resource definition " + rscName);
        ApiCallRcList answers = api.resourceDefinitionDelete(rscName);
        handleLinstorApiAnswers(answers, "Linstor: Unable to delete resource definition " + rscName);
    } catch (ApiException apiEx) {
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
    return true;
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException)

Example 3 with DevelopersApi

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

the class LinstorStorageAdaptor method getLinstorAPI.

private DevelopersApi getLinstorAPI(KVMStoragePool pool) {
    ApiClient client = Configuration.getDefaultApiClient();
    client.setBasePath(pool.getSourceHost());
    return new DevelopersApi(client);
}
Also used : DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiClient(com.linbit.linstor.api.ApiClient)

Example 4 with DevelopersApi

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

the class LinstorPrimaryDataStoreDriverImpl method createResourceFromSnapshot.

private String createResourceFromSnapshot(long csSnapshotId, String rscName, StoragePoolVO storagePoolVO) {
    final String rscGrp = storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ? storagePoolVO.getUserInfo() : "DfltRscGrp";
    final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
    SnapshotVO snapshotVO = _snapshotDao.findById(csSnapshotId);
    String snapName = LinstorUtil.RSC_PREFIX + snapshotVO.getUuid();
    VolumeVO volumeVO = _volumeDao.findById(snapshotVO.getVolumeId());
    String cloneRes = LinstorUtil.RSC_PREFIX + volumeVO.getPath();
    try {
        s_logger.debug("Create new resource definition: " + rscName);
        ResourceDefinitionCreate rdCreate = new ResourceDefinitionCreate();
        ResourceDefinition rd = new ResourceDefinition();
        rd.setName(rscName);
        rd.setResourceGroupName(rscGrp);
        rdCreate.setResourceDefinition(rd);
        ApiCallRcList answers = linstorApi.resourceDefinitionCreate(rdCreate);
        checkLinstorAnswersThrow(answers);
        SnapshotRestore snapshotRestore = new SnapshotRestore();
        snapshotRestore.toResource(rscName);
        s_logger.debug("Create new volume definition for snapshot: " + cloneRes + ":" + snapName);
        answers = linstorApi.resourceSnapshotsRestoreVolumeDefinition(cloneRes, snapName, snapshotRestore);
        checkLinstorAnswersThrow(answers);
        // restore snapshot to new resource
        s_logger.debug("Restore resource from snapshot: " + cloneRes + ":" + snapName);
        answers = linstorApi.resourceSnapshotRestore(cloneRes, snapName, snapshotRestore);
        checkLinstorAnswersThrow(answers);
        return getDeviceName(linstorApi, rscName);
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ResourceDefinitionCreate(com.linbit.linstor.api.model.ResourceDefinitionCreate) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) SnapshotRestore(com.linbit.linstor.api.model.SnapshotRestore) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) ResourceDefinition(com.linbit.linstor.api.model.ResourceDefinition) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiException(com.linbit.linstor.api.ApiException)

Example 5 with DevelopersApi

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

the class LinstorUtil method getCapacityBytes.

public static long getCapacityBytes(String linstorUrl, String rscGroupName) {
    DevelopersApi linstorApi = getLinstorAPI(linstorUrl);
    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);
        return storagePools.stream().filter(sp -> sp.getProviderKind() != ProviderKind.DISKLESS).mapToLong(StoragePool::getTotalCapacity).sum() * // linstor uses kiB
        1024;
    } catch (ApiException apiEx) {
        s_logger.error(apiEx.getMessage());
        throw new CloudRuntimeException(apiEx);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Logger(org.apache.log4j.Logger) ApiException(com.linbit.linstor.api.ApiException) ResourceGroup(com.linbit.linstor.api.model.ResourceGroup) List(java.util.List) ApiClient(com.linbit.linstor.api.ApiClient) ProviderKind(com.linbit.linstor.api.model.ProviderKind) StoragePool(com.linbit.linstor.api.model.StoragePool) Collections(java.util.Collections) Configuration(com.linbit.linstor.api.Configuration) DevelopersApi(com.linbit.linstor.api.DevelopersApi) 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)

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