use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class RebootSystemVmCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Vm Id: " + getId());
VirtualMachine result = _mgr.rebootSystemVM(this);
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to reboot system vm");
}
}
use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class UpgradeSystemVMCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Vm Id: " + getId());
ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
VirtualMachine result = _mgr.upgradeSystemVM(this);
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to reboot system vm");
}
}
use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class MigrateSystemVMCmd method execute.
@Override
public void execute() {
Host destinationHost = _resourceService.getHost(getHostId());
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
}
try {
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
//FIXME : Should not be calling UserVmService to migrate all types of VMs - need a generic VM layer
VirtualMachine migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
if (migratedVm != null) {
// return the generic system VM instance response
SystemVmInstanceResponse response = _responseGenerator.createSystemVmInstanceResponse(migratedVm);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate the system vm");
}
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (VirtualMachineMigrationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class MigrateVMCmd method execute.
@Override
public void execute() {
if (getHostId() == null && getStoragePoolId() == null) {
throw new InvalidParameterValueException("either hostId or storageId must be specified");
}
if (getHostId() != null && getStoragePoolId() != null) {
throw new InvalidParameterValueException("only one of hostId and storageId can be specified");
}
UserVm userVm = _userVmService.getUserVm(getVirtualMachineId());
if (userVm == null) {
throw new InvalidParameterValueException("Unable to find the VM by id=" + getVirtualMachineId());
}
Host destinationHost = null;
if (getHostId() != null) {
destinationHost = _resourceService.getHost(getHostId());
if (destinationHost == null) {
throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId());
}
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId());
}
StoragePool destStoragePool = null;
if (getStoragePoolId() != null) {
destStoragePool = _storageService.getStoragePool(getStoragePoolId());
if (destStoragePool == null) {
throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM");
}
UserContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: " + getStoragePoolId());
}
try {
VirtualMachine migratedVm = null;
if (getHostId() != null) {
migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost);
} else if (getStoragePoolId() != null) {
migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool);
}
if (migratedVm != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", (UserVm) migratedVm).get(0);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate vm");
}
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (ManagementServerException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
} catch (VirtualMachineMigrationException e) {
s_logger.warn("Exception: ", e);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.
the class ListSystemVMsCmd method execute.
@Override
public void execute() {
List<? extends VirtualMachine> systemVMs = _mgr.searchForSystemVm(this);
ListResponse<SystemVmResponse> response = new ListResponse<SystemVmResponse>();
List<SystemVmResponse> vmResponses = new ArrayList<SystemVmResponse>();
for (VirtualMachine systemVM : systemVMs) {
SystemVmResponse vmResponse = _responseGenerator.createSystemVmResponse(systemVM);
vmResponse.setObjectName("systemvm");
vmResponses.add(vmResponse);
}
response.setResponses(vmResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
Aggregations