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;
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations