public NetworkAttachment mapNetworkAttachment(Map<Guid, NetworkAttachment> attachmentsById, org.ovirt.engine.api.model.NetworkAttachment model) { Mapper<org.ovirt.engine.api.model.NetworkAttachment, NetworkAttachment> networkAttachmentMapper = getMapper(org.ovirt.engine.api.model.NetworkAttachment.class, NetworkAttachment.class); NetworkAttachment attachment = null; if (model.isSetId()) { attachment = attachmentsById.get(asGuid(model.getId())); } else if (model.isSetNetwork() && (model.getNetwork().isSetName() || model.getNetwork().isSetId())) { for (Map.Entry<Guid, NetworkAttachment> backendNetworkAttachmentMapEntry : attachmentsById.entrySet()) { NetworkAttachment backendNetworkAttachment = backendNetworkAttachmentMapEntry.getValue(); String backendNetworkName = backendNetworkAttachment.getNetworkName(); String backendNetworkId = backendNetworkAttachment.getNetworkId().toString(); if (backendNetworkName.equals(model.getNetwork().getName()) || backendNetworkId.equals(model.getNetwork().getId())) { attachment = backendNetworkAttachment; break; } } } return networkAttachmentMapper.map(model, attachment); }
/** * Create an instance of {@link NetworkAttachment } * */ public NetworkAttachment createNetworkAttachment() { return new NetworkAttachment(); }
private static HostNic getModelHostNic(NetworkAttachment model) { HostNic hostNic = model.getHostNic(); if (hostNic == null) { hostNic = new HostNic(); model.setHostNic(hostNic); } return hostNic; }
private static Network getModelNetwork(NetworkAttachment model) { Network network = model.getNetwork(); if (network == null) { network = new Network(); model.setNetwork(network); } return network; } }
@Override protected NetworkAttachment addParents(NetworkAttachment model) { Host host = new Host(); model.setHost(host); model.getHost().setId(getHostId().toString()); if (model.isSetHostNic()) { model.getHostNic().setHost(host); } return model; } }
@Override public V3NetworkAttachment adapt(NetworkAttachment from) { V3NetworkAttachment to = new V3NetworkAttachment(); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); if (from.isSetComment()) { to.setComment(from.getComment()); if (from.isSetDescription()) { to.setDescription(from.getDescription()); if (from.isSetHost()) { to.setHost(adaptOut(from.getHost())); if (from.isSetHostNic()) { to.setHostNic(adaptOut(from.getHostNic())); if (from.isSetId()) { to.setId(from.getId()); if (from.isSetHref()) { to.setHref(from.getHref()); if (from.isSetInSync()) { V3ReportedConfigurations toReportedConfigurations = to.getReportedConfigurations(); if (toReportedConfigurations == null) {
@Override public NetworkAttachment adapt(V3NetworkAttachment from) { NetworkAttachment to = new NetworkAttachment(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setComment(from.getComment()); to.setDescription(from.getDescription()); to.setHost(adaptIn(from.getHost())); to.setHostNic(adaptIn(from.getHostNic())); to.setId(from.getId()); to.setHref(from.getHref()); to.setIpAddressAssignments(new IpAddressAssignments()); to.getIpAddressAssignments().getIpAddressAssignments().addAll(adaptIn(from.getIpAddressAssignments().getIpAddressAssignments())); to.setName(from.getName()); to.setNetwork(adaptIn(from.getNetwork())); to.setProperties(new Properties()); to.getProperties().getProperties().addAll(adaptIn(from.getProperties().getProperties()));
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 (model.isSetHostNic()) { HostNic hostNic = model.getHostNic(); if (hostNic.isSetId()) { entity.setNicId(GuidUtils.asGuid(hostNic.getId())); 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<>()); if (model.isSetDnsResolverConfiguration()) { entity.setDnsResolverConfiguration( DnsResolverConfigurationMapper.map(entity.getDnsResolverConfiguration(), model.getDnsResolverConfiguration())); if (model.isSetQos()) { HostNetworkQos hostNetworkQos = (HostNetworkQos) QosMapper.map(model.getQos(), null);
NetworkAttachment template) { NetworkAttachment model = template == null ? new NetworkAttachment() : template; model.setId(entity.getId().toString()); model.setProperties(CustomPropertiesParser.fromMap(entity.getProperties())); entity.getIpConfiguration(); if (entityIpConfiguration != null) { model.setIpAddressAssignments(new IpAddressAssignments()); if (!entityIpConfiguration.getIPv4Addresses().isEmpty()) { .stream() .map(NetworkAttachmentMapper::mapIpv4Address) .forEach(model.getIpAddressAssignments().getIpAddressAssignments()::add); .stream() .map(NetworkAttachmentMapper::mapIpv6AddressAssignment) .forEach(model.getIpAddressAssignments().getIpAddressAssignments()::add); model.setDnsResolverConfiguration( DnsResolverConfigurationMapper.map(entity.getDnsResolverConfiguration())); model.setInSync(entity.getReportedConfigurations().isNetworkInSync()); model.setReportedConfigurations(ReportedConfigurationsMapper.map(entity.getReportedConfigurations(), null)); model.setQos(QosMapper.map(HostNetworkQos.fromAnonymousHostNetworkQos(hostNetworkQos), null));
protected org.ovirt.engine.api.model.NetworkAttachment getModel(int index) { org.ovirt.engine.api.model.NetworkAttachment model = new org.ovirt.engine.api.model.NetworkAttachment(); model.setId(GUIDS[index].toString()); model.setNetwork(new Network()); model.getNetwork().setId(NETWORK_ID.toString()); return model; }
@Override protected void verify(org.ovirt.engine.api.model.NetworkAttachment model, org.ovirt.engine.api.model.NetworkAttachment transform) { assertNotNull(transform); assertEquals(model.getId(), transform.getId()); assertNotNull(transform.getNetwork()); assertEquals(model.getNetwork().getId(), transform.getNetwork().getId()); assertNotNull(transform.getHostNic()); assertEquals(model.getHostNic().getId(), transform.getHostNic().getId()); assertNotNull(transform.getProperties()); assertEquals(CustomPropertiesParser.toMap(model.getProperties()), CustomPropertiesParser.toMap(transform.getProperties())); assertNotNull(transform.getIpAddressAssignments()); List<IpAddressAssignment> transformAddresses = transform.getIpAddressAssignments().getIpAddressAssignments(); assertNotNull(transformAddresses); List<IpAddressAssignment> modelAddresses = model.getIpAddressAssignments().getIpAddressAssignments(); assertEquals(modelAddresses.size(), transformAddresses.size()); for (int i = 0; i < modelAddresses.size(); i++) { assertEquals(modelAddresses.get(i).getAssignmentMethod(), transformAddresses.get(i).getAssignmentMethod()); Ip modelAddress = modelAddresses.get(i).getIp(); Ip transformAddress = transformAddresses.get(i).getIp(); assertEquals(modelAddress.getAddress(), transformAddress.getAddress()); assertEquals(modelAddress.getNetmask(), transformAddress.getNetmask()); assertEquals(modelAddress.getGateway(), transformAddress.getGateway()); } }
@Override protected final void verifyModel(org.ovirt.engine.api.model.NetworkAttachment model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(GUIDS[index].toString(), model.getNetwork().getId()); verifyModel(model); verifyLinks(model); }
@Override public Response add(org.ovirt.engine.api.model.NetworkAttachment attachment) { verifyHostAndNicExistence(); if (attachment.isSetHostNic()) { Guid hostNicGuid = Guid.createGuidFromString(attachment.getHostNic().getId()); if (!nicId.equals(hostNicGuid)) { //TODO MM: add message. return Response.status(Response.Status.BAD_REQUEST).build(); } } else { HostNic hostNIC = new HostNic(); hostNIC.setId(nicId.toString()); attachment.setHostNic(hostNIC); } return super.add(attachment); } }
@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); } }
public static void validateAdd(NetworkAttachment attachment) { if (attachment == null) { throw new ValidationException("Parameter 'attachment' is mandatory but was not provided."); } if ( (attachment.getNetwork()==null || attachment.getNetwork().getName()==null) && (attachment.getNetwork()==null || attachment.getNetwork().getId()==null) ) { throw new ValidationException("Parameters 'attachment.network.name' or 'attachment.network.id' are mandatory but both were not provided."); } }
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); parameters.getNetworkAttachments().add(networkAttachment); } else { return handleError(new EntityNotFoundException("NetworkAttachment.id: " + model.getId()), true);
@Override protected void verifyModel(org.ovirt.engine.api.model.NetworkAttachment model) { assertEquals(HOST_NIC_ID.toString(), model.getHostNic().getId()); }
@Test public void testConflictedUpdate() { setUriInfo(setUpBasicUriExpectations()); setUpEntityQueryExpectations(1, 0, false); org.ovirt.engine.api.model.NetworkAttachment model = getModel(1); model.setId(GUIDS[1].toString()); verifyImmutabilityConstraint(assertThrows(WebApplicationException.class, () -> resource.update(model))); }
protected org.ovirt.engine.api.model.NetworkAttachment getModel(int index) { org.ovirt.engine.api.model.NetworkAttachment model = new org.ovirt.engine.api.model.NetworkAttachment(); model.setId(GUIDS[index].toString()); model.setNetwork(new Network()); model.getNetwork().setId(GUIDS[index].toString()); return model; }
@Override protected final void verifyModel(org.ovirt.engine.api.model.NetworkAttachment model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(GUIDS[index].toString(), model.getNetwork().getId()); verifyModel(model); verifyLinks(model); }