} else {
// Fill in the metadata from the available node metadata
// Get the IP address
if (cMetadata.containsField("publicAddresses")) {
BasicDBList publicAddresses = (BasicDBList) cMetadata.get("publicAddresses");
// TODO: How do we want to handle multiple IP addresses?
if (publicAddresses.size() > 0) {
civMetadata.put("targetIP", publicAddresses.get(0));
}
}
// Get location information (ISO 3166 code, region and availability zone)
if (cMetadata.containsField("location") && cMetadata.get("location") != null) {
BasicDBObject location = (BasicDBObject) cMetadata.get("location");
boolean regionProcessed = false;
boolean zoneProcessed = false;
while (location != null) {
if (regionProcessed && zoneProcessed) {
break;
}
String locationScope = location.containsField("scope") ? location.getString("scope") : null;
if (locationScope != null) {
LocationScope scope = LocationScope.valueOf(locationScope);
switch (scope) {
case REGION:
civMetadata.put("targetRegion", location.get("id"));
regionProcessed = true;
break;
case ZONE:
BasicDBList iso3166Codes = (BasicDBList) location.get("iso3166Codes");
civMetadata.put("targetISO3166Code", iso3166Codes.get(0));
civMetadata.put("targetZone", location.get("id"));
zoneProcessed = true;
break;
}
}