[gestion/iscsi/slonlib.py] Corrections mineures
Ignore-this: 87c7efb1d5f14c7f18ebee043fdcd46e Les fonctions d'introspection n'aiment pas trop les chaines unicode... darcs-hash:20090414001504-ffbb2-66eae3adcf7ccef2473c195db1779239f02cbc2b.gz
This commit is contained in:
parent
16bc76d995
commit
a96885b933
1 changed files with 10 additions and 10 deletions
|
@ -6,7 +6,7 @@
|
||||||
# Copyright : (c) 2008, Jeremie Dimino <jeremie@dimino.org>
|
# Copyright : (c) 2008, Jeremie Dimino <jeremie@dimino.org>
|
||||||
# Licence : BSD3
|
# Licence : BSD3
|
||||||
|
|
||||||
u'''Librairie pour accéder à la baie de stockage'''
|
'''Bibliothèque pour accéder à la baie de stockage'''
|
||||||
|
|
||||||
import telnetlib, re
|
import telnetlib, re
|
||||||
|
|
||||||
|
@ -40,8 +40,8 @@ execfile("/etc/crans/secrets/slon.py")
|
||||||
# informations qui nous intéressses:
|
# informations qui nous intéressses:
|
||||||
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:
|
class Slon(object):
|
||||||
u'''Object représentant la baie de stockage'''
|
'''Objet représentant la baie de stockage'''
|
||||||
|
|
||||||
def __init__(self, host="slon.adm.crans.org"):
|
def __init__(self, host="slon.adm.crans.org"):
|
||||||
self.tn = telnetlib.Telnet(host)
|
self.tn = telnetlib.Telnet(host)
|
||||||
|
@ -62,13 +62,13 @@ class Slon:
|
||||||
# Au delà de cette valeur il y a un overflow
|
# Au delà de cette valeur il y a un overflow
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
u'''Déconnexion de la baie'''
|
'''Déconnexion de la baie'''
|
||||||
self.tn.write("exit\r\n")
|
self.tn.write("exit\r\n")
|
||||||
self.tn.read_all()
|
self.tn.read_all()
|
||||||
self.tn.close()
|
self.tn.close()
|
||||||
|
|
||||||
def cmd(self, cmd):
|
def cmd(self, cmd):
|
||||||
u'''Exécute une commande et renvoie le résultat. Lance
|
'''Exécute une commande et renvoie le résultat. Lance
|
||||||
l'exception Error si la commande échoue'''
|
l'exception Error si la commande échoue'''
|
||||||
self.tn.write(cmd + "\r\n")
|
self.tn.write(cmd + "\r\n")
|
||||||
resp = ""
|
resp = ""
|
||||||
|
@ -93,22 +93,22 @@ class Slon:
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
def show(self, what):
|
def show(self, what):
|
||||||
u'''Raccourci pour: print slon.cmd("show <what>")'''
|
'''Raccourci pour: print slon.cmd("show <what>")'''
|
||||||
print self.cmd("show " + what)
|
print self.cmd("show " + what)
|
||||||
|
|
||||||
def help(self, what):
|
def help(self, what):
|
||||||
u'''Raccourci pour: print slon.cmd("help <what>")'''
|
'''Raccourci pour: print slon.cmd("help <what>")'''
|
||||||
print self.cmd("help " + what)
|
print self.cmd("help " + what)
|
||||||
|
|
||||||
def volume_map(self):
|
def volume_map(self):
|
||||||
u'''Retourne le mapping lun<->nom de volume'''
|
'''Retourne le mapping lun<->nom de volume'''
|
||||||
map = {}
|
map = {}
|
||||||
for m in volume_map_regexp.finditer(self.cmd("show volume-maps")):
|
for m in volume_map_regexp.finditer(self.cmd("show volume-maps")):
|
||||||
map[int(m.group(2))] = m.group(1)
|
map[int(m.group(2))] = m.group(1)
|
||||||
return map
|
return map
|
||||||
|
|
||||||
def create_volume(self, name, size, unit="GB", vdisk="slon1"):
|
def create_volume(self, name, size, unit="GB", vdisk="slon1"):
|
||||||
u'''Créé un nouveau volume. Retourne le lun sur lequel il est
|
'''Créé un nouveau volume. Retourne le lun sur lequel il est
|
||||||
mappé. La taille est en Giga-octet. L'unité doit être "KB",
|
mappé. La taille est en Giga-octet. L'unité doit être "KB",
|
||||||
"MB" ou "GB". Par défault c'est "GB".'''
|
"MB" ou "GB". Par défault c'est "GB".'''
|
||||||
|
|
||||||
|
@ -127,6 +127,6 @@ class Slon:
|
||||||
return lun
|
return lun
|
||||||
|
|
||||||
def delete_volume(self, name):
|
def delete_volume(self, name):
|
||||||
u'''Supprime un volume'''
|
'''Supprime un volume'''
|
||||||
|
|
||||||
self.cmd("delete volume %s")
|
self.cmd("delete volume %s")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue