Search in sources :

Example 1 with IpAddressAssignment

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

the class NetworkAttachmentMapperTest method postPopulate.

@Override
protected org.ovirt.engine.api.model.NetworkAttachment postPopulate(org.ovirt.engine.api.model.NetworkAttachment model) {
    model.getIpAddressAssignments().getIpAddressAssignments().get(0).setAssignmentMethod(BootProtocol.DHCP);
    model.getQos().setType(QosType.HOSTNETWORK);
    for (IpAddressAssignment ipAddressAssignment : model.getIpAddressAssignments().getIpAddressAssignments()) {
        if (IpVersion.V6 == ipAddressAssignment.getIp().getVersion()) {
            ipAddressAssignment.getIp().setNetmask(String.valueOf(new Random().nextInt(128)));
        }
    }
    return super.postPopulate(model);
}
Also used : Random(java.util.Random) IpAddressAssignment(org.ovirt.engine.api.model.IpAddressAssignment)

Example 2 with IpAddressAssignment

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

the class NetworkAttachmentMapper method mapIpv4Address.

private static IpAddressAssignment mapIpv4Address(IPv4Address iPv4Address) {
    IpAddressAssignment ipAddressAssignment = new IpAddressAssignment();
    Ip ip = new Ip();
    ip.setVersion(IpVersion.V4);
    if (iPv4Address.getAddress() != null) {
        ip.setAddress(iPv4Address.getAddress());
    }
    if (iPv4Address.getGateway() != null) {
        ip.setGateway(iPv4Address.getGateway());
    }
    if (iPv4Address.getNetmask() != null) {
        ip.setNetmask(iPv4Address.getNetmask());
    }
    ipAddressAssignment.setIp(ip);
    BootProtocol assignmentMethod = Ipv4BootProtocolMapper.map(iPv4Address.getBootProtocol());
    ipAddressAssignment.setAssignmentMethod(assignmentMethod == null ? null : assignmentMethod);
    return ipAddressAssignment;
}
Also used : Ip(org.ovirt.engine.api.model.Ip) IpAddressAssignment(org.ovirt.engine.api.model.IpAddressAssignment) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) Ipv6BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol) BootProtocol(org.ovirt.engine.api.model.BootProtocol)

Example 3 with IpAddressAssignment

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

the class NetworkAttachmentMapper method mapIpv6AddressAssignment.

static IpAddressAssignment mapIpv6AddressAssignment(IpV6Address ipV6Address) {
    IpAddressAssignment ipAddressAssignment = new IpAddressAssignment();
    Ip ip = new Ip();
    ip.setVersion(IpVersion.V6);
    if (ipV6Address.getAddress() != null) {
        ip.setAddress(ipV6Address.getAddress());
    }
    if (ipV6Address.getGateway() != null) {
        ip.setGateway(ipV6Address.getGateway());
    }
    if (ipV6Address.getPrefix() != null) {
        ip.setNetmask(ipV6Address.getPrefix().toString());
    }
    ipAddressAssignment.setIp(ip);
    BootProtocol assignmentMethod = Ipv6BootProtocolMapper.map(ipV6Address.getBootProtocol());
    ipAddressAssignment.setAssignmentMethod(assignmentMethod);
    return ipAddressAssignment;
}
Also used : Ip(org.ovirt.engine.api.model.Ip) IpAddressAssignment(org.ovirt.engine.api.model.IpAddressAssignment) Ipv4BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol) Ipv6BootProtocol(org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol) BootProtocol(org.ovirt.engine.api.model.BootProtocol)

Example 4 with IpAddressAssignment

use of org.ovirt.engine.api.model.IpAddressAssignment 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 5 with IpAddressAssignment

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

the class NetworkAttachmentMapperTest method testMapFromModelIpv6Assignment.

@Test
public void testMapFromModelIpv6Assignment() {
    final IpAddressAssignment model = new IpAddressAssignment();
    model.setAssignmentMethod(BootProtocol.STATIC);
    final Ip ip = new Ip();
    ip.setAddress(ADDRESS);
    ip.setGateway(GATEWAY);
    ip.setNetmask(PREFIX_STR);
    model.setIp(ip);
    final IpV6Address actual = NetworkAttachmentMapper.mapIpv6AddressAssignment(model);
    assertEquals(Ipv6BootProtocol.STATIC_IP, actual.getBootProtocol());
    assertEquals(ADDRESS, actual.getAddress());
    assertEquals(GATEWAY, actual.getGateway());
    assertEquals(Integer.valueOf(PREFIX), actual.getPrefix());
}
Also used : Ip(org.ovirt.engine.api.model.Ip) IpV6Address(org.ovirt.engine.core.common.businessentities.network.IpV6Address) IpAddressAssignment(org.ovirt.engine.api.model.IpAddressAssignment) Test(org.junit.Test)

Aggregations

IpAddressAssignment (org.ovirt.engine.api.model.IpAddressAssignment)7 Ip (org.ovirt.engine.api.model.Ip)4 Test (org.junit.Test)2 BootProtocol (org.ovirt.engine.api.model.BootProtocol)2 IpV6Address (org.ovirt.engine.core.common.businessentities.network.IpV6Address)2 Ipv4BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv4BootProtocol)2 Ipv6BootProtocol (org.ovirt.engine.core.common.businessentities.network.Ipv6BootProtocol)2 Random (java.util.Random)1 HostNic (org.ovirt.engine.api.model.HostNic)1 IpAddressAssignments (org.ovirt.engine.api.model.IpAddressAssignments)1 Network (org.ovirt.engine.api.model.Network)1 AnonymousHostNetworkQos (org.ovirt.engine.core.common.businessentities.network.AnonymousHostNetworkQos)1 HostNetworkQos (org.ovirt.engine.core.common.businessentities.network.HostNetworkQos)1