75 lines
1.7 KiB
Python
75 lines
1.7 KiB
Python
#!/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 %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])
|