[gestion/iscsi/slon-get-volume-mapping] produit un fichier human-readable

darcs-hash:20081216221512-c41ad-d7d7ffd4f12f08722d1a82b35f3cb3780403ce25.gz
This commit is contained in:
Jeremie Dimino 2008-12-16 23:15:12 +01:00
parent 5ab4a87493
commit 80fd857b14

View file

@ -9,7 +9,9 @@
u'''Outil pour récupérer le mapping lun/volume depuis la baie de
stockage'''
import telnetlib, re
import telnetlib, re, sys
sys.path.append("/usr/scripts/gestion")
from config import ISCSI_MAP_FILE
import affich_tools
@ -77,17 +79,31 @@ junk = re.compile("Press any key to continue \(Q to quit\)\x0d *\x0d")
resp = junk.sub("", resp)
# Parsing de la réponse
map={}
map = []
for m in volume_regexp.finditer(resp):
map[int(m.group(2))] = m.group(1)
map.append((int(m.group(2)), m.group(1)))
map.sort()
print u"Enregistrement des informations..."
file(ISCSI_MAP_FILE, "w").write("map = %s\n" % str(map))
f = open(ISCSI_MAP_FILE, "w")
f.write((u"""\
# -*- coding: utf-8 -*-
# Fichier de mapping lun -> nom de volume
#
# Ce fichier est généré par %s
map = {
""" % sys.argv[0]).encode("UTF-8"))
for lun, name in map:
f.write(' %d : "%s",\n' % (lun, name))
f.write("}\n")
f.close()
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"])
print affich_tools.tableau(titre = ["lun", "nom"], data = map, alignement = ["g", "c"])