From 1a1dabf2553b1150ee409c52dc26335f93e12fb9 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Tue, 21 Oct 2008 16:36:24 +0200 Subject: [PATCH] =?UTF-8?q?[hptools]=20Utilisation=20directe=20de=20l'adre?= =?UTF-8?q?sse=20mac=20plut=C3=B4t=20que=20des=20secrets=20pour=20l'engine?= =?UTF-8?q?id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit darcs-hash:20081021143624-ffbb2-c8e48773081e97d21998276a1990059c490d5739.gz --- gestion/hptools.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gestion/hptools.py b/gestion/hptools.py index a7399384..601caf75 100755 --- a/gestion/hptools.py +++ b/gestion/hptools.py @@ -19,9 +19,13 @@ from os import system from re import findall from config import vlans +path.append('/usr/scripts/gestion') +from ldap_crans import crans_ldap +cl = crans_ldap() + try: path.append('/usr/scripts/gestion/secrets') - from secrets import config_snmp_secrete, reconf_snmp, engineid + from secrets import config_snmp_secrete, reconf_snmp except: # Si a pas le droit de lire config_snmp_secrete # on va tenter de tout faire en snmpv1 et communauté public @@ -118,10 +122,20 @@ class snmp : """ self.host = host self.version = version + + try: + self._machine = cl.search("host=%(host)s" % {'host': host})["machineCrans"][0] + except IndexError: + raise ValueError(u"Cette machine n'est pas un switch du Cr@ns") + + # l'engineid du switch n'est que sa mac avec quelques fioritures autour... + mac = self._machine.mac().replace(':', '') + self._engineid = '0000000b0000%(mac)s0' % {'mac': mac[:-1]} + if version == '1' or version == '2c' : self.options = "-v %s -c '%s' %s " % ( version, community, host ) elif version =='3' : - self.options = "-v 3 -e %s -u %s -a %s -A '%s' -l authNoPriv" % ( engineid[host.split('.',1)[0]], username, authentication_protocol, authentication_pass ) + self.options = "-v 3 -e %s -u %s -a %s -A '%s' -l authNoPriv" % ( self._engineid, username, authentication_protocol, authentication_pass ) if privacy_pass : self.options += " -x DES -X '%s' -l authPriv" % privacy_pass self.options += " %s " % host