Search in sources :

Example 1 with ResourceDefinitionCreate

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

Aggregations

SnapshotVO (com.cloud.storage.SnapshotVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ApiException (com.linbit.linstor.api.ApiException)1 DevelopersApi (com.linbit.linstor.api.DevelopersApi)1 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)1 ResourceDefinition (com.linbit.linstor.api.model.ResourceDefinition)1 ResourceDefinitionCreate (com.linbit.linstor.api.model.ResourceDefinitionCreate)1 SnapshotRestore (com.linbit.linstor.api.model.SnapshotRestore)1