Search in sources :

Example 6 with NicResponse

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

the class ApiResponseHelper method createNicResponse.

@Override
public NicResponse createNicResponse(Nic result) {
    NicResponse response = new NicResponse();
    NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId());
    VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, result.getInstanceId());
    UserVmJoinVO userVm = _entityMgr.findById(UserVmJoinVO.class, result.getInstanceId());
    response.setId(result.getUuid());
    response.setNetworkid(network.getUuid());
    if (vm != null) {
        response.setVmId(vm.getUuid());
    }
    if (userVm != null) {
        if (userVm.getTrafficType() != null) {
            response.setTrafficType(userVm.getTrafficType().toString());
        }
        if (userVm.getGuestType() != null) {
            response.setType(userVm.getGuestType().toString());
        }
    }
    response.setIpaddress(result.getIPv4Address());
    if (result.getSecondaryIp()) {
        List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(result.getId());
        if (secondaryIps != null) {
            List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();
            for (NicSecondaryIpVO ip : secondaryIps) {
                NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
                ipRes.setId(ip.getUuid());
                ipRes.setIpAddr(ip.getIp4Address());
                ipList.add(ipRes);
            }
            response.setSecondaryIps(ipList);
        }
    }
    response.setGateway(result.getIPv4Gateway());
    response.setNetmask(result.getIPv4Netmask());
    response.setMacAddress(result.getMacAddress());
    if (result.getIPv6Address() != null) {
        response.setIp6Address(result.getIPv6Address());
    }
    if (result.getIPv6Cidr() != null) {
        response.setIp6Cidr(result.getIPv6Cidr());
    }
    response.setDeviceId(String.valueOf(result.getDeviceId()));
    response.setIsDefault(result.isDefaultNic());
    if (result instanceof NicVO) {
        if (((NicVO) result).getNsxLogicalSwitchUuid() != null) {
            response.setNsxLogicalSwitch(((NicVO) result).getNsxLogicalSwitchUuid());
        }
        if (((NicVO) result).getNsxLogicalSwitchPortUuid() != null) {
            response.setNsxLogicalSwitchPort(((NicVO) result).getNsxLogicalSwitchPortUuid());
        }
    }
    return response;
}
Also used : NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicVO(com.cloud.vm.NicVO) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Aggregations

NicResponse (org.apache.cloudstack.api.response.NicResponse)6 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)3 ArrayList (java.util.ArrayList)3 NicSecondaryIpResponse (org.apache.cloudstack.api.response.NicSecondaryIpResponse)3 TrafficType (com.cloud.network.Networks.TrafficType)2 AffinityGroupResponse (org.apache.cloudstack.affinity.AffinityGroupResponse)2 SecurityGroupResponse (org.apache.cloudstack.api.response.SecurityGroupResponse)2 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 ServiceOfferingDetailsVO (com.cloud.service.ServiceOfferingDetailsVO)1 User (com.cloud.user.User)1 Nic (com.cloud.vm.Nic)1 NicVO (com.cloud.vm.NicVO)1 UserVmDetailVO (com.cloud.vm.UserVmDetailVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1