Search in sources :

Example 16 with UserVm

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");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 17 with UserVm

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;
}
Also used : PortableIp(org.apache.cloudstack.region.PortableIp) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) UserVm(com.cloud.uservm.UserVm) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) IpAddress(com.cloud.network.IpAddress) ApplicationLoadBalancerRuleResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerRuleResponse) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse) FirewallRule(com.cloud.network.rules.FirewallRule) Map(java.util.Map) HashMap(java.util.HashMap) ApplicationLoadBalancerInstanceResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerInstanceResponse)

Example 18 with UserVm

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;
}
Also used : UserVm(com.cloud.uservm.UserVm) IpAddress(com.cloud.network.IpAddress) FirewallRule(com.cloud.network.rules.FirewallRule) IpForwardingRuleResponse(org.apache.cloudstack.api.response.IpForwardingRuleResponse)

Example 19 with UserVm

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.");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(org.apache.cloudstack.api.ApiConstants.VMDetails) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 20 with UserVm

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");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Aggregations

UserVm (com.cloud.uservm.UserVm)98 ServerApiException (org.apache.cloudstack.api.ServerApiException)45 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)45 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 ArrayList (java.util.ArrayList)19 ServerApiException (com.cloud.api.ServerApiException)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 UserVmResponse (com.cloud.api.response.UserVmResponse)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)14 Network (com.cloud.network.Network)13 Account (com.cloud.user.Account)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 VMDetails (org.apache.cloudstack.api.ApiConstants.VMDetails)9 Test (org.junit.Test)9 DataCenter (com.cloud.dc.DataCenter)6 ManagementServerException (com.cloud.exception.ManagementServerException)6 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)6 DB (com.cloud.utils.db.DB)6 TransactionStatus (com.cloud.utils.db.TransactionStatus)6