public Long getId() { return getVmId(); } }
@Override public long getEntityOwnerId() { UserVm vm = _responseGenerator.findUserVmById(getVmId()); if (vm == null) { return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked } return vm.getAccountId(); }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { UserVm result; CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVmId())); result = _userVmService.restoreVM(this); if (result != null) { UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0); response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restore vm " + getVmId()); } }
@Override public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException { // Input validation Account caller = CallContext.current().getCallingAccount(); long vmId = cmd.getVmId(); Long newTemplateId = cmd.getTemplateId(); UserVmVO vm = _vmDao.findById(vmId); if (vm == null) { InvalidParameterValueException ex = new InvalidParameterValueException("Cannot find VM with ID " + vmId); ex.addProxyObject(String.valueOf(vmId), "vmId"); throw ex; } _accountMgr.checkAccess(caller, null, true, vm); //check if there are any active snapshots on volumes associated with the VM s_logger.debug("Checking if there are any ongoing snapshots on the ROOT volumes associated with VM with ID " + vmId); if (checkStatusOfVolumeSnapshots(vmId, Volume.Type.ROOT)) { throw new CloudRuntimeException("There is/are unbacked up snapshot(s) on ROOT volume, Re-install VM is not permitted, please try again later."); } s_logger.debug("Found no ongoing snapshots on volume of type ROOT, for the vm with id " + vmId); return restoreVMInternal(caller, vm, newTemplateId); }