Skip to content

Commit a3b1345

Browse files
committed
aws sg: use tag name
1 parent 9a99c59 commit a3b1345

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

kvirt/providers/aws/__init__.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,15 @@ def get_security_groups(self, name):
595595
def get_security_group_id(self, name, vpcid):
596596
conn = self.conn
597597
for sg in conn.describe_security_groups()['SecurityGroups']:
598-
if sg['VpcId'] == vpcid and (sg['GroupName'] == name or sg['GroupId'] == name):
598+
group_name = sg['GroupName']
599+
group_id = sg['GroupId']
600+
group_tag = sg['GroupId']
601+
group_name = ''
602+
for tag in sg.get('Tags', []):
603+
if tag['Key'] == 'Name':
604+
group_name = tag['Value']
605+
break
606+
if sg['VpcId'] == vpcid and (group_name == name or group_id == name or group_tag == name):
599607
return sg['GroupId']
600608
return None
601609

@@ -1725,7 +1733,12 @@ def list_security_groups(self, network=None):
17251733
for sg in conn.describe_security_groups()['SecurityGroups']:
17261734
if vpcid is not None and sg['VpcId'] != vpcid:
17271735
continue
1728-
results.append(sg['GroupName'])
1736+
group_name = sg['GroupName']
1737+
for tag in sg.get('Tags', []):
1738+
if tag['Key'] == 'Name':
1739+
group_name = tag['Value']
1740+
break
1741+
results.append(group_name)
17291742
return results
17301743

17311744
def create_security_group(self, name, overrides={}):

0 commit comments

Comments
 (0)