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);
}
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;
}
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;
}
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;
}
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());
}
Aggregations