Search in sources :

Example 1 with V3Network

use of org.ovirt.engine.api.v3.types.V3Network in project ovirt-engine by oVirt.

the class V3NICHelper method setNetworkAndPortMirroring.

/**
 * Populates the {@code network} and {@code port_mirroring} attributes used in V3.
 *
 * @param v4Nic the V4 NIC where the details of the NIC profile will be extracted from
 * @param v3Nic the V3 NIC object that will be populated
 */
public static void setNetworkAndPortMirroring(Nic v4Nic, V3NIC v3Nic) {
    // Do nothing if the V4 NIC doesn't specify a profile:
    VnicProfile v4Profile = v4Nic.getVnicProfile();
    if (v4Profile == null) {
        return;
    }
    // Retrieve the complete representation of the profile, as we need it to compute the "network" and
    // "port_mirroring" attributes used in V3:
    BackendApiResource systemService = BackendApiResource.getInstance();
    VnicProfilesResource profilesService = systemService.getVnicProfilesResource();
    VnicProfileResource profileService = profilesService.getProfileResource(v4Profile.getId());
    v4Profile = profileService.get();
    // Populate the "network" and "port_mirroring" attributes of the V3 object:
    Network v4Network = v4Profile.getNetwork();
    V3Network v3Network = new V3Network();
    v3Network.setId(v4Network.getId());
    v4Network.setHref(v4Network.getHref());
    v3Nic.setNetwork(v3Network);
    if (v4Profile.isSetPortMirroring() && v4Profile.isPortMirroring()) {
        V3PortMirroring v3PortMirroring = new V3PortMirroring();
        V3Networks v3PortMirroringNetworks = new V3Networks();
        V3Network v3PortMirroringNetwork = new V3Network();
        v3PortMirroringNetwork.setId(v4Network.getId());
        v3PortMirroringNetwork.setHref(v4Network.getHref());
        v3PortMirroringNetworks.getNetworks().add(v3PortMirroringNetwork);
        v3PortMirroring.setNetworks(v3PortMirroringNetworks);
        v3Nic.setPortMirroring(v3PortMirroring);
    }
}
Also used : BackendApiResource(org.ovirt.engine.api.restapi.resource.BackendApiResource) VnicProfilesResource(org.ovirt.engine.api.resource.VnicProfilesResource) 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) VnicProfile(org.ovirt.engine.api.model.VnicProfile) V3PortMirroring(org.ovirt.engine.api.v3.types.V3PortMirroring) VnicProfileResource(org.ovirt.engine.api.resource.VnicProfileResource)

Example 2 with V3Network

use of org.ovirt.engine.api.v3.types.V3Network in project ovirt-engine by oVirt.

the class V3NetworkInAdapter method adapt.

@Override
public Network adapt(V3Network from) {
    Network to = new Network();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptIn(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDataCenter()) {
        to.setDataCenter(adaptIn(from.getDataCenter()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisplay()) {
        to.setDisplay(from.isDisplay());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetIp()) {
        to.setIp(adaptIn(from.getIp()));
    }
    if (from.isSetLabels()) {
        to.setNetworkLabels(new NetworkLabels());
        to.getNetworkLabels().getNetworkLabels().addAll(adaptIn(from.getLabels().getLabels()));
    }
    if (from.isSetMtu()) {
        to.setMtu(from.getMtu());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetProfileRequired()) {
        to.setProfileRequired(from.isProfileRequired());
    }
    if (from.isSetQos()) {
        to.setQos(adaptIn(from.getQos()));
    }
    if (from.isSetRequired()) {
        to.setRequired(from.isRequired());
    }
    if (from.isSetStatus() && from.getStatus().isSetState()) {
        to.setStatus(NetworkStatus.fromValue(from.getStatus().getState()));
    }
    if (from.isSetStp()) {
        to.setStp(from.isStp());
    }
    if (from.isSetUsages()) {
        Network.UsagesList toUsages = to.getUsages();
        if (toUsages == null) {
            toUsages = new Network.UsagesList();
            to.setUsages(toUsages);
        }
        List<NetworkUsage> toList = toUsages.getUsages();
        from.getUsages().getUsages().forEach(usage -> toList.add(NetworkUsage.fromValue(usage)));
    }
    if (from.isSetVlan()) {
        to.setVlan(adaptIn(from.getVlan()));
    }
    return to;
}
Also used : NetworkLabels(org.ovirt.engine.api.model.NetworkLabels) Network(org.ovirt.engine.api.model.Network) V3Network(org.ovirt.engine.api.v3.types.V3Network) NetworkUsage(org.ovirt.engine.api.model.NetworkUsage)

Example 3 with V3Network

use of org.ovirt.engine.api.v3.types.V3Network 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 4 with V3Network

use of org.ovirt.engine.api.v3.types.V3Network in project ovirt-engine by oVirt.

the class V3NetworkOutAdapter method adapt.

@Override
public V3Network adapt(Network from) {
    V3Network to = new V3Network();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptOut(from.getLinks()));
        // In version 3 of the API the name of the network labels sub-collection was just "labels", but in version
        // 4 of the API it has been renamed to "networklabels", so we need to adjust the links accordingly:
        to.getLinks().stream().filter(this::isNetworksLabelsLink).forEach(this::fixNetworkLabelsLink);
    }
    if (from.isSetActions()) {
        to.setActions(adaptOut(from.getActions()));
    }
    if (from.isSetCluster()) {
        to.setCluster(adaptOut(from.getCluster()));
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDataCenter()) {
        to.setDataCenter(adaptOut(from.getDataCenter()));
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetDisplay()) {
        to.setDisplay(from.isDisplay());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetIp()) {
        to.setIp(adaptOut(from.getIp()));
    }
    if (from.isSetNetworkLabels()) {
        to.setLabels(new V3Labels());
        to.getLabels().getLabels().addAll(adaptOut(from.getNetworkLabels().getNetworkLabels()));
    }
    if (from.isSetMtu()) {
        to.setMtu(from.getMtu());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetProfileRequired()) {
        to.setProfileRequired(from.isProfileRequired());
    }
    if (from.isSetQos()) {
        to.setQos(adaptOut(from.getQos()));
    }
    if (from.isSetRequired()) {
        to.setRequired(from.isRequired());
    }
    if (from.isSetStatus()) {
        V3Status status = new V3Status();
        status.setState(from.getStatus().value());
        to.setStatus(status);
    }
    if (from.isSetStp()) {
        to.setStp(from.isStp());
    }
    if (from.isSetUsages()) {
        V3Usages toUsages = to.getUsages();
        if (toUsages == null) {
            toUsages = new V3Usages();
            to.setUsages(toUsages);
        }
        List<String> toList = toUsages.getUsages();
        from.getUsages().getUsages().forEach(usage -> toList.add(usage.value()));
    }
    if (from.isSetVlan()) {
        to.setVlan(adaptOut(from.getVlan()));
    }
    return to;
}
Also used : V3Network(org.ovirt.engine.api.v3.types.V3Network) V3Labels(org.ovirt.engine.api.v3.types.V3Labels) V3Status(org.ovirt.engine.api.v3.types.V3Status) V3Usages(org.ovirt.engine.api.v3.types.V3Usages)

Aggregations

V3Network (org.ovirt.engine.api.v3.types.V3Network)4 Network (org.ovirt.engine.api.model.Network)3 V3Networks (org.ovirt.engine.api.v3.types.V3Networks)2 V3PortMirroring (org.ovirt.engine.api.v3.types.V3PortMirroring)2 NetworkLabels (org.ovirt.engine.api.model.NetworkLabels)1 NetworkUsage (org.ovirt.engine.api.model.NetworkUsage)1 VnicProfile (org.ovirt.engine.api.model.VnicProfile)1 ClusterNetworksResource (org.ovirt.engine.api.resource.ClusterNetworksResource)1 NetworkResource (org.ovirt.engine.api.resource.NetworkResource)1 NetworksResource (org.ovirt.engine.api.resource.NetworksResource)1 SystemResource (org.ovirt.engine.api.resource.SystemResource)1 VnicProfileResource (org.ovirt.engine.api.resource.VnicProfileResource)1 VnicProfilesResource (org.ovirt.engine.api.resource.VnicProfilesResource)1 BackendApiResource (org.ovirt.engine.api.restapi.resource.BackendApiResource)1 V3Labels (org.ovirt.engine.api.v3.types.V3Labels)1 V3Status (org.ovirt.engine.api.v3.types.V3Status)1 V3Usages (org.ovirt.engine.api.v3.types.V3Usages)1