11from netnir .helpers .scaffold .command import CommandScaffold
2- from netnir .core .template import CompileTemplate
3- from netnir .core .networking import Networking
4- from netnir .helpers import output_writer , TextColor
2+ from netnir .plugins .template import template_file
3+ from netnir .plugins .netmiko import netmiko_send_commands
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
9-
10-
11- """config plan cli commands
12- """
138
149
1510class ConfigPlan (CommandScaffold ):
@@ -47,7 +42,7 @@ def parser(parser):
4742 required = False ,
4843 )
4944
50- def run (self , template_file = "main.conf.j2" ):
45+ def run (self ):
5146 """
5247 cli execution
5348
@@ -56,36 +51,37 @@ def run(self, template_file="main.conf.j2"):
5651 :returns: result string
5752 """
5853 self .nr = self ._inventory ()
59-
60- for host in self .nr .inventory .hosts :
61- compiled_template = CompileTemplate (
62- nr = self .nr , host = host , template = template_file
63- )
64- output_writer (
65- nornir_results = compiled_template .render (), output_file = "compiled.conf" ,
66- )
67- 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 )
6862
6963 if self .args .compile :
70- if self .args .host :
71- return compiled_template .render ()
72- message = TextColor .green ("templates compiled for all hosts" )
73- return logging .info (message )
64+ return results
7465
75- networking = Networking (nr = self .nr )
76- running_config = networking .fetch (commands = "show running" )
77- output_writer (nornir_results = running_config , output_file = "running.conf" )
78- print_result (running_config )
66+ results = self .nr .run (
67+ task = netmiko_send_commands ,
68+ commands = "show running" ,
69+ name = "FETCH RUNNING CONFIG" ,
70+ )
71+ output_writer (nornir_results = results , output_file = "running.conf" )
72+ print_result (results )
7973
80- result = self .nr .run (
74+ results = self .nr .run (
8175 task = hier_host ,
8276 include_tags = self .args .include_tags ,
8377 exclude_tags = self .args .exclude_tags ,
8478 running_config = "running.conf" ,
8579 compiled_config = "compiled.conf" ,
8680 config_path = OUTPUT_DIR ,
8781 load_file = True ,
82+ 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