public static List<UsedIpInventory> valueOf(Collection<UsedIpVO> vos) { List<UsedIpInventory> invs = new ArrayList<UsedIpInventory>(vos.size()); for (UsedIpVO vo : vos) { invs.add(UsedIpInventory.valueOf(vo)); } return invs; }
public UsedIpInventory getEipGuestIp(String eipUuid) { EipVO eip = dbf.findByUuid(eipUuid, EipVO.class); if (eip.getVmNicUuid() == null || eip.getGuestIp() == null) { return null; } VmNicVO nic = dbf.findByUuid(eip.getVmNicUuid(), VmNicVO.class); for (UsedIpVO ip : nic.getUsedIps()) { if (ip.getIp().equals(eip.getGuestIp())) { return UsedIpInventory.valueOf(ip); } } return null; }
private UsedIpInventory reserveIpv4(IpRangeInventory ipRange, String ip) { try { UsedIpVO vo = new UsedIpVO(ipRange.getUuid(), ip); vo.setIpInLong(NetworkUtils.ipv4StringToLong(ip)); String uuid = ipRange.getUuid() + ip; uuid = UUID.nameUUIDFromBytes(uuid.getBytes()).toString().replaceAll("-", ""); vo.setUuid(uuid); vo.setL3NetworkUuid(ipRange.getL3NetworkUuid()); vo.setNetmask(ipRange.getNetmask()); vo.setGateway(ipRange.getGateway()); vo.setIpVersion(IPv6Constants.IPv4); vo = dbf.persistAndRefresh(vo); return UsedIpInventory.valueOf(vo); } catch (JpaSystemException e) { if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { logger.debug(String.format("Concurrent ip allocation. " + "Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " + "The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " + "we will try finding another ip", ip, ipRange.getUuid())); logger.trace("", e); } else { throw e; } return null; } }
private UsedIpInventory reserveIpv6(IpRangeInventory ipRange, String ip) { try { UsedIpVO vo = new UsedIpVO(); //vo.setIpInLong(NetworkUtils.ipv4StringToLong(ip)); String uuid = ipRange.getUuid() + ip; uuid = UUID.nameUUIDFromBytes(uuid.getBytes()).toString().replaceAll("-", ""); vo.setUuid(uuid); vo.setIpRangeUuid(ipRange.getUuid()); vo.setIp(IPv6NetworkUtils.getIpv6AddressCanonicalString(ip)); vo.setL3NetworkUuid(ipRange.getL3NetworkUuid()); vo.setNetmask(ipRange.getNetmask()); vo.setGateway(ipRange.getGateway()); vo.setIpVersion(IPv6Constants.IPv6); vo = dbf.persistAndRefresh(vo); return UsedIpInventory.valueOf(vo); } catch (JpaSystemException e) { if (e.getRootCause() instanceof MySQLIntegrityConstraintViolationException) { logger.debug(String.format("Concurrent ip allocation. " + "Ip[%s] in ip range[uuid:%s] has been allocated, try allocating another one. " + "The error[Duplicate entry] printed by jdbc.spi.SqlExceptionHelper is no harm, " + "we will try finding another ip", ip, ipRange.getUuid())); logger.trace("", e); } else { throw e; } return null; } }
@Override public void run(List<MessageReply> replies) { for (MessageReply reply : replies) { if (!reply.isSuccess()) { trigger.fail(reply.getError()); return; } final AllocateIpReply ar = reply.castReply(); final UsedIpInventory ip = ar.getIpInventory(); String nicUuid = CollectionUtils.find(nicsNeedNewIp, new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { return arg.getL3NetworkUuid().equals(ip.getL3NetworkUuid()) ? arg.getUuid() : null; } }); for (VmNicExtensionPoint ext : pluginRgty.getExtensionList(VmNicExtensionPoint.class)) { ext.afterAddIpAddress(nicUuid, ip.getUuid()); } allocatedIPs.add(UsedIpInventory.valueOf(dbf.findByUuid(ip.getUuid(), UsedIpVO.class))); } VmInstanceVO vmvo = dbf.findByUuid(vm.getUuid(), VmInstanceVO.class); spec.setVmInventory(VmInstanceInventory.valueOf(vmvo)); spec.setDestNics(spec.getVmInventory().getVmNics()); trigger.next(); } });
NetworkServiceProviderType providerType = nwServiceMgr.getTypeOfNetworkServiceProviderForService( l3NetworkUuid, EipConstant.EIP_TYPE); EipStruct struct = generateEipStruct(nicInventory, vipInventory, eip, UsedIpInventory.valueOf(guestIp)); struct.setSnatInboundTraffic(EipGlobalConfig.SNAT_INBOUND_TRAFFIC.value(Boolean.class)); attachEip(struct, providerType.toString(), new Completion(msg) {
public static VmNicInventory valueOf(VmNicVO vo) { VmNicInventory inv = new VmNicInventory(); inv.setUuid(vo.getUuid()); inv.setVmInstanceUuid(vo.getVmInstanceUuid()); inv.setUsedIpUuid(vo.getUsedIpUuid()); inv.setL3NetworkUuid(vo.getL3NetworkUuid()); inv.setInternalName(vo.getInternalName()); inv.setIp(vo.getIp()); inv.setMac(vo.getMac()); inv.setHypervisorType(vo.getHypervisorType()); inv.setDeviceId(vo.getDeviceId()); inv.setCreateDate(vo.getCreateDate()); inv.setLastOpDate(vo.getLastOpDate()); inv.setMetaData(vo.getMetaData()); inv.setNetmask(vo.getNetmask()); inv.setGateway(vo.getGateway()); inv.setIpVersion(vo.getIpVersion()); inv.setUsedIps(UsedIpInventory.valueOf(vo.getUsedIps())); return inv; }