@Override public AllocateIpMsg call(VmNicInventory arg) { AllocateIpMsg msg = new AllocateIpMsg(); msg.setL3NetworkUuid(arg.getL3NetworkUuid()); msg.setAllocateStrategy(spec.getIpAllocatorStrategy()); String staticIp = vmStaticIps.get(arg.getL3NetworkUuid()); if (staticIp != null) { msg.setRequiredIp(staticIp); } else { l3nm.updateIpAllocationMsg(msg, arg.getMac()); } bus.makeTargetServiceIdByResourceUuid(msg, L3NetworkConstant.SERVICE_ID, arg.getL3NetworkUuid()); return msg; } });
private IpAllocatorType getIpAllocatorType(AllocateIpMsg msg) { if (msg.getAllocatorStrategy() != null) { return IpAllocatorType.valueOf(msg.getAllocatorStrategy()); } L3NetworkVO l3Vo = Q.New(L3NetworkVO.class).eq(L3NetworkVO_.uuid, msg.getL3NetworkUuid()).find(); if (l3Vo.getIpVersion() == IPv6Constants.IPv4) { return RandomIpAllocatorStrategy.type; } return RandomIpv6AllocatorStrategy.type; }
@Override public void updateIpAllocationMsg(AllocateIpMsg msg, String mac) { if (msg.getRequiredIp() != null) { return; } List<IpRangeVO> iprs = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, msg.getL3NetworkUuid()).list(); if (iprs.get(0).getIpVersion() == IPv6Constants.IPv4) { return; } if (!iprs.get(0).getAddressMode().equals(IPv6Constants.Stateful_DHCP)) { msg.setRequiredIp(IPv6NetworkUtils.getIPv6AddresFromMac(iprs.get(0).getNetworkCidr(), mac)); } }
AllocateIpMsg msg = new AllocateIpMsg(); msg.setL3NetworkUuid(l3.getUuid()); String staticIp = vmStaticIps.get(l3.getUuid()); if (staticIp != null) { msg.setRequiredIp(staticIp); } else if (l3.getIpVersion() == IPv6Constants.IPv6){ l3nm.updateIpAllocationMsg(msg, nic.getMac());
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(); }
vo.setUuid(nic.getUuid()); vo.setIp(nic.getIp()); vo.setL3NetworkUuid(nic.getL3NetworkUuid()); vo.setUsedIpUuid(nic.getUsedIpUuid()); vo.setVmInstanceUuid(nic.getVmInstanceUuid());
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); }
AllocateIpMsg amsg = new AllocateIpMsg(); amsg.setL3NetworkUuid(l3Uuid); if (requiredIp != null) { amsg.setRequiredIp(requiredIp);
public void rollback(FlowRollback trigger, Map data) { ReturnIpMsg msg = new ReturnIpMsg(); msg.setL3NetworkUuid(nic.getL3NetworkUuid()); msg.setUsedIpUuid(nic.getUsedIpUuid()); bus.makeTargetServiceIdByResourceUuid(msg, L3NetworkConstant.SERVICE_ID, nic.getL3NetworkUuid());
AllocateIpMsg msg = new AllocateIpMsg(); msg.setL3NetworkUuid(nw.getUuid()); msg.setAllocateStrategy(spec.getIpAllocatorStrategy()); String staticIp = vmStaticIps.get(nw.getUuid()); if (staticIp != null) { msg.setRequiredIp(staticIp); } else { l3nm.updateIpAllocationMsg(msg, customMac);