Search in sources :

Example 6 with NameQueryParameters

use of org.ovirt.engine.core.common.queries.NameQueryParameters in project ovirt-engine by oVirt.

the class BackendExternalVmImportsResource method getClusterId.

private Guid getClusterId(ExternalVmImport vmImport) {
    if (vmImport.getCluster().isSetId()) {
        return asGuid(vmImport.getCluster().getId());
    } else /* if (vmImport.getCluster().isSetName()) */
    {
        String clusterName = vmImport.getCluster().getName();
        Cluster cluster = getEntity(Cluster.class, QueryType.GetClusterByName, new NameQueryParameters(clusterName), clusterName, true);
        return cluster.getId();
    }
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) NameQueryParameters(org.ovirt.engine.core.common.queries.NameQueryParameters)

Example 7 with NameQueryParameters

use of org.ovirt.engine.core.common.queries.NameQueryParameters in project ovirt-engine by oVirt.

the class BackendOpenStackNetworkResource method getDataCenterIdByName.

private Guid getDataCenterIdByName(String dataCenterName) {
    NameQueryParameters parameters = new NameQueryParameters(dataCenterName);
    QueryReturnValue result = runQuery(QueryType.GetStoragePoolByDatacenterName, parameters);
    checkResultAndThrowExceptionIfFailed(result);
    List<StoragePool> dataCenters = result.getReturnValue();
    if (dataCenters.isEmpty()) {
        // This will always throw a WebApplicationException
        notFound();
    }
    return dataCenters.get(0).getId();
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) NameQueryParameters(org.ovirt.engine.core.common.queries.NameQueryParameters)

Example 8 with NameQueryParameters

use of org.ovirt.engine.core.common.queries.NameQueryParameters in project ovirt-engine by oVirt.

the class BackendDataCenterResource method getStoragePool.

/**
 * Get the storage pool (i.e. datacenter entity) associated with the given
 * cluster.
 */
@SuppressWarnings("unchecked")
public static StoragePool getStoragePool(DataCenter dataCenter, AbstractBackendResource parent) {
    StoragePool pool = null;
    if (dataCenter.isSetId()) {
        String id = dataCenter.getId();
        Guid guid;
        try {
            // can't use asGuid() because the method is static.
            guid = new Guid(id);
        } catch (IllegalArgumentException e) {
            throw new MalformedIdException(e);
        }
        pool = parent.getEntity(StoragePool.class, QueryType.GetStoragePoolById, new IdQueryParameters(guid), "Datacenter: id=" + id);
    } else {
        String clusterName = dataCenter.getName();
        pool = parent.getEntity(StoragePool.class, QueryType.GetStoragePoolByDatacenterName, new NameQueryParameters(clusterName), "Datacenter: name=" + clusterName);
        dataCenter.setId(pool.getId().toString());
    }
    return pool;
}
Also used : MalformedIdException(org.ovirt.engine.api.restapi.utils.MalformedIdException) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) NameQueryParameters(org.ovirt.engine.core.common.queries.NameQueryParameters)

Example 9 with NameQueryParameters

use of org.ovirt.engine.core.common.queries.NameQueryParameters in project ovirt-engine by oVirt.

the class AsyncDataProvider method isVmNameUnique.

public void isVmNameUnique(AsyncQuery<Boolean> aQuery, String name, Guid datacenterId) {
    aQuery.converterCallback = source -> source != null && !(Boolean) source;
    NameQueryParameters params = new NameQueryParameters(name);
    params.setDatacenterId(datacenterId);
    Frontend.getInstance().runQuery(QueryType.IsVmWithSameNameExist, params, aQuery);
}
Also used : NameQueryParameters(org.ovirt.engine.core.common.queries.NameQueryParameters)

Example 10 with NameQueryParameters

use of org.ovirt.engine.core.common.queries.NameQueryParameters in project ovirt-engine by oVirt.

the class VmHandler method isVmWithSameNameExistStatic.

/**
 * Checks if VM with same name exists in the given DC. If no DC provided, check all VMs in the database.
 */
public boolean isVmWithSameNameExistStatic(String vmName, Guid storagePoolId) {
    NameQueryParameters params = new NameQueryParameters(vmName);
    params.setDatacenterId(storagePoolId);
    QueryReturnValue result = backend.runInternalQuery(QueryType.IsVmWithSameNameExist, params);
    return (Boolean) result.getReturnValue();
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) NameQueryParameters(org.ovirt.engine.core.common.queries.NameQueryParameters)

Aggregations

NameQueryParameters (org.ovirt.engine.core.common.queries.NameQueryParameters)11 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)4 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)3 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Guid (org.ovirt.engine.core.compat.Guid)2 MalformedIdException (org.ovirt.engine.api.restapi.utils.MalformedIdException)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1