Skip to content
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

Add ability to inject configurations from a list of commands #160

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

jeffkala
Copy link
Contributor

In certain circumstances and at times with certain platforms the not all configurations are in a standard get configuration method. Two common examples are:

  1. A specific default configuration only visible in the show run all version of the configuration needs to be validated. E.g. Cisco IOS you may need to validate service pad configurations, so you might want to inject thos by running show run all | i service pad.

  2. A specific configuration is not anywhere in the configuration and the ability to inject it would be valuable. E.g. Cisco NXOS doesn't show snmp-user information in the backup. This means an additional show command needs to be run to fully replicate the full configuration.

The config injection will run additional commands that are defined on the following order or precedence.

  • Prefer obj.cf["config_injections"] if is a valid integer
  • Prefer obj.get_config_context()["config_injections"] if is a valid integer
  • Prefer cls.config_injections, which by default is defined in DispatcherMixin as []

@jeffkala
Copy link
Contributor Author

Oddly enough, I don't think the original _get_tcp_port method would work with NautobotInventory would only work with NautobotORMInventory from nautobot-app-nornir. Looking into options which will allow _get_tcp_port and the new _get_config_injection in both inventory use-cases.

if isinstance(config_context, int):
return config_context
# NautobotInventory (nornir-nautobot) inventory.
if obj.data["pynautobot_dictionary"].get("custom_fields"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a obj.data.get("pynautobot_dictionary", {})?

Copy link
Contributor

@itdependsnetworks itdependsnetworks Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, may need to be:

        if hasattr(obj, "data") and obj.data.get("pynautobot_dictionary", {}).get("custom_fields"):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my perspective is pynautobot_dictionary (and data for that matter) is guaranteed to be there since the inventory plugin is creating that key. Happy to still add that, but just providing my perspective.

logger.error(error_msg, extra={"object": obj})
raise NornirNautobotException(error_msg)
except Exception: # pylint:disable=broad-exception-caught
logger.error("Exception occured during config_injection, continuing without it.", extra={"object": obj})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this exception handling?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants