From f6c7bdf9c531363c7a4e46082f311df28d320d30 Mon Sep 17 00:00:00 2001 From: Mike Mochan Date: Sat, 9 Jan 2016 15:38:39 +1000 Subject: [PATCH] updates to Documentation - Removed refs to Boto, added params dict() and removed obsolete if statements --- cloud/amazon/ec2_vpc_peer.py | 73 ++++++++++++------------------------ 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/cloud/amazon/ec2_vpc_peer.py b/cloud/amazon/ec2_vpc_peer.py index d68dec96334..9093a7c60bd 100644 --- a/cloud/amazon/ec2_vpc_peer.py +++ b/cloud/amazon/ec2_vpc_peer.py @@ -39,29 +39,6 @@ options: required: false default: present choices: ['present', 'absent', 'accept', 'reject'] - region: - description: - - The AWS region to use. Must be specified if ec2_url is not used. If not specified then the value of the EC2_REGION environment variable, if any, is used. - required: false - default: null - aliases: ['aws_region', 'ec2_region'] - profile: - description: - - boto3 profile name. - required: false - default: None - aws_secret_key: - description: - - AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used. - required: false - default: None - aliases: ['ec2_secret_key', 'secret_key'] - aws_access_key: - description: - - AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used. - required: false - default: None - aliases: ['ec2_access_key', 'access_key'] author: Mike Mochan(@mmochan) extends_documentation_fragment: aws ''' @@ -170,26 +147,19 @@ EXAMPLES = ''' ''' RETURN = ''' task: - description: details about the tast that was started - type: complex - sample: "TODO: include sample" + description: The result of the create, accept, reject or delete action. + returned: success + type: dictionary ''' try: import json - import datetime - import boto import botocore - HAS_BOTO = True -except ImportError: - HAS_BOTO = False - -try: import boto3 HAS_BOTO3 = True except ImportError: HAS_BOTO3 = False - + def describe_peering_connections(vpc_id, peer_vpc_id, client): result = client.describe_vpc_peering_connections(Filters=[ @@ -220,6 +190,13 @@ def peer_status(resource, module): def create_peer_connection(client, module): changed = False + params = dict() + params['VpcId'] = module.params.get('vpc_id') + params['PeerVpcId'] = module.params.get('peer_vpc_id') + if module.params.get('peer_owner_id'): + params['PeerOwnerId'] = str(module.params.get('peer_owner_id')) + params['DryRun'] = module.check_mode + vpc_id = module.params.get('vpc_id') peer_vpc_id = module.params.get('peer_vpc_id') peer_owner_id = module.params.get('peer_owner_id', False) @@ -229,43 +206,40 @@ def create_peer_connection(client, module): return (False, peering_conn['VpcPeeringConnectionId']) if is_pending(peering_conn): return (False, peering_conn['VpcPeeringConnectionId']) - if not peer_owner_id: - try: - peering_conn = client.create_vpc_peering_connection(VpcId=vpc_id, PeerVpcId=peer_vpc_id) - return (True, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId']) - except botocore.exceptions.ClientError as e: - module.fail_json(msg=str(e)) - else: try: - peering_conn = client.create_vpc_peering_connection(VpcId=vpc_id, PeerVpcId=peer_vpc_id, PeerOwnerId=str(peer_owner_id)) + peering_conn = client.create_vpc_peering_connection(**params) return (True, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId']) except botocore.exceptions.ClientError as e: - module.fail_json(msg=str(e)) + module.fail_json(msg=str(e)) def accept_reject_delete(state, client, resource, module): changed = False + params = dict() + params['VpcPeeringConnectionId'] = module.params.get('peering_id') + params['DryRun'] = module.check_mode + peer_id = module.params.get('peering_id') if state == "accept": if peer_status(resource, module) == "Active": return (False, peer_id) try: - client.accept_vpc_peering_connection(VpcPeeringConnectionId=peer_id) + client.accept_vpc_peering_connection(**params) return (True, peer_id) except botocore.exceptions.ClientError as e: module.fail_json(msg=str(e)) if state == "reject": if peer_status(resource, module) != "Active": try: - client.reject_vpc_peering_connection(VpcPeeringConnectionId=peer_id) + client.reject_vpc_peering_connection(**params) return (True, peer_id) except botocore.exceptions.ClientError as e: module.fail_json(msg=str(e)) else: - return (False, peer_id) + return (False, peer_id) if state == "absent": try: - client.delete_vpc_peering_connection(VpcPeeringConnectionId=peer_id) + client.delete_vpc_peering_connection(**params) return (True, peer_id) except botocore.exceptions.ClientError as e: module.fail_json(msg=str(e)) @@ -275,18 +249,17 @@ def accept_reject_delete(state, client, resource, module): def main(): argument_spec = ec2_argument_spec() argument_spec.update(dict( - region=dict(), vpc_id=dict(), peer_vpc_id=dict(), - peer_owner_id=dict(), peering_id=dict(), + peer_owner_id=dict(), profile=dict(), state=dict(default='present', choices=['present', 'absent', 'accept', 'reject']) ) ) module = AnsibleModule(argument_spec=argument_spec) - if not (HAS_BOTO or HAS_BOTO3): + if not HAS_BOTO3: module.fail_json(msg='json and boto/boto3 is required.') state = module.params.get('state').lower() try: