Commit 67e561e1 authored by Sigmund Augdal's avatar Sigmund Augdal

clean up etcd_dump script

parent 0ae0045c
import etcd
import json
import sys
import argparse
import os.path
DESCRIPTION = "Generate dhcp server config based on neighbor list in etcd"
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('--output', default="-",
help="Output file to use. Use - for stdout")
parser.add_argument('--subtree', default="/nova",
help="Subtree to dump")
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
etcd = etcd.Etcd("", 4001, ssl_cert="etcd_client.crt", ssl_key="etcd_client.key", verify="etcd_ca.crt")
def dump_subtree(etcd, tree, dump):
for entry in etcd.list(tree):
......@@ -10,6 +36,20 @@ def dump_subtree(etcd, tree, dump):
dump_subtree(etcd, entry.key, dump)
dump[entry.key] = entry.value
data = {}
dump_subtree(etcd, "/nova", data)
json.dump(data, sys.stdout)
def main():
args = parse_args()
etcd_client = etcd.Etcd(args.etcd_host, 4001, ssl_cert=args.cert,
ssl_key=args.key, verify=args.cacert)
data = {}
dump_subtree(etcd_client, args.subtree, data)
if args.output == "-":
output = sys.stdout
output = open(args.output, 'w')
json.dump(data, output)
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