private void handle(AllocateIpMsg msg) { IpAllocatorType strategyType = getIpAllocatorType(msg); IpAllocatorStrategy ias = l3NwMgr.getIpAllocatorStrategy(strategyType); AllocateIpReply reply = new AllocateIpReply(); UsedIpInventory ip = ias.allocateIp(msg); if (ip == null) { String reason = msg.getRequiredIp() == null ? String.format("no ip is available in this l3Network[name:%s, uuid:%s]", self.getName(), self.getUuid()) : String.format("IP[%s] is not available", msg.getRequiredIp()); reply.setError(err(L3Errors.ALLOCATE_IP_ERROR, "IP allocator strategy[%s] failed, because %s", strategyType, reason)); } else { logger.debug(String.format("Ip allocator strategy[%s] successfully allocates an ip[%s]", strategyType, printer.print(ip))); reply.setIpInventory(ip); } bus.reply(msg, reply); }
private UsedIpInventory acquireIp(String l3NetworkUuid, String mac, String stratgey) { AllocateIpMsg msg = new AllocateIpMsg(); msg.setL3NetworkUuid(l3NetworkUuid); l3nm.updateIpAllocationMsg(msg, mac); bus.makeTargetServiceIdByResourceUuid(msg, L3NetworkConstant.SERVICE_ID, l3NetworkUuid); msg.setAllocateStrategy(stratgey); MessageReply reply = bus.call(msg); if (!reply.isSuccess()) { throw new FlowException(reply.getError()); } AllocateIpReply areply = (AllocateIpReply) reply; return areply.getIpInventory(); }
@Override public void run(MessageReply reply) { if (reply.isSuccess()) { AllocateIpReply areply = reply.castReply(); UsedIpInventory ipInventory = areply.getIpInventory(); for (VmNicExtensionPoint ext : pluginRgty.getExtensionList(VmNicExtensionPoint.class)) { ext.afterAddIpAddress(vmNicVO.getUuid(), ipInventory.getUuid()); } data.put(VmInstanceConstant.Params.UsedIPInventory.toString(), ipInventory); VmNicInventory nicInv = VmNicInventory.valueOf(dbf.findByUuid(nic.getUuid(), VmNicVO.class)); new DualStackNicSecondaryNetworksOperator().createSecondaryNetworksByVmNic(nicInv, l3.getUuid()); trigger.next(); } else { trigger.fail(reply.getError()); } } });
@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(); } });
UsedIpInventory ip = r.getIpInventory(); dhcpServerIp = ip.getIp(); dhcpServerIpUuid = ip.getUuid();