use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.
the class DetachIsoCmd method execute.
@Override
public void execute() {
boolean result = _templateService.detachIso(virtualMachineId);
if (result) {
UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
response.setResponseName(DeployVMCmd.getResultObjectName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach iso");
}
}
use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.
the class StartVMCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
try {
UserContext.current().setEventDetails("Vm Id: " + getId());
UserVm result;
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
result = _bareMetalVmService.startVirtualMachine(this);
} else {
result = _userVmService.startVirtualMachine(this);
}
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
}
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
} catch (StorageUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ExecutionException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
}
use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.
the class ResetVMPasswordCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
password = _mgr.generateRandomPassword();
UserContext.current().setEventDetails("Vm Id: " + getId());
UserVm result = _userVmService.resetVMPassword(this, password);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reset vm password");
}
}
use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.
the class RestoreVMCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
UserVm result;
UserContext.current().setEventDetails("Vm Id: " + getVmId());
result = _userVmService.restoreVM(this);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restore vm " + getVmId());
}
}
use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.
the class AssignVMCmd method execute.
@Override
public void execute() {
try {
UserVm userVm = _userVmService.moveVMToUser(this);
if (userVm == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm");
}
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
response.setResponseName(DeployVMCmd.getResultObjectName());
this.setResponseObject(response);
} catch (Exception e) {
e.printStackTrace();
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
}
}
Aggregations