Commit b8d8643a authored by Hamza Dely's avatar Hamza Dely

[switchs2] Header : base LDAP puis interrogation du switch en SSH

parent cab6edd8
......@@ -468,8 +468,22 @@ def get_bat_num(hostname):
def get_header(hostname):
from gestion.majswitch2 import get_version
firmware, model = get_version(hostname + ".switches.crans.org")
header = "; %s Configuration Editor; Created on release #%s" % (model, firmware)
header = None
# On commence par chercher le header dans la base LDAP
try:
switch = ldap.search(
u'(&(host=%s.switches.crans.org)'
u'(objectClass=switchCrans))' % hostname
)[0]
for line, com in enumerate(switch['info']):
if com.value.startswith(';'):
header = com.value.encode('utf-8')
except (IndexError, KeyError):
pass
# S'il n'y est pas, on fallback sur celui du switch en prod'
if header is None:
firmware, model = get_version(hostname + ".switches.crans.org")
header = "; %s Configuration Editor; Created on release #%s" % (model, firmware)
return header
def conf_switch(hostname):
......
Markdown is supported
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