diff --git a/gestion/iscsi/slon-get-volume-mapping.py b/gestion/iscsi/slon-get-volume-mapping.py index b79d9224..3f826523 100755 --- a/gestion/iscsi/slon-get-volume-mapping.py +++ b/gestion/iscsi/slon-get-volume-mapping.py @@ -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"])