Search in sources :

Example 1 with VlanIpRangeResponse

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

the class DedicatePublicIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    Vlan result = _configService.dedicatePublicIpRange(this);
    if (result != null) {
        VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate vlan ip range");
    }
}
Also used : VlanIpRangeResponse(org.apache.cloudstack.api.response.VlanIpRangeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Vlan(com.cloud.dc.Vlan)

Example 2 with VlanIpRangeResponse

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

the class ListVlanIpRangesCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Vlan>, Integer> vlans = _mgr.searchForVlans(this);
    ListResponse<VlanIpRangeResponse> response = new ListResponse<VlanIpRangeResponse>();
    List<VlanIpRangeResponse> vlanResponses = new ArrayList<VlanIpRangeResponse>();
    for (Vlan vlan : vlans.first()) {
        VlanIpRangeResponse vlanResponse = _responseGenerator.createVlanIpRangeResponse(vlan);
        vlanResponse.setObjectName("vlaniprange");
        vlanResponses.add(vlanResponse);
    }
    response.setResponses(vlanResponses, vlans.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : VlanIpRangeResponse(org.apache.cloudstack.api.response.VlanIpRangeResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(com.cloud.dc.Vlan)

Example 3 with VlanIpRangeResponse

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

the class CreateVlanIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        Vlan result = _configService.createVlanAndPublicIpRange(this);
        if (result != null) {
            VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vlan ip range");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
}
Also used : VlanIpRangeResponse(org.apache.cloudstack.api.response.VlanIpRangeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Vlan(com.cloud.dc.Vlan) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 4 with VlanIpRangeResponse

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

the class ApiResponseHelper method createVlanIpRangeResponse.

@Override
public VlanIpRangeResponse createVlanIpRangeResponse(Class<? extends VlanIpRangeResponse> subClass, Vlan vlan) {
    try {
        Long podId = ApiDBUtils.getPodIdForVlan(vlan.getId());
        VlanIpRangeResponse vlanResponse = subClass.newInstance();
        vlanResponse.setId(vlan.getUuid());
        if (vlan.getVlanType() != null) {
            vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
        }
        vlanResponse.setVlan(vlan.getVlanTag());
        DataCenter zone = ApiDBUtils.findZoneById(vlan.getDataCenterId());
        if (zone != null) {
            vlanResponse.setZoneId(zone.getUuid());
        }
        if (podId != null) {
            HostPodVO pod = ApiDBUtils.findPodById(podId);
            if (pod != null) {
                vlanResponse.setPodId(pod.getUuid());
                vlanResponse.setPodName(pod.getName());
            }
        }
        vlanResponse.setGateway(vlan.getVlanGateway());
        vlanResponse.setNetmask(vlan.getVlanNetmask());
        // get start ip and end ip of corresponding vlan
        String ipRange = vlan.getIpRange();
        if (ipRange != null) {
            String[] range = ipRange.split("-");
            vlanResponse.setStartIp(range[0]);
            vlanResponse.setEndIp(range[1]);
        }
        vlanResponse.setIp6Gateway(vlan.getIp6Gateway());
        vlanResponse.setIp6Cidr(vlan.getIp6Cidr());
        String ip6Range = vlan.getIp6Range();
        if (ip6Range != null) {
            String[] range = ip6Range.split("-");
            vlanResponse.setStartIpv6(range[0]);
            vlanResponse.setEndIpv6(range[1]);
        }
        if (vlan.getNetworkId() != null) {
            Network nw = ApiDBUtils.findNetworkById(vlan.getNetworkId());
            if (nw != null) {
                vlanResponse.setNetworkId(nw.getUuid());
            }
        }
        Account owner = ApiDBUtils.getVlanAccount(vlan.getId());
        if (owner != null) {
            populateAccount(vlanResponse, owner.getId());
            populateDomain(vlanResponse, owner.getDomainId());
        } else {
            Domain domain = ApiDBUtils.getVlanDomain(vlan.getId());
            if (domain != null) {
                populateDomain(vlanResponse, domain.getId());
            } else {
                Long networkId = vlan.getNetworkId();
                if (networkId != null) {
                    Network network = _ntwkModel.getNetwork(networkId);
                    if (network != null) {
                        Long accountId = network.getAccountId();
                        populateAccount(vlanResponse, accountId);
                        populateDomain(vlanResponse, ApiDBUtils.findAccountById(accountId).getDomainId());
                    }
                }
            }
        }
        if (vlan.getPhysicalNetworkId() != null) {
            PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
            if (pnw != null) {
                vlanResponse.setPhysicalNetworkId(pnw.getUuid());
            }
        }
        vlanResponse.setObjectName("vlan");
        return vlanResponse;
    } catch (InstantiationException | IllegalAccessException e) {
        throw new CloudRuntimeException("Failed to create Vlan IP Range response", e);
    }
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) VlanIpRangeResponse(org.apache.cloudstack.api.response.VlanIpRangeResponse) HostPodVO(com.cloud.dc.HostPodVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Domain(com.cloud.domain.Domain)

Aggregations

VlanIpRangeResponse (org.apache.cloudstack.api.response.VlanIpRangeResponse)4 Vlan (com.cloud.dc.Vlan)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 DataCenter (com.cloud.dc.DataCenter)1 HostPodVO (com.cloud.dc.HostPodVO)1 Domain (com.cloud.domain.Domain)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1