Skip to content

Commit

Permalink
add reset task
Browse files Browse the repository at this point in the history
  • Loading branch information
vireakouk committed Aug 27, 2021
1 parent 930bd16 commit 99c7899
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 25 deletions.
8 changes: 4 additions & 4 deletions clear_underlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions deploy_baseconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions deploy_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions deploy_underlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
27 changes: 27 additions & 0 deletions reset_config.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 0 additions & 8 deletions templates/base.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
17 changes: 17 additions & 0 deletions templates/reset.j2
Original file line number Diff line number Diff line change
@@ -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"] }}
3 changes: 2 additions & 1 deletion templates/underlay.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99c7899

Please sign in to comment.