Commit b432ebaf authored by Sigmund Augdal's avatar Sigmund Augdal

Added support for updating library groups when entries has been updated in fwb

parent 9581508f
......@@ -174,6 +174,13 @@ def get_library_groups(etcd_client):
return library
def diff(a, b):
for attr in ('cidr', 'comment'):
if a[attr] != b[attr]:
return True
return False
def main():
args = parse_args()
etcd_client = etcd.Client(host=args.etcd_host, cert=(args.cert, args.key),
......@@ -196,8 +203,22 @@ def main():
group_id = library[ref]['id']
for entryref, entry in group['entries'].items():
if entryref not in lib_entries:
if query(args, 'Add entry {cidr}({ecomment}) to {group}'.format(cidr=entry['cidr'], ecomment=entry['comment'], group=group['name'])):
security_groups.add_library_entry(etcd_client, group_id, entry['cidr'], entry['comment'], entryref)
if query(args, 'Add entry {cidr}({ecomment}) to {group}'.format(
cidr=entry['cidr'], ecomment=entry['comment'], group=group['name'])):
security_groups.add_library_entry(etcd_client, group_id, entry['cidr'],
entry['comment'], entryref)
elif diff(entry, lib_entries[entryref]):
lentry = lib_entries[entryref]
if query(args, 'Update entry {cidr}({comment}) in {group} to {ncidr}({ncomment})'.format(
cidr=lentry['cidr'],
comment=lentry['comment'],
group=group['name'],
ncidr=entry['cidr'],
ncomment=entry['comment'])):
security_groups.del_library_entry(etcd_client, group_id, lentry['id'])
security_groups.add_library_entry(etcd_client, group_id, entry['cidr'],
entry['comment'], entryref)
for entry_ref, entry in lib_entries.items():
if entry_ref not in group['entries']:
if query(args, 'Remove entry {cidr}({comment}) from {group}'.format(cidr=entry['cidr'], comment=entry['comment'], group=group['name'])):
......
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