Fontion d'upgrade des switchs.
Amlioration base du systme de connexion ssh darcs-hash:20041205011212-41617-14e3db86fdd511a9e96c57f37bf877b0c4e99fb3.gz
This commit is contained in:
parent
4e225747ce
commit
13e162fcd6
1 changed files with 23 additions and 17 deletions
|
@ -50,6 +50,8 @@ class ssh :
|
|||
def __init__(self,host) :
|
||||
""" Ouverture d'une connexion ssh vers le switch choisi """
|
||||
self.switch = host
|
||||
self.log=open('/tmp/test_ssh','w')
|
||||
|
||||
if self.__debug : self.__logDest.write("SSH DEBUG : __init__(host=%s)\n" % host)
|
||||
self.__host = host
|
||||
self.__retour, self.__input, self.__err = popen3("/usr/bin/ssh -tt %s" % host)
|
||||
|
@ -60,7 +62,6 @@ class ssh :
|
|||
r.start()
|
||||
e = threading.Thread(target=self.__read_err,args=(threading.currentThread(),))
|
||||
e.start()
|
||||
self.log=open('/tmp/test_ssh','w')
|
||||
|
||||
# On passe l'intro, passe manager et en environnement de configuration
|
||||
self.send_cmd('\nenable\nconfigure')
|
||||
|
@ -101,7 +102,6 @@ class ssh :
|
|||
if self.__debug : self.__logDest.write("SSH DEBUG : __send_cmd(%s)\n" % cmd.strip() )
|
||||
|
||||
self.__ssh_out = '' # oubli de ce qu'il y a avant
|
||||
self.log.write('*****\n')
|
||||
self.log.flush()
|
||||
|
||||
# Envoi de la commande
|
||||
|
@ -110,30 +110,35 @@ class ssh :
|
|||
|
||||
# Premier retour
|
||||
count=0
|
||||
t = ''
|
||||
while 1:
|
||||
sleep(1)
|
||||
out = self.__ssh_out
|
||||
# On a récupéré un prompt ?
|
||||
try :
|
||||
print "|%s|" % self.__ssh_out[-45:-38]
|
||||
if self.__ssh_out[-45:-38] == ' [y/n]?' :
|
||||
while_break = 0
|
||||
for n in range(1,200) :
|
||||
try : t = out[-n-7:-n]
|
||||
except : continue
|
||||
if t == ' [y/n]?' :
|
||||
self.__input.write('y')
|
||||
self.__input.flush()
|
||||
sleep(1)
|
||||
continue
|
||||
elif self.__ssh_out[-46:-36].lower() == '(config)# ' :
|
||||
elif t == 'onfig)#' :
|
||||
if self.__debug : self.__logDest.write("SSH DEBUG : __send_cmd -> OK\n")
|
||||
break
|
||||
elif self.__ssh_out[-70:-7] == '-- MORE --, next page: Space, next line: Enter, quit: Control-C' :
|
||||
while_break=1
|
||||
elif t == 'ntrol-C' :
|
||||
# Faut appuyer sur une touche
|
||||
if self.__debug : self.__logDest.write("SSH DEBUG : __send_cmd -> MORE\n")
|
||||
self.__input.write(' ')
|
||||
self.__input.flush()
|
||||
sleep(1)
|
||||
else :
|
||||
continue
|
||||
except: pass
|
||||
|
||||
break
|
||||
|
||||
if while_break : break
|
||||
# Rien de bien, le switch es un peu lent, on attend
|
||||
if self.__debug : self.__logDest.write("SSH DEBUG : __send_cmd -> WAIT\n")
|
||||
sleep(1)
|
||||
if self.__debug : self.__logDest.write("SSH DEBUG : __send_cmd -> WAIT (%s) \n" % t)
|
||||
count += 1
|
||||
if count > timeout :
|
||||
# Il y a un problème
|
||||
|
@ -205,6 +210,7 @@ class hpswitch :
|
|||
|
||||
# Quelques paramètres
|
||||
IP_tftp = '138.231.136.7'
|
||||
firmware_file = 'firmware26xx'
|
||||
|
||||
# Variables internes
|
||||
switch = None # nom du switch
|
||||
|
@ -219,11 +225,11 @@ class hpswitch :
|
|||
# Config snmp
|
||||
self.get, self.set, self.walk = config_snmp_secrete(snmp,switch)
|
||||
|
||||
def __ssh(self,cmd) :
|
||||
def __ssh(self,cmd,timout=15) :
|
||||
if not self.__conn_ssh :
|
||||
self.__conn_ssh = ssh(self.switch)
|
||||
|
||||
return self.__conn_ssh.send_cmd(cmd)
|
||||
return self.__conn_ssh.send_cmd(cmd,timout)
|
||||
|
||||
def set_prise(self,prise,action) :
|
||||
"""
|
||||
|
@ -335,8 +341,8 @@ class hpswitch :
|
|||
def upgrade(self) :
|
||||
""" Changement de firmware, le firmware est sur la machine
|
||||
ayant le serveur tftfp et a pour nom firmware26xx """
|
||||
if self.__debug : self.__logDest.write("HP DEBUG : update()\n")
|
||||
self.__ssh("copy tftp flash %s firmware26xx" % self.IP_tftp,70)
|
||||
if self.__debug : self.__logDest.write("HP DEBUG : upgrate()\n")
|
||||
self.__ssh("copy tftp flash %s %s" % (self.IP_tftp, self.firmware_file) , 120) # Long timout
|
||||
|
||||
def reboot(self) :
|
||||
""" Reboote le switch """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue