use of com.cloud.uservm.UserVm 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());
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class DetachIsoCmdByAdmin method execute.
@Override
public void execute() {
boolean result = _templateService.detachIso(virtualMachineId);
if (result) {
UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
response.setResponseName(DeployVMCmd.getResultObjectName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach iso");
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class UpdateVMAffinityGroupCmdByAdmin method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("Vm Id: " + getId());
UserVm result = _affinityGroupService.updateVMAffinityGroups(getId(), getAffinityGroupIdList());
ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
dc.add(VMDetails.valueOf("affgrp"));
EnumSet<VMDetails> details = EnumSet.copyOf(dc);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", details, result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm's affinity groups");
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class UpdateVMCmdByAdmin method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("Vm Id: " + getId());
UserVm result = _userVmService.updateVirtualMachine(this);
if (result != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm");
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class ListLoadBalancerRuleInstancesCmdByAdmin method execute.
@Override
public void execute() {
Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
List<? extends UserVm> result = vmServiceMap.first();
List<String> serviceStates = vmServiceMap.second();
if (!isListLbVmip()) {
// list lb instances
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
if (result != null) {
vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
for (int i = 0; i < result.size(); i++) {
vmResponses.get(i).setServiceState(serviceStates.get(i));
}
}
response.setResponses(vmResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
if (result != null) {
vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
List<String> ipaddr = null;
for (int i = 0; i < result.size(); i++) {
LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
vmResponses.get(i).setServiceState(serviceStates.get(i));
lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
//get vm id from the uuid
VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
lbRuleVmIpResponse.setObjectName("lbrulevmidip");
listlbVmRes.add(lbRuleVmIpResponse);
}
}
lbRes.setResponseName(getCommandName());
lbRes.setResponses(listlbVmRes);
setResponseObject(lbRes);
}
}
Aggregations