Search in sources :

Example 31 with Network

use of org.ovirt.engine.api.model.Network in project ovirt-engine by oVirt.

the class V3NICHelper method isProfileCompatible.

/**
 * Checks if the given VNIC profile is compatible with the given NIC.
 *
 * @param profile the VNIC profile to check
 * @param nic the NIC to check
 * @return {@code true} iff the profile is compatible with the network and port mirroring configuration of the NIC
 */
private static boolean isProfileCompatible(VnicProfile profile, V3NIC nic) {
    // Retrieve the representation of the network corresponding to the profile, as we are going to need it in
    // order to check the name:
    SystemResource systemService = BackendApiResource.getInstance();
    NetworksResource networksService = systemService.getNetworksResource();
    NetworkResource networkService = networksService.getNetworkResource(profile.getNetwork().getId());
    Network profileNetwork = networkService.get();
    // If the NIC configuration explicitly specifies a network then the profile has to correspond to that same
    // network:
    V3Network nicNetwork = nic.getNetwork();
    if (nicNetwork != null) {
        if (nicNetwork.isSetId()) {
            if (!Objects.equals(profileNetwork.getId(), nicNetwork.getId())) {
                return false;
            }
        }
        if (nicNetwork.isSetName()) {
            if (!Objects.equals(profileNetwork.getName(), nicNetwork.getName())) {
                return false;
            }
        }
    }
    // If the NIC configuration explicitly specifies a port mirroring configuration then the profile must have
    // port mirroring enabled, and all the networks included in the port mirroring configuration must be the same
    // network used by the profile:
    V3PortMirroring nicPortMirroring = nic.getPortMirroring();
    if (nicPortMirroring != null) {
        if (!profile.isSetPortMirroring() || !profile.isPortMirroring()) {
            return false;
        }
        V3Networks nicPortMirroringNetworks = nicPortMirroring.getNetworks();
        if (nicPortMirroringNetworks != null) {
            for (V3Network nicPortMirroringNetwork : nicPortMirroringNetworks.getNetworks()) {
                if (nicPortMirroringNetwork.isSetId()) {
                    if (!Objects.equals(profileNetwork.getId(), nicPortMirroringNetwork.getId())) {
                        return false;
                    }
                }
                if (nicPortMirroringNetwork.isSetName()) {
                    if (!Objects.equals(profileNetwork.getName(), nicPortMirroringNetwork.getName())) {
                        return false;
                    }
                }
            }
        }
    }
    // All checks passed, so the profile is compatible:
    return true;
}
Also used : NetworkResource(org.ovirt.engine.api.resource.NetworkResource) V3Networks(org.ovirt.engine.api.v3.types.V3Networks) V3Network(org.ovirt.engine.api.v3.types.V3Network) V3Network(org.ovirt.engine.api.v3.types.V3Network) Network(org.ovirt.engine.api.model.Network) V3PortMirroring(org.ovirt.engine.api.v3.types.V3PortMirroring) SystemResource(org.ovirt.engine.api.resource.SystemResource) ClusterNetworksResource(org.ovirt.engine.api.resource.ClusterNetworksResource) NetworksResource(org.ovirt.engine.api.resource.NetworksResource)

Example 32 with Network

use of org.ovirt.engine.api.model.Network in project ovirt-engine by oVirt.

the class ManagementNetworkFinder method getManagementNetworkId.

Guid getManagementNetworkId(Cluster cluster, Guid dataCenterId) {
    Guid managementNetworkId = null;
    if (cluster.isSetManagementNetwork()) {
        backendResource.validateParameters(cluster.getManagementNetwork(), "id|name");
        final Network rawManagementNetwork = cluster.getManagementNetwork();
        if (rawManagementNetwork.isSetId()) {
            managementNetworkId = GuidUtils.asGuid(rawManagementNetwork.getId());
        } else {
            final org.ovirt.engine.core.common.businessentities.network.Network managementNetwork = backendResource.getEntity(org.ovirt.engine.core.common.businessentities.network.Network.class, QueryType.GetNetworkByNameAndDataCenter, new IdAndNameQueryParameters(dataCenterId, rawManagementNetwork.getName()), String.format("Network: %s", rawManagementNetwork.getName()));
            managementNetworkId = managementNetwork.getId();
        }
    }
    return managementNetworkId;
}
Also used : Network(org.ovirt.engine.api.model.Network) Guid(org.ovirt.engine.core.compat.Guid) IdAndNameQueryParameters(org.ovirt.engine.core.common.queries.IdAndNameQueryParameters)

Example 33 with Network

use of org.ovirt.engine.api.model.Network in project ovirt-engine by oVirt.

the class BackendNetworksResourceTest method testAddIncompleteParameters.

@Test
public void testAddIncompleteParameters() throws Exception {
    Network model = new Network();
    model.setName(NAMES[0]);
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Network", "add", "dataCenter.name|id");
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Network(org.ovirt.engine.api.model.Network) Test(org.junit.Test)

Example 34 with Network

use of org.ovirt.engine.api.model.Network in project ovirt-engine by oVirt.

the class BackendNetworksResourceTest method doTestBadAddNetwork.

private void doTestBadAddNetwork(boolean valid, boolean success, String detail) throws Exception {
    setUriInfo(setUpActionExpectations(ActionType.AddNetwork, AddNetworkStoragePoolParameters.class, new String[] { "StoragePoolId" }, new Object[] { DATA_CENTER_ID }, valid, success));
    Network model = getModel(0);
    model.setDataCenter(new DataCenter());
    model.getDataCenter().setId(DATA_CENTER_ID.toString());
    try {
        collection.add(model);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyFault(wae, detail);
    }
}
Also used : DataCenter(org.ovirt.engine.api.model.DataCenter) WebApplicationException(javax.ws.rs.WebApplicationException) AddNetworkStoragePoolParameters(org.ovirt.engine.core.common.action.AddNetworkStoragePoolParameters) Network(org.ovirt.engine.api.model.Network)

Example 35 with Network

use of org.ovirt.engine.api.model.Network in project ovirt-engine by oVirt.

the class BackendDataCenterNetworkResourceTest method testConflictedUpdate.

@Test
public void testConflictedUpdate() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpEntityQueryExpectations(1);
    Network model = getModel(1);
    model.setId(GUIDS[1].toString());
    try {
        resource.update(model);
        fail("expected WebApplicationException");
    } catch (WebApplicationException wae) {
        verifyImmutabilityConstraint(wae);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Network(org.ovirt.engine.api.model.Network) Test(org.junit.Test)

Aggregations

Network (org.ovirt.engine.api.model.Network)45 Test (org.junit.Test)16 WebApplicationException (javax.ws.rs.WebApplicationException)9 Response (javax.ws.rs.core.Response)6 DataCenter (org.ovirt.engine.api.model.DataCenter)6 VnicProfile (org.ovirt.engine.api.model.VnicProfile)5 V3Network (org.ovirt.engine.api.v3.types.V3Network)4 Guid (org.ovirt.engine.core.compat.Guid)4 Networks (org.ovirt.engine.api.model.Networks)3 V3Networks (org.ovirt.engine.api.v3.types.V3Networks)3 V3PortMirroring (org.ovirt.engine.api.v3.types.V3PortMirroring)3 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)3 HostNic (org.ovirt.engine.api.model.HostNic)2 NetworkLabels (org.ovirt.engine.api.model.NetworkLabels)2 Nic (org.ovirt.engine.api.model.Nic)2 ClusterNetworksResource (org.ovirt.engine.api.resource.ClusterNetworksResource)2 NetworkResource (org.ovirt.engine.api.resource.NetworkResource)2 NetworksResource (org.ovirt.engine.api.resource.NetworksResource)2 SystemResource (org.ovirt.engine.api.resource.SystemResource)2 VnicProfileResource (org.ovirt.engine.api.resource.VnicProfileResource)2