public static Set<String> getIpsFromVApp(VApp vApp) {
// TODO make this work with composite vApps
if (vApp.getChildren().isEmpty())
return ImmutableSet.of();
Builder<String> ips = ImmutableSet.builder();
Vm vm = Iterables.get(vApp.getChildren(), 0);
// TODO: figure out how to differentiate public from private ip addresses
// assumption is that we'll do this from the network object, which may
// have
// enough data to tell whether or not it is a public network without
// string
// parsing. At worst, we could have properties set per cloud provider to
// declare the networks which are public, then check against these in
// networkconnection.getNetwork
if (vm.getNetworkConnectionSection() != null) {
for (NetworkConnection connection : vm.getNetworkConnectionSection().getConnections()) {
if (connection.getIpAddress() != null)
ips.add(connection.getIpAddress());
if (connection.getExternalIpAddress() != null)
ips.add(connection.getExternalIpAddress());
}
} else {
for (ResourceAllocationSettingData net : filter(vm.getVirtualHardwareSection().getItems(),
CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
if (net instanceof VCloudNetworkAdapter) {
VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
if (vNet.getIpAddress() != null)
ips.add(vNet.getIpAddress());