private NodeMetadataBuilder getIpAddresses(IMachine vm, NodeMetadataBuilder nodeMetadataBuilder) {
List<String> publicIpAddresses = Lists.newArrayList();
List<String> privateIpAddresses = Lists.newArrayList();
for (long slot = 0; slot < 4; slot ++) {
INetworkAdapter adapter = vm.getNetworkAdapter(slot);
if (adapter != null) {
if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) {
String hostIP = adapter.getNATEngine().getHostIP();
if (!hostIP.isEmpty())
publicIpAddresses.add(hostIP);
for (String nameProtocolnumberAddressInboudportGuestTargetport : adapter.getNATEngine().getRedirects()) {
Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport);
String protocolNumber = Iterables.get(stuff, 1);
String hostAddress = Iterables.get(stuff, 2);
String inboundPort = Iterables.get(stuff, 3);
String targetPort = Iterables.get(stuff, 5);
if ("1".equals(protocolNumber) && "22".equals(targetPort)) {
int inPort = Integer.parseInt(inboundPort);
publicIpAddresses.add(hostAddress);
nodeMetadataBuilder.loginPort(inPort);
}
}
} else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) {
String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
privateIpAddresses.add(clientIpAddress);
} else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) {
String clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName());
publicIpAddresses.add(clientIpAddress);
}
}
}