Skip to content

Commit

Permalink
added update_config
Browse files Browse the repository at this point in the history
  • Loading branch information
vireakouk committed Jan 13, 2022
1 parent 158887d commit 4832af9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ steps:
from_secret: NORNIR_SECRET
commands:
- git fetch
- python deploy_baseconfig.py --dry_run
- python update_config.py --dry_run
when:
branch:
- dev
Expand All @@ -56,7 +56,7 @@ steps:
NORNIR_SECRET:
from_secret: NORNIR_SECRET
commands:
- python deploy_baseconfig.py
- python update_config.py
when:
branch:
- main
Expand Down
31 changes: 31 additions & 0 deletions update_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from nornir import InitNornir
from nornir.core.task import Task, Result
from nornir_utils.plugins.functions import print_result
from nornir_scrapli.tasks import send_configs_from_file, send_commands
from utils import nornir_set_creds
import argparse

parser = argparse.ArgumentParser()

parser.add_argument("--dry_run", dest="drill", action="store_true", default=False, help="This is a drill.")
args = parser.parse_args()

isDryrun = args.drill


def update_cfg(task: Task) -> Result:

task.run(task=send_configs_from_file,
name="Update config configuration on the device.",
dry_run=isDryrun,
file=f"./snapshots/configs/{task.host}.cfg")

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", core={"raise_on_error": True})
nornir_set_creds(nr)
r = nr.run(task=update_cfg, raise_on_error=True)
print_result(r)

0 comments on commit 4832af9

Please sign in to comment.