diff --git a/device_connector.py b/device_connector.py index 7f55ec3..4437275 100644 --- a/device_connector.py +++ b/device_connector.py @@ -131,9 +131,43 @@ def send_command(self, cmd): def send_config_set(self, set_list): if self.device_type == 'juniper_junos': - return self.device_connection.send_config_set(set_list, config_mode_command='configure exclusive') + return self.device_connection.send_config_set(set_list, exit_config_mode=False, config_mode_command='configure exclusive') + elif self.device_type == 'cisco_ios': + return self.device_connection.send_config_set(set_list, exit_config_mode=True) + elif self.device_type == 'hp_procurve': + return self.device_connection.send_config_set(set_list, exit_config_mode=True) + elif self.device_type == 'sentry_pdu': + return self.device_connection.send_config_set(set_list, exit_config_mode=False) + elif self.device_type == 'paloalto_panos': + try: + return self.device_connection.send_config_set(set_list, exit_config_mode=False) + except OSError: + return "Did not find expected pattern. Likely nothing to commit!" + else: + pass + + def save_config_and_exit(self): + + buf = "" + + if self.device_type == 'juniper_junos': + buf += self.device_connection.commit(and_quit=True) + elif self.device_type == 'cisco_ios': + buf += self.device_connection.save_config() + elif self.device_type == 'hp_procurve': + buf += self.device_connection.save_config() + elif self.device_type == 'sentry_pdu': + try: # e.g. sentry_pdu uses netmiko's accedian device - it doesn't impl save_config as config is auto-saved + buf += self.device_connection.save_config() + except NotImplementedError: + return buf + elif self.device_type == 'paloalto_panos': + buf += self.device_connection.commit() else: - return self.device_connection.send_config_set(set_list) + pass + + buf += self.device_connection.exit_config_mode() + return buf def disconnect(self): diff --git a/swITch.py b/swITch.py index e67c1b2..09ddd03 100755 --- a/swITch.py +++ b/swITch.py @@ -213,6 +213,7 @@ def main(self, auth, commands, debug, enable, ip_list, log_only, port_list, set, log.event('verbose', dev.find_prompt() + cmd + "\n") log.event('log_only', dev.send_config_set(list_of_set_cmds) + "\n") # send command log.event('debug', "DEBUG PROMPT:" + dev.find_prompt() + "\n") + log.event('verbose', dev.save_config_and_exit() + "\n") dev.disconnect() log.event('info', "SSH connection closed to " + dev.ip + "\n")