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

Mikrotik RouterOS CLI Support #76

Merged
merged 17 commits into from
Jun 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: made it compatible with #79
	modified:   nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
  • Loading branch information
pato23arg committed May 18, 2023
commit 689400feba03c813822b4ed81d4630e07480e987
13 changes: 6 additions & 7 deletions nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
from nornir_nautobot.exceptions import NornirNautobotException
from .default import NetmikoNautobotNornirDriver as DefaultNautobotNornirDriver

GET_VERSION_COMMAND = "system resource print"
NETMIKO_DEVICE_TYPE = "mikrotik_routeros"


class NautobotNornirDriver(DefaultNautobotNornirDriver):
"""Driver for Mikrotik Router OS."""

config_command = "export terse"
version_command = "system resource print"

@staticmethod
def get_config( # pylint: disable=R0913
task: Task, logger, obj, backup_file: str, remove_lines: list, substitute_lines: list
@classmethod
def get_config( # pylint: disable=R0913,R0914
cls, task: Task, logger, obj, backup_file: str, remove_lines: list, substitute_lines: list
) -> Result:
"""Get the latest configuration from the device using Netmiko. Overrides default get_config.

Expand All @@ -42,9 +42,8 @@ def get_config( # pylint: disable=R0913
"""
task.host.platform = NETMIKO_DEVICE_TYPE
logger.log_debug(f"Analyzing Software Version for {task.host.name} on {task.host.platform}")
command = GET_VERSION_COMMAND
try:
result = task.run(task=netmiko_send_command, command_string=GET_VERSION_COMMAND)
result = task.run(task=netmiko_send_command, command_string=cls.version_command)
except NornirSubTaskError as exc:
if isinstance(exc.result.exception, NetmikoAuthenticationException):
logger.log_failure(obj, f"Failed with an authentication issue: `{exc.result.exception}`")
Expand All @@ -68,7 +67,7 @@ def get_config( # pylint: disable=R0913

major_version = result[0].result.split()[3].split(".")[0]

command = NautobotNornirDriver.config_command
command = cls.config_command
if major_version > "6":
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure how we should handle this. I don't have an answer, but just want to raise the question .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the alternative could be to split it into separate drivers, for 6.X and 7.X and deal with netmiko having a unique module for this platform. Need to think pros and cons about that, good point.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with the idea for the concept of adding commands based on versions, if that is matches what is needed.

We could probably do this with a native Python module though rather than regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can probably get consistent results across versions by splitting the output multiple times. Will test and update if that's ok.

command += " show-sensitive"

Expand Down