Search in sources :

Example 6 with NetworkResponse

use of com.cloud.api.response.NetworkResponse in project CloudStack-archive by CloudStack-extras.

the class CreateNetworkCmd method execute.

@Override
public // an exception thrown by createNetwork() will be caught by the dispatcher. 
void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
    Network result = _networkService.createNetwork(this);
    if (result != null) {
        NetworkResponse response = _responseGenerator.createNetworkResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) Network(com.cloud.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse)

Example 7 with NetworkResponse

use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createVpcResponse.

@Override
public VpcResponse createVpcResponse(final ResponseView view, final Vpc vpc) {
    final VpcResponse response = new VpcResponse();
    response.setId(vpc.getUuid());
    response.setName(vpc.getName());
    response.setDisplayText(vpc.getDisplayText());
    response.setState(vpc.getState().name());
    final VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
        response.setVpcOfferingName(voff.getName());
        response.setVpcOfferingDisplayText(voff.getDisplayText());
    }
    response.setCidr(vpc.getCidr());
    response.setRestartRequired(vpc.isRestartRequired());
    response.setNetworkDomain(vpc.getNetworkDomain());
    response.setForDisplay(vpc.isDisplay());
    response.setRedundantRouter(vpc.isRedundant());
    response.setSourceNatList(vpc.getSourceNatList());
    response.setSyslogServerList(vpc.getSyslogServerList());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
    final List<ServiceResponse> serviceResponses = getServiceResponses(serviceProviderMap);
    final List<NetworkResponse> networkResponses = new ArrayList<>();
    final List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
    for (final Network network : networks) {
        final NetworkResponse ntwkRsp = createNetworkResponse(view, network);
        networkResponses.add(ntwkRsp);
    }
    final DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setNetworks(networkResponses);
    response.setServices(serviceResponses);
    populateOwner(response, vpc);
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setObjectName("vpc");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) ServiceResponse(com.cloud.api.response.ServiceResponse) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VpcResponse(com.cloud.api.response.VpcResponse) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VpcOffering(com.cloud.network.vpc.VpcOffering) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse)

Example 8 with NetworkResponse

use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.

the class ListNetworksCmd method execute.

@Override
public void execute() {
    final Pair<List<? extends Network>, Integer> networks = _networkService.searchForNetworks(this);
    final ListResponse<NetworkResponse> response = new ListResponse<>();
    final List<NetworkResponse> networkResponses = new ArrayList<>();
    for (final Network network : networks.first()) {
        final NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Restricted, network);
        networkResponses.add(networkResponse);
    }
    response.setResponses(networkResponses, networks.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) Network(com.cloud.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with NetworkResponse

use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.

the class UpdateNetworkCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
    final User callerUser = _accountService.getActiveUser(CallContext.current().getCallingUserId());
    final Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
    final Network network = _networkService.getNetwork(id);
    if (network == null) {
        throw new InvalidParameterValueException("Couldn't find network by ID");
    }
    final Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr(), getDisplayNetwork(), getCustomId(), getDns1(), getDns2(), getIpExclusionList());
    if (result != null) {
        final NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, 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(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Network(com.cloud.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse)

Example 10 with NetworkResponse

use of com.cloud.api.response.NetworkResponse in project cosmic by MissionCriticalCloud.

the class ListNiciraNvpDeviceNetworksCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final List<? extends Network> networks = niciraNvpElementService.listNiciraNvpDeviceNetworks(this);
        final ListResponse<NetworkResponse> response = new ListResponse<>();
        final List<NetworkResponse> networkResponses = new ArrayList<>();
        if (networks != null && !networks.isEmpty()) {
            for (final Network network : networks) {
                final NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(ResponseView.Full, network);
                networkResponses.add(networkResponse);
            }
        }
        response.setResponses(networkResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (final InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (final CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse) ArrayList(java.util.ArrayList)

Aggregations

NetworkResponse (com.cloud.api.response.NetworkResponse)12 Network (com.cloud.network.Network)11 ServerApiException (com.cloud.api.ServerApiException)7 ArrayList (java.util.ArrayList)6 ListResponse (com.cloud.api.response.ListResponse)4 PhysicalNetworkResponse (com.cloud.api.response.PhysicalNetworkResponse)4 Account (com.cloud.user.Account)3 User (com.cloud.user.User)3 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)2 ServiceResponse (com.cloud.api.response.ServiceResponse)2 DataCenter (com.cloud.dc.DataCenter)2 Service (com.cloud.network.Network.Service)2 ResourceTag (com.cloud.server.ResourceTag)2 HashSet (java.util.HashSet)2 List (java.util.List)2 CapabilityResponse (com.cloud.api.response.CapabilityResponse)1 VpcResponse (com.cloud.api.response.VpcResponse)1 Domain (com.cloud.domain.Domain)1 Capability (com.cloud.network.Network.Capability)1