@Transactional(readOnly = true) private void checkIfVmAlreadyHasVipNetwork(String vmUuid, VipVO vip) { String sql = "select count(*) from VmNicVO nic, VmInstanceVO vm where nic.vmInstanceUuid = vm.uuid" + " and vm.uuid = :vmUuid and nic.l3NetworkUuid = :vipL3Uuid"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("vmUuid", vmUuid); q.setParameter("vipL3Uuid", vip.getL3NetworkUuid()); Long c = q.getSingleResult(); if (c > 0) { throw new ApiMessageInterceptionException(argerr("the vm[uuid:%s] that the EIP is about to attach is already on the public network[uuid:%s] from which" + " the vip[uuid:%s, name:%s, ip:%s] comes", vmUuid, vip.getL3NetworkUuid(), vip.getUuid(), vip.getName(), vip.getIp())); } }
protected void returnVip(Completion completion) { ReturnIpMsg msg = new ReturnIpMsg(); msg.setL3NetworkUuid(self.getL3NetworkUuid()); msg.setUsedIpUuid(self.getUsedIpUuid()); bus.makeTargetServiceIdByResourceUuid(msg, L3NetworkConstant.SERVICE_ID, self.getL3NetworkUuid()); bus.send(msg, new CloudBusCallBack(completion){ @Override public void run(MessageReply reply) { completion.success(); } }); }
to.setNetmask(vip.getNetmask()); to.setOwnerEthernetMac(vr.getVmNics().stream() .filter(n -> n.getL3NetworkUuid().equals(vip.getL3NetworkUuid())) .findFirst().get().getMac()); to.setVipUuid(vip.getUuid());
s.setProviderType(self.getServiceProvider()); s.setOfferingValidator(offering -> { if (!offering.getPublicNetworkUuid().equals(self.getL3NetworkUuid())) { throw new OperationFailureException(operr("found a virtual router offering[uuid:%s] for L3Network[uuid:%s] in zone[uuid:%s]; however, the network's public network[uuid:%s] is not the same to VIP[uuid:%s]'s; you may need to use system tag" + " guestL3Network::l3NetworkUuid to specify a particular virtual router offering for the L3Network", offering.getUuid(), s.getL3Network().getUuid(), s.getL3Network().getZoneUuid(), self.getL3NetworkUuid(), self.getUuid()));
VipVO vipvo = dbf.findByUuid(pfvo.getVipUuid(), VipVO.class); L3NetworkVO l3vo = dbf.findByUuid(vipvo.getL3NetworkUuid(), L3NetworkVO.class);
to.vipNetmask = vip.getNetmask(); to.vipUuid = vip.getUuid(); List<IpRangeVO> vipIprs = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, vip.getL3NetworkUuid()).list(); to.vipPrefixLen = vipIprs.get(0).getPrefixLen(); to.publicBridgeName = pubBridgeNames.get(eip.getVipUuid());
self.getUuid(), self.getIp(), self.getL3NetworkUuid()));
public static VipInventory valueOf(VipVO vo) { VipInventory inv = new VipInventory(); inv.setName(vo.getName()); inv.setDescription(vo.getDescription()); inv.setCreateDate(vo.getCreateDate()); inv.setGateway(vo.getGateway()); inv.setIp(vo.getIp()); inv.setIpRangeUuid(vo.getIpRangeUuid()); inv.setServiceProvider(vo.getServiceProvider()); inv.setL3NetworkUuid(vo.getL3NetworkUuid()); inv.setLastOpDate(vo.getLastOpDate()); inv.setNetmask(vo.getNetmask()); inv.setPrefixLen(vo.getPrefixLen()); inv.setUseFor(vo.getUseFor()); inv.setUuid(vo.getUuid()); inv.setState(vo.getState().toString()); inv.setUsedIpUuid(vo.getUsedIpUuid()); if (vo.getPeerL3NetworkRefs() != null && !vo.getPeerL3NetworkRefs().isEmpty()) { inv.setPeerL3NetworkUuids(vo.getPeerL3NetworkRefs().stream() .map(ref -> ref.getL3NetworkUuid()) .collect(Collectors.toList())); } return inv; }
private PortForwardingStruct makePortForwardingStruct(PortForwardingRuleInventory rule) { VipVO vipvo = dbf.findByUuid(rule.getVipUuid(), VipVO.class); L3NetworkVO vipL3vo = dbf.findByUuid(vipvo.getL3NetworkUuid(), L3NetworkVO.class); VmNicVO nic = dbf.findByUuid(rule.getVmNicUuid(), VmNicVO.class); L3NetworkVO guestL3vo = dbf.findByUuid(nic.getL3NetworkUuid(), L3NetworkVO.class); PortForwardingStruct struct = new PortForwardingStruct(); struct.setRule(rule); struct.setVip(VipInventory.valueOf(vipvo)); struct.setGuestIp(nic.getIp()); struct.setGuestMac(nic.getMac()); struct.setGuestL3Network(L3NetworkInventory.valueOf(guestL3vo)); struct.setSnatInboundTraffic(PortForwardingGlobalConfig.SNAT_INBOUND_TRAFFIC.value(Boolean.class)); struct.setVipL3Network(L3NetworkInventory.valueOf(vipL3vo)); return struct; }
vq.add(VmNicVO_.uuid, Op.EQ, msg.getVmNicUuid()); String guestL3Uuid = vq.findValue(); if (guestL3Uuid.equals(vip.getL3NetworkUuid())) { throw new ApiMessageInterceptionException(argerr("guest l3Network of vm nic[uuid:%s] and vip l3Network of port forwarding rule[uuid:%s] are the same network", msg.getVmNicUuid(), msg.getRuleUuid()));
String vipL3Uuid = vipVO.getL3NetworkUuid();
private void validate(APICreateEipMsg msg) { VipVO vip = dbf.findByUuid(msg.getVipUuid(), VipVO.class); if (vip.getUseFor() != null) { VipUseForList useForList = new VipUseForList(vip.getUseFor()); if(!useForList.validateNewAdded(EipConstant.EIP_NETWORK_SERVICE_TYPE)) { throw new ApiMessageInterceptionException(operr("vip[uuid:%s] has been occupied other network service entity[%s]", msg.getVipUuid(), vip.getUseFor())); } } if (vip.getState() != VipState.Enabled) { throw new ApiMessageInterceptionException(operr("vip[uuid:%s] is not in state[%s], current state is %s", msg.getVipUuid(), VipState.Enabled, vip.getState())); } if (msg.getVmNicUuid() != null) { SimpleQuery<VmNicVO> nicq = dbf.createQuery(VmNicVO.class); nicq.add(VmNicVO_.uuid, Op.EQ, msg.getVmNicUuid()); VmNicVO nic = nicq.find(); if (VmNicHelper.getL3Uuids(nic).contains(vip.getL3NetworkUuid())) { throw new ApiMessageInterceptionException(argerr("guest l3Network of vm nic[uuid:%s] and vip l3Network of vip[uuid: %s] are the same network", msg.getVmNicUuid(), msg.getVipUuid())); } if (msg.getUsedIpUuid() == null) { msg.setUsedIpUuid(nic.getUsedIpUuid()); } else { validateEipGuestIpUuid(msg.getVmNicUuid(), msg.getUsedIpUuid()); } // check if the vm already has a network where the vip comes checkIfVmAlreadyHasVipNetwork(nic.getVmInstanceUuid(), vip); } if (msg.getUsedIpUuid() != null) { isVipInVmNicSubnet(msg.getVipUuid(), msg.getUsedIpUuid()); } }
if (VmNicHelper.getL3Uuids(nic).contains(vip.getL3NetworkUuid())){ throw new ApiMessageInterceptionException(argerr("guest l3Network of vm nic[uuid:%s] and vip l3Network of EIP[uuid:%s] are the same network", msg.getVmNicUuid(), msg.getEipUuid()));