@Mapping(from = HostNic.class, to = Bond.class) public static Bond map(HostNic model, Bond template) { Bond entity = template == null ? new Bond() : template; if (model.isSetId()) { entity.setId(GuidUtils.asGuid(model.getId())); } if (model.isSetName()) { entity.setName(model.getName()); } if (model.isSetBonding()) { entity.setBonded(true); if (model.getBonding().isSetSlaves()) { entity.getSlaves().clear(); for (HostNic slave : model.getBonding().getSlaves().getHostNics()) { if (slave.isSetName()) { entity.getSlaves().add(slave.getName()); } } } if (model.getBonding().isSetOptions()) { entity.setBondOptions(calculateBondingOptionsString(model)); } } if (model.isSetQos()) { entity.setQos((HostNetworkQos) QosMapper.map(model.getQos(), null)); } return entity; }
private org.ovirt.engine.core.common.businessentities.network.Network getNewNetwork(HostNic nic) { org.ovirt.engine.core.common.businessentities.network.Network newNetwork = null; if(nic.isSetNetwork()){ newNetwork = map(nic.getNetwork(), parent.lookupClusterNetwork(nic.getNetwork())); } return newNetwork; }
private void completeSlaveNames(BusinessEntityMap<VdsNetworkInterface> nicsFromBackend, HostNic bond) { if (bond.isSetBonding() && bond.getBonding().isSetSlaves()) { for (HostNic slave : bond.getBonding().getSlaves().getHostNics()) { if (!slave.isSetName() && slave.isSetId()){ Guid slaveId = new Guid(slave.getId()); String slaveNameFromBackend = nicsFromBackend.get(slaveId).getName(); slave.setName(slaveNameFromBackend); } } } }
@Override public V3HostNIC adapt(HostNic from) { V3HostNIC to = new V3HostNIC(); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); if (from.isSetBaseInterface()) { to.setBaseInterface(from.getBaseInterface()); if (from.isSetBonding()) { to.setBonding(adaptOut(from.getBonding())); if (from.isSetBootProtocol()) { to.setBootProtocol(from.getBootProtocol().value()); if (from.isSetBridged()) { to.setBridged(from.isBridged()); if (from.isSetCheckConnectivity()) { to.setCheckConnectivity(from.isCheckConnectivity()); if (from.isSetComment()) { to.setComment(from.getComment()); if (from.isSetCustomConfiguration()) { to.setCustomConfiguration(from.isCustomConfiguration());
@Override public HostNic adapt(V3HostNIC from) { HostNic to = new HostNic(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setBaseInterface(from.getBaseInterface()); to.setBonding(adaptIn(from.getBonding())); to.setBootProtocol(BootProtocol.fromValue(from.getBootProtocol())); to.setBridged(from.isBridged()); to.setCheckConnectivity(from.isCheckConnectivity()); to.setComment(from.getComment()); to.setCustomConfiguration(from.isCustomConfiguration()); to.setDescription(from.getDescription()); to.setHost(adaptIn(from.getHost())); to.setId(from.getId()); to.setHref(from.getHref());
@Mapping(from = VdsNetworkInterface.class, to = HostNic.class) public static HostNic map(VdsNetworkInterface entity, HostNic template) { HostNic model = template != null ? template : new HostNic(); if (entity.getId() != null) { model.setId(entity.getId().toString()); model.setNetwork(new Network()); model.getNetwork().setName(entity.getNetworkName()); model.setName(entity.getName()); model.setBaseInterface(entity.getBaseInterface()); model.setVlan(new org.ovirt.engine.api.model.Vlan()); model.getVlan().setId(entity.getVlanId()); model.setMac(new Mac()); model.getMac().setAddress(entity.getMacAddress()); model.setStatus(nicStatus); model.setSpeed(entity.getSpeed() * 1000L * 1000); if(model.getBonding() == null) { model.setBonding(new Bonding()); model.getBonding().setOptions(new Options()); for(String opt : entity.getBondOptions().split(OPTIONS_DELIMITER)){ String[] option_pair = opt.split(OPTIONS_EQ);
if (template != null) { entity = template; } else if (model.isSetBonding()) { entity = new Bond(); } else if (model.isSetVlan()) { entity = new Vlan(); } else { if (model.isSetId()) { entity.setId(GuidUtils.asGuid(model.getId())); if (model.isSetNetwork() && model.getNetwork().isSetName()) { entity.setNetworkName(model.getNetwork().getName()); if (model.isSetName()) { entity.setName(model.getName()); if (model.isSetBaseInterface()) { entity.setBaseInterface(model.getBaseInterface()); if (model.isSetMac() && model.getMac().isSetAddress()) { entity.setMacAddress(model.getMac().getAddress()); if (model.isSetBonding()) { entity.setBonded(true); if (model.getBonding().isSetOptions()) { List<Option> bondingOptions = model.getBonding().getOptions().getOptions(); String optionsString = bondingOptions.stream()
@Test public void testCompleteListSubFields() { HostNic bond = new HostNic(); bond.setName("joe"); bond.setNetwork(new Network()); bond.getNetwork().setId("0"); bond.setBonding(new Bonding()); bond.getBonding().setSlaves(new HostNics()); HostNic slave = new HostNic(); slave.setId("0"); bond.getBonding().getSlaves().getHostNics().add(slave); slave = new HostNic(); slave.setId("0"); bond.getBonding().getSlaves().getHostNics().add(slave); CompletenessAssertor.validateParameters(bond, "name", "network.id|name", "bonding.slaves.id|name"); }
@Test public void testBondMapping() { HostNic model = new HostNic(); model.setId(Guid.newGuid().toString()); model.setName(RandomUtils.instance().nextString(10)); model.setBonding(new Bonding()); model.getBonding().setSlaves(new HostNics()); HostNic slaveA = new HostNic(); slaveA.setName(RandomUtils.instance().nextString(10)); model.getBonding().getSlaves().getHostNics().add(slaveA); Bond entity = HostNicMapper.map(model, null); assertNotNull(entity); assertEquals(model.getId(), entity.getId().toString()); assertEquals(model.getName(), entity.getName()); assertEquals(model.getBonding().getSlaves().getHostNics().size(), entity.getSlaves().size()); for (HostNic slave : model.getBonding().getSlaves().getHostNics()) { assertTrue(entity.getSlaves().contains(slave.getName())); } }
@Override protected void verify(HostNic model, HostNic transform) { assertNotNull(transform); assertEquals(model.getName(), transform.getName()); assertEquals(model.getId(), transform.getId()); assertNotNull(transform.getNetwork()); assertEquals(model.getNetwork().getName(), transform.getNetwork().getName()); assertNotNull(transform.getIp()); assertEquals(model.getIp().getAddress(), transform.getIp().getAddress()); assertEquals(model.getIp().getNetmask(), transform.getIp().getNetmask()); assertEquals(model.getIp().getGateway(), transform.getIp().getGateway()); assertNotNull(transform.getMac()); assertThat(model.getMac().getAddress(), IsEqualIgnoringCase.equalToIgnoringCase(transform.getMac().getAddress())); assertNotNull(model.getBonding()); assertEquals(model.getBonding().getOptions().getOptions().size(), transform.getBonding() .getOptions() .getOptions() .size()); for (int i = 0; i < model.getBonding().getOptions().getOptions().size(); i++) { assertEquals(model.getBonding().getOptions().getOptions().get(i).getName(), transform.getBonding() .getOptions() .getOptions() .get(i) .getName()); assertEquals(model.getBonding().getOptions().getOptions().get(i).getValue(), transform.getBonding() .getOptions() .getOptions() assertNotNull(model.getProperties());
public void verifyModelSpecific(HostNic model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(NAMES[index], model.getName()); assertNotNull(model.getNetwork()); assertEquals(NETWORK_NAME, model.getNetwork().getName()); assertEquals(calcSpeed(NIC_SPEED), model.getSpeed()); assertNotNull(model.getStatus()); assertEquals(HostNicMapper.mapNicStatus(NIC_STATUS), model.getStatus()); assertEquals(Ipv4BootProtocolMapper.map(IPV4_BOOT_PROTOCOL), model.getBootProtocol()); assertEquals(Ipv6BootProtocolMapper.map(IPV6_BOOT_PROTOCOL), model.getIpv6BootProtocol()); }
protected void verifyMaster(HostNic model) { assertEquals(MASTER_GUID.toString(), model.getId()); assertEquals(MASTER_NAME, model.getName()); assertNotNull(model.getNetwork()); assertEquals(NETWORK_NAME, model.getNetwork().getName()); assertNotNull(model.getBonding()); assertNotNull(model.getBonding().getSlaves()); assertEquals(1, model.getBonding().getSlaves().getHostNics().size()); assertEquals(SLAVE_GUID.toString(), model.getBonding().getSlaves().getHostNics().get(0).getId()); assertNotNull(model.getBonding().getSlaves().getHostNics().get(0).getHref()); }
public CreateOrUpdateBond mapBonds(BusinessEntityMap<Bond> bonds, HostNic model) { Mapper<HostNic, Bond> hostNicMapper = getMapper(HostNic.class, Bond.class); Bond bond; if (model.isSetId()) { Guid nicId = asGuid(model.getId()); bond = hostNicMapper.map(model, bonds.get(nicId)); } else { Bond template = model.isSetName() ? bonds.get(model.getName()) : null; bond = hostNicMapper.map(model, template); } return CreateOrUpdateBond.fromBond(bond); }
@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); } }
protected void verifySlave(HostNic model) { assertEquals(SLAVE_GUID.toString(), model.getId()); assertEquals(SLAVE_NAME, model.getName()); assertNotNull(model.getNetwork()); assertEquals(NETWORK_NAME, model.getNetwork().getName()); assertEquals(5, model.getLinks().size()); assertTrue("master".equals(model.getLinks().get(0).getRel()) || "master".equals(model.getLinks().get(1).getRel())); assertNotNull(model.getLinks().get(0).getHref()); }
protected HostNic addSlaveLinks(HostNic nic, List<VdsNetworkInterface> ifaces) { if(nic.getBonding() == null) { nic.setBonding(new Bonding()); } nic.getBonding().setSlaves(new HostNics()); for (VdsNetworkInterface i : ifaces) { if (i.isPartOfBond(nic.getName())) { nic.getBonding().getSlaves().getHostNics().add(slave(i.getId().toString())); } } return nic; }
@Override protected HostNic doPopulate(HostNic model, VdsNetworkInterface entity) { final HostNic hostNic = super.doPopulate(model, entity); final Guid nicId = entity.getId(); final HostNicVfsConfig hostNicVfsConfig = findVfsConfig(nicId); if (hostNicVfsConfig == null) { final Map<Guid, Guid> vfMap = retriveVfMap(); final Guid physicalFunctionNicId = vfMap.get(nicId); if (physicalFunctionNicId != null) { final HostNic physicalFunction = new HostNic(); physicalFunction.setId(physicalFunctionNicId.toString()); hostNic.setPhysicalFunction(physicalFunction); } } else { final Mapper<HostNicVfsConfig, HostNicVirtualFunctionsConfiguration> mapper = getMapper(HostNicVfsConfig.class, HostNicVirtualFunctionsConfiguration.class); final HostNicVirtualFunctionsConfiguration vfsConfigModel = mapper.map(hostNicVfsConfig, new HostNicVirtualFunctionsConfiguration()); hostNic.setVirtualFunctionsConfiguration(vfsConfigModel); } return hostNic; }
private static void mapIpv4FromModel(HostNic model, VdsNetworkInterface entity) { if (model.isSetIp()) { if (model.getIp().isSetAddress()) { entity.setIpv4Address(model.getIp().getAddress()); } if (model.getIp().isSetGateway()) { entity.setIpv4Gateway(model.getIp().getGateway()); } if (model.getIp().isSetNetmask()) { entity.setIpv4Subnet(model.getIp().getNetmask()); } } if (model.isSetBootProtocol()) { Ipv4BootProtocol ipv4BootProtocol = Ipv4BootProtocolMapper.map(model.getBootProtocol()); if (ipv4BootProtocol != null) { entity.setIpv4BootProtocol(ipv4BootProtocol); } } }