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 gitlab file plugin #324

Merged

Conversation

wvandeun
Copy link
Contributor

I have been using this plugin mainly for backing up device configurations and saving of staged configurations in a git repo on Gitlab.
Thought it might be useful for other people, so I'm sharing this.

A quick example to show how this can be used

from nornir.plugins.tasks.networking import netmiko_send_command
from nornir.plugins.tasks.files.gitlab import gitlab

def backup(task):
    res = task.run(
        task = netmiko_send_command,
        name = "grab config",
        command_string="show running-config"
    )
    task.host["config"] = res.result

    res = task.run(
        task = gitlab,
        action = "create",
        url = "https://gitlab.local",
        token = "mygitlabapitoken",
        respository = "backup",
        branch = "master",
        content = task.host["config"],
        filename = task.host.name,
        commit_message = "backup"
    )

@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch 3 times, most recently from a715b94 to 87f78b6 Compare February 17, 2019 23:18
@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch from 87f78b6 to a6faba3 Compare February 17, 2019 23:31
@dbarrosop
Copy link
Contributor

Hello,
I have a couple of questions. I am not familiar with gitlab but my understanding is that it's a git repository, isn't it? If yes, why not a generic set of functions to deal with git repositories that can be reused?

Regards
David

@dbarrosop
Copy link
Contributor

By the way, nice work. This is something I have been wanting for a while now :) I just want to discuss the possibility of generalizing this so it's not gitlab specific :)

@wvandeun
Copy link
Contributor Author

wvandeun commented Feb 22, 2019 via email

@dbarrosop
Copy link
Contributor

ok, finally found some time to look into this a bit more in depth. A few comments:

  1. Good job, specially in the testing part
  2. I think we should move the plugin to a dedicated section for source_control plugins. Although I am not 100% sure. I was thinking in tasks.plugins.source_control.gitlab. Thoughts?
  3. Regarding documentation, I was wondering if you could rewrite it using a jupyter notebook. I am trying to use notebooks as much as possible for documentation as they are more visual and can be tested. For instance:

https://github.com/nornir-automation/nornir/blob/76247d3684ff06e2f2b43908bc9bf838ee2badaf/nornir/plugins/tasks/data/echo_data.py
https://github.com/nornir-automation/nornir/blob/344fa4ead1edaec8f554323e267993f745ca701a/docs/plugins/tasks/data/echo_data.ipynb

which renders:

https://nornir.readthedocs.io/en/stable/plugins/tasks/data/echo_data.html

and is tested:

https://travis-ci.org/nornir-automation/nornir/jobs/498697369#L553

Not sure how familiar you are with notebooks but happy to help out. If you don't have the time or the energy we can proceed as it is, not a big deal.

@wvandeun
Copy link
Contributor Author

The dedicated section definitely makes sense to me, but personally I would name it version_control. I think that name covers the package a bit better no? It can be used for more then 'source'.
I'm not really familiar with jupyter notebooks yet, but this might be a good way to start learning about it. I'll have a look.

@dbarrosop
Copy link
Contributor

I would name it version_control

Yes, I think that's better too.

@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch 2 times, most recently from e669949 to 4ec40cd Compare March 29, 2019 07:57
@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch from 4ec40cd to 7931006 Compare March 29, 2019 10:18
@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch from c82adbb to 60caf7c Compare March 29, 2019 22:02
@wvandeun
Copy link
Contributor Author

Moved plugin to version_control directory & created documentation.
Still working on a "get" action to retrieve file(s) from a repository ( + test(s) & doc).

@dbarrosop
Copy link
Contributor

Awesome work so far! Let me know when you are done :)

@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch from a21baae to 050df21 Compare April 26, 2019 05:51
@wvandeun wvandeun force-pushed the feature_plugin_tasks_files_gitlab branch from 050df21 to 89b825c Compare April 26, 2019 05:53
@wvandeun
Copy link
Contributor Author

I'm done.
But the build is failing due to a strict implementation of PEP517 from pip v19
Basically pip doesn't allow a editable install if a pyproject.toml file is present.

More info can be found here:
pypa/pip#6434

There seem to be multiple issues opened for this with poetry as well:
python-poetry/poetry#1049

@dbarrosop
Copy link
Contributor

Impressive job!

Looks like the issue with poetry is solved :)

@dbarrosop dbarrosop merged commit 0dab758 into nornir-automation:develop Apr 27, 2019
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