From 91644167c92846a2f36111dd5a74fafa6d6f12fa Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Thu, 20 Apr 2017 16:40:37 -0400 Subject: [PATCH] improve exception handling (#23722) make pep8 --- .../modules/cloud/amazon/ec2_vpc_subnet.py | 33 ++++++++++--------- test/sanity/pep8/legacy-files.txt | 1 - 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet.py index ae28392c08..03b599d190 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet.py +++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_subnet.py @@ -113,19 +113,20 @@ class AnsibleTagCreationException(AnsibleVPCSubnetException): def get_subnet_info(subnet): - subnet_info = { 'id': subnet.id, - 'availability_zone': subnet.availability_zone, - 'available_ip_address_count': subnet.available_ip_address_count, - 'cidr_block': subnet.cidr_block, - 'default_for_az': subnet.defaultForAz, - 'map_public_ip_on_launch': subnet.mapPublicIpOnLaunch, - 'state': subnet.state, - 'tags': subnet.tags, - 'vpc_id': subnet.vpc_id - } + subnet_info = {'id': subnet.id, + 'availability_zone': subnet.availability_zone, + 'available_ip_address_count': subnet.available_ip_address_count, + 'cidr_block': subnet.cidr_block, + 'default_for_az': subnet.defaultForAz, + 'map_public_ip_on_launch': subnet.mapPublicIpOnLaunch, + 'state': subnet.state, + 'tags': subnet.tags, + 'vpc_id': subnet.vpc_id + } return subnet_info + def subnet_exists(vpc_conn, subnet_id): filters = {'subnet-id': subnet_id} subnet = vpc_conn.get_all_subnets(filters=filters) @@ -149,6 +150,8 @@ def create_subnet(vpc_conn, vpc_id, cidr, az, check_mode): except EC2ResponseError as e: if e.error_code == "DryRunOperation": subnet = None + elif e.error_code == "InvalidSubnet.Conflict": + raise AnsibleVPCSubnetCreationException("%s: the CIDR %s conflicts with another subnet with the VPC ID %s." % (e.error_code, cidr, vpc_id)) else: raise AnsibleVPCSubnetCreationException( 'Unable to create subnet {0}, error: {1}'.format(cidr, e)) @@ -231,11 +234,11 @@ def main(): argument_spec = ec2_argument_spec() argument_spec.update( dict( - az = dict(default=None, required=False), - cidr = dict(default=None, required=True), - state = dict(default='present', choices=['present', 'absent']), - tags = dict(default={}, required=False, type='dict', aliases=['resource_tags']), - vpc_id = dict(default=None, required=True) + az=dict(default=None, required=False), + cidr=dict(default=None, required=True), + state=dict(default='present', choices=['present', 'absent']), + tags=dict(default={}, required=False, type='dict', aliases=['resource_tags']), + vpc_id=dict(default=None, required=True) ) ) diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index dc758774bc..85d23ddd97 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -181,7 +181,6 @@ lib/ansible/modules/cloud/amazon/ec2_vpc_nat_gateway.py lib/ansible/modules/cloud/amazon/ec2_vpc_net.py lib/ansible/modules/cloud/amazon/ec2_vpc_net_facts.py lib/ansible/modules/cloud/amazon/ec2_vpc_peer.py -lib/ansible/modules/cloud/amazon/ec2_vpc_subnet.py lib/ansible/modules/cloud/amazon/ec2_vpc_vgw.py lib/ansible/modules/cloud/amazon/ec2_vpc_vgw_facts.py lib/ansible/modules/cloud/amazon/ec2_win_password.py