Search in sources :

Example 1 with ResourceDefinitionCloneRequest

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

the class LinstorPrimaryDataStoreDriverImpl method cloneResource.

private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolVO storagePoolVO) {
    // get the cached template on this storage
    VMTemplateStoragePoolVO tmplPoolRef = _vmTemplatePoolDao.findByPoolTemplate(storagePoolVO.getId(), csCloneId, null);
    if (tmplPoolRef != null) {
        final String cloneRes = LinstorUtil.RSC_PREFIX + tmplPoolRef.getLocalDownloadPath();
        final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getUuid();
        final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
        try {
            s_logger.debug("Clone resource definition " + cloneRes + " to " + rscName);
            ResourceDefinitionCloneRequest cloneRequest = new ResourceDefinitionCloneRequest();
            cloneRequest.setName(rscName);
            ResourceDefinitionCloneStarted cloneStarted = linstorApi.resourceDefinitionClone(cloneRes, cloneRequest);
            checkLinstorAnswersThrow(cloneStarted.getMessages());
            if (!CloneWaiter.waitFor(linstorApi, cloneStarted)) {
                throw new CloudRuntimeException("Clone for resource " + rscName + " failed.");
            }
            return getDeviceName(linstorApi, rscName);
        } catch (ApiException apiEx) {
            s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
            throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
        }
    } else {
        throw new CloudRuntimeException("Unable to find Linstor resource for the following template data-object ID: " + csCloneId);
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceDefinitionCloneRequest(com.linbit.linstor.api.model.ResourceDefinitionCloneRequest) ResourceDefinitionCloneStarted(com.linbit.linstor.api.model.ResourceDefinitionCloneStarted) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ApiException (com.linbit.linstor.api.ApiException)1 DevelopersApi (com.linbit.linstor.api.DevelopersApi)1 ResourceDefinitionCloneRequest (com.linbit.linstor.api.model.ResourceDefinitionCloneRequest)1 ResourceDefinitionCloneStarted (com.linbit.linstor.api.model.ResourceDefinitionCloneStarted)1