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

Cleaned up etcd_restore script

parent e5f4dc58
import etcd
import json
import sys
import argparse
import os.path
etcd = etcd.Etcd("158.38.213.2", 4001, ssl_cert="etcd_client.crt", ssl_key="etcd_client.key", verify="etcd_ca.crt")
data = json.load(sys.stdin)
for key, value in data.items():
etcd.set(key, value)
DESCRIPTION = "Restore saved values from backup into 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('--input', default="-",
help="Input 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))
sys.exit(1)
return args
def restore(etcd, input):
data = json.load(input)
for key, value in data.items():
etcd.set(key, value)
def main():
args = parse_args()
etcd_client = etcd.Etcd(args.etcd_host, 4001, ssl_cert=args.cert,
ssl_key=args.key, verify=args.cacert)
if args.input == "-":
input = sys.stdin
else:
input = open(args.input)
restore(etcd_client, input)
if __name__ == '__main__':
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