Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:nornir-automation/nornir into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
dbarrosop committed Jul 12, 2018
2 parents aeecd7a + 0bbd518 commit 21a6859
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 131 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,3 @@ output/
.pytest_cache/

.vscode

# Generated when testing
nsot-docker.sqlite3
9 changes: 0 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
format:
black .

.PHONY: start_nsot
start_nsot:
cp $(PWD)/tests/inventory_data/nsot/nsot.sqlite3 $(PWD)/tests/inventory_data/nsot/nsot-docker.sqlite3
docker run -v $(PWD)/tests/inventory_data/nsot/nsot-docker.sqlite3:/nsot.sqlite3 -p 8990:8990 -d --name=nsot nsot/nsot start --noinput

.PHONY: stop_nsot
stop_nsot:
docker rm -f nsot

.PHONY: tests
tests:
tox
30 changes: 20 additions & 10 deletions docs/howto/writing_a_custom_inventory.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
Writing a custom inventory
==========================

If you have your own backend with host information or you don't like the provided ones you can write your own custom inventory. Doing so is quite easy. A continuation you can find a very simple one with static data::
If you have your own backend with host information or you don't like the provided ones you can write your own custom inventory. Doing so is quite easy. A continuation you can find a very simple one with static data.

.. code-block:: python
from builtins import super
Expand All @@ -15,13 +17,13 @@ If you have your own backend with host information or you don't like the provide
hosts = {
"host1": {
"data1": "value1",
"data2": "value2".
"group": "my_group1",
"data2": "value2",
"groups": ["my_group1"],
},
"host2": {
"data1": "value1",
"data2": "value2".
"group": "my_group1",
"data2": "value2",
"groups": ["my_group1"],
}
}
groups = {
Expand All @@ -30,19 +32,27 @@ If you have your own backend with host information or you don't like the provide
"more_data2": "more_value2",
}
}
defaults = {
"location": "internet",
"language": "Python",
}
# passing the data to the parent class so the data is
# transformed into actual Host/Group objects
super().__init__(hosts, groups, **kwargs)
# and set default data for all hosts
super().__init__(hosts, groups, defaults, **kwargs)
So if you want to make it dynamic everything you have to do is get the data yourself and organize it in a similar format to the one described in the example above.

.. note:: it is not mandatory to use groups. Feel free to skip the attribute ``group`` and just pass and empty dict or ``None`` to ``super()``.
.. note:: it is not mandatory to use groups or defaults. Feel free to skip the attribute ``groups`` and just pass and empty dict or ``None`` to ``super()``.

Finally, to have nornir use it, you can:

.. code-block:: python
Finally, to have nornir use it, you can do::
from nornir.core import InitNornir
nr = InitNornir(inventory=MyInventory)
inv = MyInventory()
nornir = Nornir(inventory=inv)
And that's it, you now have your own inventory plugin :)
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ How the documentation is structured

- The :doc:`Tutorial </tutorials/intro/index>` is a great place to start for new users.
- :doc:`How-to guides </howto/index>` aim to solve a specific use case or answer key problems. These guides can be more advanced than the tutorial and can assume some knowledge about how Nornir and related technologies work.
- :doc:`Reference guides </ref/index>` contains the API reference for Nornir and describe the core functions and plugins.
- :doc:`Reference guides </ref/index>` contains the API reference for Nornir and describe the core functions.
- :doc:`Configuration </configuration/index>` describe the configuration parameters of Nornir and their default settings.
- :doc:`Plugins </plugins/index>` shows which tasks and functions are available out of the box with Nornir and describe how they work.

Is something missing from the documentation? Please open an issue and `tell us what you are missing <https://github.com/nornir-automation/nornir/issues>`_ or `open a pull request <https://github.com/nornir-automation/nornir/pulls>`_ and suggest an improvement.

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/intro/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Before you go ahead and install Nornir it's recommended to create your own Pytho

.. note::

This tutorial doesn't cover the creation of a Python virtual environment. The Python documentation offers a guide where you can learn more about `virtualenvs <http://docs.python-guide.org/en/latest/dev/virtualenvs/>`_. We also won't cover the `installation of pip <https://pip.pypa.io/en/stable/installing/>`_, but changes are that you already have pip on your system.
This tutorial doesn't cover the creation of a Python virtual environment. The Python documentation offers a guide where you can learn more about `virtualenvs <http://docs.python-guide.org/en/latest/dev/virtualenvs/>`_. We also won't cover the `installation of pip <https://pip.pypa.io/en/stable/installing/>`_, but chances are that you already have pip on your system.

Nornir is published to `PyPI <https://pypi.org/project/nornir/>`_ and can be installed like most other Python packages using the pip tool. You can verify that you have pip installed by typing:

Expand All @@ -15,7 +15,7 @@ Nornir is published to `PyPI <https://pypi.org/project/nornir/>`_ and can be ins
pip 9.0.3 from /Users/patrick/nornir/lib/python3.6/site-packages (python 3.6)
It could be that you need to use the pip3 binary instead of pip as pip3 is for Python 3 on some systems. Speaking of Python 3, this tutorial is written with Python 3.6 in mind. This has mostly to do with the use of f-strings, you should however be able to follow along even if you are still at Python 2.7. However, if you are starting something new don't use Python 2.7. If you have to make sure that you're pip is up to date as you might have trouble installing some of the Nornir dependencies if you have a very old pip if you are on version 9.0 or later you should be find.
It could be that you need to use the pip3 binary instead of pip as pip3 is for Python 3 on some systems. Speaking of Python 3, this tutorial is written with Python 3.6 in mind. This has mostly to do with the use of f-strings, you should however be able to follow along even if you are still at Python 2.7. However, if you are starting something new don't use Python 2.7. You have to make sure that your pip is up to date as you might have trouble installing some of the Nornir dependencies if you have a very old pip. If you are on version 9.0 or later you should be fine.

As you would assume, the installation is then very easy.

Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pytest
pytest-cov
pylama
flake8-import-order
requests-mock
tox
black==18.4a1; python_version >= '3.6'
-r requirements.txt
79 changes: 0 additions & 79 deletions tests/inventory_data/nsot/nsot.sh

This file was deleted.

Binary file removed tests/inventory_data/nsot/nsot.sqlite3
Binary file not shown.
58 changes: 58 additions & 0 deletions tests/plugins/inventory/nsot/1.3.0/devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"attributes": {
"router_id": "10.1.1.1",
"host": "127.0.0.1",
"user": "vagrant",
"password": "vagrant",
"os": "eos",
"port": "12443",
"asn": "65001"
},
"hostname": "rtr00-site1",
"site_id": 1,
"id": 1
},
{
"attributes": {
"router_id": "10.1.1.2",
"host": "127.0.0.1",
"user": "vagrant",
"password": "",
"os": "junos",
"port": "12203",
"asn": "65002"
},
"hostname": "rtr01-site1",
"site_id": 1,
"id": 2
},
{
"attributes": {
"router_id": "10.1.1.1",
"host": "127.0.0.1",
"user": "vagrant",
"password": "vagrant",
"os": "eos",
"port": "12443",
"asn": "65001"
},
"hostname": "rtr00-site2",
"site_id": 2,
"id": 3
},
{
"attributes": {
"router_id": "10.1.1.2",
"host": "127.0.0.1",
"user": "vagrant",
"password": "",
"os": "junos",
"port": "12203",
"asn": "65002"
},
"hostname": "rtr01-site2",
"site_id": 2,
"id": 4
}
]

0 comments on commit 21a6859

Please sign in to comment.