add DGS1510
This commit is contained in:
parent
221f666ebd
commit
32cef28497
@ -172,6 +172,37 @@ class backup_switch(backup_generic):
|
|||||||
f = open(filename, 'w')
|
f = open(filename, 'w')
|
||||||
f.write(resp.read())
|
f.write(resp.read())
|
||||||
|
|
||||||
|
def switch_dlink_DGS1510(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("terminal length 0\r")
|
||||||
|
child.expect("#")
|
||||||
|
child.sendline("show run\r")
|
||||||
|
child.logfile_read = open(filename, "a")
|
||||||
|
child.expect('End of configuration file')
|
||||||
|
child.expect('#--')
|
||||||
|
child.expect("#")
|
||||||
|
child.close()
|
||||||
|
myre = re.compile("#--+")
|
||||||
|
config = myre.split(open(filename).read())[2]
|
||||||
|
with open(filename,'w') as f:
|
||||||
|
f.write(config)
|
||||||
|
|
||||||
|
|
||||||
def do_backup(self,stats):
|
def do_backup(self,stats):
|
||||||
try:
|
try:
|
||||||
@ -191,6 +222,9 @@ class backup_switch(backup_generic):
|
|||||||
elif "DLINK-DGS1210" == self.switch_type:
|
elif "DLINK-DGS1210" == self.switch_type:
|
||||||
dest_filename += '.bin'
|
dest_filename += '.bin'
|
||||||
self.switch_dlink_DGS1210(dest_filename)
|
self.switch_dlink_DGS1210(dest_filename)
|
||||||
|
elif "DLINK-DGS1510" == self.switch_type:
|
||||||
|
dest_filename += '.cfg'
|
||||||
|
self.switch_dlink_DGS1510(dest_filename)
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown Switch type")
|
raise Exception("Unknown Switch type")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user