public void checkHostsDedication(VMInstanceVO vm, long srcHostId, long destHostId) { HostVO srcHost = _hostDao.findById(srcHostId); HostVO destHost = _hostDao.findById(destHostId); boolean srcExplDedicated = checkIfHostIsDedicated(srcHost); boolean destExplDedicated = checkIfHostIsDedicated(destHost); if (!((accountOfDedicatedHost(srcHost) == null) || (accountOfDedicatedHost(srcHost).equals(accountOfDedicatedHost(destHost))))) { String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(srcHost) + " to host " + destHost.getName() + " explicitly dedicated to account " + accountOfDedicatedHost(destHost); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); s_logger.warn(msg); if (!((domainOfDedicatedHost(srcHost) == null) || (domainOfDedicatedHost(srcHost).equals(domainOfDedicatedHost(destHost))))) { String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly dedicated to domain " + domainOfDedicatedHost(srcHost) + " to host " + destHost.getName() + " explicitly dedicated to domain " + domainOfDedicatedHost(destHost); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); s_logger.warn(msg); List<VMInstanceVO> vmsOnDest = getVmsOnHost(destHostId); if (vmsOnDest == null || vmsOnDest.isEmpty()) { emptyDestination = true; if (!isServiceOfferingUsingPlannerInPreferredMode(vm.getServiceOfferingId())) { if (!checkIfAllVmsCreatedInStrictMode(accountOfVm, vmsOnDest)) { msg = "VM of account " + accountOfVm + " with strict implicit deployment planner being migrated to host " + destHost.getName() + " not having all vms strict implicitly dedicated to account " + accountOfVm;
@Override @ActionEvent(eventType = EventTypes.EVENT_VM_UPDATE, eventDescription = "updating Vm") public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException { validateInputsAndPermissionForUpdateVirtualMachineCommand(cmd); String hostName = cmd.getHostName(); Map<String,String> details = cmd.getDetails(); List<Long> securityGroupIdList = getSecurityGroupIdList(cmd); boolean cleanupDetails = cmd.isCleanupDetails(); String extraConfig = cmd.getExtraConfig(); updateDisplayVmFlag(isDisplayVm, id, vmInstance); addExtraConfig(vmInstance, account, extraConfig); return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName, cmd.getInstanceName(), securityGroupIdList, cmd.getDhcpOptionsMap());
private boolean updateUserDataInternal(UserVm vm) throws ResourceUnavailableException, InsufficientCapacityException { VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId()); List<? extends Nic> nics = _nicDao.listByVmId(vm.getId()); if (nics == null || nics.isEmpty()) { s_logger.error("unable to find any nics for vm " + vm.getUuid()); return false; } boolean userDataApplied = false; for (Nic nic : nics) { userDataApplied |= applyUserData(template.getHypervisorType(), vm, nic); } return userDataApplied; }
if (checkStatusOfVolumeSnapshots(vmId, Volume.Type.ROOT)) { throw new CloudRuntimeException("There is/are unbacked up snapshot(s) on ROOT volume, vm destroy is not permitted, please try again later."); List<VolumeVO> volumes = getVolumesFromIds(cmd); checkForUnattachedVolumes(vmId, volumes); validateVolumes(volumes); stopVirtualMachine(vmId, VmDestroyForcestop.value()); detachVolumesFromVm(volumes); UserVm destroyedVm = destroyVm(vmId, expunge); if (expunge) { if (!expunge(vm, ctx.getCallingUserId(), ctx.getCallingAccount())) { throw new CloudRuntimeException("Failed to expunge vm " + destroyedVm); deleteVolumesFromVm(volumes);
if (offering.isDynamic()) { offering.setDynamicFlag(true); validateCustomParameters(offering, customParameters); offering = _offeringDao.getcomputeOffering(offering, customParameters); resourceLimitCheck(owner, isDisplayVm, new Long(offering.getCpu()), new Long(offering.getRamSize())); userData = validateUserData(userData, httpmethod); checkNameForRFCCompliance(hostName); hostName = displayName; } else { hostName = generateHostName(uuidName); hostName = generateHostName(uuidName); checkNameForRFCCompliance(hostName); checkIfHostNameUniqueInNtwkDomain(hostName, networkList); UserVmVO vm = commitUserVm(zone, template, hostName, displayName, owner, diskOfferingId, diskSize, userData, caller, isDisplayVm, keyboard, accountId, userId, offering, isIso, sshPublicKey, networkNicMap, id, instanceName, uuidName, hypervisorType, customParameters, dhcpOptionMap, datadiskTemplateToDiskOfferringMap); boolean addToGroup = addInstanceToGroup(Long.valueOf(id), group); if (!addToGroup) { throw new CloudRuntimeException("Unable to assign Vm to the group " + group);
checkIfHostOfVMIsInPrepareForMaintenanceState(vm.getHostId(), vmId, "Migrate"); if (!isOnSupportedHypevisorForMigration(vm)) { if (s_logger.isDebugEnabled()) { s_logger.debug(vm + " is not XenServer/VMware/KVM/Ovm/Hyperv, cannot migrate this VM form hypervisor type " + vm.getHypervisorType()); if (isVMUsingLocalStorage(vm)) { if (s_logger.isDebugEnabled()) { s_logger.debug(vm + " is using Local Storage, cannot migrate this VM."); checkHostsDedication(vm, srcHostId, destinationHost.getId()); if (checkStatusOfVolumeSnapshots(vmId, null)) { throw new CloudRuntimeException("There is/are unbacked up snapshot(s) on volume(s) attached to this VM, VM Migration is not permitted, please try again later."); collectVmDiskStatistics(uservm); collectVmNetworkStatistics(uservm);
userData = validateUserData(userData, httpMethod); addInstanceToGroup(id, group); if (hostName != null) { checkNameForRFCCompliance(hostName); vmNtwks.add(_networkDao.findById(nic.getNetworkId())); checkIfHostNameUniqueInNtwkDomain(hostName, vmNtwks); .collect(Collectors.toList()); verifyExtraDhcpOptionsNetwork(extraDhcpOptionsMap, networks); for (Nic nic : nics) { _networkMgr.saveExtraDhcpOptions(networks.stream() boolean result = updateUserDataInternal(_vmDao.findById(id)); if (result) { s_logger.debug("User data successfully updated for vm id=" + id);
verifyDetails(cmd.getDetails()); throw new InvalidParameterValueException("Can't specify network Ids in Basic zone"); } else { vm = createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size , group , cmd.getHypervisor(), cmd.getHttpMethod(), userData , sshKeyPairName , cmd.getIpToNetworkMap(), addrs, displayVm , keyboard , cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap); vm = createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, cmd.getNetworkIds(), getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap); throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone"); vm = createAdvancedVirtualMachine(zone, serviceOffering, template, cmd.getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId(), cmd.getDhcpOptionsMap(), dataDiskTemplateToDiskOfferingMap); String extraConfig = cmd.getExtraConfig(); if (StringUtils.isNotBlank(extraConfig) && EnableAdditionalVmConfig.valueIn(callerId) ) { addExtraConfig(vm, caller, extraConfig);
if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) { if (volumeToPool.isEmpty()) { checkHostsDedication(vm, srcHostId, destinationHost.getId());
checkDestinationHypervisorType(destPool, vm);