Search in sources :

Example 1 with ResourceDefinitionModify

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

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

the class LinstorStorageAdaptor method disconnectPhysicalDiskByPath.

/**
 * disconnectPhysicalDiskByPath is called after e.g. a live migration.
 * The problem is we have no idea just from the path to which linstor-controller
 * this resource would belong to. But as it should be highly unlikely that someone
 * uses more than one linstor-controller to manage resource on the same kvm host.
 * We will just take the first stored storagepool.
 */
@Override
public boolean disconnectPhysicalDiskByPath(String localPath) {
    // get first storage pool from the map, as we don't know any better:
    if (!MapStorageUuidToStoragePool.isEmpty()) {
        s_logger.debug("Linstor: disconnectPhysicalDiskByPath " + localPath);
        String firstKey = MapStorageUuidToStoragePool.keySet().stream().findFirst().get();
        final KVMStoragePool pool = MapStorageUuidToStoragePool.get(firstKey);
        s_logger.debug("Linstor: Using storpool: " + pool.getUuid());
        final DevelopersApi api = getLinstorAPI(pool);
        try {
            List<ResourceWithVolumes> resources = api.viewResources(Collections.singletonList(localNodeName), null, null, null, null, null);
            Optional<ResourceWithVolumes> rsc = getResourceByPath(resources, localPath);
            if (rsc.isPresent()) {
                ResourceDefinitionModify rdm = new ResourceDefinitionModify();
                rdm.deleteProps(Collections.singletonList("DrbdOptions/Net/allow-two-primaries"));
                ApiCallRcList answers = api.resourceDefinitionModify(rsc.get().getName(), rdm);
                if (answers.hasError()) {
                    s_logger.error("Failed to remove 'allow-two-primaries' on " + rsc.get().getName());
                    throw new CloudRuntimeException(answers.get(0).getMessage());
                }
                return true;
            }
            s_logger.warn("Linstor: Couldn't find resource for this path: " + localPath);
        } catch (ApiException apiEx) {
            s_logger.error(apiEx);
            throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
        }
    }
    return false;
}
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) ResourceWithVolumes(com.linbit.linstor.api.model.ResourceWithVolumes) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ApiException (com.linbit.linstor.api.ApiException)2 DevelopersApi (com.linbit.linstor.api.DevelopersApi)2 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)2 ResourceDefinitionModify (com.linbit.linstor.api.model.ResourceDefinitionModify)2 Properties (com.linbit.linstor.api.model.Properties)1 ResourceMakeAvailable (com.linbit.linstor.api.model.ResourceMakeAvailable)1 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)1