1+ from typing import List
2+
3+ from ciscoconfparse import CiscoConfParse
4+
15from suzieq .engines .pandas .engineobj import SqPandasEngine
26
37
@@ -8,3 +12,47 @@ class DevconfigObj(SqPandasEngine):
812 def table_name ():
913 '''Table name'''
1014 return 'devconfig'
15+
16+ def get (self , ** kwargs ):
17+ '''Retrieve the devconfig table info'''
18+
19+ section = kwargs .pop ('section' , None )
20+ columns = kwargs .pop ('columns' , ['default' ])
21+ query_str = kwargs .pop ('query_str' , '' )
22+
23+ df = super ().get (columns = columns , ** kwargs )
24+ if df .empty or 'error' in df .columns or not section :
25+ return df
26+
27+ devdf = self ._get_table_sqobj ('device' ) \
28+ .get (columns = ['namespace' , 'hostname' , 'os' ], ** kwargs )
29+
30+ if devdf .empty or 'errror' in devdf .columns :
31+ return df
32+
33+ drop_indices : List [int ] = []
34+ for index , row in enumerate (df .itertuples ()):
35+ os = devdf .loc [(devdf ['hostname' ] == row .hostname ) &
36+ (devdf ['namespace' ] == row .namespace ),
37+ 'os' ].values [0 ]
38+ if os .startswith ('junos' ) or os == 'panos' :
39+ os = 'junos'
40+ elif os == 'nxos' :
41+ os = 'nxos'
42+ else :
43+ os = 'ios'
44+
45+ parsed_conf = CiscoConfParse (row .config .split ('\n ' ), syntax = os )
46+ conf = '\n ' .join (parsed_conf .find_all_children (section ))
47+ if not conf :
48+ drop_indices .append (index )
49+ else :
50+ df .loc [index , 'config' ] = conf
51+
52+ if drop_indices :
53+ df = df .drop (index = drop_indices )
54+
55+ if query_str :
56+ df = df .query (query_str ).reset_index (drop = True )
57+
58+ return df
0 commit comments