Search in sources :

Example 1 with VolumeDefinitionModify

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

Answer (com.cloud.agent.api.Answer)1 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)1 ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)1 StoragePool (com.cloud.storage.StoragePool)1 ApiException (com.linbit.linstor.api.ApiException)1 DevelopersApi (com.linbit.linstor.api.DevelopersApi)1 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)1 VolumeDefinitionModify (com.linbit.linstor.api.model.VolumeDefinitionModify)1 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)1 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)1 VolumeObject (org.apache.cloudstack.storage.volume.VolumeObject)1