[gestion/iscsi] création d'un module slonlib
darcs-hash:20081217131852-c41ad-390349e9eefc27174449f5323f5d08f98194efb5.gz
This commit is contained in:
parent
a7d7d6f006
commit
9a0f43b6dd
2 changed files with 106 additions and 61 deletions
|
@ -9,80 +9,24 @@
|
|||
u'''Outil pour récupérer le mapping lun/volume depuis la baie de
|
||||
stockage'''
|
||||
|
||||
import telnetlib, re, sys
|
||||
import slonlib, re, sys
|
||||
|
||||
sys.path.append("/usr/scripts/gestion")
|
||||
from config import ISCSI_MAP_FILE
|
||||
import affich_tools
|
||||
|
||||
# Ce script utilise l'interface telnet de la baie.
|
||||
|
||||
# La réponse à la commande "show volume-map" est une séquence
|
||||
# d'éléments de la forme:
|
||||
#
|
||||
# nom du volume
|
||||
# |
|
||||
# v
|
||||
# > Volume [SN 00c0ffd5e51800004ca1454901000000, Name (o2_slash)] mapping view:
|
||||
# > CH ID LUN Access Host-Port-Identifier Nickname
|
||||
# > -------------------------------------------------------------------------------
|
||||
# > 0,1 0 4 rw all other hosts
|
||||
# ^
|
||||
# |
|
||||
# lun
|
||||
|
||||
# On utilise cette expression un peu barbare pour récupérer les deux
|
||||
# informations qui nous intéressses:
|
||||
volume_regexp = re.compile("Volume \[SN [0-9a-f]+, Name \(([^)]*)\)\][^\n]*\n[^\n]*\n[^\n]*\n[0-9,-]+ *[0-9]+ *([0-9]+)[^\n]*\n")
|
||||
|
||||
username = ""
|
||||
password = ""
|
||||
|
||||
# Récupération des identifiants. Cela écrase les deux variables
|
||||
# username et password:
|
||||
execfile("/etc/crans/secrets/slon.py")
|
||||
|
||||
print u"Connection à la baie de stockage..."
|
||||
|
||||
tn = telnetlib.Telnet("slon.adm.crans.org")
|
||||
|
||||
# Identification
|
||||
tn.read_until("Login: ")
|
||||
tn.write(username + "\r\n")
|
||||
tn.read_until("Password: ")
|
||||
tn.write(password + "\r\n")
|
||||
|
||||
# Ça c'est pour attendre la l'invite de commande:
|
||||
tn.read_until("#")
|
||||
slon = slonlib.Slon()
|
||||
|
||||
print u"Récupération des informations..."
|
||||
|
||||
tn.write("show volume-maps" + "\r\n")
|
||||
resp = ""
|
||||
# Lecture de la réponse, c'est terminé quand on atteint un nouveau
|
||||
# prompt:
|
||||
while resp.find("#") < 0:
|
||||
resp = resp + tn.read_some()
|
||||
# Parfois le serveur attend que l'on appuie sur une touche pour
|
||||
# continuer à envoyer les données:
|
||||
if resp.endswith("Press any key to continue (Q to quit)"):
|
||||
tn.write(" ")
|
||||
map = slon.volume_map().items()
|
||||
map.sort()
|
||||
|
||||
print u"Déconnection..."
|
||||
|
||||
tn.write("exit\r\n")
|
||||
tn.read_all()
|
||||
tn.close()
|
||||
|
||||
# On retire les messages parasites
|
||||
junk = re.compile("Press any key to continue \(Q to quit\)\x0d *\x0d")
|
||||
resp = junk.sub("", resp)
|
||||
|
||||
# Parsing de la réponse
|
||||
map = []
|
||||
for m in volume_regexp.finditer(resp):
|
||||
map.append((int(m.group(2)), m.group(1)))
|
||||
map.sort()
|
||||
slon.logout()
|
||||
|
||||
print u"Enregistrement des informations..."
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue