From 6b97f8605f5125379fc47cc7e5619b6912394bc0 Mon Sep 17 00:00:00 2001 From: David Barroso Date: Fri, 10 Apr 2020 09:57:40 +0200 Subject: [PATCH] removed plugins documentation --- docs/index.rst | 1 - docs/plugins/connections/index.rst | 20 - docs/plugins/functions/index.rst | 8 - docs/plugins/functions/text.rst | 6 - docs/plugins/index.rst | 11 - docs/plugins/inventory/ansible.rst | 6 - docs/plugins/inventory/index.rst | 13 - docs/plugins/inventory/netbox.rst | 6 - docs/plugins/inventory/nsot.rst | 6 - docs/plugins/inventory/simple.rst | 6 - docs/plugins/processors/index.rst | 8 - docs/plugins/tasks/apis.rst | 6 - docs/plugins/tasks/commands.rst | 6 - docs/plugins/tasks/data.rst | 14 - docs/plugins/tasks/data/echo_data.ipynb | 156 ------ .../data/echo_data/inventory/groups.yaml | 18 - .../tasks/data/echo_data/inventory/hosts.yaml | 78 --- docs/plugins/tasks/files.rst | 6 - docs/plugins/tasks/index.rst | 14 - docs/plugins/tasks/networking.rst | 6 - docs/plugins/tasks/text.rst | 6 - docs/plugins/tasks/version_control.rst | 14 - .../tasks/version_control/gitlab.ipynb | 493 ------------------ .../gitlab_data/inventory/hosts.yaml | 11 - 24 files changed, 919 deletions(-) delete mode 100644 docs/plugins/connections/index.rst delete mode 100644 docs/plugins/functions/index.rst delete mode 100644 docs/plugins/functions/text.rst delete mode 100644 docs/plugins/index.rst delete mode 100644 docs/plugins/inventory/ansible.rst delete mode 100644 docs/plugins/inventory/index.rst delete mode 100644 docs/plugins/inventory/netbox.rst delete mode 100644 docs/plugins/inventory/nsot.rst delete mode 100644 docs/plugins/inventory/simple.rst delete mode 100644 docs/plugins/processors/index.rst delete mode 100644 docs/plugins/tasks/apis.rst delete mode 100644 docs/plugins/tasks/commands.rst delete mode 100644 docs/plugins/tasks/data.rst delete mode 100644 docs/plugins/tasks/data/echo_data.ipynb delete mode 100644 docs/plugins/tasks/data/echo_data/inventory/groups.yaml delete mode 100644 docs/plugins/tasks/data/echo_data/inventory/hosts.yaml delete mode 100644 docs/plugins/tasks/files.rst delete mode 100644 docs/plugins/tasks/index.rst delete mode 100644 docs/plugins/tasks/networking.rst delete mode 100644 docs/plugins/tasks/text.rst delete mode 100644 docs/plugins/tasks/version_control.rst delete mode 100644 docs/plugins/tasks/version_control/gitlab.ipynb delete mode 100644 docs/plugins/tasks/version_control/gitlab_data/inventory/hosts.yaml diff --git a/docs/index.rst b/docs/index.rst index d932dd1a..3f1de488 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -65,7 +65,6 @@ Contents Tutorials Howto configuration/index - plugins/index ref/index upgrading/index Contribute diff --git a/docs/plugins/connections/index.rst b/docs/plugins/connections/index.rst deleted file mode 100644 index 68b09e4e..00000000 --- a/docs/plugins/connections/index.rst +++ /dev/null @@ -1,20 +0,0 @@ -Connections -=========== - -Netmiko -------- - -.. automodule:: nornir.plugins.connections.netmiko - :members: - -Paramiko --------- - -.. automodule:: nornir.plugins.connections.paramiko - :members: - -Netconf -------- - -.. automodule:: nornir.plugins.connections.netconf - :members: diff --git a/docs/plugins/functions/index.rst b/docs/plugins/functions/index.rst deleted file mode 100644 index cf781f1d..00000000 --- a/docs/plugins/functions/index.rst +++ /dev/null @@ -1,8 +0,0 @@ -Functions -========= - -.. toctree:: - :maxdepth: 2 - :glob: - - * diff --git a/docs/plugins/functions/text.rst b/docs/plugins/functions/text.rst deleted file mode 100644 index 94cf53d9..00000000 --- a/docs/plugins/functions/text.rst +++ /dev/null @@ -1,6 +0,0 @@ -Text -==== - -.. automodule:: nornir.plugins.functions.text - :members: - :undoc-members: diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst deleted file mode 100644 index 5b765c60..00000000 --- a/docs/plugins/index.rst +++ /dev/null @@ -1,11 +0,0 @@ -Plugins -======= - -.. toctree:: - :maxdepth: 2 - - connections/index - functions/index - inventory/index - tasks/index - processors/index diff --git a/docs/plugins/inventory/ansible.rst b/docs/plugins/inventory/ansible.rst deleted file mode 100644 index d6460539..00000000 --- a/docs/plugins/inventory/ansible.rst +++ /dev/null @@ -1,6 +0,0 @@ -Ansible -======= - -.. automodule:: nornir.plugins.inventory.ansible - :members: - :undoc-members: diff --git a/docs/plugins/inventory/index.rst b/docs/plugins/inventory/index.rst deleted file mode 100644 index 4aba0357..00000000 --- a/docs/plugins/inventory/index.rst +++ /dev/null @@ -1,13 +0,0 @@ -.. _ref-inventory: - -Inventory -========= - -.. toctree:: - :maxdepth: 2 - :caption: Categories: - - simple - ansible - netbox - nsot diff --git a/docs/plugins/inventory/netbox.rst b/docs/plugins/inventory/netbox.rst deleted file mode 100644 index 84ad68ee..00000000 --- a/docs/plugins/inventory/netbox.rst +++ /dev/null @@ -1,6 +0,0 @@ -Netbox -====== - -.. automodule:: nornir.plugins.inventory.netbox - :members: - :undoc-members: diff --git a/docs/plugins/inventory/nsot.rst b/docs/plugins/inventory/nsot.rst deleted file mode 100644 index 5df87118..00000000 --- a/docs/plugins/inventory/nsot.rst +++ /dev/null @@ -1,6 +0,0 @@ -NSOT -==== - -.. automodule:: nornir.plugins.inventory.nsot - :members: - :undoc-members: diff --git a/docs/plugins/inventory/simple.rst b/docs/plugins/inventory/simple.rst deleted file mode 100644 index 1c8542fd..00000000 --- a/docs/plugins/inventory/simple.rst +++ /dev/null @@ -1,6 +0,0 @@ -Simple -====== - -.. automodule:: nornir.plugins.inventory.simple - :members: - :undoc-members: diff --git a/docs/plugins/processors/index.rst b/docs/plugins/processors/index.rst deleted file mode 100644 index faf71c25..00000000 --- a/docs/plugins/processors/index.rst +++ /dev/null @@ -1,8 +0,0 @@ -Processors -========== - -print_result ------------- - -.. automodule:: nornir.plugins.processors.print_result - :members: diff --git a/docs/plugins/tasks/apis.rst b/docs/plugins/tasks/apis.rst deleted file mode 100644 index 7072b1cc..00000000 --- a/docs/plugins/tasks/apis.rst +++ /dev/null @@ -1,6 +0,0 @@ -APIs -==== - -.. automodule:: nornir.plugins.tasks.apis - :members: - :undoc-members: diff --git a/docs/plugins/tasks/commands.rst b/docs/plugins/tasks/commands.rst deleted file mode 100644 index f3466be2..00000000 --- a/docs/plugins/tasks/commands.rst +++ /dev/null @@ -1,6 +0,0 @@ -Commands -======== - -.. automodule:: nornir.plugins.tasks.commands - :members: - :undoc-members: diff --git a/docs/plugins/tasks/data.rst b/docs/plugins/tasks/data.rst deleted file mode 100644 index 6a142405..00000000 --- a/docs/plugins/tasks/data.rst +++ /dev/null @@ -1,14 +0,0 @@ -Data -==== - -.. toctree:: - :maxdepth: 1 - :glob: - - data/* - -Old-style docs: - -.. automodule:: nornir.plugins.tasks.data - :members: - :undoc-members: diff --git a/docs/plugins/tasks/data/echo_data.ipynb b/docs/plugins/tasks/data/echo_data.ipynb deleted file mode 100644 index 17285671..00000000 --- a/docs/plugins/tasks/data/echo_data.ipynb +++ /dev/null @@ -1,156 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# echo_data" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - " Dummy task that echoes the data passed to it. Useful in grouped_tasks\n", - " to debug data passed to tasks.\n", - "\n", - " Arguments:\n", - " ``**kwargs``: Any pair you want\n", - "\n", - " Returns:\n", - " Result object with the following attributes set:\n", - " * result (``dict``): ``**kwargs`` passed to the task\n", - " \n" - ] - } - ], - "source": [ - "from nornir.plugins.tasks.data import echo_data\n", - "\n", - "print(echo_data.__doc__)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Example" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[1m\u001b[36mgrouped_task********************************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* bat ** changed : False *******************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m---- bat ** changed : False ---------------------------------------------------- INFO\u001b[0m\n", - "\u001b[0m{\u001b[0m \u001b[0m'diet'\u001b[0m: \u001b[0m'carnivore'\u001b[0m,\n", - " \u001b[0m'even_complex'\u001b[0m: \u001b[0m{'a': 1, 'b': 2, 'c': 'asd'}\u001b[0m,\n", - " \u001b[0m'famous_members'\u001b[0m: \u001b[0m['batman', 'count chocula', 'nosferatu']\u001b[0m,\n", - " \u001b[0m'more_data'\u001b[0m: \u001b[0m'whatever you want'\u001b[0m}\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* canary ** changed : False ****************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m---- canary ** changed : False ------------------------------------------------- INFO\u001b[0m\n", - "\u001b[0m{\u001b[0m \u001b[0m'diet'\u001b[0m: \u001b[0m'herbivore'\u001b[0m,\n", - " \u001b[0m'even_complex'\u001b[0m: \u001b[0m{'a': 1, 'b': 2, 'c': 'asd'}\u001b[0m,\n", - " \u001b[0m'famous_members'\u001b[0m: \u001b[0m['tweetie']\u001b[0m,\n", - " \u001b[0m'more_data'\u001b[0m: \u001b[0m'whatever you want'\u001b[0m}\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* cat ** changed : False *******************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m---- cat ** changed : False ---------------------------------------------------- INFO\u001b[0m\n", - "\u001b[0m{\u001b[0m \u001b[0m'diet'\u001b[0m: \u001b[0m'omnivore'\u001b[0m,\n", - " \u001b[0m'even_complex'\u001b[0m: \u001b[0m{'a': 1, 'b': 2, 'c': 'asd'}\u001b[0m,\n", - " \u001b[0m'famous_members'\u001b[0m: \u001b[0m['garfield', 'felix', 'grumpy']\u001b[0m,\n", - " \u001b[0m'more_data'\u001b[0m: \u001b[0m'whatever you want'\u001b[0m}\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* caterpillaer ** changed : False **********************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m---- caterpillaer ** changed : False ------------------------------------------- INFO\u001b[0m\n", - "\u001b[0m{\u001b[0m \u001b[0m'diet'\u001b[0m: \u001b[0m'herbivore'\u001b[0m,\n", - " \u001b[0m'even_complex'\u001b[0m: \u001b[0m{'a': 1, 'b': 2, 'c': 'asd'}\u001b[0m,\n", - " \u001b[0m'famous_members'\u001b[0m: \u001b[0m['Hookah-Smoking']\u001b[0m,\n", - " \u001b[0m'more_data'\u001b[0m: \u001b[0m'whatever you want'\u001b[0m}\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* eagle ** changed : False *****************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m---- eagle ** changed : False -------------------------------------------------- INFO\u001b[0m\n", - "\u001b[0m{\u001b[0m \u001b[0m'diet'\u001b[0m: \u001b[0m'carnivore'\u001b[0m,\n", - " \u001b[0m'even_complex'\u001b[0m: \u001b[0m{'a': 1, 'b': 2, 'c': 'asd'}\u001b[0m,\n", - " \u001b[0m'famous_members'\u001b[0m: \u001b[0m['thorondor', 'sam']\u001b[0m,\n", - " \u001b[0m'more_data'\u001b[0m: \u001b[0m'whatever you want'\u001b[0m}\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* octopus ** changed : False ***************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32mvvvv grouped_task ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m---- octopus ** changed : False ------------------------------------------------ INFO\u001b[0m\n", - "\u001b[0m{\u001b[0m \u001b[0m'diet'\u001b[0m: \u001b[0m'carnivore'\u001b[0m,\n", - " \u001b[0m'even_complex'\u001b[0m: \u001b[0m{'a': 1, 'b': 2, 'c': 'asd'}\u001b[0m,\n", - " \u001b[0m'famous_members'\u001b[0m: \u001b[0m['sharktopus']\u001b[0m,\n", - " \u001b[0m'more_data'\u001b[0m: \u001b[0m'whatever you want'\u001b[0m}\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[32m^^^^ END grouped_task ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m" - ] - } - ], - "source": [ - "from nornir import InitNornir\n", - "from nornir.plugins.tasks.data import echo_data\n", - "from nornir.plugins.functions.text import print_result\n", - "\n", - "nr = InitNornir(\n", - " inventory={\n", - " \"options\": {\n", - " \"host_file\": \"echo_data/inventory/hosts.yaml\",\n", - " \"group_file\": \"echo_data/inventory/groups.yaml\"\n", - " }\n", - " }\n", - ")\n", - "\n", - "def grouped_task(task):\n", - " task.run(task=echo_data,\n", - " name=task.host.name,\n", - " diet=task.host[\"diet\"],\n", - " famous_members=task.host[\"additional_data\"][\"famous_members\"],\n", - " more_data=\"whatever you want\",\n", - " even_complex={\"a\": 1, \"b\": 2, \"c\": \"asd\"})\n", - " \n", - "r = nr.run(task=grouped_task)\n", - "print_result(r)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.8" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/plugins/tasks/data/echo_data/inventory/groups.yaml b/docs/plugins/tasks/data/echo_data/inventory/groups.yaml deleted file mode 100644 index 175bae52..00000000 --- a/docs/plugins/tasks/data/echo_data/inventory/groups.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -mammal: - data: - reproduction: birth - fly: false - -bird: - data: - reproduction: eggs - fly: true - -invertebrate: - data: - reproduction: mitosis - fly: false - -terrestrial: {} -marine: {} diff --git a/docs/plugins/tasks/data/echo_data/inventory/hosts.yaml b/docs/plugins/tasks/data/echo_data/inventory/hosts.yaml deleted file mode 100644 index e5d3acbb..00000000 --- a/docs/plugins/tasks/data/echo_data/inventory/hosts.yaml +++ /dev/null @@ -1,78 +0,0 @@ ---- -cat: - groups: - - terrestrial - - mammal - data: - domestic: true - diet: omnivore - additional_data: - lifespan: 17 - famous_members: - - garfield - - felix - - grumpy - -bat: - groups: - - terrestrial - - mammal - data: - domestic: false - fly: true - diet: carnivore - additional_data: - lifespan: 15 - famous_members: - - batman - - count chocula - - nosferatu - -eagle: - groups: - - terrestrial - - bird - data: - domestic: false - diet: carnivore - additional_data: - lifespan: 50 - famous_members: - - thorondor - - sam - -canary: - groups: - - terrestrial - - bird - data: - domestic: true - diet: herbivore - additional_data: - lifespan: 15 - famous_members: - - tweetie - -caterpillaer: - groups: - - terrestrial - - invertebrate - data: - domestic: false - diet: herbivore - additional_data: - lifespan: 1 - famous_members: - - Hookah-Smoking - -octopus: - groups: - - marine - - invertebrate - data: - domestic: false - diet: carnivore - additional_data: - lifespan: 1 - famous_members: - - sharktopus diff --git a/docs/plugins/tasks/files.rst b/docs/plugins/tasks/files.rst deleted file mode 100644 index 1fb152cb..00000000 --- a/docs/plugins/tasks/files.rst +++ /dev/null @@ -1,6 +0,0 @@ -Files -===== - -.. automodule:: nornir.plugins.tasks.files - :members: - :undoc-members: diff --git a/docs/plugins/tasks/index.rst b/docs/plugins/tasks/index.rst deleted file mode 100644 index ba15b3ac..00000000 --- a/docs/plugins/tasks/index.rst +++ /dev/null @@ -1,14 +0,0 @@ -Tasks -===== - -.. toctree:: - :maxdepth: 2 - :caption: Categories: - - apis - commands - data - files - networking - text - version_control diff --git a/docs/plugins/tasks/networking.rst b/docs/plugins/tasks/networking.rst deleted file mode 100644 index 9992a7c5..00000000 --- a/docs/plugins/tasks/networking.rst +++ /dev/null @@ -1,6 +0,0 @@ -Networking -========== - -.. automodule:: nornir.plugins.tasks.networking - :members: - :undoc-members: diff --git a/docs/plugins/tasks/text.rst b/docs/plugins/tasks/text.rst deleted file mode 100644 index 3e7edca7..00000000 --- a/docs/plugins/tasks/text.rst +++ /dev/null @@ -1,6 +0,0 @@ -Text -==== - -.. automodule:: nornir.plugins.tasks.text - :members: - :undoc-members: diff --git a/docs/plugins/tasks/version_control.rst b/docs/plugins/tasks/version_control.rst deleted file mode 100644 index 60551163..00000000 --- a/docs/plugins/tasks/version_control.rst +++ /dev/null @@ -1,14 +0,0 @@ -Version control -=============== - -.. toctree:: - :maxdepth: 1 - :glob: - - version_control/* - -Old-style docs: - -.. automodule:: nornir.plugins.tasks.version_control - :members: - :undoc-members: diff --git a/docs/plugins/tasks/version_control/gitlab.ipynb b/docs/plugins/tasks/version_control/gitlab.ipynb deleted file mode 100644 index 833597f1..00000000 --- a/docs/plugins/tasks/version_control/gitlab.ipynb +++ /dev/null @@ -1,493 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "# Gitlab" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "scrolled": false, - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - " Exposes some of the Gitlab API functionality for operations on files\n", - " in a Gitlab repository.\n", - "\n", - " Example:\n", - "\n", - " nornir.run(files.gitlab,\n", - " action=\"create\",\n", - " url=\"https://gitlab.localhost.com\",\n", - " token=\"ABCD1234\",\n", - " repository=\"test\",\n", - " filename=\"config\",\n", - " ref=\"master\")\n", - "\n", - " Arguments:\n", - " dry_run: Whether to apply changes or not\n", - " url: Gitlab instance URL\n", - " token: Personal access token\n", - " repository: source/destination repository\n", - " filename: source/destination file name\n", - " content: content to write\n", - " action: ``create``, ``update``, ``get``\n", - " branch: destination branch\n", - " destination: local destination filename (only used in get action)\n", - " ref: branch, commit hash or tag (only used in get action)\n", - " commit_message: commit message\n", - "\n", - " Returns:\n", - " Result object with the following attributes set:\n", - " * changed (``bool``):\n", - " * diff (``str``): unified diff\n", - "\n", - " \n" - ] - } - ], - "source": [ - "from nornir.plugins.tasks.version_control import gitlab\n", - "print(gitlab.__doc__)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "## Example 1 : create a file in a git repository on a gitlab server\n", - "\n", - "In this example we will create a new file in a git repository on a gitlab server.\n", - "\n", - "The contents that we will write to the file is a arbitrary string, in a real world scenario this could be the running configuration of a device that we fetched using napalm or through another method.\n", - "\n", - "First let's import the necessary methods & tasks, then we will create a variable called `content` which is an arbitrary string." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "scrolled": true, - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from nornir import InitNornir\n", - "from nornir.plugins.tasks.version_control import gitlab\n", - "from nornir.plugins.tasks.commands import remote_command\n", - "from nornir.plugins.functions.text import print_result\n", - "\n", - "inventory = {\n", - " \"plugin\": \"nornir.plugins.inventory.simple.SimpleInventory\",\n", - " \"options\": {\n", - " \"host_file\": \"gitlab_data/inventory/hosts.yaml\"\n", - " }\n", - "}\n", - "\n", - "n = InitNornir(inventory=inventory)\n", - "\n", - "content = \"\"\"127.0.0.1\\t\\tlocalhost\n", - "255.255.255.255\\tbroadcasthost\n", - "::1\\t\\tlocalhost\n", - "\"\"\"" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "And create a new file called `hosts` in the repository `test` on the `master` branch." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "nbsphinx": "hidden", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "import requests_mock\n", - "from functools import wraps\n", - "\n", - "def wrap_gitlab(f):\n", - " @wraps(f)\n", - " def wrapper(*args, **kwargs):\n", - " with requests_mock.Mocker() as m:\n", - " if kwargs.get(\"ref\", None):\n", - " kwargs[\"branch\"] = kwargs[\"ref\"]\n", - " m.get(url=f\"{kwargs['url']}/api/v4/projects?search={kwargs['repository']}\", status_code=200, json=[{\"name\":\"test\",\"id\":1}])\n", - " m.post(url=f\"{kwargs['url']}/api/v4/projects/1/repository/files/{kwargs['filename']}\", status_code=201)\n", - " m.get(url=f\"{kwargs['url']}/api/v4/projects/1/repository/files/{kwargs['filename']}?ref={kwargs['branch']}\",status_code=200, json={\"content\":\"MTI3LjAuMC4xCQlsb2NhbGhvc3QKMjU1LjI1NS4yNTUuMjU1CWJyb2FkY2FzdGhvc3QKOjoxCQls\\nb2NhbGhvc3QK\\n\"})\n", - " m.put(url=f\"{kwargs['url']}/api/v4/projects/1/repository/files/{kwargs['filename']}\", status_code=200)\n", - " return f(*args, **kwargs)\n", - " return wrapper\n", - "\n", - "gitlab = wrap_gitlab(gitlab)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "result = n.run(\n", - " gitlab,\n", - " action=\"create\",\n", - " url=\"http://localhost:8080\",\n", - " token = \"SuperSecretToken\",\n", - " repository=\"test\",\n", - " branch=\"master\",\n", - " filename=\"hosts\",\n", - " #content=results[\"dev5.no_group\"][0]\n", - " content=content,\n", - " commit_message=\"Nornir is AWESOME!\"\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "The result of the task shows us a diff of the created `hosts` file and the content we provided." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[1m\u001b[36mgitlab**************************************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* alpine ** changed : True *****************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[33mvvvv gitlab ** changed : True vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m--- \n", - "\n", - "+++ hosts\n", - "\n", - "@@ -0,0 +1,3 @@\n", - "\n", - "+127.0.0.1\t\tlocalhost\n", - "+255.255.255.255\tbroadcasthost\n", - "+::1\t\tlocalhost\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[33m^^^^ END gitlab ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m" - ] - } - ], - "source": [ - "print_result(result)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "## Example 2 : update an existing file in a git repository on a gitlab server" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "In this example we will update the contents of the hosts file that we created in the previous step. The new contents could come again from a remote host or device, but in this case we will use an arbitrary value for the new contents of the file." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "result = n.run(\n", - " gitlab,\n", - " action=\"update\",\n", - " url=\"http://localhost:8080\",\n", - " token=\"SuperSecretToken\",\n", - " repository=\"test\",\n", - " branch=\"master\",\n", - " filename=\"hosts\",\n", - " content=f\"{content}8.8.8.8\\t\\tgoogledns\",\n", - " commit_message=\"Added new line to hosts file\"\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "The result of the task should show us a diff of the changes that we made." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[1m\u001b[36mgitlab**************************************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* alpine ** changed : True *****************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[33mvvvv gitlab ** changed : True vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m--- hosts\n", - "\n", - "+++ hosts\n", - "\n", - "@@ -1,3 +1,4 @@\n", - "\n", - " 127.0.0.1\t\tlocalhost\n", - " 255.255.255.255\tbroadcasthost\n", - " ::1\t\tlocalhost\n", - "+8.8.8.8\t\tgoogledns\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[33m^^^^ END gitlab ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m" - ] - } - ], - "source": [ - "print_result(result)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "## Example 3: get a file from a gitlab repository\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "In this example we will get/download a file from a repository in gitlab. The contents of this file could be a staged configuration of a device or a service on a device. This configuration could then be pushed to the device.\n", - "\n", - "In our example we will download the file `hosts` from the `master` branch and save it as `/tmp/hosts`.\n", - "The `ref` parameter can also be a commit hash or tag." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[0m\u001b[0m" - ] - } - ], - "source": [ - "!rm -f /tmp/hosts\n", - "result = n.run(\n", - " gitlab,\n", - " action=\"get\",\n", - " url=\"http://localhost:8080\",\n", - " token=\"SuperSecretToken\",\n", - " repository=\"test\",\n", - " ref=\"master\",\n", - " filename=\"hosts\",\n", - " destination=\"/tmp/hosts\"\n", - ")\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "The result should show us a new file `/tmp/hosts` being created on the local system." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[1m\u001b[36mgitlab**************************************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[34m* alpine ** changed : True *****************************************************\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[33mvvvv gitlab ** changed : True vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO\u001b[0m\n", - "\u001b[0m--- /tmp/hosts\n", - "\n", - "+++ /tmp/hosts\n", - "\n", - "@@ -0,0 +1,3 @@\n", - "\n", - "+127.0.0.1\t\tlocalhost\n", - "+255.255.255.255\tbroadcasthost\n", - "+::1\t\tlocalhost\u001b[0m\n", - "\u001b[0m\u001b[1m\u001b[33m^^^^ END gitlab ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n", - "\u001b[0m" - ] - } - ], - "source": [ - "print_result(result)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "autoscroll": false, - "ein.hycell": false, - "ein.tags": "worksheet-0", - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.10" - }, - "name": "gitlab.ipynb" - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/plugins/tasks/version_control/gitlab_data/inventory/hosts.yaml b/docs/plugins/tasks/version_control/gitlab_data/inventory/hosts.yaml deleted file mode 100644 index 52f6da15..00000000 --- a/docs/plugins/tasks/version_control/gitlab_data/inventory/hosts.yaml +++ /dev/null @@ -1,11 +0,0 @@ ---- -alpine: - data: - domestic: true - diet: omnivore - additional_data: - lifespan: 17 - famous_members: - - garfield - - felix - - grumpy