Skip to content

Commit

Permalink
Merge pull request #435 from mmojzis/fix_ec2_subnets_and_routers_list
Browse files Browse the repository at this point in the history
[RFR]List routers/subnets that have tags and don't have Name tag
  • Loading branch information
mshriver authored Feb 5, 2020
2 parents d968deb + 8a398d5 commit 956b4b7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions wrapanapi/systems/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,12 +1237,15 @@ def list_subnet(self):
# Subnets are not having mandatory tags names. They can have multiple tags, but only the tag
# 'Name' will be taken as the subnet name. If not tag is given, CFME displays the SubnetId
for subnet in subnets:
subnet_name = None
if 'Tags' in subnet and subnet['Tags']:
for tag in subnet['Tags']:
if 'Name' in list(tag.values()):
subnets_names.append(tag['Value'])
else:
subnets_names.append(subnet['SubnetId'])
subnet_name = tag['Value']
break
if not subnet_name:
subnet_name = subnet['SubnetId']
subnets_names.append(subnet_name)
return subnets_names

def list_security_group(self):
Expand All @@ -1258,13 +1261,15 @@ def list_router(self):
# used to name the router. If no tag name is provided, the routerTableId will be
# displayed as name in CFME.
for route in route_tables:
router_name = None
if route['Tags']:
for tag in route['Tags']:
if 'Name' in list(tag.values()):
routers_names.append(tag['Value'])
else:
routers_names.append(route['RouteTableId'])

router_name = tag['Value']
break
if not router_name:
router_name = route['RouteTableId']
routers_names.append(router_name)
return routers_names

def list_own_snapshots(self):
Expand Down

0 comments on commit 956b4b7

Please sign in to comment.