added backup switch CISCO (tested on our 3750 only...)
backup running config and vlan config
This commit is contained in:
parent
1805b22476
commit
e26612d2cf
@ -39,8 +39,11 @@ class backup_switch(backup_generic):
|
||||
"""Backup a startup-config on a switch"""
|
||||
type = 'switch'
|
||||
|
||||
required_params = backup_generic.required_params + ['switch_ip','switch_user' , 'switch_type']
|
||||
optional_params = backup_generic.optional_params + ['switch_password']
|
||||
required_params = backup_generic.required_params + ['switch_ip','switch_type']
|
||||
optional_params = backup_generic.optional_params + [ 'switch_user', 'switch_password']
|
||||
|
||||
switch_user = ''
|
||||
switch_password = ''
|
||||
|
||||
def switch_hp(self, filename):
|
||||
|
||||
@ -77,6 +80,46 @@ class backup_switch(backup_generic):
|
||||
for line in lines.split("\n")[1:-1]:
|
||||
open(filename,"a").write(line.strip()+"\n")
|
||||
|
||||
def switch_cisco(self, filename):
|
||||
s = socket.socket()
|
||||
try:
|
||||
s.connect((self.switch_ip, 23))
|
||||
s.close()
|
||||
except:
|
||||
raise
|
||||
|
||||
child=pexpect.spawn('telnet '+self.switch_ip)
|
||||
time.sleep(1)
|
||||
if self.switch_user:
|
||||
child.sendline(self.switch_user)
|
||||
child.expect('Password: ')
|
||||
child.sendline(self.switch_password+'\r')
|
||||
try:
|
||||
child.expect(">")
|
||||
except:
|
||||
raise Exception("Bad Credentials")
|
||||
child.sendline('enable\r')
|
||||
child.expect('Password: ')
|
||||
child.sendline(self.switch_password+'\r')
|
||||
try:
|
||||
child.expect("#")
|
||||
except:
|
||||
raise Exception("Bad Credentials")
|
||||
child.sendline( "terminal length 0\r")
|
||||
child.expect("#")
|
||||
child.sendline("show run\r")
|
||||
child.expect('Building configuration...')
|
||||
child.expect("#")
|
||||
running_config = child.before
|
||||
child.sendline("show vlan\r")
|
||||
child.expect('VLAN')
|
||||
child.expect("#")
|
||||
vlan = 'VLAN'+child.before
|
||||
open(filename,"a").write(running_config+'\n'+vlan)
|
||||
child.send('exit\r')
|
||||
child.close()
|
||||
|
||||
|
||||
def switch_linksys_SRW2024(self, filename):
|
||||
s = socket.socket()
|
||||
try:
|
||||
@ -139,6 +182,9 @@ class backup_switch(backup_generic):
|
||||
if "LINKSYS-SRW2024" == self.switch_type:
|
||||
dest_filename += '.txt'
|
||||
self.switch_linksys_SRW2024(dest_filename)
|
||||
elif self.switch_type in [ "CISCO", ]:
|
||||
dest_filename += '.txt'
|
||||
self.switch_cisco(dest_filename)
|
||||
elif self.switch_type in [ "HP-PROCURVE-4104GL", "HP-PROCURVE-2524" ]:
|
||||
dest_filename += '.txt'
|
||||
self.switch_hp(dest_filename)
|
||||
|
Loading…
Reference in New Issue
Block a user