def _getCurrentAWSZone(spotBid=None, nodeType=None, ctx=None): zone = None try: import boto from boto.utils import get_instance_metadata except ImportError: pass else: zone = os.environ.get('TOIL_AWS_ZONE', None) if not zone and runningOnEC2(): try: zone = get_instance_metadata()['placement']['availability-zone'] except KeyError: pass if not zone and spotBid: # if spot bid is present, all the other parameters must be as well assert bool(spotBid) == bool(nodeType) == bool(ctx) # if the zone is unset and we are using the spot market, optimize our # choice based on the spot history return optimize_spot_bid(ctx=ctx, instance_type=nodeType, spot_bid=float(spotBid)) if not zone: zone = boto.config.get('Boto', 'ec2_region_name') if zone is not None: zone += 'a' # derive an availability zone in the region return zone