Commit 176e3aa3 authored by Ales Mrazek's avatar Ales Mrazek

autodoc of modules

parent c26d3e6a
......@@ -10,8 +10,8 @@ YANG data models and tools for unified configuration of DNS resolvers
Data model and library for DNS resolvers:
* [Knot Resolver](https://www.knot-resolver.cz/)
* [Unbound](https://www.unbound.net/)
[//]: # "* [PowerDNS](https://www.powerdns.com/)"
[//]: # "* [BIND](https://www.isc.org/downloads/bind/)"
[//]: # (* [PowerDNS](https://www.powerdns.com/))
[//]: # (* [BIND](https://www.isc.org/downloads/bind/))
## Data Model
* [Current schema tree](https://gitlab.labs.nic.cz/labs/resolvers-yang/raw/master/data-model/model.tree)
......@@ -45,11 +45,11 @@ $ python3 setup.py install
## Create local documentation
Local [Sphinx](http://www.sphinx-doc.org/en/master/) documentation is located in `resolvers-yang/docs` directory.
Local [Sphinx](http://www.sphinx-doc.org/en/master/) documentation is located in `docs` directory.
```
$ cd docs/
$ make html
```
In `_build/html` open `index.html` in your web browser.
\ No newline at end of file
Then open `_build/html/index.html` in your web browser.
\ No newline at end of file
......@@ -12,10 +12,10 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
sys.path.append('../resolvers_yang')
# -- Project information -----------------------------------------------------
......
......@@ -30,19 +30,19 @@ No output means that ``example-data.json`` is valid.
generate_conf.py
================================
This script will generate ``unbound.conf`` and ``kresd.conf`` files in local files.
The script will generate ``unbound.conf`` and ``kresd.conf`` resolvers configuration files.
Run ``generate_conf.py`` script with path to Json file as parameter::
$ python generate_conf.py example-data.json
If generated ``unbound.conf`` is converted to JSON using ``unb_to_json.py`` script. The result do not have to be the same as input JSON for ``generate_conf.py`` script because the configuration designed to Knot Resolver is ignored for Unbound.
If generated ``unbound.conf`` is converted to JSON by ``unb_to_json.py`` script. The result does not have to be the same as input JSON for ``generate_conf.py`` script, because the configuration solely for Knot Resolver is ignored for Unbound.
============================
unb_to_json.py
============================
This script will convert Unbound configuration text file``unbound.conf`` to `resolvers-yang` data model valid Json-encoded file ``unb-data.json``.
The script will convert Unbound configuration file ``unbound.conf`` to Json-encoded file ``unb-data.json``, which is validate with ``resolvers-yang`` data model.
As example configuration file can be used ``unbound.conf`` created by running ``generate_conf.py``
Run ``unb_to_conf.py`` with path to ``unbound.conf`` as parameter::
......@@ -51,4 +51,4 @@ Run ``unb_to_conf.py`` with path to ``unbound.conf`` as parameter::
No output means that the JSON data in created ``unb-data.json`` is valid.
If you generate another ``unbound.conf`` from this Json using ``generate_conf.py`` script, it should be equal to ``unbound.conf``, which was used as input parameter to ``unb_to_json.py`` script.
\ No newline at end of file
If you generate another ``unbound.conf`` from this Json using ``generate_conf.py`` script, it should be equal to ``unbound.conf``, which was used as input parameter for ``unb_to_json.py`` script.
\ No newline at end of file
......@@ -48,14 +48,18 @@ Validate data against the data model:
>>> json_data.validate()
Now you can use Resolvers-YANG utilities.
Now the data is valid and you can work with it.
=================
Library Modules
=================
Generator
---------
Generator module
----------------
.. automodule:: generator
:members:
Import ``gen_unbound`` and ``gen_kresd`` functions to generate Unbound and Knot Resolver configuration strings from valid python dictionary loaded from Json. Returns string.
......@@ -73,10 +77,14 @@ Call generator functions to generate `unbound.conf` and `kresd.conf`.
``unbound_conf`` and ``kresd_conf`` are configuration strings , which can be save as text files.
Converter
---------
Converter module
----------------
.. automodule:: converter
:members:
Import ``from_unbound`` function for converting Unbound configuration string to valid python dictionary which can be save as Json file.
Import ``from_unbound`` function for converting Unbound configuration string to python dictionary, which can be validate against `resolvers-yang` data model and save as Json file.
.. doctest::
......
......@@ -21,7 +21,7 @@ Data Model is located in ``data-model/`` project directory.
* `Current schema tree`_
* `Example JSON data`_
Data model is divided into several smaller sections.
Common Data model is divided into several sections.
server:
-------------
......
"""Module for converting Unbound configuration file to dictionary structure, which can be validate with data model
and save as Json. """
from re import compile
# regular expressions
......@@ -43,6 +46,13 @@ def parse_line(line: str):
def from_unbound(unbound_data: list):
"""
:param unbound_data: data loaded from Unbound configuration file
:type list:
:return: Dictionary structure of common-resolvers configuration
:rtype: dictionary
"""
data = {'cznic-resolver-common:dns-resolver': {}}
interface_num = 0
......
"""
Module for generating Unbound´s and Knot Resolver´s configuration files from valid loaded Json.
"""
from re import compile
from socket import gethostbyname
......@@ -22,6 +26,13 @@ def order_data(data: dict):
# Function for generate Unbound configuration string
def gen_unbound(data: dict):
"""
:param data: data loaded from Json and Validated with Data Model
:type dict: Python Dictionary
:return: Unbound configuration
:rtype: string
"""
server = "server:\n"
stub = ""
......@@ -230,6 +241,13 @@ def gen_unbound(data: dict):
def gen_kresd(data: dict):
"""
:param data: data loaded from Json and Validated with Data Model
:type dict: Python Dictionary
:return: Knot Resolver configuration
:rtype: string
"""
kresd_conf = ""
# order data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment