1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

improve exception handling (#23722)

make pep8
This commit is contained in:
Sloane Hertel 2017-04-20 16:40:37 -04:00 committed by Ryan Brown
parent 11c292bac2
commit 91644167c9
2 changed files with 18 additions and 16 deletions

View file

@ -113,19 +113,20 @@ class AnsibleTagCreationException(AnsibleVPCSubnetException):
def get_subnet_info(subnet): def get_subnet_info(subnet):
subnet_info = { 'id': subnet.id, subnet_info = {'id': subnet.id,
'availability_zone': subnet.availability_zone, 'availability_zone': subnet.availability_zone,
'available_ip_address_count': subnet.available_ip_address_count, 'available_ip_address_count': subnet.available_ip_address_count,
'cidr_block': subnet.cidr_block, 'cidr_block': subnet.cidr_block,
'default_for_az': subnet.defaultForAz, 'default_for_az': subnet.defaultForAz,
'map_public_ip_on_launch': subnet.mapPublicIpOnLaunch, 'map_public_ip_on_launch': subnet.mapPublicIpOnLaunch,
'state': subnet.state, 'state': subnet.state,
'tags': subnet.tags, 'tags': subnet.tags,
'vpc_id': subnet.vpc_id 'vpc_id': subnet.vpc_id
} }
return subnet_info return subnet_info
def subnet_exists(vpc_conn, subnet_id): def subnet_exists(vpc_conn, subnet_id):
filters = {'subnet-id': subnet_id} filters = {'subnet-id': subnet_id}
subnet = vpc_conn.get_all_subnets(filters=filters) 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: except EC2ResponseError as e:
if e.error_code == "DryRunOperation": if e.error_code == "DryRunOperation":
subnet = None 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: else:
raise AnsibleVPCSubnetCreationException( raise AnsibleVPCSubnetCreationException(
'Unable to create subnet {0}, error: {1}'.format(cidr, e)) 'Unable to create subnet {0}, error: {1}'.format(cidr, e))
@ -231,11 +234,11 @@ def main():
argument_spec = ec2_argument_spec() argument_spec = ec2_argument_spec()
argument_spec.update( argument_spec.update(
dict( dict(
az = dict(default=None, required=False), az=dict(default=None, required=False),
cidr = dict(default=None, required=True), cidr=dict(default=None, required=True),
state = dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
tags = dict(default={}, required=False, type='dict', aliases=['resource_tags']), tags=dict(default={}, required=False, type='dict', aliases=['resource_tags']),
vpc_id = dict(default=None, required=True) vpc_id=dict(default=None, required=True)
) )
) )

View file

@ -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.py
lib/ansible/modules/cloud/amazon/ec2_vpc_net_facts.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_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.py
lib/ansible/modules/cloud/amazon/ec2_vpc_vgw_facts.py lib/ansible/modules/cloud/amazon/ec2_vpc_vgw_facts.py
lib/ansible/modules/cloud/amazon/ec2_win_password.py lib/ansible/modules/cloud/amazon/ec2_win_password.py