diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-10-27 17:10:30 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-10-27 17:10:30 +0100 |
commit | ad9bbd9edff6a057ba0c4d2a8984e2184345ca71 (patch) | |
tree | f625c62412aed6458ff3d2971b893319ada8d435 /src | |
parent | a5d800400aaf9d1df61feb79c3626d37d0a3015d (diff) | |
download | vyos-1x-ad9bbd9edff6a057ba0c4d2a8984e2184345ca71.tar.gz vyos-1x-ad9bbd9edff6a057ba0c4d2a8984e2184345ca71.zip |
T1773, T1774: add a show config operation with JSON and raw options.
Diffstat (limited to 'src')
-rwxr-xr-x | src/services/vyos-http-api-server | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server index 04c44c2be..571ec1258 100755 --- a/src/services/vyos-http-api-server +++ b/src/services/vyos-http-api-server @@ -207,11 +207,21 @@ def get_value(): elif op == 'exists': res = config.exists(path) elif op == 'showConfig': - config_format = 'raw' + config_format = 'json' if 'configFormat' in command: config_format = command['configFormat'] - res = session.show_config(command['path'], format=config_format) + res = session.show_config(path=command['path']) + if config_format == 'json': + config_tree = vyos.configtree.ConfigTree(res) + res = json.loads(config_tree.to_json()) + elif config_format == 'json_ast': + config_tree = vyos.configtree.ConfigTree(res) + res = json.loads(config_tree.to_json_ast()) + elif config_format == 'raw': + pass + else: + return error(400, "\"{0}\" is not a valid config format") else: return error(400, "\"{0}\" is not a valid operation".format(op)) except VyOSError as e: |