Search in sources :

Example 6 with NicSecondaryIpVO

use of com.cloud.vm.dao.NicSecondaryIpVO 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

NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 Account (com.cloud.user.Account)3 ArrayList (java.util.ArrayList)3 NicResponse (org.apache.cloudstack.api.response.NicResponse)3 NicSecondaryIpResponse (org.apache.cloudstack.api.response.NicSecondaryIpResponse)3 DataCenter (com.cloud.dc.DataCenter)2 ActionEvent (com.cloud.event.ActionEvent)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 TransactionStatus (com.cloud.utils.db.TransactionStatus)2 NicVO (com.cloud.vm.NicVO)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 VirtualMachine (com.cloud.vm.VirtualMachine)2 AffinityGroupResponse (org.apache.cloudstack.affinity.AffinityGroupResponse)2 SecurityGroupResponse (org.apache.cloudstack.api.response.SecurityGroupResponse)2 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 IpAddress (com.cloud.network.IpAddress)1