[slon-get-volume-mapping] script pour récupérer le mapping des volumes iscsi en telnet
darcs-hash:20081216041008-c41ad-cd632cdd9e2df777b356f7250dc5d87e8b1884e5.gz
This commit is contained in:
parent
a2e9a287e5
commit
edc0315878
1 changed files with 93 additions and 0 deletions
93
gestion/slon-get-volume-mapping.py
Executable file
93
gestion/slon-get-volume-mapping.py
Executable file
|
@ -0,0 +1,93 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# slon-get-volume-mapping.py
|
||||||
|
# --------------------------
|
||||||
|
# Copyright : (c) 2008, Jeremie Dimino <dimino@crans.org>
|
||||||
|
# Licence : BSD3
|
||||||
|
|
||||||
|
u'''Outil pour récupérer le mapping lun/volume depuis la baie de
|
||||||
|
stockage'''
|
||||||
|
|
||||||
|
import telnetlib, re
|
||||||
|
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("#")
|
||||||
|
|
||||||
|
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(" ")
|
||||||
|
|
||||||
|
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[int(m.group(2))] = m.group(1)
|
||||||
|
|
||||||
|
print u"Enregistrement des informations..."
|
||||||
|
|
||||||
|
file(ISCSI_MAP_FILE, "w").write("map = %s\n" % str(map))
|
||||||
|
|
||||||
|
print u"Terminé, mapping enregistré dans %s" % ISCSI_MAP_FILE
|
||||||
|
|
||||||
|
print u"Le mapping actuel est:"
|
||||||
|
l = [[lun, name] for lun, name in map.iteritems()]
|
||||||
|
l.sort()
|
||||||
|
print affich_tools.tableau(titre = ["lun", "nom"], data = l, alignement = ["g", "c"])
|
Loading…
Add table
Add a link
Reference in a new issue