-
Notifications
You must be signed in to change notification settings - Fork 92
/
clean_config.py
39 lines (37 loc) · 1.33 KB
/
clean_config.py
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
31
32
33
34
35
36
37
38
39
class Clean_Config(object):
def process_config(self):
self.cfg_modules = []
print "\nProcessing Configuration...\n\n"
config = exsh.clicmd('show config', capture=True)
config = config.splitlines(True)
print "\n->show configuration\n"
moduleName = ''
moduleStr = ''
configExist = False
for line in config:
if '#' not in line and line != '\n':
moduleStr += line
configExist = True
elif configExist is True and '#' in line:
self.cfg_modules.append(moduleName)
moduleStr = line
moduleName = ''
configExist = False
elif '#' in line:
moduleStr += line
configExist = False
if '# Module ' in line:
moduleName = line.replace('# Module ','')
moduleName = moduleName.replace(' configuration.\n','')
moduleName = moduleName.lower()
elif configExist is True and line == '\n':
moduleStr += line
else:
moduleStr = ''
def main():
cfg = Clean_Config()
cfg.process_config()
for module in cfg.cfg_modules:
cmd = 'show config %s' % module
print exsh.clicmd(cmd, capture=True)
main()