use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.
the class AddNicToVMCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Network Id: " + getNetworkId());
final UserVm result = _userVmService.addNicToVirtualMachine(this);
final ArrayList<VMDetails> dc = new ArrayList<>();
dc.add(VMDetails.valueOf("nics"));
final EnumSet<VMDetails> details = EnumSet.copyOf(dc);
if (result != null) {
final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add NIC to vm. Refer to server logs for details.");
}
}
use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.
the class DeployVMCmd method create.
@Override
public void create() {
try {
// Verify that all objects exist before passing them to the service
final Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
verifyDetails();
final Zone zone = zoneRepository.findOne(zoneId);
if (zone == null) {
throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
}
final ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
final VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
// Make sure a valid template ID was specified
if (template == null) {
throw new InvalidParameterValueException("Unable to find the template " + templateId);
}
DiskOffering diskOffering = null;
if (diskOfferingId != null) {
diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
}
}
if (!zone.isLocalStorageEnabled()) {
if (serviceOffering.getUseLocalStorage()) {
throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
}
if (diskOffering != null && diskOffering.getUseLocalStorage()) {
throw new InvalidParameterValueException("Zone is not configured to use local storage but disk offering " + diskOffering.getName() + " uses it");
}
}
final IpAddresses addrs = new IpAddresses(ipAddress, ip6Address, getMacAddress());
final UserVm vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(), getDetails(), getCustomId());
if (vm != null) {
setEntityId(vm.getId());
setEntityUuid(vm.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm");
}
} catch (final InsufficientCapacityException ex) {
s_logger.info(ex.toString());
s_logger.trace(ex.getMessage(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final ResourceAllocationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
}
}
use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.
the class DeployVMCmd method execute.
@Override
public void execute() {
final UserVm result;
if (getStartVm()) {
try {
CallContext.current().setEventDetails("Vm Id: " + getEntityId());
result = _userVmService.startVirtualMachine(this);
} catch (final ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (final ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (final InsufficientCapacityException ex) {
final StringBuilder message = new StringBuilder(ex.getMessage());
if (ex instanceof InsufficientServerCapacityException) {
if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
}
}
s_logger.info(ex.toString());
s_logger.info(message.toString(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
}
} else {
result = _userVmService.getUserVm(getEntityId());
}
if (result != null) {
final UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm uuid:" + getEntityUuid());
}
}
use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.
the class DestroyVMCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
CallContext.current().setEventDetails("Vm Id: " + getId());
final UserVm result = _userVmService.destroyVm(this);
UserVmResponse response = new UserVmResponse();
if (result != null) {
final List<UserVmResponse> responses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result);
if (responses != null && !responses.isEmpty()) {
response = responses.get(0);
}
response.setResponseName("virtualmachine");
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy vm");
}
}
use of com.cloud.uservm.UserVm in project cosmic by MissionCriticalCloud.
the class CreateSnapshotFromVMSnapshotCmd method getHostId.
private Long getHostId() {
final VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
if (vmsnapshot == null) {
throw new InvalidParameterValueException("Unable to find vm snapshot by id=" + getVMSnapshotId());
}
final UserVm vm = _entityMgr.findById(UserVm.class, vmsnapshot.getVmId());
if (vm != null) {
if (vm.getHostId() != null) {
return vm.getHostId();
} else if (vm.getLastHostId() != null) {
return vm.getLastHostId();
}
}
return null;
}
Aggregations