Search in sources :

Example 11 with NetworkResponse

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

the class UpdateNetworkCmdByAdmin method execute.

@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
    User callerUser = _accountService.getActiveUser(CallContext.current().getCallingUserId());
    Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
    Network network = _networkService.getNetwork(id);
    if (network == null) {
        throw new InvalidParameterValueException("Couldn't find network by id");
    }
    Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId(), getUpdateInSequence(), getForced());
    if (result != null) {
        NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
    }
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse)

Example 12 with NetworkResponse

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

the class CreateNetworkCmdByAdmin method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public // an exception thrown by createNetwork() will be caught by the dispatcher.
void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
    Network result = _networkService.createGuestNetwork(this);
    if (result != null) {
        NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, 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) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse)

Example 13 with NetworkResponse

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

the class UpdateNetworkCmd method execute.

@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
    Network network = _networkService.getNetwork(id);
    if (network == null) {
        throw new InvalidParameterValueException("Couldn't find network by ID");
    }
    Network result = _networkService.updateGuestNetwork(this);
    if (result != null) {
        NetworkResponse response = _responseGenerator.createNetworkResponse(getResponseView(), result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update network");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse)

Example 14 with NetworkResponse

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

the class ListF5LoadBalancerNetworksCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<? extends Network> networks = _f5DeviceManagerService.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 15 with NetworkResponse

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

the class ListNetscalerLoadBalancerNetworksCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<? extends Network> networks = _netsclarLbService.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)

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