Search in sources :

Example 6 with VMDetails

use of org.apache.cloudstack.api.ApiConstants.VMDetails 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");
    }
}
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 7 with VMDetails

use of org.apache.cloudstack.api.ApiConstants.VMDetails in project cloudstack by apache.

the class AddNicToVMCmd 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.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.");
    }
}
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 8 with VMDetails

use of org.apache.cloudstack.api.ApiConstants.VMDetails in project cloudstack by apache.

the class UpdateDefaultNicForVMCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Nic Id: " + getNicId());
    UserVm result = _userVmService.updateDefaultNicForVirtualMachine(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.Restricted, "virtualmachine", details, result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set default nic for 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 9 with VMDetails

use of org.apache.cloudstack.api.ApiConstants.VMDetails in project cloudstack by apache.

the class UpdateVmNicIpCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Nic Id: " + getNicId());
    String ip;
    if ((ip = getIpaddress()) != null) {
        if (!NetUtils.isValidIp(ip)) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Invalid ip address " + ip);
        }
    }
    UserVm vm = _userVmService.updateNicIpForVirtualMachine(this);
    ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
    dc.add(VMDetails.valueOf("nics"));
    EnumSet<VMDetails> details = EnumSet.copyOf(dc);
    if (vm != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", details, vm).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update ip address on vm NIC. 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 10 with VMDetails

use of org.apache.cloudstack.api.ApiConstants.VMDetails in project cloudstack by apache.

the class ListVMsCmd method getDetails.

public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
    EnumSet<VMDetails> dv;
    if (viewDetails == null || viewDetails.size() <= 0) {
        dv = EnumSet.of(VMDetails.all);
    } else {
        try {
            ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
            for (String detail : viewDetails) {
                dc.add(VMDetails.valueOf(detail));
            }
            dv = EnumSet.copyOf(dc);
        } catch (IllegalArgumentException e) {
            throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(VMDetails.class));
        }
    }
    return dv;
}
Also used : VMDetails(org.apache.cloudstack.api.ApiConstants.VMDetails) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)10 VMDetails (org.apache.cloudstack.api.ApiConstants.VMDetails)10 UserVm (com.cloud.uservm.UserVm)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1