Search in sources :

Example 1 with PortableIpResponse

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

the class ListPortableIpRangesCmd method execute.

@Override
public void execute() {
    ListResponse<PortableIpRangeResponse> response = new ListResponse<PortableIpRangeResponse>();
    List<PortableIpRangeResponse> responses = new ArrayList<PortableIpRangeResponse>();
    List<? extends PortableIpRange> portableIpRanges = _configService.listPortableIpRanges(this);
    if (portableIpRanges != null && !portableIpRanges.isEmpty()) {
        for (PortableIpRange range : portableIpRanges) {
            PortableIpRangeResponse rangeResponse = _responseGenerator.createPortableIPRangeResponse(range);
            List<? extends PortableIp> portableIps = _configService.listPortableIps(range.getId());
            if (portableIps != null && !portableIps.isEmpty()) {
                List<PortableIpResponse> portableIpResponses = new ArrayList<PortableIpResponse>();
                for (PortableIp portableIP : portableIps) {
                    PortableIpResponse portableIpresponse = _responseGenerator.createPortableIPResponse(portableIP);
                    portableIpResponses.add(portableIpresponse);
                }
                rangeResponse.setPortableIpResponses(portableIpResponses);
            }
            responses.add(rangeResponse);
        }
        response.setResponses(responses, portableIpRanges.size());
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : PortableIpRangeResponse(org.apache.cloudstack.api.response.PortableIpRangeResponse) PortableIpResponse(org.apache.cloudstack.api.response.PortableIpResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) PortableIp(org.apache.cloudstack.region.PortableIp) ArrayList(java.util.ArrayList) PortableIpRange(org.apache.cloudstack.region.PortableIpRange)

Example 2 with PortableIpResponse

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

the class ApiResponseHelper method createPortableIPResponse.

@Override
public PortableIpResponse createPortableIPResponse(PortableIp portableIp) {
    PortableIpResponse response = new PortableIpResponse();
    response.setAddress(portableIp.getAddress());
    Long accountId = portableIp.getAllocatedInDomainId();
    if (accountId != null) {
        Account account = ApiDBUtils.findAccountById(accountId);
        response.setAllocatedToAccountId(account.getAccountName());
        Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
        response.setAllocatedInDomainId(domain.getUuid());
    }
    response.setAllocatedTime(portableIp.getAllocatedTime());
    if (portableIp.getAssociatedDataCenterId() != null) {
        DataCenter zone = ApiDBUtils.findZoneById(portableIp.getAssociatedDataCenterId());
        if (zone != null) {
            response.setAssociatedDataCenterId(zone.getUuid());
        }
    }
    if (portableIp.getPhysicalNetworkId() != null) {
        PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(portableIp.getPhysicalNetworkId());
        if (pnw != null) {
            response.setPhysicalNetworkId(pnw.getUuid());
        }
    }
    if (portableIp.getAssociatedWithNetworkId() != null) {
        Network ntwk = ApiDBUtils.findNetworkById(portableIp.getAssociatedWithNetworkId());
        if (ntwk != null) {
            response.setAssociatedWithNetworkId(ntwk.getUuid());
        }
    }
    if (portableIp.getAssociatedWithVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(portableIp.getAssociatedWithVpcId());
        if (vpc != null) {
            response.setAssociatedWithVpcId(vpc.getUuid());
        }
    }
    response.setState(portableIp.getState().name());
    response.setObjectName("portableip");
    return response;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) PortableIpResponse(org.apache.cloudstack.api.response.PortableIpResponse) DataCenter(com.cloud.dc.DataCenter) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Vpc(com.cloud.network.vpc.Vpc) Domain(com.cloud.domain.Domain)

Aggregations

PortableIpResponse (org.apache.cloudstack.api.response.PortableIpResponse)2 DataCenter (com.cloud.dc.DataCenter)1 Domain (com.cloud.domain.Domain)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 Vpc (com.cloud.network.vpc.Vpc)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 ArrayList (java.util.ArrayList)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 PortableIpRangeResponse (org.apache.cloudstack.api.response.PortableIpRangeResponse)1 PortableIp (org.apache.cloudstack.region.PortableIp)1 PortableIpRange (org.apache.cloudstack.region.PortableIpRange)1