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

Conversation

pato23arg
Copy link
Contributor

add support for Mikrotik Router OS version 6.X and 7.X.

	modified:   nornir_nautobot/plugins/tasks/dispatcher/mikrotik_routeros.py
major_version = search_result.group(1)

command = GET_CONFIG_ROS
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.


running_config = result[0].result

if remove_lines:
Copy link
Contributor

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})

Copy link
Contributor Author

@pato23arg pato23arg Apr 25, 2023

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@pato23arg pato23arg Apr 30, 2023

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

What are helpers?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
@mzbroch mzbroch changed the title Mikrotik Router OS Support Mikrotik RouterOS CLI Support May 29, 2023
@jvanderaa jvanderaa merged commit 5929dc9 into nautobot:develop Jun 6, 2023
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.

3 participants