private UserVm rebootVirtualMachine(long userId, long vmId) throws InsufficientCapacityException, ResourceUnavailableException { UserVmVO vm = _vmDao.findById(vmId); if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging || vm.getRemoved() != null) { s_logger.warn("Vm id=" + vmId + " doesn't exist"); return null; if (vm.getState() == State.Running && vm.getHostId() != null) { collectVmDiskStatistics(vm); collectVmNetworkStatistics(vm); DataCenterVO dc = _dcDao.findById(vm.getDataCenterId()); try { if (dc.getNetworkType() == DataCenter.NetworkType.Advanced) { s_logger.warn("Trying to start router " + routerToStart.getInstanceName() + " as part of vm: " + vm.getInstanceName() + " reboot"); _virtualNetAppliance.startRouter(routerToStart.getId(),true); throw new CloudRuntimeException("Router start failed due to" + ex); }finally { s_logger.info("Rebooting vm " + vm.getInstanceName()); _itMgr.reboot(vm.getUuid(), null);
@Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { UserVmVO vm = _vmDao.findById(profile.getId()); Map<String, String> details = userVmDetailsDao.listDetailsKeyPairs(vm.getId()); vm.setDetails(details); // add userdata info into vm profile Nic defaultNic = _networkModel.getDefaultNic(vm.getId()); if(defaultNic != null) { Network network = _networkModel.getNetwork(defaultNic.getNetworkId()); if (_networkModel.isSharedNetworkWithoutServices(network.getId())) { final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows"); List<String[]> vmData = _networkModel.generateVmData(vm.getUserData(), serviceOffering, vm.getDataCenterId(), vm.getInstanceName(), vm.getHostName(), vm.getId(), vm.getUuid(), defaultNic.getIPv4Address(), vm.getDetail("SSH.PublicKey"), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows); String vmName = vm.getInstanceName(); String configDriveIsoRootFolder = "/tmp"; String isoFile = configDriveIsoRootFolder + "/" + vmName + "/configDrive/" + vmName + ".iso"; profile.setVmData(vmData); profile.setConfigDriveLabel(VirtualMachineManager.VmConfigDriveLabel.value()); profile.setConfigDriveIsoRootFolder(configDriveIsoRootFolder); profile.setConfigDriveIsoFile(isoFile); } } _templateMgr.prepareIsoForVmProfile(profile, dest); return true; }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm()); resourceCountDecrement(oldAccount.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); vm.setAccountId(newAccount.getAccountId()); vm.setDomainId(cmd.getDomainId()); _vmDao.persist(vm); resourceCountIncrement(newAccount.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString(), VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplayVm());
@Override public void loadDetails(UserVmVO vm) { Map<String, String> details = _detailsDao.listDetailsKeyPairs(vm.getId()); vm.setDetails(details); }
@Override public void saveDetails(UserVmVO vm) { Map<String, String> detailsStr = vm.getDetails(); if (detailsStr == null) { return; } final Map<String, Boolean> visibilityMap = _detailsDao.listDetailsVisibility(vm.getId()); List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>(); for (Map.Entry<String, String> entry : detailsStr.entrySet()) { boolean display = visibilityMap.getOrDefault(entry.getKey(), true); details.add(new UserVmDetailVO(vm.getId(), entry.getKey(), entry.getValue(), display)); } _detailsDao.saveDetails(details); }
/** * Create, persist and return vm snapshot for userVmVo with given parameters. * Persistence and support for custom service offerings are done on the same transaction * @param userVmVo user vm * @param vmId vm id * @param vsDescription vm description * @param vmSnapshotName vm snapshot name * @param vsDisplayName vm snapshot display name * @param vmSnapshotType vm snapshot type * @return vm snapshot * @throws CloudRuntimeException if vm snapshot couldn't be persisted */ protected VMSnapshot createAndPersistVMSnapshot(UserVmVO userVmVo, String vsDescription, String vmSnapshotName, String vsDisplayName, VMSnapshot.Type vmSnapshotType) { final Long vmId = userVmVo.getId(); final Long serviceOfferingId = userVmVo.getServiceOfferingId(); final VMSnapshotVO vmSnapshotVo = new VMSnapshotVO(userVmVo.getAccountId(), userVmVo.getDomainId(), vmId, vsDescription, vmSnapshotName, vsDisplayName, serviceOfferingId, vmSnapshotType, null); return Transaction.execute(new TransactionCallbackWithException<VMSnapshot, CloudRuntimeException>() { @Override public VMSnapshot doInTransaction(TransactionStatus status) { VMSnapshot vmSnapshot = _vmSnapshotDao.persist(vmSnapshotVo); if (vmSnapshot == null) { throw new CloudRuntimeException("Failed to create snapshot for vm: " + vmId); } addSupportForCustomServiceOffering(vmId, serviceOfferingId, vmSnapshot.getId()); return vmSnapshot; } }); }
@PostConstruct void init() { AccountSearch = createSearchBuilder(); AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountSearch.done(); HostSearch.and("host", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostSearch.done(); LastHostSearch.and("lastHost", LastHostSearch.entity().getLastHostId(), SearchCriteria.Op.EQ); LastHostSearch.and("state", LastHostSearch.entity().getState(), SearchCriteria.Op.EQ); LastHostSearch.done(); HostUpSearch.and("host", HostUpSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostUpSearch.and("states", HostUpSearch.entity().getState(), SearchCriteria.Op.NIN); HostUpSearch.done(); HostRunningSearch.and("host", HostRunningSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostRunningSearch.and("state", HostRunningSearch.entity().getState(), SearchCriteria.Op.EQ); HostRunningSearch.done(); AccountPodSearch.and("account", AccountPodSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountPodSearch.and("pod", AccountPodSearch.entity().getPodIdToDeployIn(), SearchCriteria.Op.EQ); AccountPodSearch.done(); AccountDataCenterSearch.and("account", AccountDataCenterSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountDataCenterSearch.and("dc", AccountDataCenterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AccountDataCenterSearch.done(); StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ);
private VolumeVO sendAttachVolumeCommand(UserVmVO vm, VolumeVO volumeToAttach, Long deviceId) { String errorMsg = "Failed to attach volume " + volumeToAttach.getName() + " to VM " + vm.getHostName(); boolean sendCommand = vm.getState() == State.Running; AttachAnswer answer = null; Long hostId = vm.getHostId(); hostId = vm.getLastHostId(); DiskTO disk = storageMgr.getDiskWithThrottling(volTO, volumeToAttach.getVolumeType(), deviceId, volumeToAttach.getPath(), vm.getServiceOfferingId(), volumeToAttach.getDiskOfferingId()); AttachCommand cmd = new AttachCommand(disk, vm.getInstanceName()); controllerInfo.put(VmDetailConstants.ROOT_DISK_CONTROLLER, vm.getDetail(VmDetailConstants.ROOT_DISK_CONTROLLER)); controllerInfo.put(VmDetailConstants.DATA_DISK_CONTROLLER, vm.getDetail(VmDetailConstants.DATA_DISK_CONTROLLER)); cmd.setControllerInfo(controllerInfo); s_logger.debug("Attach volume id:" + volumeToAttach.getId() + " on VM id:" + vm.getId() + " has controller info:" + controllerInfo); _volsDao.attachVolume(volumeToAttach.getId(), vm.getId(), disk.getDiskSeq()); _volsDao.attachVolume(volumeToAttach.getId(), vm.getId(), deviceId); if (vm.getHypervisorType() == HypervisorType.KVM && volumeToAttachStoragePool.isManaged() && volumeToAttach.getPath() == null) { volumeToAttach.setPath(volumeToAttach.get_iScsiName()); VmDiskStatisticsVO diskstats = _vmDiskStatsDao.findBy(vm.getAccountId(), vm.getDataCenterId(), vm.getId(), volumeToAttach.getId()); if (diskstats == null) { diskstats = new VmDiskStatisticsVO(vm.getAccountId(), vm.getDataCenterId(), vm.getId(), volumeToAttach.getId()); _vmDiskStatsDao.persist(diskstats);
private boolean configureConfigDriveData(final VirtualMachineProfile profile, final NicProfile nic) { final UserVmVO vm = _userVmDao.findById(profile.getId()); if (vm.getType() != VirtualMachine.Type.User) { return false; } final Nic defaultNic = _networkModel.getDefaultNic(vm.getId()); if (defaultNic != null) { final String sshPublicKey = getSshKey(profile); final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows"); final List<String[]> vmData = _networkModel.generateVmData(vm.getUserData(), serviceOffering, vm.getDataCenterId(), vm.getInstanceName(), vm.getHostName(), vm.getId(), vm.getUuid(), nic.getIPv4Address(), sshPublicKey, (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows); profile.setVmData(vmData); profile.setConfigDriveLabel(VirtualMachineManager.VmConfigDriveLabel.value()); } return true; }
Account owner = _accountDao.findById(vm.getAccountId()); _userDao.findById(userId); long vmId = vm.getId(); boolean needRestart = false; throw new InvalidParameterValueException("The owner of " + vm + " does not exist: " + vm.getAccountId()); throw new PermissionDeniedException("The owner of " + vm + " is disabled: " + vm.getAccountId()); if (vm.getState() != VirtualMachine.State.Running && vm.getState() != VirtualMachine.State.Stopped) { throw new CloudRuntimeException("Vm " + vm.getUuid() + " currently in " + vm.getState() + " state, restore vm can only execute when VM in Running or Stopped"); if (vm.getState() == VirtualMachine.State.Running) { needRestart = true; InvalidParameterValueException ex = new InvalidParameterValueException("Can not find root volume for VM " + vm.getUuid()); ex.addProxyObject(vm.getUuid(), "vmId"); throw ex; InvalidParameterValueException ex = new InvalidParameterValueException("There are " + rootVols.size() + " root volumes for VM " + vm.getUuid()); ex.addProxyObject(vm.getUuid(), "vmId"); throw ex; templateId = vm.getIsoId(); if (template == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Cannot find template/ISO for specified volumeid and vmId"); ex.addProxyObject(vm.getUuid(), "vmId"); ex.addProxyObject(root.getUuid(), "volumeId");
@Override public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCapacityException { UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, template.getGuestOSId(), offering.isOfferHA(), offering.getLimitCpuUse(), owner.getDomainId(), owner.getId(), userId, offering.getId(), userData, hostName, diskOfferingId); vm.setUuid(uuidName); vm.setDynamicallyScalable(template.isDynamicallyScalable()); vm.setDetail("SSH.PublicKey", sshPublicKey); vm.setDetail(VmDetailConstants.KEYBOARD, keyboard); vm.setIsoId(template.getId()); vm.setDisplayVm(isDisplayVm); } else { vm.setDisplayVm(true); vm.setDetail("smc.present", "TRUE"); vm.setDetail(VmDetailConstants.ROOT_DISK_CONTROLLER, "scsi"); vm.setDetail(VmDetailConstants.DATA_DISK_CONTROLLER, "scsi"); vm.setDetail("firmware", "efi"); s_logger.info("guestOS is OSX : overwrite root disk controller to scsi, use smc and efi"); } else { String controllerSetting = _configDao.getValue("vmware.root.disk.controller"); if (vm.getDetail(VmDetailConstants.ROOT_DISK_CONTROLLER) == null) { vm.setDetail(VmDetailConstants.ROOT_DISK_CONTROLLER, controllerSetting); if (vm.getDetail(VmDetailConstants.DATA_DISK_CONTROLLER) == null) { if (controllerSetting.equalsIgnoreCase("scsi")) {
if (vm.getState() == State.Error || vm.getState() == State.Expunging) { s_logger.error("vm is not in the right state: " + id); throw new InvalidParameterValueException("Vm with id " + id + " is not in the right state"); displayName = vm.getDisplayName(); ha = vm.isHaEnabled(); ServiceOffering offering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId()); if (!offering.isOfferHA() && ha) { throw new InvalidParameterValueException("Can't enable ha for the vm as it's created from the Service offering having HA disabled"); isDisplayVmEnabled = vm.isDisplayVm(); userData = vm.getUserData(); isDynamicallyScalable = vm.isDynamicallyScalable(); osTypeId = vm.getGuestOSId(); isDynamicallyScalable = vm.isDynamicallyScalable(); boolean isVMware = (vm.getHypervisorType() == HypervisorType.VMware); DataCenterVO zone = _dcDao.findById(vm.getDataCenterId()); NicVO defaultNic = _nicDao.findDefaultNicForVM(vm.getId()); if (defaultNic != null) { defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
if (vm == null) { throw new InvalidParameterValueException("There is no vm by that id " + cmd.getVmId()); } else if (vm.getState() == State.Running) { // VV 3: check if vm is ex.addProxyObject(vm.getUuid(), "vmId"); throw ex; final Account oldAccount = _accountService.getActiveAccountById(vm.getAccountId()); if (oldAccount == null) { throw new InvalidParameterValueException("Invalid account for VM " + vm.getAccountId() + " in domain."); List<FirewallRuleVO> snrules = _rulesDao.listStaticNatByVmId(vm.getId()); if (snrules != null && snrules.size() > 0) { throw new InvalidParameterValueException("Remove the StaticNat rules for this VM before assigning to another user."); List<LoadBalancerVMMapVO> maps = _loadBalancerVMMapDao.listByInstanceId(vm.getId()); if (maps != null && maps.size() > 0) { throw new InvalidParameterValueException("Remove the load balancing rules for this VM before assigning to another user."); DataCenterVO zone = _dcDao.findById(vm.getDataCenterId()); final ServiceOfferingVO offering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()); resourceLimitCheck(newAccount, vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); VirtualMachineTemplate template = _templateDao.findById(vm.getTemplateId()); if (!template.isPublicTemplate()) { Account templateOwner = _accountMgr.getAccount(template.getAccountId());
private void updateVmStateForFailedVmCreation(Long vmId, Long hostId) { UserVmVO vm = _vmDao.findById(vmId); if (vm != null) { if (vm.getState().equals(State.Stopped)) { s_logger.debug("Destroying vm " + vm + " as it failed to create on Host with Id:" + hostId); try { _itMgr.stateTransitTo(vm, VirtualMachine.Event.OperationFailedToError, null); } catch (NoTransitionException e1) { s_logger.warn(e1.getMessage()); } // destroy associated volumes for vm in error state // get all volumes in non destroyed state List<VolumeVO> volumesForThisVm = _volsDao.findUsableVolumesForInstance(vm.getId()); for (VolumeVO volume : volumesForThisVm) { if (volume.getState() != Volume.State.Destroy) { volumeMgr.destroyVolume(volume); } } String msg = "Failed to deploy Vm with Id: " + vmId + ", on Host with Id: " + hostId; _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(), msg, msg); // Get serviceOffering for Virtual Machine ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId()); // Update Resource Count for the given account resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); } } }
if (vm == null || vm.getRemoved() != null) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a virtual machine with specified vmId"); throw ex; if (vm.getState() == State.Destroyed || vm.getState() == State.Expunging) { s_logger.trace("Vm id=" + vmId + " is already destroyed"); return vm; State vmState = vm.getState(); VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); status = vmEntity.destroy(Long.toString(userId), expunge); } catch (CloudException e) { CloudRuntimeException ex = new CloudRuntimeException("Unable to destroy with specified vmId", e); ex.addProxyObject(vm.getUuid(), "vmId"); throw ex; ServiceOfferingVO offering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()); resourceCountDecrement(vm.getAccountId(), vm.isDisplayVm(), new Long(offering.getCpu()), new Long(offering.getRamSize())); ex.addProxyObject(vm.getUuid(), "vmId"); throw ex;
String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); String zoneName = _dcDao.findById(vm.getDataCenterId()).getName(); NicVO nvo = _nicDao.findById(nic.getId()); VmDataCommand cmd = new VmDataCommand(nvo.getIPv4Address(), vm.getInstanceName(), _ntwkModel.getExecuteInSeqNtwkElmtCmd()); cmd.addVmData("userdata", "user-data", vm.getUserData()); cmd.addVmData("metadata", "service-offering", StringUtils.unicodeEscape(serviceOffering)); cmd.addVmData("metadata", "availability-zone", StringUtils.unicodeEscape(zoneName)); cmd.addVmData("metadata", "local-ipv4", nic.getIPv4Address()); cmd.addVmData("metadata", "local-hostname", StringUtils.unicodeEscape(vm.getInstanceName())); cmd.addVmData("metadata", "public-ipv4", nic.getIPv4Address()); cmd.addVmData("metadata", "public-hostname", StringUtils.unicodeEscape(vm.getInstanceName())); cmd.addVmData("metadata", "instance-id", String.valueOf(vm.getUuid())); cmd.addVmData("metadata", "vm-id", String.valueOf(vm.getInstanceName())); cmd.addVmData("metadata", "public-keys", null); String cloudIdentifier = _configDao.getValue("cloud.identifier"); List<PhysicalNetworkVO> phys = _phynwDao.listByZone(vm.getDataCenterId()); if (phys.isEmpty()) { throw new CloudRuntimeException(String.format("Cannot find physical network in zone %s", vm.getDataCenterId())); vm.getDataCenterId(), phys.size())); BaremetalPxeVO pxeVo = sc.find(); if (pxeVo == null) { throw new CloudRuntimeException("No PXE server found in pod: " + vm.getPodIdToDeployIn() + ", you need to add it before starting VM"); Answer ans = _agentMgr.send(pxeVo.getHostId(), cmd); if (!ans.getResult()) {
if (vm.getType() == VirtualMachine.Type.User) // user vm vmIds.add(vm.getId()); continue; s_logger.debug("Now we are updating the user_statistics table for VM: " + userVm.getInstanceName() + " after collecting vm network statistics from host: " + host.getName()); for (VmNetworkStatsEntry vmNetworkStat : vmNetworkStats) { if (vlan == null || vlan.size() == 0 || vlan.get(0).getVlanType() != VlanType.DirectAttached) continue; // only get network statistics for DirectAttached network (shared networks in Basic zone and Advanced zone with/without SG) UserStatisticsVO previousvmNetworkStats = _userStatsDao.findBy(userVm.getAccountId(), userVm.getDataCenterId(), nic.getNetworkId(), nic.getIPv4Address(), vmId, "UserVm"); if (previousvmNetworkStats == null) { previousvmNetworkStats = new UserStatisticsVO(userVm.getAccountId(), userVm.getDataCenterId(), nic.getIPv4Address(), vmId, "UserVm", nic.getNetworkId()); _userStatsDao.persist(previousvmNetworkStats); UserStatisticsVO vmNetworkStat_lock = _userStatsDao.lock(userVm.getAccountId(), userVm.getDataCenterId(), nic.getNetworkId(), nic.getIPv4Address(), vmId, "UserVm"); s_logger.warn("unable to find vm network stats from host for account: " + userVm.getAccountId() + " with vmId: " + userVm.getId() + " and nicId:" + nic.getId()); continue;
if (userVm.getState() != VirtualMachine.State.Running && userVm.getState() != VirtualMachine.State.Stopped) { throw new InvalidParameterValueException("VM Snapshot reverting failed due to vm is not in the state of Running or Stopped."); if (userVm.getState() == VirtualMachine.State.Stopped && vmSnapshotVo.getType() == VMSnapshot.Type.DiskAndMemory) { try { _itMgr.advanceStart(userVm.getUuid(), new HashMap<VirtualMachineProfile.Param, Object>(), null); vm = _userVMDao.findById(userVm.getId()); hostId = vm.getHostId(); } catch (Exception e) { s_logger.error("Start VM " + userVm.getInstanceName() + " before reverting failed due to " + e.getMessage()); throw new CloudRuntimeException(e.getMessage()); if (userVm.getState() == VirtualMachine.State.Running && vmSnapshotVo.getType() == VMSnapshot.Type.Disk) { try { _itMgr.advanceStop(userVm.getUuid(), true); } catch (Exception e) { s_logger.error("Stop VM " + userVm.getInstanceName() + " before reverting failed due to " + e.getMessage()); throw new CloudRuntimeException(e.getMessage()); if (hasActiveVMSnapshotTasks(userVm.getId())) { throw new InvalidParameterValueException("There is other active vm snapshot tasks on the instance, please try again later");
Account owner = _accountDao.findById(vm.getAccountId()); throw new InvalidParameterValueException("The owner of " + vm + " does not exist: " + vm.getAccountId()); throw new PermissionDeniedException("The owner of " + vm + " is disabled: " + vm.getAccountId()); SecurityGroup defaultSecurityGroup = _securityGroupMgr.getDefaultSecurityGroup(vm.getAccountId()); if (defaultSecurityGroup != null) { List<Long> groupList = new ArrayList<Long>(); if (destinationHost != null) { s_logger.debug("Destination Host to deploy the VM is specified, specifying a deployment plan to deploy the VM"); plan = new DataCenterDeployment(vm.getDataCenterId(), destinationHost.getPodId(), destinationHost.getClusterId(), destinationHost.getId(), null, null); if (!AllowDeployVmIfGivenHostFails.value()) { deployOnGivenHost = true; if (vm.isUpdateParameters()) { _vmDao.loadDetails(vm); template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId()); if (vm.getDetail("password") != null) { password = DBEncryptionUtil.decrypt(vm.getDetail("password")); } else { password = _mgr.generateRandomPassword(); vm.setPassword(password); VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid());
UserVmVO tmpVm = _vmDao.findById(vm.getId()); if (!tmpVm.getState().equals(State.Running)) { s_logger.error("VM " + tmpVm + " unexpectedly went to " + tmpVm.getState() + " state"); throw new ConcurrentOperationException("Failed to deploy VM "+vm); List<VolumeVO> vols = _volsDao.findByInstance(tmpVm.getId()); for (VolumeVO vol : vols) { if (vol.getVolumeType() == Volume.Type.DATADISK) { DiskOffering doff = _entityMgr.findById(DiskOffering.class, vol.getDiskOfferingId()); _volService.resizeVolumeOnHypervisor(vol.getId(), doff.getDiskSize(), tmpVm.getHostId(), vm.getInstanceName()); s_logger.fatal("Unable to resize the data disk for vm " + vm.getDisplayName() + " due to " + e.getMessage(), e); updateVmStateForFailedVmCreation(vm.getId(), hostId); VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId()); if (template.isEnablePassword()) { vm.setPassword((String)vmParamPair.second().get(VirtualMachineProfile.Param.VmPassword));