if (zone == null || iaasInfo == null) {
String msg =
"Zone or IaaSProvider is null: zone: " + zone + " - IaaSProvider: " +
iaasInfo;
log.error(msg);
throw new InvalidZoneException(msg);
}
ComputeServiceContext context = iaasInfo.getComputeService().getContext();
AvailabilityZoneAndRegionApi zoneRegionApi = context.unwrapApi(AWSEC2Api.class).
getAvailabilityZoneAndRegionApiForRegion(region).get();
Set<AvailabilityZoneInfo> availabilityZones =
zoneRegionApi.describeAvailabilityZonesInRegion(region,
new DescribeAvailabilityZonesOptions[0]);
for (AvailabilityZoneInfo zoneInfo : availabilityZones) {
String configuredZone = zoneInfo.getZone();
if (zone.equalsIgnoreCase(configuredZone)) {
if (log.isDebugEnabled()) {
log.debug("Found a matching zone: " + zone);
}
return true;
}
}
String msg = "Invalid zone: " + zone +" in the region: "+region+ " and of the iaas: "+iaasInfo.getType();
log.error(msg);
throw new InvalidZoneException(msg);
}