summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2016-09-06 10:31:16 +0600
committerDaniil Baturin <daniil@baturin.org>2016-09-06 10:31:16 +0600
commit97b35d3aad1be5382db7e6e891c64157fc35ed3f (patch)
treefd2a66be9048ccf2b2d1fc4c4b0ef5c13dbaceb8
parent7ab8b31cac7bf8a290f42afbea3b7c9820a4dde3 (diff)
downloadpython-vyos-mgmt-97b35d3aad1be5382db7e6e891c64157fc35ed3f.tar.gz
python-vyos-mgmt-97b35d3aad1be5382db7e6e891c64157fc35ed3f.zip
Create pxssh instance when user logins, rather than when the object is created.
This allows reusing the same router object with multiple logins and logouts, pxssh refuses to login from the same instance again after logout for some reason.
-rw-r--r--vymgmt/router.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/vymgmt/router.py b/vymgmt/router.py
index b62b15d..c638e31 100644
--- a/vymgmt/router.py
+++ b/vymgmt/router.py
@@ -39,8 +39,6 @@ class Router(object):
self.__session_saved = True
self.__conf_mode = False
- self.__conn = pxssh.pxssh()
-
# String codec, hardcoded for now
self.__codec = "utf8"
@@ -75,6 +73,12 @@ class Router(object):
"""Login the router
"""
+
+ # XXX: after logout, old pxssh instance stops working,
+ # so we create a new one for each login
+ # There may or may not be a better way to handle it
+ self.__conn = pxssh.pxssh()
+
self.__conn.login(self.__address, self.__user, self.__password)
self.__logged_in = True
@@ -91,7 +95,6 @@ class Router(object):
else:
self.__conn.close()
self.__logged_in = False
- self.__conn = pxssh.pxssh()
def configure(self):
"""Enter the VyOS configure mode
@@ -115,7 +118,6 @@ class Router(object):
if not self.__conn.prompt():
raise VyOSError("Entering configure mode failed (possibly due to timeout)")
- # self.__conn.set_unique_prompt()
self.__conf_mode = True
# XXX: There should be a check for operator vs. admin