public static List<String> getL3Uuids(List<VmNicInventory> nics) { List<String> ret = new ArrayList<>(); for (VmNicInventory nic : nics) { ret.addAll(getL3Uuids(nic)); } return ret; }
private List<String> getCleanTrafficIp(VmNicInventory nic) { boolean isUserVm = Q.New(VmInstanceVO.class) .eq(VmInstanceVO_.uuid, nic.getVmInstanceUuid()).select(VmInstanceVO_.type) .findValue().equals(VmInstanceConstant.USER_VM_TYPE); if (!isUserVm) { return null; } String tagValue = VmSystemTags.CLEAN_TRAFFIC.getTokenByResourceUuid(nic.getVmInstanceUuid(), VmSystemTags.CLEAN_TRAFFIC_TOKEN); if (Boolean.valueOf(tagValue) || (tagValue == null && VmGlobalConfig.VM_CLEAN_TRAFFIC.value(Boolean.class))) { return VmNicHelper.getIpAddresses(nic); } return null; }
protected void selectDefaultL3(VmNicInventory nic) { if (self.getDefaultL3NetworkUuid() != null && !VmNicHelper.isDefaultNic(nic, VmInstanceInventory.valueOf(self))) { return; String newDefaultL3 = VmNicHelper.getPrimaryL3Uuid(VmNicInventory.valueOf(candidate)); CollectionUtils.safeForEach( pluginRgty.getExtensionList(VmDefaultL3NetworkChangedExtensionPoint.class), logger.debug(String.format( "after detaching the nic[uuid:%s, L3 uuid:%s], change the default L3 of the VM[uuid:%s]" + " to the L3 network[uuid: %s]", nic.getUuid(), VmNicHelper.getL3Uuids(nic), self.getUuid(), newDefaultL3)); } else { logger.debug(String.format( "after detaching the nic[uuid:%s, L3 uuid:%s], change the default L3 of the VM[uuid:%s]" + " to null, as the VM has no other nics", nic.getUuid(), VmNicHelper.getL3Uuids(nic), self.getUuid()));
@Override public void run(final FlowTrigger trigger, final Map data) { final VmNicInventory nic = (VmNicInventory) data.get(VmInstanceConstant.Params.VmNicInventory.toString()); if (nic.getVmInstanceUuid() == null) { trigger.next(); return; } VmInstanceVO vmVo = dbf.findByUuid(nic.getVmInstanceUuid(), VmInstanceVO.class); VmNicInventory vmNic = VmNicInventory.valueOf(dbf.findByUuid(nic.getUuid(), VmNicVO.class)); /* if this is default nic and vm default l3 is different from nic l3 */ if (vmVo.getDefaultL3NetworkUuid() == null || VmNicHelper.isDefaultNic(nic, VmInstanceInventory.valueOf(vmVo))) { String primaryL3 = VmNicHelper.getPrimaryL3Uuid(vmNic); if (vmVo.getDefaultL3NetworkUuid() == null || !vmVo.getDefaultL3NetworkUuid().equals(primaryL3)) { vmVo.setDefaultL3NetworkUuid(primaryL3); dbf.updateAndRefresh(vmVo); } } trigger.next(); } }
@Override public void rollback(final FlowRollback chain, Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); List<DetachIpAddressFromVmNicMsg> msgs = new ArrayList<>(); /* reload vmnic */ List<VmNicVO> vmNicVOS = Q.New(VmNicVO.class).eq(VmNicVO_.vmInstanceUuid, spec.getVmInventory().getUuid()).list(); for (VmNicVO nic : vmNicVOS) { List<String> ipUuids = VmNicHelper.getCanDetachL3List(VmNicInventory.valueOf(nic), spec.getL3Networks()); for (String uuid : ipUuids) { DetachIpAddressFromVmNicMsg msg = new DetachIpAddressFromVmNicMsg(); msg.setVmNicUuid(nic.getUuid()); msg.setUsedIpUuid(uuid); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, nic.getUuid()); msgs.add(msg); } } new While<>(msgs).each((msg, comp) -> bus.send(msg, new CloudBusCallBack(comp) { @Override public void run(MessageReply reply) { comp.done(); } })).run(new NoErrorCompletion(chain) { @Override public void done() { chain.rollback(); } }); } }
if (VmNicHelper.includeAllNicL3s(nic, l3Uuids)) { DetachNicFromVmMsg msg = new DetachNicFromVmMsg(); msg.setVmInstanceUuid(vm.getInventory().getUuid());
List<String> l3Uuids = VmNicHelper.getCanAttachL3List(VmNicInventory.valueOf(nic), spec.getL3Networks()); for (String uuid : l3Uuids) { AttachL3NetworkToVmNicMsg msg = new AttachL3NetworkToVmNicMsg();
String l3Uuid = VmNicHelper.getPrimaryL3Uuid(VmNicInventory.valueOf(vmNicVO));
for (String l3uuid: self.getVmNics().stream().flatMap(nic -> VmNicHelper.getL3Uuids(VmNicInventory.valueOf(nic)).stream()) .distinct().collect(Collectors.toList())){ clusterUuids = getCandidateClusterUuidsFromAttachedL3(l3uuid, clusterUuids); List<String> vmL3Uuids = self.getVmNics().stream().flatMap(nic -> VmNicHelper.getL3Uuids(VmNicInventory.valueOf(nic)).stream()) .distinct().collect(Collectors.toList()); l3s = l3s.stream().filter(l3 -> !vmL3Uuids.contains(l3.getUuid())).collect(Collectors.toList());
private ForwardDnsStruct makeForwardDnsStruct(VmInstanceSpec spec, final L3NetworkInventory l3) { VmNicInventory nic = null; for (VmNicInventory inv : spec.getDestNics()) { if (VmNicHelper.getL3Uuids(inv).contains(l3.getUuid())) { nic = inv; break; } } ForwardDnsStruct struct = new ForwardDnsStruct(); struct.setL3Network(l3); struct.setMac(nic.getMac()); return struct; }
private SnatStruct makeSnatStruct(VmInstanceSpec spec, L3NetworkInventory l3) { VmNicInventory nic = null; for (VmNicInventory inv : spec.getDestNics()) { if (VmNicHelper.getL3Uuids(inv).contains(l3.getUuid())){ nic = inv; break; } } SnatStruct struct = new SnatStruct(); struct.setL3Network(l3); struct.setGuestGateway(nic.getGateway()); struct.setGuestIp(nic.getIp()); struct.setGuestMac(nic.getMac()); struct.setGuestNetmask(nic.getNetmask()); return struct; }
if (VmNicHelper.getL3Uuids(nic).contains(previousL3)) { pnic = nic; } else if (VmNicHelper.getL3Uuids(nic).contains(nowL3)) { nnic = nic;
protected List<PortForwardingStruct> makePortForwardingStruct(List<VmNicInventory> nics, boolean releaseVmNicInfo,L3NetworkInventory l3) { VmNicInventory nic = null; for (VmNicInventory inv : nics) { if (VmNicHelper.getL3Uuids(inv).contains(l3.getUuid())) { nic = inv; break;
amsg.setAllocatorStrategy(HostAllocatorConstant.MIGRATE_VM_ALLOCATOR_TYPE); amsg.setVmOperation(VmOperation.Migrate.toString()); amsg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); amsg.setDryRun(true); amsg.setAllowNoL3Networks(true);
String defaultL3Uuid = dbf.findByUuid(spec.getVmInventory().getUuid(), VmInstanceVO.class).getDefaultL3NetworkUuid(); if (defaultL3Uuid != null && VmNicHelper.getL3Uuids(nic).contains(defaultL3Uuid)) {
@Override public void run(FlowTrigger chain, Map data) { DesignatedAllocateHostMsg msg = new DesignatedAllocateHostMsg(); msg.setCpuCapacity(cpuNum - oldCpuNum); msg.setMemoryCapacity(struct.alignedMemory - oldMemorySize); msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE); msg.setVmInstance(VmInstanceInventory.valueOf(self)); if (self.getImageUuid() != null && dbf.findByUuid(self.getImageUuid(), ImageVO.class) != null) { msg.setImage(ImageInventory.valueOf(dbf.findByUuid(self.getImageUuid(), ImageVO.class))); } msg.setHostUuid(self.getHostUuid()); msg.setFullAllocate(false); msg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); msg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); bus.send(msg, new CloudBusCallBack(chain) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { ErrorCode err = operr("host[uuid:%s] capacity is not enough to offer cpu[%s], memory[%s bytes]", self.getHostUuid(), cpuNum - oldCpuNum, struct.alignedMemory - oldMemorySize); err.setCause(reply.getError()); chain.fail(err); } else { result = true; logger.debug(String.format("reserve memory %s bytes and cpu %s on host[uuid:%s]", memorySize - self.getMemorySize(), cpuNum - self.getCpuNum(), self.getHostUuid())); chain.next(); } } }); }
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()); } }
private void getStartingCandidateHosts(final NeedReplyMessage msg, final ReturnValueCompletion completion) { refreshVO(); ErrorCode err = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR); if (err != null) { throw new OperationFailureException(err); } final DesignatedAllocateHostMsg amsg = new DesignatedAllocateHostMsg(); amsg.setCpuCapacity(self.getCpuNum()); amsg.setMemoryCapacity(self.getMemorySize()); amsg.setVmInstance(VmInstanceInventory.valueOf(self)); amsg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); amsg.setAllocatorStrategy(self.getAllocatorStrategy()); amsg.setVmOperation(VmOperation.Start.toString()); if (self.getImageUuid() != null && dbf.findByUuid(self.getImageUuid(), ImageVO.class) != null) { amsg.setImage(ImageInventory.valueOf(dbf.findByUuid(self.getImageUuid(), ImageVO.class))); } amsg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); amsg.setDryRun(true); amsg.setListAllHosts(true); bus.send(amsg, new CloudBusCallBack(completion) { @Override public void run(MessageReply re) { if (!re.isSuccess()) { completion.fail(re.getError()); } else { completion.success(re); } } }); }
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()));