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

Nettoyage de printemps relatif à hptools/snmp

parent 6e03728f
......@@ -16,9 +16,9 @@
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
"""Fournit des outils et fonctions appelables au besoin"""
from gestion import annuaires_pg
from multiprocessing import Process, Manager
from gestion import annuaires_pg
from .switch import HPSwitch
from .mac import MACFactory, format_mac
......
......@@ -13,7 +13,7 @@ from socket import gethostname
from lc_ldap import shortcuts
from gestion.hptools import hpswitch, ConversationError
from gestion import hptools2
from gestion.affich_tools import cprint
import gestion.affichage as affichage
import gestion.mail as mail_module
......@@ -165,10 +165,10 @@ class WhosThere(object):
def populate_from_switch(self, host, port):
"""Rempli les macs à partir de la prise d'un switch"""
sw = hpswitch(host)
sw = hptools2.HPSwitch(host)
try:
macs = sw.show_prise_mac(port)
except ConversationError:
macs = sw.show_port_macs(port)[0]
except hptools2.SwitchNotFound:
cprint("Impossible de communiquer avec le switch !", 'rouge')
for mac in macs:
self.populate_from_mac(mac)
......
......@@ -54,7 +54,7 @@ from ldap_crans import is_actif, crans_ldap, AssociationCrans, hostname
from ldap_crans import MachineCrans, MachineWifi, BorneWifi
from ldap_crans import Adherent
from ldap_crans import datetimeFromGTF
from hptools import sw_chbre, ConversationError
import gestion.hptools2 as hptools2
import gestion.annuaires_pg as annuaires_pg
import gestion.config as config
import ridtools
......@@ -603,7 +603,7 @@ def adher_details(adher) :
f += coul(u'Chambre invalide\n','violet')
else :
# Chambre + prise (d'après annuaire)
etat, vlans, cablage = prise_etat(adher.chbre())
etat, vlans = prise_etat(adher.chbre())
f += coul(u'Chambre : ','gras') + u"%s " % chbre
f += u'(%s)' % etat
f += u'\n'
......@@ -810,8 +810,23 @@ def machine_details(machine) :
if (machine.prise() != 'N/A'):
try:
f += coul(u'VLANs : ', 'gras')
from hptools import sw_prise
f += ', '.join(sw_prise(machine.prise()).vlans())
try:
prise = machine.prise()
__sw_name = annuaires_pg.guess_switch_fqdn(
"bat%s-%s" % (prise[0].lower(), prise[1].lower())
)
__switch = hptools2.HPSwitch(
__sw_name,
)
__vlans = [
unicode(__vlan)
for __vlan in __switch.get_vlans(int(prise[2:]))
]
except hptools2.SwitchNotFound:
__vlans = [u"erreur interne lors de la récupération des vlans",]
f += ', '.join(__vlans)
f += '\n'
except:
pass
......@@ -919,7 +934,7 @@ def club_details(club) :
f += '\n'
# Chambre + prise
etat, vlans, cablage = prise_etat(club.chbre())
etat, vlans = prise_etat(club.chbre())
f += coul(u'Local : ','gras') + u"%s " % club.local()
f += u'(%s)' % etat
f += u'\n'
......@@ -1126,19 +1141,41 @@ def prise_etat(chbre) :
"""
f = u''
vlans = u''
cablage = u''
try:
# On met aussi l'état
prise = sw_chbre(chbre)
vlans += ', '.join(prise.vlans())
bat = chbre[0].lower()
chbre = chbre[1:].lower()
prise = annuaires_pg.chbre_prises(bat, chbre)
sw_num = int(prise[0])
prise_num = int(prise[1:])
if bat in config.bats_virtuels:
f += u'prise %s' % prise
f += u', ' + coul(u"Chambre virtuelle", "violet")
vlans += u"VLAN Virtuel"
return f, vlans
else:
switch = hptools2.HPSwitch(
annuaires_pg.guess_switch_fqdn(
"bat%s-%s" % (
bat,
sw_num,
),
)
)
vlans += ', '.join([
str(vlan)
for vlan in switch.get_vlans(prise_num)
])
f += u'prise %s' % prise.prise_brute
f += u'prise %s' % prise
rows, cols = get_screen_size()
if prise.is_up() :
if switch.is_up(prise_num):
f += u', ' + coul(u'machine branchée','vert')
reste_cols = cols - 45
f+=', '
macs = prise.show_prise_mac()
macs = switch.show_port_macs(prise_num)[0]
if len(macs) == 0:
if reste_cols < 20 :
# Faut aller à la ligne
......@@ -1162,11 +1199,8 @@ def prise_etat(chbre) :
f += u', '
f += u"%s" % macs.pop()
count += 1
elif not prise.is_enable():
if prise.is_fake():
f += u', ' + coul(u"Chambre virtuelle", "violet")
else:
f += u', ' + coul(u'prise désactivée','rouge')
elif not switch.is_enabled(prise_num):
f += u', ' + coul(u'prise désactivée','rouge')
else :
f += u', activée, lien non détecté'
try:
......@@ -1175,21 +1209,14 @@ def prise_etat(chbre) :
f += u'\n' + ' '*10 + extra_info
except ValueError:
pass
except ConversationError, r:
except hptools2.SwitchNotFound, r:
# Switch non manageable ou down
f += ', '
f+= {'Unknown host (No such file or directory)' :
u'switch non manageable',
'Failure in sendto (Operation not permitted)' :
u'infos prise non dispo : filtre vers adm par fw',
'sh: line 1: command not found' :
u'infos prise non dispo depuis cette machine'
}.get(r.args[0],r.args[0])
f += u', switch inexistant ou injoignable!'
except ValueError, r :
f = r
except :
f = u'infos prise non dispo : erreur interne'
return f, vlans, cablage
return f, vlans
##############################################################################
## Partie dévolue au système de recherche
......
......@@ -13,7 +13,6 @@ import BeautifulSoup
import requests
import HTMLParser
import sys
from gestion.hptools import snmp
STATUS_URL = 'https://imprimante.adm.crans.org/hp/device/DeviceStatus/Index'
CA = '/etc/ssl/certs/cacert.org.pem'
......
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