public NetworkAttachment(NetworkAttachment networkAttachment) { id = networkAttachment.getId(); nicId = networkAttachment.getNicId(); nicName = networkAttachment.getNicName(); networkId = networkAttachment.getNetworkId(); networkName = networkAttachment.getNetworkName(); ipConfiguration = networkAttachment.getIpConfiguration(); properties = networkAttachment.getProperties(); overrideConfiguration = networkAttachment.isOverrideConfiguration(); reportedConfigurations = networkAttachment.getReportedConfigurations(); }
@Override public DnsResolverConfiguration getDnsResolverConfiguration() { return networkAttachment.getDnsResolverConfiguration(); }
private void verifyRelationWithHostNetworkQos(NetworkAttachment entity) { AnonymousHostNetworkQos hostNetworkQos = entity.getHostNetworkQos(); if (hostNetworkQos != null && !Objects.equals(hostNetworkQos.getId(), entity.getId())) { throw new IllegalArgumentException( String.format("Overridden HostNetworkQos using id %s which does not related to given entity id %s", hostNetworkQos.getId(), entity.getId())); } }
@Override public boolean isValid(NetworkAttachment value, ConstraintValidatorContext context) { boolean networkIdNotSet = value.getNetworkId() == null; boolean networkNameNotSet = value.getNetworkName() == null; return !(networkIdNotSet && networkNameNotSet); } }
public void addNetworkAttachmentToParameters(NetworkAttachment networkAttachment) { assert networkAttachment.getId() == null : "When adding attachment to parameters its id should be null"; //$NON-NLS-1$ Guid idOfAttachmentNetworkWasPreviouslyAttachedTo = networkIdToExistingAttachmentId.get(networkAttachment.getNetworkId()); networkAttachment.setId(idOfAttachmentNetworkWasPreviouslyAttachedTo); if (idOfAttachmentNetworkWasPreviouslyAttachedTo != null) { removedNetworkAttachments.remove(idOfAttachmentNetworkWasPreviouslyAttachedTo); } networkAttachments.add(networkAttachment); }
if (entity.getId() != null) { model.setId(entity.getId().toString()); if (entity.getNetworkId() != null) { getModelNetwork(model).setId(entity.getNetworkId().toString()); if (entity.getNicId() != null) { getModelHostNic(model).setId(entity.getNicId().toString()); if (entity.hasProperties()) { model.setProperties(CustomPropertiesParser.fromMap(entity.getProperties())); entity.getIpConfiguration(); if (entityIpConfiguration != null) { model.setIpAddressAssignments(new IpAddressAssignments()); if (entity.getDnsResolverConfiguration() != null) { model.setDnsResolverConfiguration( DnsResolverConfigurationMapper.map(entity.getDnsResolverConfiguration())); if (entity.getReportedConfigurations() != null) { model.setInSync(entity.getReportedConfigurations().isNetworkInSync()); model.setReportedConfigurations(ReportedConfigurationsMapper.map(entity.getReportedConfigurations(), null)); AnonymousHostNetworkQos hostNetworkQos = entity.getHostNetworkQos(); if (hostNetworkQos != null) { model.setQos(QosMapper.map(HostNetworkQos.fromAnonymousHostNetworkQos(hostNetworkQos), null));
private void assertNetworkAttachmentEquals(NetworkAttachment expected, NetworkAttachment actual) { assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getNetworkId(), actual.getNetworkId()); assertEquals(expected.getNicId(), actual.getNicId()); assertEquals(expected.getNicName(), actual.getNicName()); assertEquals(expected.getIpConfiguration(), actual.getIpConfiguration()); assertEquals(expected.getProperties().entrySet(), actual.getProperties().entrySet()); assertEquals(expected.getDnsResolverConfiguration(), actual.getDnsResolverConfiguration()); }
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; entity.setId(GuidUtils.asGuid(model.getId())); Network networkModel = model.getNetwork(); if (networkModel.isSetId()) { entity.setNetworkId(GuidUtils.asGuid(networkModel.getId())); entity.setNetworkName(networkModel.getName()); HostNic hostNic = model.getHostNic(); if (hostNic.isSetId()) { entity.setNicId(GuidUtils.asGuid(hostNic.getId())); } else { entity.setNicId(null); entity.setNicName(hostNic.getName()); } else { entity.setNicName(null); entity.setProperties(CustomPropertiesParser.toMap(model.getProperties())); 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<>());
@BeforeEach @Override public void setUp() throws Exception { super.setUp(); networkAttachment = new NetworkAttachment(); networkAttachment.setNicId(FixturesTool.VDS_NETWORK_INTERFACE); networkAttachment.setProperties(new HashMap<>()); networkAttachment.setId(Guid.newGuid()); networkAttachment.setNetworkId(FixturesTool.NETWORK_ENGINE); networkAttachment.setIpConfiguration(createIpConfiguration(Ipv4BootProtocol.DHCP, Ipv6BootProtocol.AUTOCONF)); networkAttachment.setDnsResolverConfiguration(new DnsResolverConfiguration()); networkAttachment.getDnsResolverConfiguration().setNameServers( new ArrayList<>(Arrays.asList(new NameServer("1.1.1.1")))); }
private void initNetworkIdToExistingAttachmentMap() { Map<Guid, Guid> networkIdToExistingAttachmentId = new HashMap<>(); for (NetworkAttachment attachment : hostSetupNetworksParametersData.getNetworkAttachments()) { networkIdToExistingAttachmentId.put(attachment.getNetworkId(), attachment.getId()); } hostSetupNetworksParametersData.setNetworkIdToExistingAttachmentId(networkIdToExistingAttachmentId); }
@Override protected MapSqlParameterSource createFullParametersMapper(NetworkAttachment networkAttachment) { MapSqlParameterSource mapper = createIdParameterMapper(networkAttachment.getId()) .addValue("network_id", networkAttachment.getNetworkId()) .addValue("nic_id", networkAttachment.getNicId()) .addValue("custom_properties", SerializationFactory.getSerializer().serialize(networkAttachment.getProperties())); mapIpConfiguration(networkAttachment, mapper); mapper.addValue("dns_resolver_configuration_id", getDnsResolverConfigurationId(networkAttachment)); return mapper; }
/** * Ensures that the update is working correctly */ @Test public void testUpdate() { networkAttachment.setNicId(FixturesTool.NETWORK_ATTACHMENT_NIC); dao.save(networkAttachment); IpConfiguration ipConfiguration = populateIpConfiguration(networkAttachment.getIpConfiguration(), Ipv4BootProtocol.STATIC_IP, Ipv6BootProtocol.NONE); networkAttachment.setIpConfiguration(ipConfiguration); Map<String, String> properties = new HashMap<>(); properties.put("key", "value"); networkAttachment.setProperties(properties); networkAttachment.setNicId(FixturesTool.NETWORK_ATTACHMENT_NIC2); networkAttachment.getDnsResolverConfiguration().getNameServers().add(new NameServer("2.2.2.2")); dao.update(networkAttachment); NetworkAttachment result = dao.get(networkAttachment.getId()); assertNotNull(result); assertNetworkAttachmentEquals(networkAttachment, result); }
private void verifyInput(Network network, VdsNetworkInterface nic, NetworkAttachment networkAttachment) { boolean unmanaged = networkAttachment == null && nic != null; boolean newAttachment = networkAttachment != null && networkAttachment.getId() == null && network != null; boolean existingAttachment = networkAttachment != null && networkAttachment.getId() != null && network != null && nic != null; assert unmanaged || newAttachment || existingAttachment : "the input of the ctor is wrong"; //$NON-NLS-1$ }
private void storeAttachmentParamsBeforeDetach() { NetworkAttachment networkAttachment = networkModel.getNetworkAttachment(); if (networkAttachment == null) { return; } NetworkParameters netParams = new NetworkParameters(); IPv4Address ipv4Address = networkAttachment.getIpConfiguration().getIpv4PrimaryAddress(); if (ipv4Address != null) { netParams.setIpv4BootProtocol(ipv4Address.getBootProtocol()); netParams.setIpv4Address(ipv4Address.getAddress()); netParams.setIpv4Netmask(ipv4Address.getNetmask()); netParams.setIpv4Gateway(ipv4Address.getGateway()); } IpV6Address ipv6Address = networkAttachment.getIpConfiguration().getIpv6PrimaryAddress(); if (ipv6Address != null) { netParams.setIpv6BootProtocol(ipv6Address.getBootProtocol()); netParams.setIpv6Address(ipv6Address.getAddress()); netParams.setIpv6Prefix(ipv6Address.getPrefix()); netParams.setIpv6Gateway(ipv6Address.getGateway()); } netParams.setHostNetworkQos(HostNetworkQos.fromAnonymousHostNetworkQos(networkAttachment.getHostNetworkQos())); netParams.setQosOverridden(networkAttachment.isQosOverridden()); netParams.setCustomProperties(networkAttachment.getProperties()); netParams.setDnsResolverConfiguration(networkAttachment.getDnsResolverConfiguration()); networkModel.getSetupModel().getNetworkToLastDetachParams().put(networkModel.getName(), netParams); }
@Override public void save(NetworkAttachment entity) { verifyRelationWithHostNetworkQos(entity); hostNetworkQosDao.persistQosChanges(entity.getId(), asHostNetworkQos(entity.getHostNetworkQos())); DnsResolverConfiguration dnsResolverConfiguration = entity.getDnsResolverConfiguration(); if (dnsResolverConfiguration != null) { Validate.isTrue(dnsResolverConfiguration.getId() == null); dnsResolverConfigurationDao.save(dnsResolverConfiguration); } super.save(entity); }
private void assertNetworkAttachment(NetworkAttachment networkAttachment, Guid attachmentId, Guid networkId, Guid nicId) { assertThat("id mismatch", networkAttachment.getId(), is(attachmentId)); //$NON-NLS-1$ assertThat("network id mismatch", networkAttachment.getNetworkId(), equalTo(networkId)); //$NON-NLS-1$ assertThat("nicId mismatch", networkAttachment.getNicId(), equalTo(nicId)); //$NON-NLS-1$ }
private IpConfiguration getIpConfigurationOfNetworkAttachment() { return networkAttachment == null ? null : networkAttachment.getIpConfiguration(); }
private void applyOnAttachmentParamsFrom(InterfacePropertiesAccessor interfacePropertiesAccessor, NetworkAttachment networkAttachment) { populateIpv4Details(interfacePropertiesAccessor, networkAttachment.getIpConfiguration().getIpv4PrimaryAddress()); populateIpv6Details(interfacePropertiesAccessor, networkAttachment.getIpConfiguration().getIpv6PrimaryAddress()); if (interfacePropertiesAccessor.isQosOverridden()) { AnonymousHostNetworkQos anonymousHostNetworkQos = AnonymousHostNetworkQos.fromHostNetworkQos(interfacePropertiesAccessor.getHostNetworkQos()); networkAttachment.setHostNetworkQos(anonymousHostNetworkQos); } networkAttachment.setProperties(interfacePropertiesAccessor.getCustomProperties()); networkAttachment.setDnsResolverConfiguration(interfacePropertiesAccessor.getDnsResolverConfiguration()); }
@Test public void testDnsResolverConfigurationInSyncWithHostWhenDhcpIsUsed() { iface.setIpv4DefaultRoute(false); network.setDnsResolverConfiguration(sampleDnsResolverConfiguration2); testedNetworkAttachment.setDnsResolverConfiguration(null); iface.setIpv4BootProtocol(Ipv4BootProtocol.DHCP); IPv4Address address = new IPv4Address(); address.setBootProtocol(Ipv4BootProtocol.DHCP); testedNetworkAttachment.getIpConfiguration().setIPv4Addresses(Collections.singletonList(address)); assertThat(createTestedInstance(true, sampleDnsResolverConfiguration).isNetworkInSync(), is(false)); }
/** * Ensures that the remove is working correctly */ @Test public void testRemove() { dao.save(networkAttachment); NetworkAttachment result = dao.get(networkAttachment.getId()); assertNotNull(result); dao.remove(networkAttachment.getId()); assertNull(dao.get(networkAttachment.getId())); assertNull(dnsResolverConfigurationDao.get(networkAttachment.getDnsResolverConfiguration().getId())); }