[whos] Option -6 ou --ipv6 pour afficher les ipv6 en mode list_machines ou list_bornes, et on essaye plus d'avoir l'état des bornes quand on les liste (trop long)

This commit is contained in:
Pierre-Elliott Bécue 2013-03-03 04:17:12 +01:00
parent f95bb6d82f
commit 0f194550cc

View file

@ -38,6 +38,7 @@ d'historique affichées (défaut %(limit_aff_historique)i)
-d <num> ou --limit-blacklist=<num> : limitation du nombre de lignes -d <num> ou --limit-blacklist=<num> : limitation du nombre de lignes
d'historique des déconnexions affichées (défaut %(limit_aff_blacklist)i) d'historique des déconnexions affichées (défaut %(limit_aff_blacklist)i)
-s ou --ssh : affiche les fingerprint ssh des machines -s ou --ssh : affiche les fingerprint ssh des machines
-6 ou --ipv6 : affiche les ipv6 dans l'affichage synthétique
""" """
try: try:
@ -66,6 +67,7 @@ limit_aff_historique = 4
limit_aff_blacklist = 4 limit_aff_blacklist = 4
aff_ipsec = 0 aff_ipsec = 0
aff_ssh = 0 aff_ssh = 0
aff_ipv6 = 0
################################################################################ ################################################################################
### Fonctions utiles ### Fonctions utiles
@ -338,12 +340,17 @@ def list_machines(machines) :
t, bl = __bases_machines(m) t, bl = __bases_machines(m)
# Données # Données
data.append([m.id(), m.rid(), t, m.nom().split('.')[0], m.ip(), m.ipv6(), m.mac(), bl]) if not aff_ipv6:
data.append([m.id(), m.rid(), t, m.nom().split('.')[0], m.ip(), m.mac(), bl])
larg = 15
else:
larg = 22
data.append([m.id(), m.rid(), t, m.nom().split('.')[0], m.ipv6(), m.mac(), bl])
return tableau(data, return tableau(data,
titre = [u'mid', u'rid', u'Type', u'Nom de machine', u'Adresse IP', u'Adresse IPv6', u'Adresse MAC', u'Limitation'], titre = [u'mid', u'rid', u'Type', u'Nom de machine', u'Adresse IP', u'Adresse MAC', u'Limitation'],
largeur = [5, 5, 4, '*', 15, 22, 17, 10], largeur = [5, 5, 4, '*', larg, 17, 10],
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c']) alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c'])
def list_bornes(bornes) : def list_bornes(bornes) :
""" """
@ -376,22 +383,20 @@ def list_bornes(bornes) :
except : except :
l = u'????' l = u'????'
if borne_etat(b.nom()):
etat = ok
else:
etat = nok
if '-' in b.puissance() : if '-' in b.puissance() :
puiss = coul(b.puissance(),'rouge') puiss = coul(b.puissance(),'rouge')
else : else :
puiss = b.puissance() puiss = b.puissance()
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ip(), b.mac(), etat, b.canal(), puiss, b.prise(), l]) if aff_ipv6:
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ipv6(), b.mac(), b.canal(), puiss, b.prise(), l])
else:
data.append([b.id(), b.rid(), b.nom().split('.')[0], b.ip(), b.mac(), b.canal(), puiss, b.prise(), l])
return u"Can=canaux, P=puissance, E=état\n" + \ return u"Can=canaux, P=puissance, E=état\n" + \
tableau(data, tableau(data,
titre = [u'mid', u'rid', u'Nom', u'Adresse IP', u'Adresse MAC', u'E', u'Can', u'P', u'Pris', u'Lieu'], titre = [u'mid', u'rid', u'Nom', u'Adresse IP', u'Adresse MAC', u'Can', u'P', u'Pris', u'Lieu'],
largeur = [5, 5, 23, 15, 17, 1, 5, 3, 4, '*'], largeur = [5, 5, 16, 22, 17, 1, 5, 3, 4, '*'],
alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c']) alignement = ['d', 'd', 'c', 'c', 'c', 'c', 'c', 'c', 'g', 'c'])
def adher_details(adher) : def adher_details(adher) :
@ -1112,7 +1117,7 @@ def __recherche() :
""" """
Recherche et affichage des résultats à partir des options founies (sys.argv) Recherche et affichage des résultats à partir des options founies (sys.argv)
""" """
global aff_ipsec, aff_ssh, limit_aff_details, limit_aff_historique, limit_aff_blacklist, debug global aff_ipsec, aff_ssh, limit_aff_details, limit_aff_historique, limit_aff_blacklist, debug, aff_ipv6
# Récupération des options # Récupération des options
if len(sys.argv) == 1 : if len(sys.argv) == 1 :
@ -1120,7 +1125,7 @@ def __recherche() :
__usage_brief() __usage_brief()
try : try :
options, arg = getopt.getopt(sys.argv[1:], 'hamcstbil:L:d:', [ 'debug', 'help', 'adherent', 'machine', 'club' , 'tech', 'bornes', 'limit=', 'limit-historique=', 'limit-blacklist=', 'ipsec', 'crans', 'ssh' ]) options, arg = getopt.getopt(sys.argv[1:], 'hamcs6tbil:L:d:', [ 'debug', 'help', 'adherent', 'machine', 'club' , 'tech', 'bornes', 'limit=', 'limit-historique=', 'limit-blacklist=', 'ipsec', 'crans', 'ssh', 'ipv6' ])
except getopt.error, msg : except getopt.error, msg :
__usage_brief(unicode(msg)) __usage_brief(unicode(msg))
@ -1185,6 +1190,8 @@ def __recherche() :
aff_ipsec = 1 aff_ipsec = 1
elif opt in [ '-s', '--ssh' ]: elif opt in [ '-s', '--ssh' ]:
aff_ssh = 1 aff_ssh = 1
elif opt in [ '-6', '--ipv6' ]:
aff_ipv6 = 1
if only_adh + only_mac + only_club + only_bornes > 1 : if only_adh + only_mac + only_club + only_bornes > 1 :
__usage_brief(u'Options utilisées incompatibles') __usage_brief(u'Options utilisées incompatibles')