Commit 9b12529f authored by Sigmund Augdal's avatar Sigmund Augdal

Added support for manipulating entries in library groups

parent 9c27cd88
......@@ -37,6 +37,13 @@ def security_group_rule_key(group, rule=None):
return key
def library_group_entry_key(group, entry=None):
key = library_group_key(group) + "/entries"
if entry:
key += "/" + str(entry)
return key
def get_group_name(etcd_client, group_id, library=False):
return etcd_client.get(group_key(group_id, library=library) + "/name").value
......@@ -131,7 +138,34 @@ def get_library_groups(etcd_client, cloudid=None):
return groups
def get_group_references(etcd_client, groupid):
def add_library_entry(etcd_client, group_id, cidr, comment):
entry_id = uuid.uuid4()
entry_key = library_group_entry_key(group_id, entry_id)
etcd_client.set(entry_key + '/cidr', cidr)
etcd_client.set(entry_key + '/comment', comment)
return entry_id
def get_library_entry(etcd_client, group_id, entry_id):
entry_key = library_group_entry_key(group_id, entry_id)
entry = {}
for etcd_entry in, recursive=True,
parts = etcd_entry.key.split("/")
if len(parts) < 2:
e_id, info = parts[-2:]
if e_id != entry_id:
logging.warning("Unexpected etcd key {} found".format(etcd_entry.key))
entry[info] = etcd_entry.value
return entry
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)
references = []
for entry in, recursive=True,
......@@ -41,6 +41,8 @@ def parse_args():
help="Find groups that use GROUP as source in a rule")
parser.add_argument('--create-group', metavar="NAME",
help="Create a new shared security/library group called NAME")
parser.add_argument('--add-library-entry', metavar=("GROUP", "CIDR", "COMMENT"), nargs=3,
help="Add entry to cidr group")
args = parser.parse_args()
for filename, description in ((args.cert, "certificate"),
(args.key, "private key"),
......@@ -99,5 +101,9 @@ def main():
if args.create_group:
security_groups.create_security_group(etcd_client, args.create_group, None,
if args.add_library_entry:
group_id, cidr, comment = args.add_library_entry
security_groups.add_library_entry(etcd_client, group_id, cidr, comment)
if __name__ == '__main__':
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