Commit 0e11e3a7 authored by Sigmund Augdal's avatar Sigmund Augdal

Allow finding references for library groups

parent f5f8f8db
......@@ -166,6 +166,13 @@ def get_library_entry(etcd_client, group_id, entry_id):
def del_library_entry(etcd_client, group_id, entry_id):
entry_key = library_group_entry_key(group_id, entry_id)
etcd_client.delete(entry_key, recursive=True)
def get_group_references(etcd_client, groupid, library=False):
if library:
match_rule = "source_library_group"
else:
match_rule = "source_security_group"
references = []
try:
for entry in etcd_client.read(security_group_key(), recursive=True,
......@@ -174,7 +181,7 @@ def del_library_entry(etcd_client, group_id, entry_id):
if len(parts) < 4:
continue
referer_group, _, rule_id, rule_target = parts[-4:]
if rule_target == "source_security_group" and entry.value == groupid:
if rule_target == match_rule and entry.value == groupid:
print(entry.key)
references.append((referer_group, rule_id))
except KeyError:
......
......@@ -96,7 +96,8 @@ def main():
if args.make_shared:
security_groups.set_group_cloud(etcd_client, args.make_shared, None, library=args.library)
if args.get_references:
for group, rule in security_groups.get_group_references(etcd_client, args.get_references):
for group, rule in security_groups.get_group_references(etcd_client, args.get_references,
library=args.library):
print(group)
if args.create_group:
security_groups.create_security_group(etcd_client, args.create_group, None,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment