diff --git a/gestion/config/config.py b/gestion/config/config.py index dba84a55..dc134677 100644 --- a/gestion/config/config.py +++ b/gestion/config/config.py @@ -104,7 +104,7 @@ mac_titanic = 'aa:73:65:63:6f:76' bcfg2_main = "bcfg2.adm.crans.org" #: Fichier de mapping lun/nom de volume iscsi -ISCSI_MAP_FILE = "/usr/scripts/var/iscsi_names.py" +ISCSI_MAP_FILE = "/usr/scripts/var/iscsi_names_%s.py" #: Algorithmes de hashage pour le champ SSHFP # format : { algorithm : (IANA_id, ssh_algo) } diff --git a/gestion/iscsi/get_volume_mapping.py b/gestion/iscsi/get_volume_mapping.py new file mode 100644 index 00000000..3a66c428 --- /dev/null +++ b/gestion/iscsi/get_volume_mapping.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# slon-get-volume-mapping.py +# -------------------------- +# Copyright : (c) 2012, Olivier Iffrig +# Copyright : (c) 2008, Jeremie Dimino +# Licence : BSD3 + +u'''Outil pour récupérer le mapping lun/volume depuis la baie de +stockage''' + +import slonlib +import nolslib +import re +import sys + +coding = "utf-8" + +sys.path.append("/usr/scripts/gestion") +from config import ISCSI_MAP_FILE +import affich_tools + +def get_mapping(baie_name): + map_file = ISCSI_MAP_FILE % (baie_name,) + print u"Connexion à la baie de stockage…".encode(coding) + + if baie_name == "slon": + baie = slonlib.Slon() + else: + baie = nolslib.Nols() + + print u"Récupération des informations…".encode(coding) + + map = baie.volume_map().items() + map.sort() + + print u"Déconnexion…".encode(coding) + + baie.logout() + + print u"Enregistrement des informations…".encode(coding) + + f = open(map_file, "w") + f.write((u"""\ +# /usr/bin/env python +# -*- coding: utf-8 -*- +# Fichier de mapping lun -> nom de volume +# +# Ce fichier est généré par %s + + map = { + """ % (sys.argv[0], baie)).encode(coding)) + + for lun, name in map: + f.write(' %d : "%s",\n' % (lun, name)) + + f.write("}\n") + + f.close() + + print u"Terminé, mapping enregistré dans %s" % map_file + + print u"Le mapping actuel est : " + print affich_tools.tableau(titre = ["lun", "nom"], data = map, alignement = ["g", "c"]) + +if __name__ == "__main__": + if len(sys.argv) < 2: + print """\ +Usage : get_volume_mapping.py baie + +Récupère le volume mapping sur la baie de disques choisie. + """ + else: + get_mapping(sys.argv[1]) diff --git a/gestion/iscsi/nols_get_volume_mapping.py b/gestion/iscsi/nols_get_volume_mapping.py deleted file mode 100644 index 82ef9a01..00000000 --- a/gestion/iscsi/nols_get_volume_mapping.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# nols-get-volume-mapping.py -# -------------------------- -# Qui taper si ça marche pas : Pierre-Elliott Bécue -# Merci à : Jérémie Dimino , je n'ai fait que s/slon/nols/ sur ce script. -# Licence : BSD3 - -u'''Outil pour récupérer le mapping lun/volume depuis la baie de -stockage''' - -import nolslib, re, sys - -sys.path.append("/usr/scripts/gestion") -from config import ISCSI_MAP_FILE -import affich_tools - -map_file = ISCSI_MAP_FILE - -print u"Connexion a la baie de stockage..." - -nols = nolslib.Nols() - -print u"Recuperation des informations..." - -map = nols.volume_map().items() -map.sort() - -print u"Deconnexion..." - -nols.logout() - -print u"Enregistrement des informations..." - -f = open(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"Termine, mapping enregistre dans %s" % map_file - -print u"Le mapping actuel est:" -print affich_tools.tableau(titre = ["lun", "nom"], data = map, alignement = ["g", "c"]) diff --git a/gestion/iscsi/nolslib.py b/gestion/iscsi/nolslib.py index f7677fc8..85240a9d 100644 --- a/gestion/iscsi/nolslib.py +++ b/gestion/iscsi/nolslib.py @@ -1,10 +1,15 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# baie_lib.py +# nolslib.py +# Ce script est inspiré de slonlib.py, développé par +# Jérémie Dimino en 2008. +# Développé pour communiquer en telnet avec une baie MSA 2012a (modèle à +# vérifier), il a été adapté pour communiquer avec une MSA P2000, qui sait +# retourner des sorties compatibles avec des api. # ---------- -# Type à taper si ça chie : Pierre-Elliott Bécue -# Licence : WTFPL +# Auteur : Pierre-Elliott Bécue +# Licence : GPLv3 '''Bibliothèque pour accéder à la baie de stockage nols, récupère les données formatées en XML''' @@ -109,40 +114,14 @@ class Nols(object): root = fromstring(XML_map) tree = ElementTree(root) - ## Cf juste en dessous - Objects = tree.findall("OBJECT") - #Objects = tree.findall("OBJECT[@name='volume-view']") - ## Fin cf juste en dessous + # XML c'est trobyien + Objects = tree.findall("OBJECT[@name='volume-view']") for Object in Objects: name = None lun = None - # Quand on passera à wheezy, décommenter ces lignes, et virer - # la merde que j'ai fait juste après. - #name = Object.findall("PROPERTY[@name='volume-name']")[0].text - #lun = Object.findall("OBJECT/PROPERTY[@name='lun']")[0].text - - ######## Début merde que j'ai faite juste après ########### - if not (Object.attrib['name'] == "volume-view"): - pass - - properties = Object.findall("PROPERTY") - for property in properties: - if property.attrib['name'] == "volume-name": - name = property.text - else: - pass - - subObjects = Object.findall("OBJECT") - for subObject in subObjects: - properties = subObject.findall("PROPERTY") - for property in properties: - if property.attrib['name'] == "lun": - lun = property.text - else: - pass - ####### Fin merde que j'ai faite juste après ############# - + name = Object.findall("PROPERTY[@name='volume-name']")[0].text + lun = Object.findall("OBJECT/PROPERTY[@name='lun']")[0].text if lun is None: pass diff --git a/gestion/iscsi/slon_get_volume_mapping.py b/gestion/iscsi/slon_get_volume_mapping.py deleted file mode 100644 index e78b1c7d..00000000 --- a/gestion/iscsi/slon_get_volume_mapping.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# slon-get-volume-mapping.py -# -------------------------- -# Copyright : (c) 2012, Olivier Iffrig -# Copyright : (c) 2008, Jeremie Dimino -# Licence : BSD3 - -u'''Outil pour récupérer le mapping lun/volume depuis la baie de -stockage''' - -import slonlib, re, sys - -sys.path.append("/usr/scripts/gestion") -from config import ISCSI_MAP_FILE_TEMPLATE -import affich_tools - -map_file = ISCSI_MAP_FILE_TEMPLATE % "slon" - -print u"Connection à la baie de stockage..." - -slon = slonlib.Slon() - -print u"Récupération des informations..." - -map = slon.volume_map().items() -map.sort() - -print u"Déconnection..." - -slon.logout() - -print u"Enregistrement des informations..." - -f = open(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" % map_file - -print u"Le mapping actuel est:" -print affich_tools.tableau(titre = ["lun", "nom"], data = map, alignement = ["g", "c"]) diff --git a/gestion/iscsi/slonlib.py b/gestion/iscsi/slonlib.py index 2007f5cd..1c4688f8 100644 --- a/gestion/iscsi/slonlib.py +++ b/gestion/iscsi/slonlib.py @@ -37,7 +37,7 @@ execfile("/etc/crans/secrets/slon.py") # lun # # On utilise cette expression un peu barbare pour récupérer les deux -# informations qui nous intéressses: +# informations qui nous intéresssent : volume_map_regexp = re.compile("Volume \[SN [0-9a-f]+, Name \(([^)]*)\)\][^\n]*\n[^\n]*\n[^\n]*\n[0-9,-]+ *[0-9]+ *([0-9]+)[^\n]*\n") class Slon(object): diff --git a/gestion/iscsi/update.sh b/gestion/iscsi/update.sh index ce4c051d..dea50a23 100755 --- a/gestion/iscsi/update.sh +++ b/gestion/iscsi/update.sh @@ -28,7 +28,8 @@ exec_cmd() { } exec_cmd "Récupération du mapping lun<->nom de volume" \ - python /usr/scripts/gestion/iscsi/nols_get_volume_mapping.py + python /usr/scripts/gestion/iscsi/get_volume_mapping.py nols + python /usr/scripts/gestion/iscsi/get_volume_mapping.py slon exec_cmd "Rechargement des règles de udev" \ invoke-rc.d udev reload