Search in sources :

Example 6 with VMDetails

use of com.cloud.api.ApiConstants.VMDetails in project cosmic by MissionCriticalCloud.

the class ListVMsCmd method getDetails.

public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
    final EnumSet<VMDetails> dv;
    if (viewDetails == null || viewDetails.size() <= 0) {
        dv = EnumSet.of(VMDetails.all);
    } else {
        try {
            final ArrayList<VMDetails> dc = new ArrayList<>();
            for (final String detail : viewDetails) {
                dc.add(VMDetails.valueOf(detail));
            }
            dv = EnumSet.copyOf(dc);
        } catch (final 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(com.cloud.api.ApiConstants.VMDetails) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList)

Example 7 with VMDetails

use of com.cloud.api.ApiConstants.VMDetails in project cosmic by MissionCriticalCloud.

the class RemoveNicFromVMCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Nic Id: " + getNicId());
    final UserVm result = _userVmService.removeNicFromVirtualMachine(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 remove NIC from vm, see error log for details");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(com.cloud.api.ApiConstants.VMDetails) ServerApiException(com.cloud.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 8 with VMDetails

use of com.cloud.api.ApiConstants.VMDetails in project cosmic by MissionCriticalCloud.

the class UpdateVMAffinityGroupCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
    CallContext.current().setEventDetails("VM ID: " + getId());
    final UserVm result = _affinityGroupService.updateVMAffinityGroups(getId(), getAffinityGroupIdList());
    final ArrayList<VMDetails> dc = new ArrayList<>();
    dc.add(VMDetails.valueOf("affgrp"));
    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 update VM's affinity groups");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(com.cloud.api.ApiConstants.VMDetails) ServerApiException(com.cloud.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 9 with VMDetails

use of com.cloud.api.ApiConstants.VMDetails in project cosmic by MissionCriticalCloud.

the class UpdateDefaultNicForVMCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + getVmId() + " Nic Id: " + getNicId());
    final UserVm result = _userVmService.updateDefaultNicForVirtualMachine(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 set default nic for VM. Refer to server logs for details.");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(com.cloud.api.ApiConstants.VMDetails) ServerApiException(com.cloud.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 10 with VMDetails

use of com.cloud.api.ApiConstants.VMDetails in project cosmic by MissionCriticalCloud.

the class AddNicToVMCmdByAdmin 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.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(com.cloud.api.ApiConstants.VMDetails) ServerApiException(com.cloud.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(com.cloud.api.response.UserVmResponse)

Aggregations

VMDetails (com.cloud.api.ApiConstants.VMDetails)11 ArrayList (java.util.ArrayList)11 ServerApiException (com.cloud.api.ServerApiException)9 UserVmResponse (com.cloud.api.response.UserVmResponse)9 UserVm (com.cloud.uservm.UserVm)9 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1