-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conversation
modified: nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
major_version = search_result.group(1) | ||
|
||
command = GET_CONFIG_ROS | ||
if major_version > "6": |
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 am not sure how we should handle this. I don't have an answer, but just want to raise the question .
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 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.
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 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?
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 can probably get consistent results across versions by splitting the output multiple times. Will test and update if that's ok.
|
||
running_config = result[0].result | ||
|
||
if remove_lines: |
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 think it makes sense centralize some of this. I would make something like the below on the NautobotNornirDriver
:
@staticmethod
def _remove_lines(<proper_args>):
if remove_lines:
logger.log_debug("Removing lines from configuration based on `remove_lines` definition")
running_config = clean_config(running_config, remove_lines)
@staticmethod
def _substitute_lines(<proper_args>):
if substitute_lines:
logger.log_debug("Substitute lines from configuration based on `substitute_lines` definition")
running_config = sanitize_config(running_config, substitute_lines)
@staticmethod
def _create_file(<proper_args>):
make_folder(os.path.dirname(backup_file))
with open(backup_file, "w", encoding="utf8") as filehandler:
filehandler.write(running_config)
Then call it here with something like:
self._remove_lines()
self._substitute_lines()
self._create_file()
return Result(host=task.host, result={"config": running_config})
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.
would it be ok to break the pattern and make get_config(...) a normal Instance method? as static methods do not receive the instance as an arg. It would end up something like this:
NautobotNornirDriver._remove_lines(remove_lines: list, _running_config: str, logger) NautobotNornirDriver._substitute_lines(substitute_lines: list, _running_config: str, logger) NautobotNornirDriver._create_file(backup_file: str)
Another option would be to convert get_config() into a classmethod, but that would also break the pattern used so far.
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.
a normal Instance method
, I don;t think so, I think that will break the dispatcher.
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.
we can call them as class static methods as a short-term solution. Since that functionality is also in use by NornirNautobotDriver
and NetmikoNautobotNornirDriver
I think it would make sense to incorporate them into helpers.py in the future. How does that sound @itdependsnetworks ?
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.
What are helpers?
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.
nornir_nautobot/utils/helpers.py make folder
resides there, I believe removelines(), substitutelines() and savefile() could be moved there as well so they can be reused.
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.
@itdependsnetworks changes implemented.
modified: nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
modified: nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
modified: nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
add support for Mikrotik Router OS version 6.X and 7.X.