11from netnir .helpers .scaffold .command import CommandScaffold
2- from netnir .core .template import CompileTemplate
2+ from netnir .plugins .template import template_file
33from netnir .plugins .netmiko import netmiko_send_commands
4- from netnir .helpers import output_writer , TextColor
54from netnir .plugins .hier import hier_host
5+ from netnir .helpers import output_writer
66from netnir .constants import OUTPUT_DIR
77from nornir .plugins .functions .text import print_result
8- import logging
98
109
1110class ConfigPlan (CommandScaffold ):
@@ -43,7 +42,7 @@ def parser(parser):
4342 required = False ,
4443 )
4544
46- def run (self , template_file = "main.conf.j2" ):
45+ def run (self ):
4746 """
4847 cli execution
4948
@@ -52,31 +51,27 @@ def run(self, template_file="main.conf.j2"):
5251 :returns: result string
5352 """
5453 self .nr = self ._inventory ()
55-
56- for host in self .nr .inventory .hosts :
57- compiled_template = CompileTemplate (
58- nr = self .nr , host = host , template = template_file
59- )
60- output_writer (
61- nornir_results = compiled_template .render (), output_file = "compiled.conf" ,
62- )
63- print_result (compiled_template .render ())
54+ results = self .nr .run (
55+ task = template_file ,
56+ template_file = "main.conf.j2" ,
57+ output_file = "compiled.conf" ,
58+ name = "COMPILE TEMPLATES" ,
59+ )
60+ output_writer (nornir_results = results , output_file = "compiled.conf" )
61+ print_result (results )
6462
6563 if self .args .compile :
66- if self .args .host :
67- return compiled_template .render ()
68- message = TextColor .green ("templates compiled for all hosts" )
69- return logging .info (message )
64+ return results
7065
71- results = self .nr (
66+ results = self .nr . run (
7267 task = netmiko_send_commands ,
7368 commands = "show running" ,
7469 name = "FETCH RUNNING CONFIG" ,
7570 )
7671 output_writer (nornir_results = results , output_file = "running.conf" )
7772 print_result (results )
7873
79- result = self .nr .run (
74+ results = self .nr .run (
8075 task = hier_host ,
8176 include_tags = self .args .include_tags ,
8277 exclude_tags = self .args .exclude_tags ,
@@ -86,6 +81,7 @@ def run(self, template_file="main.conf.j2"):
8681 load_file = True ,
8782 name = "RENDER REMEDIATION CONFIG" ,
8883 )
84+ output_writer (nornir_results = results , output_file = "remediation.conf" )
85+ print_result (results )
8986
90- print_result (result )
91- return result
87+ return results
0 commit comments