diff --git a/clear_underlay.py b/clear_underlay.py index c4a2894..b1a5870 100644 --- a/clear_underlay.py +++ b/clear_underlay.py @@ -2,7 +2,7 @@ from nornir.core.task import Task, Result from nornir_utils.plugins.functions import print_result from nornir_jinja2.plugins.tasks import template_file -from nornir_scrapli.tasks import send_command, send_config +from nornir_scrapli.tasks import send_commands, send_config def deploy_int(task: Task) -> Result: r = task.run(task=template_file, @@ -15,9 +15,9 @@ def deploy_int(task: Task) -> Result: dry_run=False, config=task.host["config"]) - task.run(task=send_command, - name="Show new config", - command="show run") + task.run(task=send_commands, + name="Show new config", + commands=["show run", "write memory"]) if __name__ == "__main__": nr = InitNornir(config_file="config.yml") diff --git a/deploy_baseconfig.py b/deploy_baseconfig.py index e3d0304..2cef79a 100644 --- a/deploy_baseconfig.py +++ b/deploy_baseconfig.py @@ -2,7 +2,7 @@ from nornir.core.task import Task, Result from nornir_utils.plugins.functions import print_result from nornir_jinja2.plugins.tasks import template_file -from nornir_scrapli.tasks import send_config, send_command +from nornir_scrapli.tasks import send_config, send_commands def deploy_base(task: Task) -> Result: @@ -17,9 +17,9 @@ def deploy_base(task: Task) -> Result: dry_run=False, config=task.host["config"]) - task.run(task=send_command, - name="Show new config", - command="show run") + task.run(task=send_commands, + name="Show new config and copy running config to startup config.", + commands=["show run", "write memory"]) if __name__ == "__main__": nr = InitNornir(config_file="config.yml") diff --git a/deploy_interfaces.py b/deploy_interfaces.py index d6fa6ec..10e5e74 100644 --- a/deploy_interfaces.py +++ b/deploy_interfaces.py @@ -2,7 +2,7 @@ from nornir.core.task import Task, Result from nornir_utils.plugins.functions import print_result from nornir_jinja2.plugins.tasks import template_file -from nornir_scrapli.tasks import send_command, send_config +from nornir_scrapli.tasks import send_commands, send_config def deploy_int(task: Task) -> Result: r = task.run(task=template_file, @@ -15,9 +15,10 @@ def deploy_int(task: Task) -> Result: dry_run=False, config=task.host["config"]) - task.run(task=send_command, - name="Show new config", - command="show run") + task.run(task=send_commands, + name="Show new config and copy running config to startup config.", + commands=["show run", "write memory"]) + if __name__ == "__main__": nr = InitNornir(config_file="config.yml") diff --git a/deploy_underlay.py b/deploy_underlay.py index d91d885..52c84d3 100644 --- a/deploy_underlay.py +++ b/deploy_underlay.py @@ -2,7 +2,7 @@ from nornir.core.task import Task, Result from nornir_utils.plugins.functions import print_result from nornir_jinja2.plugins.tasks import template_file -from nornir_scrapli.tasks import send_command, send_config +from nornir_scrapli.tasks import send_commands, send_config def deploy_int(task: Task) -> Result: r = task.run(task=template_file, @@ -15,9 +15,9 @@ def deploy_int(task: Task) -> Result: dry_run=False, config=task.host["config"]) - task.run(task=send_command, - name="Show new config", - command="show run") + task.run(task=send_commands, + name="Show new config and copy running config to startup config.", + commands=["show run", "write memory"]) if __name__ == "__main__": nr = InitNornir(config_file="config.yml") diff --git a/reset_config.py b/reset_config.py new file mode 100644 index 0000000..5c8a58a --- /dev/null +++ b/reset_config.py @@ -0,0 +1,27 @@ +from nornir import InitNornir +from nornir.core.task import Task, Result +from nornir_utils.plugins.functions import print_result +from nornir_jinja2.plugins.tasks import template_file +from nornir_scrapli.tasks import send_config, send_commands + + +def deploy_base(task: Task) -> Result: + r = task.run(task=template_file, + template="reset.j2", + path="./templates") + + task.host["config"] = r.result + + task.run(task=send_config, + name="Clear all device config!", + dry_run=False, + config=task.host["config"]) + + task.run(task=send_commands, + name="Show new config and copy running config to startup config.", + commands=["show run", "write memory"]) + +if __name__ == "__main__": + nr = InitNornir(config_file="config.yml") + r = nr.run(task=deploy_base) + print_result(r) \ No newline at end of file diff --git a/templates/base.j2 b/templates/base.j2 index 81d0896..df6f836 100644 --- a/templates/base.j2 +++ b/templates/base.j2 @@ -8,11 +8,3 @@ interface Loopback0 ip address {{ host["lo0"]["ipv4"] }} ipv6 address {{ host["lo0"]["ipv6"] }} ! -{% for interface in host["interfaces"].values() %} -interface {{ interface["name"] }} - no description - no ip address - no ipv6 address - shutdown -! -{% endfor %} \ No newline at end of file diff --git a/templates/reset.j2 b/templates/reset.j2 new file mode 100644 index 0000000..3f6bfa6 --- /dev/null +++ b/templates/reset.j2 @@ -0,0 +1,17 @@ +no hostname {{ host["name"] }} +no username {{ host["default_user"] }} privilege 15 role network-admin secret sha512 {{ host["default_password_sha512"] }} +! +no ip routing +! +no interface Loopback0 +! +{% for interface in host["interfaces"].values() %} +interface {{ interface["name"] }} + no description + no ip address + no ipv6 address + shutdown +! +{% endfor %} +! +no router bgp {{ host["asn"] }} \ No newline at end of file diff --git a/templates/underlay.j2 b/templates/underlay.j2 index 72c56b2..13f3a65 100644 --- a/templates/underlay.j2 +++ b/templates/underlay.j2 @@ -3,10 +3,11 @@ router bgp {{ host["asn"] }} no bgp default ipv4-unicast bgp log-neighbor-changes distance bgp 20 200 200 - bgp allowas-in {% for neighbor in host["neighbors"].values() %} neighbor {{ neighbor["ipv4"] }} remote-as {{ neighbor["remote-as"] }} + neighbor {{ neighbor["ipv4"] }} allowas-in 1 neighbor {{ neighbor["ipv6"] }} remote-as {{ neighbor["remote-as"] }} + neighbor {{ neighbor["ipv6"] }} allowas-in 1 ! address-family ipv4 neighbor {{ neighbor["ipv4"] }} activate