def get_agent_regions()

in source/CRRdeployagent/CRRdeployagent.py [0:0]


def get_agent_regions():
    try:
        client = boto3.client('s3')
        replica_buckets = get_replica_buckets(client)
        agent_set = set([])
        for bucket in replica_buckets:
            try:
                response = client.head_bucket(
                    Bucket=bucket
                )
                region = response['ResponseMetadata']['HTTPHeaders']['x-amz-bucket-region']
                if region == None:
                    region = 'us-east-1'
                agent_set.add(region)
            except Exception as e:
                print('Unable to get region for bucket ' + bucket)
                print(e)

        for bucket in source_buckets:
            try:
                response = client.head_bucket(
                    Bucket=bucket
                )
                region = response['ResponseMetadata']['HTTPHeaders']['x-amz-bucket-region']
                if region == None:
                    region = 'us-east-1'
                agent_set.add(region)
            except Exception as e:
                print('Unable to get region for bucket ' + bucket)
                print(e)

        agent_regions = list(agent_set)
        print('get_agent_regions: agent_regions = ')
        print(*agent_regions, sep = "\n")
    except Exception as e:
        print(e)
        raise e
    return agent_regions