Search in sources :

Example 1 with VolumeDefinition

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);
    }
}
Also used : VolumeDefinition(com.linbit.linstor.api.model.VolumeDefinition) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ApiException (com.linbit.linstor.api.ApiException)1 DevelopersApi (com.linbit.linstor.api.DevelopersApi)1 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)1 VolumeDefinition (com.linbit.linstor.api.model.VolumeDefinition)1