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;
}
Aggregations