Commit bdbc0b5b authored by Pierre-Elliott Bécue's avatar Pierre-Elliott Bécue
Browse files

[iscsi] On améliore encore, parce que c'est un peu buggué.

parent a42896d8
......@@ -18,8 +18,14 @@ from config import ISCSI_MAP_FILE
def getname(device):
map_file = ISCSI_MAP_FILE
if not device.isalpha():
block = "".join([i for i in device if i.isalpha()])
part = "_part" + device.replace(block, "")
else:
block = device
part = ""
# Rechreche le nom complet du périphérique dans /sys
dev = os.readlink("/sys/block/%s/device" % device)
dev = os.readlink("/sys/block/%s/device" % block)
# L'identifiant est de la forme "../../../0:0:0:42", où 42 (j'ai perdu)
# est le lun.
......@@ -36,7 +42,7 @@ def getname(device):
globals()['map'] = {}
execfile(map_file, globals())
return map.get(lun, "lun%d" % lun)
return map.get(lun, "lun%d" % lun) + part
if __name__ == '__main__':
if len(sys.argv) != 2:
......
......@@ -29,54 +29,59 @@ def store_iscsi_volumes():
if line.startswith('ip-'):
device = os.readlink(PATH+line) # de la forme ../../sdb42
device = device.rsplit('/', 1)[1]
symlink = 'iscsi_' + ugin.getname(device)
if line.rsplit('-', 1)[1][0:4] == "part":
symlink = 'iscsi_' + ugin.getname("".join([i for i in device if i.isalpha()])) + "_part" + line.rsplit('-', 1)[1][4:]
lun = line.rsplit('-', 2)[1]
else:
symlink = 'iscsi_' + ugin.getname(device)
line = line.rsplit('-', 1)[1]
_ = links.setdefault(line, [symlink, device])
lun = line.rsplit('-', 1)[1]
if links.has_key(lun):
if not (True in [(symlink in tup) for tup in links[lun]]):
links[lun].append((symlink, device))
else:
links[lun] = [(symlink, device)]
return links
def make_link(couple):
"""Crée le symlink /dev/iscsi_nom -> /dev/sdb42"""
os.chdir("/dev/")
sym, dev = couple
diskstatus = subprocess.Popen(['file', '-sb', '/dev/' + dev], stdout=subprocess.PIPE)
diskstatus = diskstatus.stdout.readlines()[0]
if not (os.path.islink(sym)) and not 'empty' in diskstatus and not 'ERROR' in diskstatus:
sys.stdout.write("Création du lien /dev/" + sym + " -> /dev/" + dev + " … ")
try:
os.symlink(dev, sym)
sys.stdout.write(coul("OK", 'vert'))
res = True
except:
sys.stdout.write(coul("ECHEC", 'rouge'))
res = False
sys.stdout.write('\n')
elif os.path.islink(sym) and ('empty' in diskstatus or 'ERROR' in diskstatus):
sys.stdout.write("Destruction du lien /dev/" + sym + " … ")
try:
os.remove(sym)
sys.stdout.write(coul("OK", 'vert'))
res = True
except:
sys.stdout.write(coul("ECHEC", 'rouge'))
res = False
sys.stdout.write('\n')
elif os.path.islink(sym) and os.readlink(sym) != dev:
sys.stdout.write("Mise à jour du lien /dev/" + sym + " -> /dev/" + dev + " … ")
try:
os.remove(sym)
os.symlink(dev, sym)
sys.stdout.write(coul("OK", 'vert'))
res = True
except:
sys.stdout.write(coul("ECHEC", 'rouge'))
res = False
sys.stdout.write('\n')
else:
res = None
res = []
for (sym, dev) in couple:
diskstatus = subprocess.Popen(['file', '-sb', '/dev/' + dev], stdout=subprocess.PIPE)
diskstatus = diskstatus.stdout.readlines()[0]
if not (os.path.islink(sym)) and not 'empty' in diskstatus and not 'ERROR' in diskstatus:
sys.stdout.write("Création du lien /dev/" + sym + " -> /dev/" + dev + " … ")
try:
os.symlink(dev, sym)
sys.stdout.write(coul("OK", 'vert'))
res.append(True)
except:
sys.stdout.write(coul("ECHEC", 'rouge'))
res.append(False)
sys.stdout.write('\n')
elif os.path.islink(sym) and ('empty' in diskstatus or 'ERROR' in diskstatus):
sys.stdout.write("Destruction du lien /dev/" + sym + " … ")
try:
os.remove(sym)
sys.stdout.write(coul("OK", 'vert'))
res.append(True)
except:
sys.stdout.write(coul("ECHEC", 'rouge'))
res.append(False)
sys.stdout.write('\n')
elif os.path.islink(sym) and os.readlink(sym) != dev:
sys.stdout.write("Mise à jour du lien /dev/" + sym + " -> /dev/" + dev + " … ")
try:
os.remove(sym)
os.symlink(dev, sym)
sys.stdout.write(coul("OK", 'vert'))
res.ppend(True)
except:
sys.stdout.write(coul("ECHEC", 'rouge'))
res.append(False)
sys.stdout.write('\n')
else:
res.append(None)
return res
def clean_iscsi_links():
......@@ -91,7 +96,7 @@ def clean_iscsi_links():
if line.startswith('iscsi_'):
device = os.readlink('/dev/'+line) # de la forme ../../sdb42
symlink = line
make_link((symlink, device))
make_link([(symlink, device)])
return links
if __name__ == '__main__':
......@@ -105,7 +110,7 @@ if __name__ == '__main__':
links = store_iscsi_volumes()
for path in links.keys():
cmd = make_link(links[path])
if cmd != None:
if True in cmd or False in cmd:
nothing = False
if nothing:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment