aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2014-12-19 17:53:43 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2014-12-19 17:53:43 +0000
commit095b445215ed4b2190605e15b7e1559be4c291f7 (patch)
treea7a25b2fc13afe22ef0ab69bc9794f52fbe1e439
parent3256b18da9931e38647b755609848638853d34d0 (diff)
Added switch_restart method - use to force config rollback
This will be horrendous to use, as it's a very slow operation. But AFAICS it's the only safe way to force a switch to revert config Used by error paths in complex API calls Change-Id: Ib042dacfcf026d754398dfb1f40d31f6e2a4f1cc
-rw-r--r--drivers/CiscoCatalyst.py18
-rw-r--r--drivers/CiscoSX300.py19
2 files changed, 36 insertions, 1 deletions
diff --git a/drivers/CiscoCatalyst.py b/drivers/CiscoCatalyst.py
index c00b830..c731000 100644
--- a/drivers/CiscoCatalyst.py
+++ b/drivers/CiscoCatalyst.py
@@ -100,6 +100,22 @@ class CiscoCatalyst(SwitchDriver):
self._cli("startup-config")
self.connection.expect("OK")
+ # Restart the switch - we need to reload config to do a
+ # roll-back. Do NOT save running-config first if the switch asks -
+ # we're trying to dump recent changes, not save them.
+ #
+ # This will also implicitly cause a connection to be closed
+ def switch_restart(self):
+ self._cli("reload")
+ index = self.connection.expect(['has been modified', 'Proceed'])
+ if index == 0:
+ self._cli("n") # No, don't save
+ self.connection.expect("Proceed")
+
+ # Fall through
+ self._cli("y") # Yes, continue to reset
+ self.connection.close(True)
+
# List the capabilities of the switch (and driver) - some things
# make no sense to abstract. Returns a dict of strings, each one
# describing an extra feature that that higher levels may care
@@ -539,6 +555,8 @@ if __name__ == "__main__":
buf = p.port_get_trunk_vlan_list("Gi1/0/9")
p._dump_list(buf)
+ print 'Restarting switch, to explicitly reset config'
+ p.switch_restart()
# p.switch_save_running_config()
diff --git a/drivers/CiscoSX300.py b/drivers/CiscoSX300.py
index 7cdeb40..c875ca6 100644
--- a/drivers/CiscoSX300.py
+++ b/drivers/CiscoSX300.py
@@ -98,6 +98,22 @@ class CiscoSX300(SwitchDriver):
self._cli("y")
self.connection.expect("Copy succeeded")
+ # Restart the switch - we need to reload config to do a
+ # roll-back. Do NOT save running-config first if the switch asks -
+ # we're trying to dump recent changes, not save them.
+ #
+ # This will also implicitly cause a connection to be closed
+ def switch_restart(self):
+ self._cli("reload")
+ index = self.connection.expect(['Are you sure', 'will reset'])
+ if index == 0:
+ self._cli("y") # Yes, continue without saving
+ self.connection.expect("reset the whole")
+
+ # Fall through
+ self._cli("y") # Yes, continue to reset
+ self.connection.close(True)
+
################################
### VLAN API functions
################################
@@ -498,7 +514,8 @@ if __name__ == "__main__":
buf = p.vlan_get_list()
p._dump_list(buf)
-# p.switch_save_running_config()
+ print 'Restarting switch, to explicitly reset config'
+ p.switch_restart()
p.switch_disconnect()
# p._show_config()