The unified diff between revisions [c1adc84f..] and [c65bc853..] is displayed below. It can also be downloaded as a raw diff.
#
#
# patch "plugins/cisco_ios.py"
# from [19feaff94350a58fc05c4cc35ae258285a38655c]
# to [342b04adca958885588dcf59b73292c012393175]
#
============================================================
--- plugins/cisco_ios.py 19feaff94350a58fc05c4cc35ae258285a38655c
+++ plugins/cisco_ios.py 342b04adca958885588dcf59b73292c012393175
@@ -5,7 +5,6 @@ def adjacency(table_name, table_io, devi
def adjacency(table_name, table_io, device):
def h2i(s):
- print "h2i called, with argument:", s
h = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'A':10,'B':11,'C':12,'D':13,'E':14,'F':15}
if len(s) == 1: return h[s[0]]
else :return 16*h[s[0]] + h[s[1]]
@@ -17,24 +16,26 @@ def adjacency(table_name, table_io, devi
asdigits = [h2i(t) for t in s.split(' ')]
asdigits = filter(lambda x: x >= 32 and x <= 122, asdigits)
return ''.join([chr(t) for t in asdigits])
- row_to_field = { 4 : 'ip_address', 6 : 'name', 7 : 'remote_port' }
+ row_to_field = { 4 : ('Hex-STRING', 'ip_address'),
+ 6 : ('STRING', 'name'),
+ 7 : ('STRING', 'remote_port') }
table = {}
for oid, type, value in snmpwalk(device.device_name, device.config['community'], "2c", "SNMPv2-SMI::enterprises.9.9.23.1.2.1.1", ssh_dest=device.config.get('ssh')):
- print oid, type, value
- id = tuple(oid[-2:])
- row = int(oid[-3])
+ id, row = tuple(oid[-2:]), int(oid[-3])
if not table.has_key(id): table[id] = {}
- if row_to_field.has_key(row):
- table[id][row_to_field[row]] = value
+ match_type, match_name = row_to_field.get(row, (None, None))
+ if match_name and match_type and match_type == type:
+ table[id][match_name] = value
+
+ print table
for row in table:
- ip = to_ipaddr(table[row].get('ip_address'))
- name = table[row].get('name')[1:-1]
- if re.match(r'^(..?)+ ..?$', name):
- name = to_ascii(name)
- m = re.match(r'[^A-Za-z0-9]*([A-Za-z0-9]+)', name)
- if m: name = m.groups()[0]
- remote_port = table[row].get('remote_port')[1:-1]
- yield device.config['zone'], ip, name, remote_port
+ vals = table[row]
+ if not vals.has_key('ip_address') or not vals.has_key('name') or not vals.has_key('remote_port'):
+ continue
+ ip = to_ipaddr(vals['ip_address'])
+ name = vals['name'][1:-1]
+ remote_port = vals['remote_port'][1:-1]
+ yield device.config['zone'], name, remote_port, ip
# see: http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a0080094a9b.shtml
def ethernet_forwarding(table_name, table_io, device):