-
Notifications
You must be signed in to change notification settings - Fork 47
Simplify netmiko_send_commands method for clarity and maintainability #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
jeffkala
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Relying on the test quite a bit for the logic not changing but went through it slowly and I think this is a much cleaner and manage code base.
Just a few questions but otherwise I"m good with it.
| if validation_result: | ||
| return validation_result | ||
|
|
||
| if connectivity_test and not _check_connectivity(task): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this is also already in nornir-nautobot as a dispatcher function. I understand this is step 1 of this revamp, but keeping here for awareness for future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes — I needed to simplify it initially so that I could more easily migrate to nornir-nautobot.
|
|
||
| def _handle_netmiko_error(task, exception): | ||
| """Handle connection/authentication errors gracefully.""" | ||
| from netmiko.exceptions import NetmikoTimeoutException, NetmikoAuthenticationException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's incorrect here.
| skip_list = [ | ||
| "cables", | ||
| "interfaces__tagged_vlans", | ||
| "interfaces__untagged_vlan", | ||
| "interfaces__vrf", | ||
| "software_version", | ||
| "vlan_map", | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this, mind explaining this a bit more?
| skip_list = [ | ||
| "cables", | ||
| "interfaces__tagged_vlans", | ||
| "interfaces__untagged_vlan", | ||
| "software_version", | ||
| "vlan_map", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the explaination from the previous comment, maybe we should move this somehow into constants.py
| ) | ||
| }, | ||
| defaults=Defaults(data={"sync_vlans": False, "sync_vrfs": False, "sync_cables": False}), | ||
| # defaults=Defaults(data={"sync_vlans": False, "sync_vrfs": False, "sync_cables": False}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intentional?
Summary
This PR is
Stage 1refactor before moving components out of onboarding app to nornir-nautobot.PR refactors the
netmiko_send_commandsfunction to remove duplicated logic, improve readability, and make command filtering more maintainable — without changing any behavior..Key Improvements
✅ Removed redundant loops and conditions
Consolidated repeated logic for handling commands as lists or dicts.
✅ Centralized skip logic
Introduced a single
command_exclusionsmapping instead of multiple scattered if not sync_* checks.✅ Decoupled jobs from automation runner
Removed job and job inputs dependency in lower level methods, separating them from actual user input
✅ Improved readability
Clearer handling of the "pre_processor" section and command collection flow.
✅ Behavior preserved
All original skip rules, deduplication behavior, and flag-based filters remain identical.
✅ Safer and cleaner
Uses get("commands", []) and .extend() for simpler and more resilient logic.