summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/configsession.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py
index c84d80a77..39a9713e0 100644
--- a/python/vyos/configsession.py
+++ b/python/vyos/configsession.py
@@ -14,6 +14,7 @@
import os
import re
+import sys
import subprocess
CLI_SHELL_API = '/bin/cli-shell-api'
@@ -21,7 +22,9 @@ SET = '/opt/vyatta/sbin/my_set'
DELETE = '/opt/vyatta/sbin/my_delete'
COMMENT = '/opt/vyatta/sbin/my_comment'
COMMIT = '/opt/vyatta/sbin/my_commit'
+DISCARD = '/opt/vyatta/sbin/my_discard'
+# Default "commit via" string
APP = "vyos-api"
@@ -48,6 +51,7 @@ class ConfigSession(object):
"""
env_str = subprocess.check_output([CLI_SHELL_API, 'getSessionEnv', str(session_id)])
+ self.__session_id = session_id
# Extract actual variables from the chunk of shell it outputs
# XXX: it's better to extend cli-shell-api to provide easily readable output
@@ -62,6 +66,14 @@ class ConfigSession(object):
self.__run_command([CLI_SHELL_API, 'setupSession'])
+ def __del__(self):
+ try:
+ output = subprocess.check_output([CLI_SHELL_API, 'teardownSession'], env=self.__session_env).decode().strip()
+ if output:
+ print("cli-shell-api teardownSession output for sesion {0}: {1}".format(self.__session_id, output), file=sys.stderr)
+ except Exception as e:
+ print("Could not tear down session {0}: {1}".format(self.__session_id, e), file=sys.stderr)
+
def __run_command(self, cmd_list):
p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.__session_env)
result = p.wait()
@@ -95,3 +107,6 @@ class ConfigSession(object):
def commit(self):
self.__run_command([COMMIT])
+
+ def discard(self):
+ self.__run_command([DISCARD])