@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); } }
private void addStatistics(HostNic model, VdsNetworkInterface entity) { model.setStatistics(new Statistics()); HostNicStatisticalQuery query = new HostNicStatisticalQuery(newModel(model.getId())); List<Statistic> statistics = query.getStatistics(entity); for (Statistic statistic : statistics) { LinkHelper.addLinks(statistic, query.getParentType()); } model.getStatistics().getStatistics().addAll(statistics); }
@Override protected void verifyModel(org.ovirt.engine.api.model.NetworkAttachment model) { assertEquals(HOST_NIC_ID.toString(), model.getHostNic().getId()); }
@Override protected void verifyModel(org.ovirt.engine.api.model.NetworkAttachment model) { assertEquals(HOST_NIC_ID.toString(), model.getHostNic().getId()); }
private HostNic clone(HostNic parent) { HostNic nic = new HostNic(); nic.setId(parent.getId()); nic.setHost(new Host()); nic.getHost().setId(parent.getHost().getId()); return nic; } };
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); }
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()); }
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); } } } }
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()); }
@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; }
nicLabel.setLabel(label.getId()); if (label.isSetHostNic()) { nicLabel.setNicId(label.getHostNic().isSetId() ? asGuid(label.getHostNic().getId()) : null); nicLabel.setNicName(label.getHostNic().getName());
entity.setId(GuidUtils.asGuid(model.getId()));
@Mapping(from = UnmanagedNetwork.class, to = org.ovirt.engine.core.common.businessentities.UnmanagedNetwork.class) public static org.ovirt.engine.core.common.businessentities.UnmanagedNetwork map(UnmanagedNetwork model, org.ovirt.engine.core.common.businessentities.UnmanagedNetwork template) { if (model == null) { return template; } org.ovirt.engine.core.common.businessentities.UnmanagedNetwork entity = template == null ? new org.ovirt.engine.core.common.businessentities.UnmanagedNetwork() : template; if (model.isSetId()) { entity.setId(HexUtils.hex2string(model.getId())); } if (model.isSetName()) { entity.setNetworkName(model.getName()); } if (model.isSetHostNic()) { HostNic hostNic = model.getHostNic(); if (hostNic.isSetId()) { entity.setNicId(GuidUtils.asGuid(hostNic.getId())); } if (hostNic.isSetName()) { entity.setNicName(hostNic.getName()); } } return entity; }
@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()); } }
HostNic hostNic = model.getHostNic(); if (hostNic.isSetId()) { entity.setNicId(GuidUtils.asGuid(hostNic.getId())); } else { entity.setNicId(null);
@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())); } }
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()); }
to.setId(from.getId());
protected void verifyQuery(AbstractStatisticalQuery<HostNic, VdsNetworkInterface> query, VdsNetworkInterface entity) throws Exception { assertEquals(HostNic.class, query.getParentType()); assertSame(entity, query.resolve(NIC_ID)); List<Statistic> statistics = query.getStatistics(entity); verifyStatistics(statistics, new String[] { "data.current.rx", "data.current.tx", "data.current.rx.bps", "data.current.tx.bps", "errors.total.rx", "errors.total.tx", "data.total.rx", "data.total.tx" }, new BigDecimal[] { asDec(RxTxCalculator.percent2bytes(SPEED, RECEIVE_RATE)), asDec(RxTxCalculator.percent2bytes(SPEED, TRANSMIT_RATE)), asDec(RxTxCalculator.percent2bits(SPEED, RECEIVE_RATE)), asDec(RxTxCalculator.percent2bits(SPEED, TRANSMIT_RATE)), asDec(RECEIVE_DROP_RATE), asDec(TRANSMIT_DROP_RATE), asDec(RECEIVED_BYTES), asDec(TRANSMITTED_BYTES) }); Statistic adopted = query.adopt(new Statistic()); assertTrue(adopted.isSetHostNic()); assertEquals(NIC_ID.toString(), adopted.getHostNic().getId()); assertTrue(adopted.getHostNic().isSetHost()); assertEquals(GUIDS[0].toString(), adopted.getHostNic().getHost().getId()); }