public void setParametersFromVmInventory(VmInstanceInventory inv) { vmUuid = inv.getUuid(); vmNics = inv.getVmNics(); hostUuid = inv.getHostUuid(); }
@Override public void vmPreAttachL3Network(final VmInstanceInventory vm, final L3NetworkInventory l3) { final List<String> nicUuids = CollectionUtils.transformToList(vm.getVmNics(), VmNicInventory::getUuid); if (nicUuids.isEmpty()) { return; } new Runnable() { @Override @Transactional(readOnly = true) public void run() { String sql = "select count(*)" + " from EipVO eip, VipVO vip" + " where eip.vipUuid = vip.uuid" + " and vip.l3NetworkUuid = :l3Uuid" + " and eip.vmNicUuid in (:nicUuids)"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("l3Uuid", l3.getUuid()); q.setParameter("nicUuids", nicUuids); Long count = q.getSingleResult(); if (count > 0) { throw new OperationFailureException(operr("unable to attach the L3 network[uuid:%s, name:%s] to the vm[uuid:%s, name:%s]," + " because the L3 network is providing EIP to one of the vm's nic", l3.getUuid(), l3.getName(), vm.getUuid(), vm.getName())); } } }.run(); }
private List<VmNicSecurityGroupRefInventory> refFromAction(CascadeAction action) { List<VmDeletionStruct> vms = action.getParentIssuerContext(); List<String> nicUuids = new ArrayList<String>(); for (VmDeletionStruct vm : vms) { nicUuids.addAll(CollectionUtils.transformToList(vm.getInventory().getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { return arg.getUuid(); } })); } if (nicUuids.isEmpty()) { return new ArrayList<VmNicSecurityGroupRefInventory>(); } SimpleQuery<VmNicSecurityGroupRefVO> q = dbf.createQuery(VmNicSecurityGroupRefVO.class); q.add(VmNicSecurityGroupRefVO_.vmNicUuid, SimpleQuery.Op.IN, nicUuids); List<VmNicSecurityGroupRefVO> vos = q.list(); return VmNicSecurityGroupRefInventory.valueOf(vos); }
@Override public void failedToMigrateVm(final VmInstanceInventory inv, final String destHostUuid, ErrorCode reason) { RuleCalculator cal = new RuleCalculator(); cal.vmNicUuids = CollectionUtils.transformToList(inv.getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { return arg.getUuid(); } }); cal.vmStates = asList(VmInstanceState.Unknown); List<HostRuleTO> htos = cal.calculate(); logger.debug(String.format("vm[uuid:%s, name:%s] failed to migrate to host[uuid:%s], recover its rules on previous host[uuid:%s]", inv.getUuid(), inv.getName(), destHostUuid, inv.getHostUuid())); applyRules(htos); }
@Override public void run(FlowTrigger chain, Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); if (spec.getVmInventory().getVmNics().isEmpty()) { chain.next(); return; List<ReturnIpMsg> msgs = new ArrayList<ReturnIpMsg>(spec.getVmInventory().getVmNics().size()); for (VmNicInventory nic : spec.getVmInventory().getVmNics()) { for (UsedIpInventory ip : nic.getUsedIps()) { ReturnIpMsg msg = new ReturnIpMsg();
@Override public void afterMigrateVm(final VmInstanceInventory inv, final String srcHostUuid) { RuleCalculator cal = new RuleCalculator(); cal.vmNicUuids = CollectionUtils.transformToList(inv.getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) {
@Override public void preMigrateVm(VmInstanceInventory inv, String destHostUuid) { List<VmNicInventory> nics = inv.getVmNics(); List<L3NetworkVO> l3vos = new ArrayList<>();
List<String> iprUuids = iprs.stream().map(ipr -> ipr.getUuid()).collect(Collectors.toList()); for (VmDeletionStruct vm : vminvs) { for (VmNicInventory nic : vm.getInventory().getVmNics()) { List<String> rangeUuids = nic.getUsedIps().stream().map(n -> n.getIpRangeUuid()).collect(Collectors.toList()); rangeUuids.removeAll(iprUuids);
for (VmNicInventory nic : spec.getVmInventory().getVmNics()) { deviceIdBitmap.set(nic.getDeviceId());
List<String> nicUuidToDel = CollectionUtils.transformToList(inv.getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { spec.setDestNics(inv.getVmNics()); List<VmNicSpec> nicSpecs = new ArrayList<>(); for (VmNicInventory nic : inv.getVmNics()) { List<L3NetworkInventory> l3Invs = new ArrayList<>();
VmNicInventory nnic = null; for (VmNicInventory nic : vm.getVmNics()) { if (VmNicHelper.getL3Uuids(nic).contains(previousL3)) { pnic = nic;
@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(); } });
String l3Uuid = CollectionUtils.find(spec.getVmInventory().getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) {
public VmInstanceInventory(VmInstanceInventory origin) { VmInstanceInventory inv; try { inv = (VmInstanceInventory) origin.clone(); } catch (CloneNotSupportedException e) { throw new CloudRuntimeException(e); } this.setClusterUuid(inv.getClusterUuid()); this.setCreateDate(inv.getCreateDate()); this.setDescription(inv.getDescription()); this.setHostUuid(inv.getHostUuid()); this.setHypervisorType(inv.getHypervisorType()); this.setImageUuid(inv.getImageUuid()); this.setInstanceOfferingUuid(inv.getInstanceOfferingUuid()); this.setLastHostUuid(inv.getLastHostUuid()); this.setLastOpDate(inv.getLastOpDate()); this.setName(inv.getName()); this.setRootVolumeUuid(inv.getRootVolumeUuid()); this.setState(inv.getState()); this.setType(inv.getType()); this.setUuid(inv.getUuid()); this.setZoneUuid(inv.getZoneUuid()); this.setAllVolumes(inv.getAllVolumes()); this.setVmNics(inv.getVmNics()); this.setInternalId(inv.getInternalId()); this.setCpuNum(inv.getCpuNum()); this.setCpuSpeed(inv.getCpuSpeed()); this.setMemorySize(inv.getMemorySize()); this.setAllocatorStrategy(inv.getAllocatorStrategy()); }