protected Long destroyVM(final HaWorkVO work) { final VirtualMachine vm = _itMgr.findById(work.getInstanceId()); s_logger.info("Destroying " + vm.toString()); try { if (vm.getState() != State.Destroyed) { s_logger.info("VM is no longer in Destroyed state " + vm.toString()); return null; } if (vm.getHostId() != null) { _itMgr.destroy(vm.getUuid(), false); s_logger.info("Successfully destroy " + vm); return null; } else { if (s_logger.isDebugEnabled()) { s_logger.debug(vm + " has already been stopped"); } return null; } } catch (final AgentUnavailableException e) { s_logger.debug("Agnet is not available" + e.getMessage()); } catch (OperationTimedoutException e) { s_logger.debug("operation timed out: " + e.getMessage()); } catch (ConcurrentOperationException e) { s_logger.debug("concurrent operation: " + e.getMessage()); } return (System.currentTimeMillis() >> 10) + _stopRetryInterval; }
@Override public boolean saveUserData(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException { // saveUserData is called by updateVirtualMachine API which requires VM to be shutdown // Upper layers should save userdata in db, we do not need to update/create config drive iso at this point // Config drive will be created with updated password when VM starts in future if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) { throw new CloudRuntimeException("VM should to stopped to reset password"); } return canHandle(network.getTrafficType()); }
protected boolean cleanup(final VirtualMachineGuru guru, final VirtualMachineProfile profile, final ItWorkVO work, final Event event, final boolean cleanUpEvenIfUnableToStop) { final VirtualMachine vm = profile.getVirtualMachine(); final State state = vm.getState(); s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state"); try {
private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) { VirtualMachine virtualMachine = volumeInfo.getAttachedVM(); if (virtualMachine != null && VirtualMachine.State.Running.equals(virtualMachine.getState())) { String vmSnapshotName = UUID.randomUUID().toString().replace("-", ""); VMSnapshotVO vmSnapshotVO = new VMSnapshotVO(virtualMachine.getAccountId(), virtualMachine.getDomainId(), virtualMachine.getId(), vmSnapshotName, vmSnapshotName, vmSnapshotName, virtualMachine.getServiceOfferingId(), VMSnapshot.Type.Disk, null); VMSnapshot vmSnapshot = vmSnapshotDao.persist(vmSnapshotVO); if (vmSnapshot == null) { throw new CloudRuntimeException("Unable to allocate a VM snapshot object"); } vmSnapshot = vmSnapshotService.createVMSnapshot(virtualMachine.getId(), vmSnapshot.getId(), true); if (vmSnapshot == null) { throw new CloudRuntimeException("Unable to create a hypervisor-side snapshot"); } try { Thread.sleep(60000); } catch (Exception ex) { s_logger.warn(ex.getMessage(), ex); } return vmSnapshot; } // We didn't need to take a hypervisor-side snapshot. Return 'null' to indicate this. return null; }
@Override public boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey) throws ResourceUnavailableException { // saveSSHKey is called by resetSSHKeyForVirtualMachine API which requires VM to be shutdown // Upper layers should save ssh public key in db, we do not need to update/create config drive iso at this point // Config drive will be created with updated password when VM starts in future if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) { throw new CloudRuntimeException("VM should to stopped to reset password"); } final boolean canHandle = canHandle(network.getTrafficType()); if (canHandle) { storePasswordInVmDetails(vm); } return canHandle; }
@Override public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException { // savePassword is called by resetPasswordForVirtualMachine API which requires VM to be shutdown // Upper layers should save password in db, we do not need to update/create config drive iso at this point // Config drive will be created with updated password when VM starts in future if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) { throw new CloudRuntimeException("VM should to stopped to reset password"); } final boolean canHandle = canHandle(network.getTrafficType()); if (canHandle) { storePasswordInVmDetails(vm); } return canHandle; }
return null; } else if (work.getWorkType() == WorkType.CheckStop) { if ((vm.getState() != work.getPreviousState()) || vm.getUpdated() != work.getUpdateTime() || vm.getHostId() == null || vm.getHostId().longValue() != work.getHostId()) { s_logger.info(vm + " is different now. Scheduled Host: " + work.getHostId() + " Current Host: " + (vm.getHostId() != null ? vm.getHostId() : "none") + " State: " + vm.getState()); return null; return null; } else if (work.getWorkType() == WorkType.ForceStop) { if ((vm.getState() != work.getPreviousState()) || vm.getUpdated() != work.getUpdateTime() || vm.getHostId() == null || vm.getHostId().longValue() != work.getHostId()) { s_logger.info(vm + " is different now. Scheduled Host: " + work.getHostId() + " Current Host: " + (vm.getHostId() != null ? vm.getHostId() : "none") + " State: " + vm.getState()); return null;
public VspVm buildVspVm(VirtualMachine vm, Network network) { VspVm.Builder vspVmBuilder = new VspVm.Builder() .uuid(vm.getUuid()) .name(vm.getInstanceName()) .state(getEnumValue(vm.getState(), VspVm.State.Unknown)); boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter); vspVmBuilder.domainRouter(isDomainRouter); if (network.getBroadcastUri() != null) { String domainRouterIp = network.getBroadcastUri().getPath().substring(1); vspVmBuilder.domainRouterIp(domainRouterIp); } return vspVmBuilder.build(); }
if (!(vmInstance.getState().equals(State.Stopped) || vmInstance.getState().equals(State.Running))) { s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState()); throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " + " in state " + vmInstance.getState() + "; make sure the virtual machine is stopped/running");
@Override public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) { SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse(); vmResponse.setId(vm.getUuid()); vmResponse.setSystemVmType(vm.getType().toString().toLowerCase()); vmResponse.setName(vm.getHostName()); if (vm.getHostId() != null) { Host host = ApiDBUtils.findHostById(vm.getHostId()); if (host != null) { vmResponse.setHostId(host.getUuid()); } } if (vm.getState() != null) { vmResponse.setState(vm.getState().toString()); } if (vm.getType() == Type.DomainRouter) { VirtualRouter router = (VirtualRouter)vm; if (router.getRole() != null) { vmResponse.setRole(router.getRole().toString()); } } vmResponse.setObjectName("systemvminstance"); return vmResponse; }
if (vm.getState() == State.Running) { final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType()); s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network); return false; } else if (vm.getState() != State.Stopped) { s_logger.warn("Unable to remove vm " + vm + " from network " + network); throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId());
@Override public EndPoint select(DataObject srcData, DataObject destData, StorageAction action) { s_logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId()); if (action == StorageAction.BACKUPSNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) { SnapshotInfo srcSnapshot = (SnapshotInfo)srcData; VolumeInfo volumeInfo = srcSnapshot.getBaseVolume(); VirtualMachine vm = volumeInfo.getAttachedVM(); if (srcSnapshot.getHypervisorType() == Hypervisor.HypervisorType.KVM) { if (vm != null && vm.getState() == VirtualMachine.State.Running) { return getEndPointFromHostId(vm.getHostId()); } } if (srcSnapshot.getHypervisorType() == Hypervisor.HypervisorType.VMware) { if (vm != null) { Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId(); if (hostId != null) { return getEndPointFromHostId(hostId); } } } } return select(srcData, destData); }
VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); VirtualMachine vm = volumeInfo.getAttachedVM(); if ((vm != null) && (vm.getState() == VirtualMachine.State.Running)) { Long hostId = vm.getHostId(); return getEndPointFromHostId(hostId); if (volume.getHypervisorType() == Hypervisor.HypervisorType.Hyperv || volume.getHypervisorType() == Hypervisor.HypervisorType.VMware) { VirtualMachine vm = volume.getAttachedVM(); if ((vm != null) && (vm.getState() == VirtualMachine.State.Running)) { Long hostId = vm.getHostId(); return getEndPointFromHostId(hostId);
if (vm.getState() == State.Running) { final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType()); s_logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network " + network); return false; } else if (vm.getState() != State.Stopped) { s_logger.warn("Unable to remove vm " + vm + " from network " + network); throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId());
private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) { VirtualMachine vm = srcVolumeInfo.getAttachedVM(); if (vm == null || vm.getState() != VirtualMachine.State.Running) { throw new CloudRuntimeException("Currently, a volume to migrate from non-managed storage to managed storage on XenServer must be attached to " + "a VM in the Running state.");
to.setConfigDriveIsoRootFolder(vmProfile.getConfigDriveIsoRootFolder()); to.setConfigDriveIsoFile(vmProfile.getConfigDriveIsoFile()); to.setState(vm.getState());
VirtualMachine vm = srcVolumeInfo.getAttachedVM(); if (vm != null && vm.getState() != VirtualMachine.State.Stopped) { throw new CloudRuntimeException("Currently, if a volume to copy from managed storage to secondary storage is attached to " + "a VM, the VM must be in the Stopped state.");
VirtualMachine vm = srcVolumeInfo.getAttachedVM(); if (vm != null && vm.getState() != VirtualMachine.State.Stopped) { throw new CloudRuntimeException("Currently, if a volume to migrate from managed storage to non-managed storage is attached to " + "a VM, the VM must be in the Stopped state.");
private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) { VirtualMachine vm = srcVolumeInfo.getAttachedVM(); if (vm != null && vm.getState() != VirtualMachine.State.Stopped) { throw new CloudRuntimeException("Currently, if a volume to migrate from non-managed storage to managed storage on KVM is attached to " + "a VM, the VM must be in the Stopped state."); } destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null); VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId()); volumeVO.setPath(volumeVO.get_iScsiName()); _volumeDao.update(volumeVO.getId(), volumeVO); destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore()); long srcStoragePoolId = srcVolumeInfo.getPoolId(); StoragePoolVO srcStoragePoolVO = _storagePoolDao.findById(srcStoragePoolId); HostVO hostVO; if (srcStoragePoolVO.getClusterId() != null) { hostVO = getHostInCluster(srcStoragePoolVO.getClusterId()); } else { hostVO = getHost(destVolumeInfo.getDataCenterId(), HypervisorType.KVM, false); } // migrate the volume via the hypervisor migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo, hostVO, "Unable to migrate the volume from non-managed storage to managed storage"); volumeVO = _volumeDao.findById(destVolumeInfo.getId()); volumeVO.setFormat(ImageFormat.QCOW2); _volumeDao.update(volumeVO.getId(), volumeVO); }