Commit 56cd56f1 authored by Sigmund Augdal's avatar Sigmund Augdal

Added cli tool to manipulate library groups

parent c37c0c12
#! /usr/bin/env python
import etcd
import sys
import argparse
import os.path
from nova_router import security_groups
DESCRIPTION = "Utility for manipulating library groups"
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument("--etcd-host", default="localhost",
help="Etcd host to connet to")
parser.add_argument('--cert', default="client.crt", help="client certificate to use")
parser.add_argument('--key', default="client.key",
help="private key to use for client certificate")
parser.add_argument('--cacert', default="etcd_ca.crt", help="ca certificate to use")
parser.add_argument('--change-cloud', default=None, metavar=("GROUP", "CLOUD"), nargs=2,
help="move group to new cloud")
parser.add_argument('--rename-group', default=None, metavar=("GROUP", "NAME"), nargs=2,
help="rename a group")
parser.add_argument('--lock-group', metavar="GROUP",
help="Make a group locked")
parser.add_argument('--unlock-group', metavar="GROUP",
help="Make a group not locked")
parser.add_argument('--make-shared', metavar="GROUP",
help="Make a group shared acress clouds")
parser.add_argument('--get-references', metavar="GROUP",
help="Find groups that use GROUP as source in a rule")
args = parser.parse_args()
for filename, description in ((args.cert, "certificate"),
(args.key, "private key"),
(args.cacert, "ca certificate")):
if filename and not os.path.exists(filename):
print("Specified {}: {} does not exist".format(description, filename))
return args
def dump_subtree(etcd, tree, dump):
for entry in, recursive=True).leaves:
dump[entry.key] = entry.value
def main():
args = parse_args()
etcd_client = etcd.Client(host=args.etcd_host, cert=(args.cert, args.key),
ca_cert=args.cacert, protocol='https')
if args.change_cloud is not None:
group, cloud = args.change_cloud
security_groups.set_group_cloud(etcd_client, group, cloud, library=True)
if args.rename_group is not None:
group, name = args.rename_group
security_groups.set_group_name(etcd_client, group, name, library=True)
if args.lock_group:
security_groups.set_locked(etcd_client, args.lock_group, library=True)
if args.unlock_group:
security_groups.set_locked(etcd_client, args.unlock_group, False, library=True)
if args.make_shared:
security_groups.set_group_cloud(etcd_client, args.make_shared, None, library=True)
if args.get_references:
for group, rule in security_groups.get_group_references(etcd_client, args.get_references):
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