diff options
author | francois.cellier <francois.cellier@orange.com> | 2018-02-27 13:51:25 +0100 |
---|---|---|
committer | francois.cellier <francois.cellier@orange.com> | 2018-03-08 14:30:45 +0100 |
commit | 7343cf25ad890e18b2f5b8d35c6acfc821dfd5ec (patch) | |
tree | 635e01c4a17326a05c4ec40b3df48d2d33a0de59 /python_moonclient/python_moonclient/cli/export.py | |
parent | c5104c3308f7aa6cb44a678a25c553c027c249be (diff) |
Add import and export pdps
Change-Id: I2c9b1f2b86af862887df4b890cd8b11db7c308ee
Diffstat (limited to 'python_moonclient/python_moonclient/cli/export.py')
-rw-r--r-- | python_moonclient/python_moonclient/cli/export.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/python_moonclient/python_moonclient/cli/export.py b/python_moonclient/python_moonclient/cli/export.py new file mode 100644 index 00000000..a16928de --- /dev/null +++ b/python_moonclient/python_moonclient/cli/export.py @@ -0,0 +1,32 @@ +import json + +from python_moonclient.core import models, policies, pdp, json_export +from python_moonclient.cli.parser import Parser + +from cliff.command import Command + + +class Export(Command): + """dump the complete moon database into a json file""" + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + Parser.add_filename_argument(parser) + Parser.add_common_options(parser) + return parser + + def take_action(self, parsed_args): + consul_host = parsed_args.consul_host + consul_port = parsed_args.consul_port + + models.init(consul_host, consul_port) + policies.init(consul_host, consul_port) + pdp.init(consul_host, consul_port) + json_export.init(consul_host, consul_port) + res = json_export.export_to_json() + if "content" in res: + json_file = open(parsed_args.filename, "w") + json.dump(res["content"], json_file) + return "Export ok!" + else: + return "Unexpected results : the returned json does not have the correct syntax" + |