@Override public void applyNetworkService(VmInstanceSpec spec, Map<String, Object> data, Completion completion) { // For new created vm, there is no eip if (spec.getCurrentVmOperation() == VmInstanceConstant.VmOperation.NewCreate) { completion.success(); return; } Map<String, List<EipStruct>> map = workOutEipStruct(spec); Map<String, List<EipStruct>> applieds = new HashMap<String, List<EipStruct>>(); data.put(SUCCESS, applieds); applyNetworkService(map.entrySet().iterator(), applieds, completion); }
@Override public void applyNetworkService(VmInstanceSpec spec, Map<String, Object> data, Completion completion) { // For new created vm, there is no port forwarding rule if (spec.getCurrentVmOperation() == VmInstanceConstant.VmOperation.NewCreate) { completion.success(); return; } Map<String, List<PortForwardingStruct>> structs = workoutPortForwarding(spec); Map<String, List<PortForwardingStruct>> applieds = new HashMap<String, List<PortForwardingStruct>>(); data.put(SUCCESS, applieds); applyNetworkService(structs.entrySet().iterator(), applieds, completion); }
@Override public void releaseNetworkService(VmInstanceSpec spec, Map<String, Object> data, NoErrorCompletion completion) { // For new created vm, there is no eip if (spec.getCurrentVmOperation() == VmInstanceConstant.VmOperation.NewCreate) { completion.done(); return; } Map<String, List<EipStruct>> map; if (data.containsKey(SUCCESS)) { map = (Map<String, List<EipStruct>>) data.get(SUCCESS); } else { map = workOutEipStruct(spec); } if (map.isEmpty()) { completion.done(); return; } boolean updateDb = spec.getCurrentVmOperation() == VmOperation.Destroy || spec.getCurrentVmOperation() == VmOperation.DetachNic; releaseNetworkService(map.entrySet().iterator(), updateDb, completion); } }
private Map<String, List<PortForwardingStruct>> workoutPortForwarding(VmInstanceSpec spec) { Map<String, List<PortForwardingStruct>> map = new HashMap<String, List<PortForwardingStruct>>(); Map<NetworkServiceProviderType, List<L3NetworkInventory>> providerMap = getNetworkServiceProviderMap(NetworkServiceType.PortForwarding, VmNicSpec.getL3NetworkInventoryOfSpec(spec.getL3Networks())); for (Map.Entry<NetworkServiceProviderType, List<L3NetworkInventory>> e : providerMap.entrySet()) { NetworkServiceProviderType ptype = e.getKey(); List<PortForwardingStruct> lst = new ArrayList<PortForwardingStruct>(); for (L3NetworkInventory l3 : e.getValue()) { lst.addAll(makePortForwardingStruct(spec.getDestNics(), spec.getCurrentVmOperation() == VmOperation.Destroy || spec.getCurrentVmOperation() == VmOperation.DetachNic, l3)); } map.put(ptype.toString(), lst); } return map; } }
@Override public Flow marshalTheNextFlow(String previousFlowClassName, String nextFlowClassName, FlowChain chain, Map data) { Flow nflow = null; for (MarshalVmOperationFlowExtensionPoint mext : pluginRgty.getExtensionList(MarshalVmOperationFlowExtensionPoint.class)) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); nflow = mext.marshalVmOperationFlow(previousFlowClassName, nextFlowClassName, chain, spec); if (nflow != null) { logger.debug(String.format("a VM[uuid: %s, operation: %s] operation flow[%s] is changed to the flow[%s] by %s", self.getUuid(), spec.getCurrentVmOperation(), nextFlowClassName, nflow.getClass(), mext.getClass())); break; } } return nflow; } });
@Override public void releaseVmResource(VmInstanceSpec spec, Completion completion) { VmInstanceInventory inv = spec.getVmInventory(); if (spec.getCurrentVmOperation() != VmOperation.Destroy) { completion.success(); return; } // only has root volume if (inv.getAllVolumes().size() == 1) { completion.success(); return; } detachDataVolume(inv); completion.success(); } }
@Override public void run(MessageReply reply) { if (!reply.isSuccess()) { logger.debug(String.format("failed to remove security group rules for vm[uuid:%s], %s", servedVm.getVmInventory().getUuid(), reply.getError())); } if (servedVm.getCurrentVmOperation() == VmInstanceConstant.VmOperation.DetachNic) { for (VmNicInventory nic: servedVm.getDestNics()) { deleteVmNicSecurityGroupRef(nic.getUuid()); } } completion.done(); } });
@Override public Flow marshalVmOperationFlow(String previousFlowName, String nextFlowName, FlowChain chain, VmInstanceSpec spec) { if (VmAllocatePrimaryStorageFlow.class.getName().equals(nextFlowName)) { if (spec.getCurrentVmOperation() == VmOperation.NewCreate) { List<String> localStorageUuids = getLocalStorageInCluster(spec.getDestHost().getClusterUuid()); if (localStorageUuids != null && !localStorageUuids.isEmpty()) { } else if (spec.getCurrentVmOperation() == VmOperation.AttachVolume) { VolumeInventory volume = spec.getDestDataVolumes().get(0); if (VolumeStatus.NotInstantiated.toString().equals(volume.getStatus()) } else if (spec.getCurrentVmOperation() == VmOperation.Migrate && isRootVolumeOnLocalStorage(spec.getVmInventory().getRootVolumeUuid()) && VmMigrateOnHypervisorFlow.class.getName().equals(nextFlowName)) { if (KVMConstant.KVM_HYPERVISOR_TYPE.equals(spec.getVmInventory().getHypervisorType())) {
if (spec.getCurrentVmOperation() == VmOperation.NewCreate) { final ApplianceVmSpec aspec = spec.getExtensionData(ApplianceVmConstant.Params.applianceVmSpec.toString(), ApplianceVmSpec.class); if (spec.getCurrentVmOperation() == VmOperation.Destroy) {
@Override public void run(List<MessageReply> replies) { // if ChangeImage, resume rootVolumeUuid if (spec.getCurrentVmOperation() == VmInstanceConstant.VmOperation.ChangeImage) { VmInstanceVO vm = dbf.findByUuid(spec.getVmInventory().getUuid(), VmInstanceVO.class); vm.setRootVolumeUuid(spec.getVmInventory().getRootVolumeUuid()); dbf.update(vm); } chain.rollback(); } });
protected void selectBootOrder(VmInstanceSpec spec) { if (spec.getCurrentVmOperation() == null) { throw new CloudRuntimeException("selectBootOrder must be called after VmOperation is set"); } List<CdRomSpec> cdRomSpecs = spec.getCdRomSpecs().stream() .filter(cdRom -> cdRom.getImageUuid() != null) .collect(Collectors.toList()); if (spec.getCurrentVmOperation() == VmOperation.NewCreate && !cdRomSpecs.isEmpty()) { ImageVO imageVO = dbf.findByUuid(spec.getVmInventory().getImageUuid(), ImageVO.class); assert imageVO != null; if(imageVO.getMediaType() == ImageMediaType.ISO) { spec.setBootOrders(list(VmBootDevice.CdRom.toString())); } else { spec.setBootOrders(list(VmBootDevice.HardDisk.toString())); } } else { String order = VmSystemTags.BOOT_ORDER.getTokenByResourceUuid(self.getUuid(), VmSystemTags.BOOT_ORDER_TOKEN); if (order == null) { spec.setBootOrders(list(VmBootDevice.HardDisk.toString())); } else { spec.setBootOrders(list(order.split(","))); // set vm to boot from cdrom once only if (VmSystemTags.CDROM_BOOT_ONCE.hasTag(self.getUuid(), VmInstanceVO.class)) { VmSystemTags.BOOT_ORDER.deleteInherentTag(self.getUuid()); VmSystemTags.CDROM_BOOT_ONCE.deleteInherentTag(self.getUuid()); } } } }
VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); if (VmOperation.NewCreate == spec.getCurrentVmOperation() || VmOperation.ChangeImage == spec.getCurrentVmOperation()) { final String bsUuid = findBackupStorage(spec, spec.getImageSpec().getInventory().getUuid()); spec.getImageSpec().setSelectedBackupStorage(CollectionUtils.find( ); }); } else if ((VmOperation.Start == spec.getCurrentVmOperation() || VmOperation.Reboot == spec.getCurrentVmOperation()) && !spec.getCdRomSpecs().isEmpty()) { spec.getCdRomSpecs().forEach(cdRomSpec -> {
@Override public void preInstantiateVmResource(VmInstanceSpec spec, Completion completion) { if (!(VmInstanceConstant.VmOperation.NewCreate == spec.getCurrentVmOperation()) && VmInstanceConstant.VmOperation.ChangeImage != spec.getCurrentVmOperation()) { completion.success(); return;
@Override public void preBeforeInstantiateVmResource(VmInstanceSpec spec) throws VmInstantiateResourceException { if (spec.getCurrentVmOperation() != VmInstanceConstant.VmOperation.ChangeImage || !spec.getVolumeSpecs().get(0).getPrimaryStorageInventory().getType().equals(CephConstants.CEPH_PRIMARY_STORAGE_TYPE)) { return; } //get old ready root volume VolumeVO oldRootVolume = Q.New(VolumeVO.class).eq(VolumeVO_.vmInstanceUuid, spec.getVmInventory().getUuid()) .eq(VolumeVO_.type, VolumeType.Root) .eq(VolumeVO_.status, VolumeStatus.Ready) .find(); //sync root pool tag if exist if (oldRootVolume != null && CephSystemTags.USE_CEPH_ROOT_POOL.hasTag(oldRootVolume.getUuid())) { String token = CephSystemTags.USE_CEPH_ROOT_POOL.getTokenByResourceUuid(oldRootVolume.getUuid(), CephSystemTags.USE_CEPH_ROOT_POOL_TOKEN); SystemTagCreator creator = CephSystemTags.USE_CEPH_ROOT_POOL.newSystemTagCreator(spec.getDestRootVolume().getUuid()); creator.setTagByTokens(map(e(CephSystemTags.USE_CEPH_ROOT_POOL_TOKEN, token))); creator.inherent = false; creator.ignoreIfExisting = true; creator.create(); } }
if (spec.getCurrentVmOperation() == VmOperation.NewCreate) { rmsg.setPurpose(PrimaryStorageAllocationPurpose.CreateNewVm.toString()); } else if (spec.getCurrentVmOperation() == VmOperation.AttachVolume) { rmsg.setPurpose(PrimaryStorageAllocationPurpose.CreateVolume.toString());
@Override public void rollback(FlowRollback chain, Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); HostInventory host = spec.getDestHost(); // if ChangeImage, then no need to ReturnHostCapacity, and resume vm info if (spec.getCurrentVmOperation() == VmOperation.ChangeImage) { VmInstanceVO vmvo = dbf.findByUuid(spec.getVmInventory().getUuid(), VmInstanceVO.class); vmvo.setClusterUuid(spec.getVmInventory().getClusterUuid()); vmvo.setLastHostUuid(spec.getVmInventory().getLastHostUuid()); vmvo.setHypervisorType(spec.getVmInventory().getHypervisorType()); dbf.update(vmvo); } else if (host != null) { ReturnHostCapacityMsg msg = new ReturnHostCapacityMsg(); msg.setCpuCapacity(spec.getVmInventory().getCpuNum()); msg.setMemoryCapacity(spec.getVmInventory().getMemorySize()); msg.setHostUuid(host.getUuid()); msg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); bus.send(msg); } chain.rollback(); } }
if (VmOperation.NewCreate == spec.getCurrentVmOperation()) { VolumeSpec vspec = spec.getVolumeSpecs().get(0); PrimaryStorageInventory pinv = vspec.getPrimaryStorageInventory();
if (VmOperation.NewCreate == spec.getCurrentVmOperation()) { VolumeSpec rootVolumeSpec = spec.getVolumeSpecs().get(0); psUuid = rootVolumeSpec.getPrimaryStorageInventory().getUuid();
msg.setVmOperation(spec.getCurrentVmOperation().toString()); msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE); msg.setL3NetworkUuids(CollectionUtils.transformToList(VmNicSpec.getL3NetworkInventoryOfSpec(spec.getL3Networks()), new Function<String, L3NetworkInventory>() {
if (spec.getCurrentVmOperation() == VmOperation.ChangeImage) { ReturnHostCapacityMsg msg = new ReturnHostCapacityMsg(); msg.setCpuCapacity(spec.getVmInventory().getCpuNum());