File size: 4,660 Bytes
5980447 |
1 2 |
{"repo": "zalando/spilo", "pull_number": 177, "instance_id": "zalando__spilo-177", "issue_numbers": "", "base_commit": "3f96f137a9ce23f9d487b9598bdefbbd2467b446", "patch": "diff --git a/postgres-appliance/callback_aws.py b/postgres-appliance/callback_aws.py\n--- a/postgres-appliance/callback_aws.py\n+++ b/postgres-appliance/callback_aws.py\n@@ -1,15 +1,11 @@\n #!/usr/bin/env python\n \n-import boto3\n+import boto.ec2\n+import boto.utils\n import logging\n-import requests\n import sys\n import time\n \n-from botocore.exceptions import ClientError\n-from requests.exceptions import RequestException\n-\n-\n logger = logging.getLogger(__name__)\n \n \n@@ -19,47 +15,39 @@ def wrapped(*args, **kwargs):\n while True:\n try:\n return func(*args, **kwargs)\n- except ClientError as e:\n- if not (e.response['Error']['Code'] == 'Throttling' or 'RequestLimitExceeded' in str(e)):\n+ except boto.exception.BotoServerError as e:\n+ if count >= 10 or str(e.error_code) not in ('Throttling', 'RequestLimitExceeded'):\n raise\n logger.info('Throttling AWS API requests...')\n- except RequestException:\n- logger.exception('Exception when running %s', func)\n+ time.sleep(2 ** count * 0.5)\n+ count += 1\n \n- if count >= 10:\n- break\n- time.sleep(2 ** count * 0.5)\n- count += 1\n return wrapped\n \n \n-@retry\n def get_instance_metadata():\n- response = requests.get('http://169.254.169.254/latest/dynamic/instance-identity/document')\n- return response.json() if response.ok else {}\n+ return boto.utils.get_instance_identity()['document']\n \n \n @retry\n def associate_address(ec2, allocation_id, instance_id):\n- return ec2.associate_address(AllocationId=allocation_id, InstanceId=instance_id, AllowReassociation=True)\n+ return ec2.associate_address(instance_id=instance_id, allocation_id=allocation_id, allow_reassociation=True)\n \n \n @retry\n def tag_instance(ec2, instance_id, tags):\n- return ec2.create_tags(Resources=[instance_id], Tags=tags)\n+ return ec2.create_tags([instance_id], tags)\n \n \n @retry\n def list_volumes(ec2, instance_id):\n- paginator = ec2.get_paginator('describe_volumes')\n- for record_set in paginator.paginate(Filters=[{'Name': 'attachment.instance-id', 'Values': [instance_id]}]):\n- for volume in record_set['Volumes']:\n- yield volume['VolumeId']\n+ volumes = ec2.get_all_volumes(filters={'attachment.instance-id': instance_id})\n+ return [v.id for v in volumes]\n \n \n @retry\n-def tag_volumes(ec2, instance_id, tags):\n- return ec2.create_tags(Resources=list(list_volumes(ec2, instance_id)), Tags=tags)\n+def tag_volumes(ec2, volumes, tags):\n+ return ec2.create_tags(volumes, tags)\n \n \n def main():\n@@ -73,16 +61,17 @@ def main():\n \n instance_id = metadata['instanceId']\n \n- ec2 = boto3.client('ec2', region_name=metadata['region'])\n+ ec2 = boto.ec2.connect_to_region(metadata['region'])\n \n if role == 'master' and action in ('on_start', 'on_role_change'):\n associate_address(ec2, sys.argv[1], instance_id)\n \n- tags = [{'Key': 'Role', 'Value': role}]\n+ tags = {'Role': role}\n tag_instance(ec2, instance_id, tags)\n \n- tags += [{'Key': 'Instance', 'Value': instance_id}, {'Key': 'Name', 'Value': 'spilo_' + cluster}]\n- tag_volumes(ec2, instance_id, tags)\n+ tags.update({'Instance': instance_id, 'Name': 'spilo_' + cluster})\n+ volumes = list_volumes(ec2, instance_id)\n+ tag_volumes(ec2, volumes, tags)\n \n \n if __name__ == '__main__':\ndiff --git a/postgres-appliance/configure_spilo.py b/postgres-appliance/configure_spilo.py\n--- a/postgres-appliance/configure_spilo.py\n+++ b/postgres-appliance/configure_spilo.py\n@@ -282,7 +282,7 @@ def get_placeholders(provider):\n placeholders['USE_WALE'] = True\n if not USE_KUBERNETES: # AWS specific callback to tag the instances with roles\n if placeholders.get('EIP_ALLOCATION'):\n- placeholders['CALLBACK_SCRIPT'] = '/callback_aws.py {0}'.format(placeholders['EIP_ALLOCATION'])\n+ placeholders['CALLBACK_SCRIPT'] = 'python3 /callback_aws.py {0}'.format(placeholders['EIP_ALLOCATION'])\n else:\n placeholders['CALLBACK_SCRIPT'] = 'patroni_aws'\n elif provider == PROVIDER_GOOGLE and 'WAL_GCS_BUCKET' in placeholders:\n", "test_patch": "", "problem_statement": "", "hints_text": "", "created_at": "2017-07-28T07:25:34Z"}
|