updates to Documentation - Removed refs to Boto, added params dict() and removed obsolete if statements

reviewable/pr18780/r1
Mike Mochan 9 years ago committed by Toshio Kuratomi
parent 34ae687ae3
commit f6c7bdf9c5

@ -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,21 +147,14 @@ 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:
@ -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,15 +206,8 @@ 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))
@ -245,19 +215,23 @@ def create_peer_connection(client, module):
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))
@ -265,7 +239,7 @@ def accept_reject_delete(state, client, resource, module):
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:

Loading…
Cancel
Save