File: vlan-and-interfaces.py

package info (click to toggle)
snimpy 0.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 484 kB
  • ctags: 435
  • sloc: python: 3,361; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/snimpy

"""
On Nortel switches, list vlan on all active ports
"""

import os
import sys

load("SNMPv2-MIB")
load("IF-MIB")
load(os.path.expanduser("~/.snmp/mibs/RAPID-CITY-MIB"))
load(os.path.expanduser("~/.snmp/mibs/RC-VLAN-MIB"))

s = M(host=sys.argv[1], community=sys.argv[2])

vlans = {}

for interface in s.ifIndex:
    if s.ifOperStatus[interface] == "up":
        vlans[int(interface)] = []

for vlan in s.rcVlanId:
    for interface in vlans:
        if s.rcVlanStaticMembers[vlan] & interface:
            vlans[interface].append("%s(%s)" % (vlan, s.rcVlanName[vlan]))

import pprint
pprint.pprint(vlans)