Search in sources :

Example 21 with HostNic

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

the class NetworkAttachmentMapper method getModelHostNic.

private static HostNic getModelHostNic(NetworkAttachment model) {
    HostNic hostNic = model.getHostNic();
    if (hostNic == null) {
        hostNic = new HostNic();
        model.setHostNic(hostNic);
    }
    return hostNic;
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic)

Example 22 with HostNic

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

the class NetworkAttachmentMapper method map.

@Mapping(from = NetworkAttachment.class, to = org.ovirt.engine.core.common.businessentities.network.NetworkAttachment.class)
public static org.ovirt.engine.core.common.businessentities.network.NetworkAttachment map(NetworkAttachment model, org.ovirt.engine.core.common.businessentities.network.NetworkAttachment template) {
    org.ovirt.engine.core.common.businessentities.network.NetworkAttachment entity = template == null ? new org.ovirt.engine.core.common.businessentities.network.NetworkAttachment() : template;
    if (model.isSetId()) {
        entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetNetwork()) {
        Network networkModel = model.getNetwork();
        if (networkModel.isSetId()) {
            entity.setNetworkId(GuidUtils.asGuid(networkModel.getId()));
        }
        if (networkModel.isSetName()) {
            entity.setNetworkName(networkModel.getName());
        }
    }
    if (model.isSetHostNic()) {
        HostNic hostNic = model.getHostNic();
        if (hostNic.isSetId()) {
            entity.setNicId(GuidUtils.asGuid(hostNic.getId()));
        } else {
            entity.setNicId(null);
        }
        if (hostNic.isSetName()) {
            entity.setNicName(hostNic.getName());
        } else {
            entity.setNicName(null);
        }
    }
    if (model.isSetProperties()) {
        entity.setProperties(CustomPropertiesParser.toMap(model.getProperties()));
    }
    if (model.isSetIpAddressAssignments()) {
        entity.setIpConfiguration(new org.ovirt.engine.core.common.businessentities.network.IpConfiguration());
        IpAddressAssignments ipAddressAssignments = model.getIpAddressAssignments();
        entity.getIpConfiguration().setIPv4Addresses(new ArrayList<>());
        entity.getIpConfiguration().setIpV6Addresses(new ArrayList<>());
        for (IpAddressAssignment ipAddressAssignment : ipAddressAssignments.getIpAddressAssignments()) {
            if (IpVersion.V6 == getIpVersion(ipAddressAssignment)) {
                entity.getIpConfiguration().getIpV6Addresses().add(mapIpv6AddressAssignment(ipAddressAssignment));
            } else {
                entity.getIpConfiguration().getIPv4Addresses().add(mapIpv4AddressAssignment(ipAddressAssignment));
            }
        }
    }
    if (model.isSetDnsResolverConfiguration()) {
        entity.setDnsResolverConfiguration(DnsResolverConfigurationMapper.map(entity.getDnsResolverConfiguration(), model.getDnsResolverConfiguration()));
    }
    if (model.isSetQos()) {
        HostNetworkQos hostNetworkQos = (HostNetworkQos) QosMapper.map(model.getQos(), null);
        entity.setHostNetworkQos(AnonymousHostNetworkQos.fromHostNetworkQos(hostNetworkQos));
    }
    return entity;
}
Also used : AnonymousHostNetworkQos(org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos) HostNetworkQos(org.ovirt.engine.core.common.businessentities.network.HostNetworkQos) HostNic(org.ovirt.engine.api.model.HostNic) Network(org.ovirt.engine.api.model.Network) IpAddressAssignments(org.ovirt.engine.api.model.IpAddressAssignments) IpAddressAssignment(org.ovirt.engine.api.model.IpAddressAssignment)

Example 23 with HostNic

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

the class BackendHostNicsResource method idToHref.

private String idToHref(String id) {
    HostNic master = new HostNic();
    master.setId(id);
    master.setHost(new Host());
    master.getHost().setId(hostId);
    return LinkHelper.addLinks(master).getHref();
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) Host(org.ovirt.engine.api.model.Host)

Example 24 with HostNic

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

the class BackendHostNicsResource method addLinks.

@Override
protected HostNic addLinks(HostNic hostNic, String... subCollectionsToExclude) {
    if (hostNic.isSetVirtualFunctionsConfiguration()) {
        return super.addLinks(hostNic, subCollectionsToExclude);
    } else {
        final HostNic resultHostNic = super.addLinks(hostNic, ArrayUtils.concat(PF_SUB_COLLECTIONS, subCollectionsToExclude));
        final Iterator<Link> linkIterator = resultHostNic.getActions().getLinks().iterator();
        while (linkIterator.hasNext()) {
            final Link link = linkIterator.next();
            if (link.getRel().equals(UPDATE_VFS_CONFIG_ACTION)) {
                linkIterator.remove();
            }
        }
        if (isBond(resultHostNic)) {
            removeLldpLink(resultHostNic);
        }
        return resultHostNic;
    }
}
Also used : HostNic(org.ovirt.engine.api.model.HostNic) Link(org.ovirt.engine.api.model.Link)

Example 25 with HostNic

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

the class BackendHostResource method toParameters.

private HostSetupNetworksParameters toParameters(Action action) {
    HostSetupNetworksParameters parameters = new HostSetupNetworksParameters(guid);
    Map<Guid, NetworkAttachment> attachmentsById = getBackendNetworkAttachments();
    if (action.isSetModifiedNetworkAttachments()) {
        for (org.ovirt.engine.api.model.NetworkAttachment model : action.getModifiedNetworkAttachments().getNetworkAttachments()) {
            NetworkAttachment attachment = mapNetworkAttachment(attachmentsById, model);
            parameters.getNetworkAttachments().add(attachment);
        }
    }
    if (action.isSetSynchronizedNetworkAttachments()) {
        Map<Guid, NetworkAttachment> networkAttachmentFromParams = Entities.businessEntitiesById(parameters.getNetworkAttachments());
        for (org.ovirt.engine.api.model.NetworkAttachment model : action.getSynchronizedNetworkAttachments().getNetworkAttachments()) {
            if (model.isSetId()) {
                Guid networkAttachmentId = asGuid(model.getId());
                if (networkAttachmentFromParams.containsKey(networkAttachmentId)) {
                    networkAttachmentFromParams.get(networkAttachmentId).setOverrideConfiguration(true);
                } else if (attachmentsById.containsKey(networkAttachmentId)) {
                    NetworkAttachment networkAttachment = attachmentsById.get(networkAttachmentId);
                    networkAttachment.setOverrideConfiguration(true);
                    parameters.getNetworkAttachments().add(networkAttachment);
                } else {
                    return handleError(new EntityNotFoundException("NetworkAttachment.id: " + model.getId()), true);
                }
            }
        }
    }
    if (action.isSetModifiedLabels()) {
        for (NetworkLabel label : action.getModifiedLabels().getNetworkLabels()) {
            NicLabel nicLabel = new NicLabel();
            nicLabel.setLabel(label.getId());
            if (label.isSetHostNic()) {
                nicLabel.setNicId(label.getHostNic().isSetId() ? asGuid(label.getHostNic().getId()) : null);
                nicLabel.setNicName(label.getHostNic().getName());
            }
            parameters.getLabels().add(nicLabel);
        }
    }
    if (action.isSetRemovedLabels()) {
        for (NetworkLabel label : action.getRemovedLabels().getNetworkLabels()) {
            parameters.getRemovedLabels().add(label.getId());
        }
    }
    if (action.isSetRemovedNetworkAttachments()) {
        for (org.ovirt.engine.api.model.NetworkAttachment model : action.getRemovedNetworkAttachments().getNetworkAttachments()) {
            NetworkAttachment attachment = mapNetworkAttachment(attachmentsById, model);
            parameters.getRemovedNetworkAttachments().add(attachment.getId());
        }
    }
    BusinessEntityMap<Bond> bonds = getBackendHostBonds();
    if (action.isSetModifiedBonds()) {
        BusinessEntityMap<VdsNetworkInterface> nicsFromBackend = getBackendNics();
        for (HostNic bond : action.getModifiedBonds().getHostNics()) {
            completeSlaveNames(nicsFromBackend, bond);
            parameters.getCreateOrUpdateBonds().add(mapBonds(bonds, bond));
        }
    }
    if (action.isSetRemovedBonds()) {
        for (HostNic bond : action.getRemovedBonds().getHostNics()) {
            parameters.getRemovedBonds().add(mapBonds(bonds, bond).getId());
        }
    }
    if (action.isSetCheckConnectivity()) {
        parameters.setRollbackOnFailure(action.isCheckConnectivity());
    }
    if (action.isSetConnectivityTimeout()) {
        parameters.setConectivityTimeout(action.getConnectivityTimeout());
    }
    return parameters;
}
Also used : HostSetupNetworksParameters(org.ovirt.engine.core.common.action.HostSetupNetworksParameters) Guid(org.ovirt.engine.core.compat.Guid) NetworkLabel(org.ovirt.engine.api.model.NetworkLabel) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment) HostNic(org.ovirt.engine.api.model.HostNic) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NicLabel(org.ovirt.engine.core.common.businessentities.network.NicLabel) CreateOrUpdateBond(org.ovirt.engine.core.common.action.CreateOrUpdateBond) Bond(org.ovirt.engine.core.common.businessentities.network.Bond)

Aggregations

HostNic (org.ovirt.engine.api.model.HostNic)30 Test (org.junit.Test)7 Host (org.ovirt.engine.api.model.Host)6 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)6 Guid (org.ovirt.engine.core.compat.Guid)6 Bond (org.ovirt.engine.core.common.businessentities.network.Bond)4 Bonding (org.ovirt.engine.api.model.Bonding)3 HostNics (org.ovirt.engine.api.model.HostNics)3 Network (org.ovirt.engine.api.model.Network)3 BootProtocol (org.ovirt.engine.api.model.BootProtocol)2 HostNicVirtualFunctionsConfiguration (org.ovirt.engine.api.model.HostNicVirtualFunctionsConfiguration)2 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)2 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)2 HostNicVfsConfig (org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig)2 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)2 List (java.util.List)1 Collectors.joining (java.util.stream.Collectors.joining)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 UriInfo (javax.ws.rs.core.UriInfo)1 StringUtils (org.apache.commons.lang.StringUtils)1