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

Inventory rework #243

Merged
merged 44 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e39e614
refactor configuration
dbarrosop Aug 30, 2018
f9dfb40
trying to make mypy happy
dbarrosop Aug 30, 2018
8252296
Merge branch '2.0' of github.com:nornir-automation/nornir into pydantic
dbarrosop Aug 30, 2018
5d6c31d
progress
dbarrosop Aug 31, 2018
333dbd3
tests passing
dbarrosop Sep 2, 2018
9cc059d
final touches to the inventory rework
dbarrosop Sep 3, 2018
63e329f
Data is now GlobalState
dbarrosop Sep 3, 2018
809c864
add a fixture to reset_failed_hosts
dbarrosop Sep 3, 2018
e2fec9c
fix defaults
dbarrosop Sep 3, 2018
53978f1
fix howtos
dbarrosop Sep 3, 2018
2720a0f
undo GlobalState as a class object
dbarrosop Sep 3, 2018
e310735
progress
dbarrosop Sep 4, 2018
620d446
progress
dbarrosop Sep 4, 2018
6105052
fix tests
dbarrosop Sep 4, 2018
88115da
progress
dbarrosop Sep 9, 2018
4a3efbe
fix mypy
dbarrosop Sep 9, 2018
dfea375
we need to fix doc references
dbarrosop Sep 9, 2018
7127dbb
fix circular reference
dbarrosop Sep 9, 2018
7d8aa5e
fix cyclic import
dbarrosop Sep 9, 2018
67bab3b
fix sphinx
dbarrosop Sep 9, 2018
615228a
mypy fixes
dbarrosop Sep 15, 2018
4cf47f8
fix attributes resolution
dbarrosop Sep 15, 2018
e3feae4
fix bug in tutorial
dbarrosop Sep 15, 2018
d106aec
minor bugfix
dbarrosop Sep 21, 2018
1afe62c
inhering from host atrributes
dbarrosop Sep 23, 2018
37a6db1
resolve connection_options recursively
dbarrosop Sep 23, 2018
0c0dd5f
fix nbval
dbarrosop Sep 24, 2018
ac82aa0
stop printing coverage by default
dbarrosop Oct 7, 2018
4d9d839
separate serializing function for the configuration
dbarrosop Oct 7, 2018
46bef2e
refactor config to have everything inside a section
dbarrosop Oct 13, 2018
067b042
document the configuration
dbarrosop Oct 13, 2018
32c69eb
fix docs for exceptions
dbarrosop Oct 13, 2018
a639ce0
blackify
dbarrosop Oct 13, 2018
60f336c
pylamafy
dbarrosop Oct 13, 2018
2686173
fix mypy
dbarrosop Oct 13, 2018
b34d09c
add missing directory
dbarrosop Oct 14, 2018
29a7a9e
fix typos
dbarrosop Oct 16, 2018
78fcec9
fixes #258
dbarrosop Oct 16, 2018
7c7c85c
change logger names __name__
dbarrosop Oct 19, 2018
75820ae
fix deserializer types
dbarrosop Oct 19, 2018
147ef56
classmethod should follow cls convention
dbarrosop Oct 19, 2018
1924649
various fixes
dbarrosop Oct 19, 2018
900af24
Merge pull request #254 from nornir-automation/config_continue
dbarrosop Oct 19, 2018
37a72b1
addressing PR comments
dbarrosop Oct 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions docs/_data_templates/configuration-parameters.j2
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
The configuration parameters will be set by the :doc:`Nornir.core.configuration.Config </ref/api/configuration>` class.
{% macro document_section(section, schema) %}
{{ section }}
{{ "-" * section|length }}

{% for k, v in params|dictsort %}
----------
{% for k, v in schema["properties"].items() -%}

{{ k }}
----------------------------------
``{{ k }}``
{{ "_" * (k|length + 4) }}

.. list-table::
:widths: 15 85

.. raw:: html
* - **Description**
- {{ v["description"] }}
* - **Type**
- ``{{ v["type"] }}``
* - **Default**
- {{ "``{}``".format(v["default"]) if v["default"] else "" }}
* - **Required**
- ``{{ v["required"] }}``
* - **Environment Variable**
- ``{{ "NORNIR_{}_{}".format(section, k).upper() }}``

<table border="1" class="docutils">
<th>Environment variable</th>
<th>Type</th>
<th>Default</th>
<tr>
{% if v['type'] in ('str', 'int', 'bool') %}
<td>{{ v['env'] or 'BRIGADE_' + k|upper }}</td>
{% else %}
<td>N/A</td>
{% endif %}
<td>{{ v['type'] }}</td>
<td>{{ v['default_doc'] or v['default'] }}</td>
</tr>
</table>

{{ v['description'] }}
{% endfor %}
{%- endmacro %}

{% for k, v in schema["properties"].items() if k not in ["user_defined"] %}
{{ document_section(k, v) }}
{% endfor %}
27 changes: 11 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
import os
import sys

from jinja2 import Environment
from jinja2 import FileSystemLoader
from jinja2 import Environment, FileSystemLoader

sys.path.insert(0, os.path.abspath("../"))

from nornir.core.deserializer.configuration import Config # noqa

from nornir.core.configuration import CONF # noqa

# -- General configuration ------------------------------------------------
BASEPATH = os.path.dirname(__file__)
BASEPATH = os.path.abspath(os.path.dirname(__file__))

# If your documentation needs a minimal Sphinx version, state it here.
#
Expand All @@ -54,7 +53,7 @@

# General information about the project.
project = "nornir"
copyright = "2017, David Barroso"
copyright = "2018, David Barroso"
author = "David Barroso"

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -173,30 +172,26 @@
]


def skip_slots(app, what, name, obj, skip, options):
if obj.__class__.__name__ == "member_descriptor":
return True
return None


def build_configuration_parameters(app):
"""Create documentation for configuration parameters."""

env = Environment(loader=FileSystemLoader("{0}/_data_templates".format(BASEPATH)))
template_file = env.get_template("configuration-parameters.j2")
data = {}
data["params"] = CONF
data["schema"] = Config.schema()
rendered_template = template_file.render(**data)
output_dir = "{0}/configuration/generated".format(BASEPATH)
with open("{}/parameters.rst".format(output_dir), "w") as f:
f.write(rendered_template)


def skip_slots(app, what, name, obj, skip, options):
if obj.__class__.__name__ == "member_descriptor":
return True
return None


def setup(app):
"""Map methods to states of the documentation build."""
app.connect("builder-inited", build_configuration_parameters)
app.connect("autodoc-skip-member", skip_slots)
app.add_stylesheet("css/custom.css")


build_configuration_parameters(None)
23 changes: 19 additions & 4 deletions docs/configuration/index.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
Configuration
=============

Each configuration parameter are applied in the following order:
The configuration is comprised of a set of sections and parameters for those sections. You can set the configuration programmatically using nornir by passing a dictionary of options for each section, by using a YAML file, by setting the corresponding environment variables or by a combination of the three. The order of preference from less to more preferred is "configuration file" -> "env variable" -> "code".

1. Environment variable
2. Parameter in configuration file / object
3. Default value
An example using ``InitNornir`` would be::

nr = InitNornir(
core={"num_workers": 20},
logging={"file": "mylogs", "level": "debug"}
)

A similar example using a ``yaml`` file:

.. include:: ../howto/advanced_filtering/config.yaml
:code: yaml

Next, you can find each section and their corresponding options.

.. include:: generated/parameters.rst

user_defined
------------

You can set any ``<k, v>`` pair you want here and you will have it available under your configuration object, i.e. ``nr.config.user_defined.my_app_option``.
108 changes: 58 additions & 50 deletions docs/howto/advanced_filtering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"metadata": {},
"outputs": [],
"source": [
"from nornir.core import InitNornir\n",
"from nornir import InitNornir\n",
"from nornir.core.filter import F\n",
"\n",
"nr = InitNornir(config_file=\"advanced_filtering/config.yaml\")"
Expand All @@ -32,76 +32,82 @@
"text": [
"---\r\n",
"cat:\r\n",
" domestic: true\r\n",
" diet: omnivore\r\n",
" groups:\r\n",
" - terrestrial\r\n",
" - mammal\r\n",
" additional_data:\r\n",
" lifespan: 17\r\n",
" famous_members:\r\n",
" - garfield\r\n",
" - felix\r\n",
" - grumpy\r\n",
" data:\r\n",
" domestic: true\r\n",
" diet: omnivore\r\n",
" additional_data:\r\n",
" lifespan: 17\r\n",
" famous_members:\r\n",
" - garfield\r\n",
" - felix\r\n",
" - grumpy\r\n",
"\r\n",
"bat:\r\n",
" domestic: false\r\n",
" fly: true\r\n",
" diet: carnivore\r\n",
" groups:\r\n",
" - terrestrial\r\n",
" - mammal\r\n",
" additional_data:\r\n",
" lifespan: 15\r\n",
" famous_members:\r\n",
" - batman\r\n",
" - count chocula\r\n",
" - nosferatu\r\n",
" data:\r\n",
" domestic: false\r\n",
" fly: true\r\n",
" diet: carnivore\r\n",
" additional_data:\r\n",
" lifespan: 15\r\n",
" famous_members:\r\n",
" - batman\r\n",
" - count chocula\r\n",
" - nosferatu\r\n",
"\r\n",
"eagle:\r\n",
" domestic: false\r\n",
" diet: carnivore\r\n",
" groups:\r\n",
" - terrestrial\r\n",
" - bird\r\n",
" additional_data:\r\n",
" lifespan: 50\r\n",
" famous_members:\r\n",
" - thorondor\r\n",
" - sam\r\n",
" data:\r\n",
" domestic: false\r\n",
" diet: carnivore\r\n",
" additional_data:\r\n",
" lifespan: 50\r\n",
" famous_members:\r\n",
" - thorondor\r\n",
" - sam\r\n",
"\r\n",
"canary:\r\n",
" domestic: true\r\n",
" diet: herbivore\r\n",
" groups:\r\n",
" - terrestrial\r\n",
" - bird\r\n",
" additional_data:\r\n",
" lifespan: 15\r\n",
" famous_members:\r\n",
" - tweetie\r\n",
" data:\r\n",
" domestic: true\r\n",
" diet: herbivore\r\n",
" additional_data:\r\n",
" lifespan: 15\r\n",
" famous_members:\r\n",
" - tweetie\r\n",
"\r\n",
"caterpillaer:\r\n",
" domestic: false\r\n",
" diet: herbivore\r\n",
" groups:\r\n",
" - terrestrial\r\n",
" - invertebrate\r\n",
" additional_data:\r\n",
" lifespan: 1\r\n",
" famous_members:\r\n",
" - Hookah-Smoking\r\n",
" data:\r\n",
" domestic: false\r\n",
" diet: herbivore\r\n",
" additional_data:\r\n",
" lifespan: 1\r\n",
" famous_members:\r\n",
" - Hookah-Smoking\r\n",
"\r\n",
"octopus:\r\n",
" domestic: false\r\n",
" diet: carnivore\r\n",
" groups:\r\n",
" - marine\r\n",
" - invertebrate\r\n",
" additional_data:\r\n",
" lifespan: 1\r\n",
" famous_members:\r\n",
" - sharktopus\r\n"
" data:\r\n",
" domestic: false\r\n",
" diet: carnivore\r\n",
" additional_data:\r\n",
" lifespan: 1\r\n",
" famous_members:\r\n",
" - sharktopus\r\n"
]
}
],
Expand All @@ -119,18 +125,20 @@
"output_type": "stream",
"text": [
"---\r\n",
"defaults: {}\r\n",
"mammal:\r\n",
" reproduction: birth\r\n",
" fly: false\r\n",
" data:\r\n",
" reproduction: birth\r\n",
" fly: false\r\n",
"\r\n",
"bird:\r\n",
" reproduction: eggs\r\n",
" fly: true\r\n",
" data:\r\n",
" reproduction: eggs\r\n",
" fly: true\r\n",
"\r\n",
"invertebrate:\r\n",
" reproduction: mitosis\r\n",
" fly: false\r\n",
" data:\r\n",
" reproduction: mitosis\r\n",
" fly: false\r\n",
"\r\n",
"terrestrial: {}\r\n",
"marine: {}\r\n"
Expand Down
11 changes: 7 additions & 4 deletions docs/howto/advanced_filtering/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
inventory: nornir.plugins.inventory.simple.SimpleInventory
SimpleInventory:
host_file: "advanced_filtering/inventory/hosts.yaml"
group_file: "advanced_filtering/inventory/groups.yaml"
core:
num_workers: 20
inventory:
plugin: nornir.plugins.inventory.simple.SimpleInventory
options:
host_file: "advanced_filtering/inventory/hosts.yaml"
group_file: "advanced_filtering/inventory/groups.yaml"

16 changes: 9 additions & 7 deletions docs/howto/advanced_filtering/inventory/groups.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
---
defaults: {}
mammal:
reproduction: birth
fly: false
data:
reproduction: birth
fly: false

bird:
reproduction: eggs
fly: true
data:
reproduction: eggs
fly: true

invertebrate:
reproduction: mitosis
fly: false
data:
reproduction: mitosis
fly: false

terrestrial: {}
marine: {}
Loading