Skip to content

Commit

Permalink
Merge pull request #6 from ctomkow/save_config
Browse files Browse the repository at this point in the history
Save config
  • Loading branch information
ctomkow authored Jan 24, 2020
2 parents 4344601 + 44b06b2 commit 9024553
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
38 changes: 36 additions & 2 deletions device_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
1 change: 1 addition & 0 deletions swITch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 9024553

Please sign in to comment.