Search in sources :

Example 1 with ApiCallRcList

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

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

use of com.linbit.linstor.api.model.ApiCallRcList 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 4 with ApiCallRcList

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

the class LinstorPrimaryDataStoreDriverImpl method revertSnapshot.

@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
    s_logger.debug("Linstor: revertSnapshot");
    final VolumeInfo volumeInfo = snapshot.getBaseVolume();
    VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    if (volumeVO == null || volumeVO.getRemoved() != null) {
        CommandResult commandResult = new CommandResult();
        commandResult.setResult("The volume that the snapshot belongs to no longer exists.");
        callback.complete(commandResult);
        return;
    }
    String resultMsg;
    try {
        final StoragePool pool = (StoragePool) snapshot.getDataStore();
        final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getUuid();
        final String snapName = LinstorUtil.RSC_PREFIX + snapshot.getUuid();
        final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(pool.getHostAddress());
        ApiCallRcList answers = linstorApi.resourceSnapshotRollback(rscName, snapName);
        resultMsg = checkLinstorAnswers(answers);
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        resultMsg = apiEx.getBestMessage();
    }
    if (callback != null) {
        CommandResult result = new CommandResult();
        result.setResult(resultMsg);
        callback.complete(result);
    }
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DevelopersApi(com.linbit.linstor.api.DevelopersApi) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ApiException(com.linbit.linstor.api.ApiException)

Example 5 with ApiCallRcList

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

the class LinstorPrimaryDataStoreDriverImpl method resize.

@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    final VolumeObject vol = (VolumeObject) data;
    final StoragePool pool = (StoragePool) data.getDataStore();
    final DevelopersApi api = LinstorUtil.getLinstorAPI(pool.getHostAddress());
    final ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
    final String rscName = LinstorUtil.RSC_PREFIX + vol.getPath();
    final long oldSize = vol.getSize();
    String errMsg = null;
    VolumeDefinitionModify dfm = new VolumeDefinitionModify();
    dfm.setSizeKib(resizeParameter.newSize / 1024);
    try {
        ApiCallRcList answers = api.volumeDefinitionModify(rscName, 0, dfm);
        if (answers.hasError()) {
            s_logger.error("Resize error: " + answers.get(0).getMessage());
            errMsg = answers.get(0).getMessage();
        } else {
            s_logger.info(String.format("Successfully resized %s to %d kib", rscName, dfm.getSizeKib()));
            vol.setSize(resizeParameter.newSize);
            vol.update();
        }
    } catch (ApiException apiExc) {
        s_logger.error(apiExc);
        errMsg = apiExc.getBestMessage();
    }
    CreateCmdResult result;
    if (errMsg != null) {
        result = new CreateCmdResult(null, new Answer(null, false, errMsg));
        result.setResult(errMsg);
    } else {
        // notify guests
        result = notifyResize(data, oldSize, resizeParameter);
    }
    callback.complete(result);
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) StoragePool(com.cloud.storage.StoragePool) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) VolumeDefinitionModify(com.linbit.linstor.api.model.VolumeDefinitionModify) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

ApiException (com.linbit.linstor.api.ApiException)10 DevelopersApi (com.linbit.linstor.api.DevelopersApi)10 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 VolumeVO (com.cloud.storage.VolumeVO)3 Answer (com.cloud.agent.api.Answer)2 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)2 StoragePool (com.cloud.storage.StoragePool)2 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)2 ResourceDefinition (com.linbit.linstor.api.model.ResourceDefinition)2 ResourceDefinitionModify (com.linbit.linstor.api.model.ResourceDefinitionModify)2 ResourceGroupSpawn (com.linbit.linstor.api.model.ResourceGroupSpawn)2 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)2 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)2 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)2 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)2 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)2 ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)1 SnapshotVO (com.cloud.storage.SnapshotVO)1 ApiCallRc (com.linbit.linstor.api.model.ApiCallRc)1