update to capture peer status

reviewable/pr18780/r1
Mike Mochan 9 years ago committed by Toshio Kuratomi
parent 2392395a47
commit 2291fc00d2

@ -200,12 +200,19 @@ def create_peer_connection(client, module):
return (changed, peering_conn['VpcPeeringConnectionId']) return (changed, peering_conn['VpcPeeringConnectionId'])
if is_pending(peering_conn): if is_pending(peering_conn):
return (changed, peering_conn['VpcPeeringConnectionId']) return (changed, peering_conn['VpcPeeringConnectionId'])
try: try:
peering_conn = client.create_vpc_peering_connection(**params) peering_conn = client.create_vpc_peering_connection(**params)
changed = True changed = True
return (changed, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId']) return (changed, peering_conn['VpcPeeringConnection']['VpcPeeringConnectionId'])
except botocore.exceptions.ClientError as e: except botocore.exceptions.ClientError as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
def peer_status(client, module):
params = dict()
params['VpcPeeringConnectionIds'] = [module.params.get('peering_id')]
vpc_peering_connection = client.describe_vpc_peering_connections(**params)
return vpc_peering_connection['VpcPeeringConnections'][0]['Status']['Code']
def accept_reject_delete(state, client, module): def accept_reject_delete(state, client, module):
@ -218,11 +225,12 @@ def accept_reject_delete(state, client, module):
'reject': client.reject_vpc_peering_connection, 'reject': client.reject_vpc_peering_connection,
'absent': client.delete_vpc_peering_connection 'absent': client.delete_vpc_peering_connection
} }
try: if state == 'absent' or peer_status(client, module) != 'active':
invocations[state](**params) try:
changed = True invocations[state](**params)
except botocore.exceptions.ClientError as e: changed = True
module.fail_json(msg=str(e)) except botocore.exceptions.ClientError as e:
module.fail_json(msg=str(e))
return changed, params['VpcPeeringConnectionId'] return changed, params['VpcPeeringConnectionId']
@ -241,7 +249,7 @@ def main():
module = AnsibleModule(argument_spec=argument_spec) module = AnsibleModule(argument_spec=argument_spec)
if not HAS_BOTO3: if not HAS_BOTO3:
module.fail_json(msg='json and boto/boto3 is required.') module.fail_json(msg='json and boto3 is required.')
state = module.params.get('state').lower() state = module.params.get('state').lower()
try: try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)

Loading…
Cancel
Save