|
1 | | -from netnir.constants import NR |
| 1 | +from netnir.helpers.scaffold.command import CommandScaffold |
2 | 2 | from netnir.core.template import CompileTemplate |
3 | 3 | from netnir.core.networking import Networking |
4 | 4 | from netnir.helpers import output_writer, TextColor |
5 | 5 | from netnir.plugins.hier import hier_host |
6 | | -from netnir.helpers.common.args import filter_host |
7 | 6 | from netnir.constants import OUTPUT_DIR |
8 | 7 | from nornir.plugins.functions.text import print_result |
9 | 8 | import logging |
|
13 | 12 | """ |
14 | 13 |
|
15 | 14 |
|
16 | | -class ConfigPlan: |
| 15 | +class ConfigPlan(CommandScaffold): |
17 | 16 | """ |
18 | 17 | config plan cli plugin to render configuration plans, either by |
19 | 18 | compiling from template or using hier_config to create a remediation |
20 | 19 | plan |
21 | | -
|
22 | | - :params args: type obj |
23 | 20 | """ |
24 | 21 |
|
25 | | - def __init__(self, args): |
26 | | - """ |
27 | | - initialize the config plan class |
28 | | - """ |
29 | | - self.args = args |
30 | | - self.nr = NR |
31 | | - |
32 | 22 | @staticmethod |
33 | 23 | def parser(parser): |
34 | 24 | """ |
35 | 25 | cli options parser |
36 | 26 |
|
37 | 27 | :params parser: type obj |
38 | 28 | """ |
39 | | - filter_host(parser) |
| 29 | + CommandScaffold.parser(parser) |
40 | 30 | parser.add_argument( |
41 | 31 | "--compile", |
42 | 32 | nargs="?", |
@@ -65,26 +55,16 @@ def run(self, template_file="main.conf.j2"): |
65 | 55 |
|
66 | 56 | :returns: result string |
67 | 57 | """ |
68 | | - if self.args.host: |
69 | | - self.nr = self.nr.filter(name=self.args.host) |
| 58 | + self.nr = self._inventory() |
70 | 59 |
|
| 60 | + for host in self.nr.inventory.hosts: |
71 | 61 | compiled_template = CompileTemplate( |
72 | | - nr=self.nr, host=self.args.host, template=template_file |
| 62 | + nr=self.nr, host=host, template=template_file |
73 | 63 | ) |
74 | 64 | output_writer( |
75 | | - nornir_results=compiled_template.render(), output_file="compiled.conf" |
| 65 | + nornir_results=compiled_template.render(), output_file="compiled.conf", |
76 | 66 | ) |
77 | 67 | print_result(compiled_template.render()) |
78 | | - else: |
79 | | - for host in self.nr.inventory.hosts: |
80 | | - compiled_template = CompileTemplate( |
81 | | - nr=self.nr, host=host, template=template_file |
82 | | - ) |
83 | | - output_writer( |
84 | | - nornir_results=compiled_template.render(), |
85 | | - output_file="compiled.conf", |
86 | | - ) |
87 | | - print_result(compiled_template.render()) |
88 | 68 |
|
89 | 69 | if self.args.compile: |
90 | 70 | if self.args.host: |
|
0 commit comments