Search in sources :

Example 1 with NiciraNvpDeviceResponse

use of com.cloud.api.response.NiciraNvpDeviceResponse in project cloudstack by apache.

the class ListNiciraNvpDevicesCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        List<NiciraNvpDeviceVO> niciraDevices = niciraNvpElementService.listNiciraNvpDevices(this);
        ListResponse<NiciraNvpDeviceResponse> response = new ListResponse<NiciraNvpDeviceResponse>();
        List<NiciraNvpDeviceResponse> niciraDevicesResponse = new ArrayList<NiciraNvpDeviceResponse>();
        if (niciraDevices != null && !niciraDevices.isEmpty()) {
            for (NiciraNvpDeviceVO niciraDeviceVO : niciraDevices) {
                NiciraNvpDeviceResponse niciraDeviceResponse = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO);
                niciraDevicesResponse.add(niciraDeviceResponse);
            }
        }
        response.setResponses(niciraDevicesResponse);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse)

Example 2 with NiciraNvpDeviceResponse

use of com.cloud.api.response.NiciraNvpDeviceResponse in project cloudstack by apache.

the class NiciraNvpElement method createNiciraNvpDeviceResponse.

@Override
public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(NiciraNvpDeviceVO niciraNvpDeviceVO) {
    HostVO niciraNvpHost = hostDao.findById(niciraNvpDeviceVO.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
    response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(niciraNvpDeviceVO.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    response.setId(niciraNvpDeviceVO.getUuid());
    response.setProviderName(niciraNvpDeviceVO.getProviderName());
    response.setHostName(niciraNvpHost.getDetail("ip"));
    response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
    response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
    response.setL2GatewayServiceUuid(niciraNvpHost.getDetail("l2gatewayserviceuuid"));
    response.setObjectName("niciranvpdevice");
    return response;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse) HostVO(com.cloud.host.HostVO)

Example 3 with NiciraNvpDeviceResponse

use of com.cloud.api.response.NiciraNvpDeviceResponse in project cloudstack by apache.

the class AddNiciraNvpDeviceCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        NiciraNvpDeviceVO niciraNvpDeviceVO = niciraNvpElementService.addNiciraNvpDevice(this);
        if (niciraNvpDeviceVO != null) {
            NiciraNvpDeviceResponse response = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO);
            response.setObjectName("niciranvpdevice");
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse)

Aggregations

NiciraNvpDeviceResponse (com.cloud.api.response.NiciraNvpDeviceResponse)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 HostVO (com.cloud.host.HostVO)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 ArrayList (java.util.ArrayList)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1