use of com.linbit.linstor.api.model.VolumeDefinition in project cloudstack by apache.
the class LinstorStorageAdaptor method getPhysicalDisk.
@Override
public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool) {
s_logger.debug("Linstor: getPhysicalDisk for " + name);
if (name == null) {
return null;
}
final DevelopersApi api = getLinstorAPI(pool);
try {
final String rscName = getLinstorRscName(name);
List<VolumeDefinition> volumeDefs = api.volumeDefinitionList(rscName, null, null);
final long size = volumeDefs.isEmpty() ? 0 : volumeDefs.get(0).getSizeKib() * 1024;
List<ResourceWithVolumes> resources = api.viewResources(Collections.emptyList(), Collections.singletonList(rscName), Collections.emptyList(), null, null, null);
if (!resources.isEmpty() && !resources.get(0).getVolumes().isEmpty()) {
final String devPath = resources.get(0).getVolumes().get(0).getDevicePath();
final KVMPhysicalDisk kvmDisk = new KVMPhysicalDisk(devPath, name, pool);
kvmDisk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
kvmDisk.setSize(size);
kvmDisk.setVirtualSize(size);
return kvmDisk;
} else {
s_logger.error("Linstor: viewResources didn't return resources or volumes for " + rscName);
throw new CloudRuntimeException("Linstor: viewResources didn't return resources or volumes.");
}
} catch (ApiException apiEx) {
s_logger.error(apiEx);
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
}
}
Aggregations