Search in sources :

Example 1 with NetworkResponse

use of org.apache.cloudstack.api.response.NetworkResponse in project cloudstack by apache.

the class ListSrxFirewallNetworksCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<? extends Network> networks = _srxFwService.listNetworks(this);
        ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
        List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
        if (networks != null && !networks.isEmpty()) {
            for (Network network : networks) {
                NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
                networkResponses.add(networkResponse);
            }
        }
        response.setResponses(networkResponses);
        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) Network(com.cloud.network.Network) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) ArrayList(java.util.ArrayList)

Example 2 with NetworkResponse

use of org.apache.cloudstack.api.response.NetworkResponse in project cloudstack by apache.

the class ListNetworksCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Network>, Integer> networks = _networkService.searchForNetworks(this);
    ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
    List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
    for (Network network : networks.first()) {
        NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(getResponseView(), network);
        networkResponses.add(networkResponse);
    }
    response.setResponses(networkResponses, networks.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
    if (response != null && response.getCount() > 0 && getShowIcon()) {
        updateNetworkResponse(response.getResponses());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) Network(com.cloud.network.Network) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with NetworkResponse

use of org.apache.cloudstack.api.response.NetworkResponse in project cloudstack by apache.

the class ListNetworksCmd method updateNetworkResponse.

private void updateNetworkResponse(List<NetworkResponse> response) {
    for (NetworkResponse networkResponse : response) {
        ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Network, networkResponse.getId());
        if (resourceIcon == null) {
            resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Vpc, networkResponse.getVpcId());
            if (resourceIcon == null) {
                continue;
            }
        }
        ResourceIconResponse iconResponse = _responseGenerator.createResourceIconResponse(resourceIcon);
        networkResponse.setResourceIconResponse(iconResponse);
    }
}
Also used : ResourceIconResponse(org.apache.cloudstack.api.response.ResourceIconResponse) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) ResourceIcon(com.cloud.server.ResourceIcon)

Example 4 with NetworkResponse

use of org.apache.cloudstack.api.response.NetworkResponse in project cloudstack by apache.

the class CreateNetworkCmd method execute.

@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
    Network result = _networkService.createGuestNetwork(this);
    if (result != null) {
        NetworkResponse response = _responseGenerator.createNetworkResponse(getResponseView(), result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) Network(com.cloud.network.Network) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse)

Example 5 with NetworkResponse

use of org.apache.cloudstack.api.response.NetworkResponse in project cloudstack by apache.

the class ListBrocadeVcsDeviceNetworksCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<? extends Network> networks = brocadeVcsElementService.listBrocadeVcsDeviceNetworks(this);
        ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
        List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
        if (networks != null && !networks.isEmpty()) {
            for (Network network : networks) {
                NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
                networkResponses.add(networkResponse);
            }
        }
        response.setResponses(networkResponses);
        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) Network(com.cloud.network.Network) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) ArrayList(java.util.ArrayList)

Aggregations

NetworkResponse (org.apache.cloudstack.api.response.NetworkResponse)16 Network (com.cloud.network.Network)14 ServerApiException (org.apache.cloudstack.api.ServerApiException)11 ArrayList (java.util.ArrayList)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 ListResponse (org.apache.cloudstack.api.response.ListResponse)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 PhysicalNetworkResponse (org.apache.cloudstack.api.response.PhysicalNetworkResponse)5 DataCenter (com.cloud.dc.DataCenter)2 Provider (com.cloud.network.Network.Provider)2 Service (com.cloud.network.Network.Service)2 OvsProvider (com.cloud.network.OvsProvider)2 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)2 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)2 ResourceTag (com.cloud.server.ResourceTag)2 Account (com.cloud.user.Account)2 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2