use of com.cloud.uservm.UserVm in project cloudstack by apache.
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(ResponseView.Restricted, "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 ApiResponseHelper method createLoadBalancerContainerReponse.
@Override
public ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances) {
ApplicationLoadBalancerResponse lbResponse = new ApplicationLoadBalancerResponse();
lbResponse.setId(lb.getUuid());
lbResponse.setName(lb.getName());
lbResponse.setDescription(lb.getDescription());
lbResponse.setAlgorithm(lb.getAlgorithm());
lbResponse.setForDisplay(lb.isDisplay());
Network nw = ApiDBUtils.findNetworkById(lb.getNetworkId());
lbResponse.setNetworkId(nw.getUuid());
populateOwner(lbResponse, lb);
if (lb.getScheme() == Scheme.Internal) {
lbResponse.setSourceIp(lb.getSourceIp().addr());
//TODO - create the view for the load balancer rule to reflect the network uuid
Network network = ApiDBUtils.findNetworkById(lb.getNetworkId());
lbResponse.setSourceIpNetworkId(network.getUuid());
} else {
//for public, populate the ip information from the ip address
IpAddress publicIp = ApiDBUtils.findIpAddressById(lb.getSourceIpAddressId());
lbResponse.setSourceIp(publicIp.getAddress().addr());
Network ntwk = ApiDBUtils.findNetworkById(publicIp.getNetworkId());
lbResponse.setSourceIpNetworkId(ntwk.getUuid());
}
//set load balancer rules information (only one rule per load balancer in this release)
List<ApplicationLoadBalancerRuleResponse> ruleResponses = new ArrayList<ApplicationLoadBalancerRuleResponse>();
ApplicationLoadBalancerRuleResponse ruleResponse = new ApplicationLoadBalancerRuleResponse();
ruleResponse.setInstancePort(lb.getDefaultPortStart());
ruleResponse.setSourcePort(lb.getSourcePortStart());
FirewallRule.State stateToSet = lb.getState();
if (stateToSet.equals(FirewallRule.State.Revoke)) {
stateToSet = FirewallRule.State.Deleting;
}
ruleResponse.setState(stateToSet.toString());
ruleResponse.setObjectName("loadbalancerrule");
ruleResponses.add(ruleResponse);
lbResponse.setLbRules(ruleResponses);
//set Lb instances information
List<ApplicationLoadBalancerInstanceResponse> instanceResponses = new ArrayList<ApplicationLoadBalancerInstanceResponse>();
for (Map.Entry<Ip, UserVm> entry : lbInstances.entrySet()) {
Ip ip = entry.getKey();
UserVm vm = entry.getValue();
ApplicationLoadBalancerInstanceResponse instanceResponse = new ApplicationLoadBalancerInstanceResponse();
instanceResponse.setIpAddress(ip.addr());
instanceResponse.setId(vm.getUuid());
instanceResponse.setName(vm.getInstanceName());
instanceResponse.setObjectName("loadbalancerinstance");
instanceResponses.add(instanceResponse);
}
lbResponse.setLbInstances(instanceResponses);
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, lb.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
lbResponse.setTags(tagResponses);
lbResponse.setObjectName("loadbalancer");
return lbResponse;
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class ApiResponseHelper method createIpForwardingRuleResponse.
@Override
public IpForwardingRuleResponse createIpForwardingRuleResponse(StaticNatRule fwRule) {
IpForwardingRuleResponse response = new IpForwardingRuleResponse();
response.setId(fwRule.getUuid());
response.setProtocol(fwRule.getProtocol());
IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
if (ip != null) {
response.setPublicIpAddressId(ip.getId());
response.setPublicIpAddress(ip.getAddress().addr());
if (fwRule.getDestIpAddress() != null) {
UserVm vm = ApiDBUtils.findUserVmById(ip.getAssociatedWithVmId());
if (vm != null) {
// vm might be destroyed
response.setVirtualMachineId(vm.getUuid());
response.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
response.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
response.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
}
FirewallRule.State state = fwRule.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
stateToSet = "Deleting";
}
response.setStartPort(fwRule.getSourcePortStart());
response.setEndPort(fwRule.getSourcePortEnd());
response.setProtocol(fwRule.getProtocol());
response.setState(stateToSet);
response.setObjectName("ipforwardingrule");
return response;
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class AddNicToVMCmdByAdmin method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Network Id: " + getNetworkId());
UserVm result = _userVmService.addNicToVirtualMachine(this);
ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
dc.add(VMDetails.valueOf("nics"));
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 add NIC to vm. Refer to server logs for details.");
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class RebootVMCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
CallContext.current().setEventDetails("Vm Id: " + getId());
UserVm result;
result = _userVmService.rebootVirtualMachine(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 reboot vm instance");
}
}
Aggregations