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 merge / replace for netmiko dispatcher #168

Open
jeffkala opened this issue Aug 9, 2024 · 0 comments · May be fixed by #170
Open

Add merge / replace for netmiko dispatcher #168

jeffkala opened this issue Aug 9, 2024 · 0 comments · May be fixed by #170

Comments

@jeffkala
Copy link
Contributor

jeffkala commented Aug 9, 2024

something like

    @classmethod
    def merge_config(
        cls,
        task: Task,
        logger,
        obj,
        config: str,
    ) -> Result:
        """Send configuration to merge on the device.

        Args:
            task (Task): Nornir Task.
            logger (logging.Logger): Logger that may be a Nautobot Jobs or Python logger.
            obj (Device): A Nautobot Device Django ORM object instance.
            config (str): The config set.

        Raises:
            NornirNautobotException: Authentication error.
            NornirNautobotException: Timeout error.
            NornirNautobotException: Other exception.

        Returns:
            Result: Nornir Result object with a dict as a result containing what changed and the result of the push.
        """
        logger.info("Config merge via netmiko starting", extra={"object": obj})
        # Sending None to napalm_configure for revert_in will disable it, so we don't want a default value.

        try:
            push_result = task.run(
                task=netmiko_send_config,
                config_commands=config.splitlines(),
                enable=True,
            )
        except NornirSubTaskError as exc:
            error_msg = f"`E1015:` Failed with an unknown issue. `{exc.result.exception}`"
            logger.error(error_msg, extra={"object": obj})
            raise NornirNautobotException(error_msg)

        logger.info(
            f"result: {push_result[0].result}, changed: {push_result.changed}",
            extra={"object": obj},
        )

        if push_result.diff:
            logger.info(f"Diff:\n```\n_{push_result.diff}\n```", extra={"object": obj})

        logger.info("Config merge ended", extra={"object": obj})
        return Result(
            host=task.host,
            result={"changed": push_result.changed, "result": push_result[0].result},
        )
@gsnider2195 gsnider2195 linked a pull request Sep 19, 2024 that will close this issue
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 a pull request may close this issue.

1 participant