[iscsi] Deux baies pour le prix d'une
This commit is contained in:
parent
d0d7f71576
commit
01eec6b164
7 changed files with 91 additions and 148 deletions
|
@ -104,7 +104,7 @@ mac_titanic = 'aa:73:65:63:6f:76'
|
||||||
bcfg2_main = "bcfg2.adm.crans.org"
|
bcfg2_main = "bcfg2.adm.crans.org"
|
||||||
|
|
||||||
#: Fichier de mapping lun/nom de volume iscsi
|
#: 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
|
#: Algorithmes de hashage pour le champ SSHFP
|
||||||
# format : { algorithm : (IANA_id, ssh_algo) }
|
# format : { algorithm : (IANA_id, ssh_algo) }
|
||||||
|
|
75
gestion/iscsi/get_volume_mapping.py
Normal file
75
gestion/iscsi/get_volume_mapping.py
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# slon-get-volume-mapping.py
|
||||||
|
# --------------------------
|
||||||
|
# Copyright : (c) 2012, Olivier Iffrig <iffrig@crans.org>
|
||||||
|
# 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 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])
|
|
@ -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 <peb@crans.org>
|
|
||||||
# Merci à : Jérémie Dimino <jeremie@dimino.org>, 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"])
|
|
|
@ -1,10 +1,15 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- 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 <peb@crans.org>
|
# Auteur : Pierre-Elliott Bécue <peb@crans.org>
|
||||||
# Licence : WTFPL
|
# Licence : GPLv3
|
||||||
|
|
||||||
'''Bibliothèque pour accéder à la baie de stockage nols, récupère les données
|
'''Bibliothèque pour accéder à la baie de stockage nols, récupère les données
|
||||||
formatées en XML'''
|
formatées en XML'''
|
||||||
|
@ -109,40 +114,14 @@ class Nols(object):
|
||||||
root = fromstring(XML_map)
|
root = fromstring(XML_map)
|
||||||
tree = ElementTree(root)
|
tree = ElementTree(root)
|
||||||
|
|
||||||
## Cf juste en dessous
|
# XML c'est trobyien
|
||||||
Objects = tree.findall("OBJECT")
|
Objects = tree.findall("OBJECT[@name='volume-view']")
|
||||||
#Objects = tree.findall("OBJECT[@name='volume-view']")
|
|
||||||
## Fin cf juste en dessous
|
|
||||||
|
|
||||||
for Object in Objects:
|
for Object in Objects:
|
||||||
name = None
|
name = None
|
||||||
lun = None
|
lun = None
|
||||||
# Quand on passera à wheezy, décommenter ces lignes, et virer
|
name = Object.findall("PROPERTY[@name='volume-name']")[0].text
|
||||||
# la merde que j'ai fait juste après.
|
lun = Object.findall("OBJECT/PROPERTY[@name='lun']")[0].text
|
||||||
#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 #############
|
|
||||||
|
|
||||||
|
|
||||||
if lun is None:
|
if lun is None:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# slon-get-volume-mapping.py
|
|
||||||
# --------------------------
|
|
||||||
# Copyright : (c) 2012, Olivier Iffrig <iffrig@crans.org>
|
|
||||||
# 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 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"])
|
|
|
@ -37,7 +37,7 @@ execfile("/etc/crans/secrets/slon.py")
|
||||||
# lun
|
# lun
|
||||||
#
|
#
|
||||||
# On utilise cette expression un peu barbare pour récupérer les deux
|
# 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")
|
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):
|
class Slon(object):
|
||||||
|
|
|
@ -28,7 +28,8 @@ exec_cmd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
exec_cmd "Récupération du mapping lun<->nom de volume" \
|
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" \
|
exec_cmd "Rechargement des règles de udev" \
|
||||||
invoke-rc.d udev reload
|
invoke-rc.d udev reload
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue