Split out switch_connect so we can re-use it internally
Change-Id: I27ba0384eaf7ea7299f8d03c410f456371d099ea
diff --git a/drivers/CiscoSX300.py b/drivers/CiscoSX300.py
index a7aeb6f..32d0f39 100644
--- a/drivers/CiscoSX300.py
+++ b/drivers/CiscoSX300.py
@@ -60,12 +60,20 @@
# Connect to the switch and log in
def switch_connect(self, username, password, enablepassword):
- logging.debug("Connecting to Switch with: %s" % self.exec_string)
- self.connection = pexpect.spawn(self.exec_string, logfile = self.logfile)
-
self._username = username
self._password = password
self._enable_password = enablepassword
+ self._switch_connect()
+
+ # Connect to the switch and log in
+ def _switch_connect(self):
+
+ if not self.connection is None:
+ self.connection.close(True)
+ self.connection = None
+
+ logging.debug("Connecting to Switch with: %s" % self.exec_string)
+ self.connection = pexpect.spawn(self.exec_string, logfile = self.logfile)
self._login()