use of com.cloud.api.command.admin.cloudops.ListWhoHasThisIpCmd in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method listWhoHasThisIp.
@Override
public ListResponse<WhoHasThisAddressResponse> listWhoHasThisIp(final ListWhoHasThisIpCmd cmd) {
final ListResponse<WhoHasThisAddressResponse> whoHasThisIpList = new ListResponse<>();
final List<WhoHasThisAddressResponse> responsesList = new ArrayList<>();
final String cleanedIpAddress = StringUtils.deleteWhitespace(cmd.getIpAddress());
final List<IPAddressVO> ipAddresses = _ipAddressDao.listByIpAddress(cleanedIpAddress);
ipAddresses.forEach(ipAddress -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
response.setIpAddress(ipAddress.getAddress().toString());
response.setUuid(ipAddress.getUuid());
response.setState(ipAddress.getState().toString());
final Domain domain = _domainDao.findById(ipAddress.getDomainId());
if (domain != null) {
response.setDomainName(domain.getName());
response.setDomainUuid(domain.getUuid());
}
final Network network = _networkDao.findById(ipAddress.getNetworkId());
if (network != null) {
response.setNetworkUuid(network.getUuid());
response.setCreated(ipAddress.getAllocatedTime());
response.setMode(network.getMode());
}
if (ipAddress.getVpcId() != null) {
final Vpc vpc = _vpcDao.findById(ipAddress.getVpcId());
if (vpc != null) {
response.setNetworkName(vpc.getName());
response.setVpcName(vpc.getName());
response.setVpcUuid(vpc.getUuid());
}
} else if (network != null && !StringUtils.isEmpty(network.getName())) {
response.setNetworkName(network.getName());
}
final Network associatedNetwork = _networkDao.findById(ipAddress.getAssociatedWithNetworkId());
if (associatedNetwork != null) {
response.setAssociatedNetworkName(associatedNetwork.getName());
response.setAssociatedNetworkUuid(associatedNetwork.getUuid());
}
responsesList.add(response);
});
final List<NicVO> nics = _nicDao.listByIpAddress(cleanedIpAddress);
nics.forEach(nic -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
queryNicsTableResponse(responsesList, nic, response);
});
final List<NicSecondaryIpVO> nicSecondaryIps = _nicSecondaryIpDao.listByIpAddress(cleanedIpAddress);
nicSecondaryIps.forEach(nicSecondaryIp -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
response.setIpAddress(nicSecondaryIp.getIp4Address());
response.setUuid(nicSecondaryIp.getUuid());
response.setCreated(nicSecondaryIp.getCreated());
final NicVO nicVO = _nicDao.findById(nicSecondaryIp.getNicId());
if (nicVO != null) {
response.setMode(nicVO.getMode());
response.setBroadcastUri(nicVO.getBroadcastUri());
response.setNetmask(nicVO.getIPv4Netmask());
response.setMacAddress(nicVO.getMacAddress());
response.setState(nicVO.getState().toString());
}
final Network network = _networkDao.findById(nicSecondaryIp.getNetworkId());
if (network != null) {
response.setNetworkUuid(network.getUuid());
if (!StringUtils.isEmpty(network.getName())) {
response.setNetworkName(network.getName());
}
}
final VMInstanceVO vm = _vmInstanceDao.findById(nicSecondaryIp.getVmId());
getVMInfo(response, nicVO, vm);
responsesList.add(response);
});
final Account account = CallContext.current().getCallingAccount();
final Domain domain = _domainDao.findById(account.getDomainId());
final List<WhoHasThisAddressResponse> filteredResponsesList = responsesList.stream().filter(response -> ((account.getDomainId() == Domain.ROOT_DOMAIN || domain.getUuid().equals(response.getDomainUuid())) && (StringUtils.isEmpty(cmd.getUuid()) || (!StringUtils.isEmpty(cmd.getUuid()) && response.getUuid().equals(cmd.getUuid()))))).skip(cmd.getStartIndex()).limit(cmd.getPageSizeVal()).collect(Collectors.toList());
whoHasThisIpList.setResponses(filteredResponsesList);
return whoHasThisIpList;
}
Aggregations