summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-11 11:36:13 +0100
committerGitHub <noreply@github.com>2020-03-11 11:36:13 +0100
commit3c4c7179ba40be6ccd418f22d3cee9b0e3c0f5e7 (patch)
tree839a92d1cf6a69e203e197643b9b37eba7ad5a14
parentb0952b9609da1a1e9d3cf4d0591525cde7a6bbb5 (diff)
parent508d380b8ef4079d539a3845705f1bf3aeff3a67 (diff)
downloadvyos-1x-3c4c7179ba40be6ccd418f22d3cee9b0e3c0f5e7.tar.gz
vyos-1x-3c4c7179ba40be6ccd418f22d3cee9b0e3c0f5e7.zip
Merge pull request #238 from fetzerms/http_api_show_generate
T2096: Http api show generate
-rw-r--r--python/vyos/configsession.py8
-rwxr-xr-xsrc/conf_mode/https.py2
-rwxr-xr-xsrc/services/vyos-http-api-server43
3 files changed, 51 insertions, 2 deletions
diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py
index d326b3b11..aaf08e726 100644
--- a/python/vyos/configsession.py
+++ b/python/vyos/configsession.py
@@ -29,6 +29,7 @@ SAVE_CONFIG = ['/opt/vyatta/sbin/vyatta-save-config.pl']
INSTALL_IMAGE = ['/opt/vyatta/sbin/install-image']
REMOVE_IMAGE = ['/opt/vyatta/bin/vyatta-boot-image.pl', '--del']
GENERATE = ['/opt/vyatta/bin/vyatta-op-cmd-wrapper', 'generate']
+SHOW = ['/opt/vyatta/bin/vyatta-op-cmd-wrapper', 'show']
# Default "commit via" string
APP = "vyos-http-api"
@@ -181,5 +182,10 @@ class ConfigSession(object):
return out
def generate(self, cmd):
- out = self.__run_command(GENERATE + cmd)
+ out = self.__run_command(GENERATE + cmd.split())
return out
+
+ def show(self, cmd):
+ out = self.__run_command(SHOW + cmd.split())
+ return out
+
diff --git a/src/conf_mode/https.py b/src/conf_mode/https.py
index 84d1a7691..fcbc3d384 100755
--- a/src/conf_mode/https.py
+++ b/src/conf_mode/https.py
@@ -73,7 +73,7 @@ server {
{% endif %}
# proxy settings for HTTP API, if enabled; 503, if not
- location ~ /(retrieve|configure|config-file|image) {
+ location ~ /(retrieve|configure|config-file|image|generate|show) {
{% if server.api %}
proxy_pass http://localhost:{{ server.api.port }};
proxy_buffering off;
diff --git a/src/services/vyos-http-api-server b/src/services/vyos-http-api-server
index da6e5b118..b5ad8b159 100755
--- a/src/services/vyos-http-api-server
+++ b/src/services/vyos-http-api-server
@@ -308,6 +308,49 @@ def config_file_op():
return success(res)
+@app.route('/generate', method='POST')
+@auth_required
+def generate_op():
+ session = app.config['vyos_session']
+
+ command = bottle.request.forms.get("data")
+ command = json.loads(command)
+
+ try:
+ cmd = command['cmd']
+ res = session.generate(cmd)
+ except KeyError:
+ return error(400, "Missing required field \"cmd\"")
+ except VyOSError as e:
+ return error(400, str(e))
+ except Exception as e:
+ print(traceback.format_exc(), file=sys.stderr)
+ return error(500, "An internal error occured. Check the logs for details.")
+
+ return success(res)
+
+@app.route('/show', method='POST')
+@auth_required
+def show_op():
+ session = app.config['vyos_session']
+
+ command = bottle.request.forms.get("data")
+ command = json.loads(command)
+
+ try:
+ cmd = command['cmd']
+ res = session.show(cmd)
+ except KeyError:
+ return error(400, "Missing required field \"cmd\"")
+ except VyOSError as e:
+ return error(400, str(e))
+ except Exception as e:
+ print(traceback.format_exc(), file=sys.stderr)
+ return error(500, "An internal error occured. Check the logs for details.")
+
+ return success(res)
+
+
if __name__ == '__main__':
# systemd's user and group options don't work, do it by hand here,
# else no one else will be able to commit