2023-12-17 20:25:53 +01:00
.. |Tiramisu| replace :: Tiramisu
.. _tiramisu: https://forge.cloud.silique.fr/stove/tiramisu
Getting started
====================
What is a consistency handling system ?
------------------------------------------------
.. questions :: Question: "OK, I have understood that the Rougail stuff enables me to take advantage of |Tiramisu|. But what is all this for? What is exactly a consistency handling system? And again, what is this |Tiramisu| library used for?"
*Answer* : Well, let's explain what |Tiramisu| is and how we are using the |Tiramisu| library.
.. glossary ::
Tiramisu
2024-03-05 15:34:08 +01:00
|Tiramisu| is a consistency handling system that has initially been designed
2023-12-17 20:25:53 +01:00
in the configuration management scope. To put it more simply,
this library is generally used to handle configuration options.
It manages variables and group of variables. In the Tiramisu scope we call
it *options* and *option descriptions* .
In the Rougail scope, we call it :term: `variable` \ s and :term: `families` .
In Rougail, the families and variables are located in the :term: `dictionaries` .
And this is what we are going to explain in this page.
The dictionaries
---------------------
.. glossary ::
dictionary
dictionaries
A dictionary in the Rougail meaning is a YAML file that describes variables
and their dependencies / consistencies.
There can be a lot of dictionary files located in many different folders.
Rougail reads all the dictionaries and loads them into a single object
that handles the variables consistency.
.. image :: images/schema.png
2024-03-05 15:34:08 +01:00
The main advantage is that declaring variables and writing consistency is as simple
as writing YAML. With Rougail it is not necessary to write :term: `Tiramisu` code any more.
2023-12-17 20:25:53 +01:00
It simplifies a lot of things.
2024-03-05 15:34:08 +01:00
And rather than writing :term: `Tiramisu` code, we can declare variables and describe the relationships between variables in a declarative mode (that is, in a YAML file).
2023-12-17 20:25:53 +01:00
Once the dictionaries are loaded by Rougail, we find all the power of the :term: `Tiramisu` configuration management tool.
2024-03-05 15:34:08 +01:00
The YAML dictionaries format
-----------------------------
2023-12-17 20:25:53 +01:00
Before getting started with Rougail we need to learn the specifics of the YAML dictionaries file format (as well as some templating concepts).
.. FIXME parler de jinja https://jinja.palletsprojects.com
Here is a :term: `dictionary` example:
.. code-block :: yaml
:linenos:
---
2024-03-28 09:43:33 +01:00
version: '1.1'
2023-12-17 20:25:53 +01:00
proxy:
description: Configure Proxy Access to the Internet
type: family
Line 3, we declare a **variable** named `proxy` with his `description` line 4 and his `type` line 5.
The variables
-----------------
variable
Here is a second definition of a :term: `variable` : it is a declaration unit that represents a business domain metaphor,
2024-03-05 15:34:08 +01:00
the most common example is that a variable that represents a configuration option
2023-12-17 20:25:53 +01:00
in a application, but a variable represents something more that a configuration option.
It provides a business domain specific representation unit.
2024-03-05 15:34:08 +01:00
.. note :: Dictionaries can just define a list of variables, but we will see that
2023-12-17 20:25:53 +01:00
we can specify a lot more. We can define variables **and** their relations,
2024-03-05 15:34:08 +01:00
**and** the consistency between them.
2023-12-17 20:25:53 +01:00
In the next step, we will explain through a tutorial how to construct a list of variables.
Families of variables
--------------------------
.. glossary ::
family
families
A family of variables is simply a collection of variables that refer to
the same business model category. It's just a variables container.
Think of it as a container as well as a namespace.
A "hello world" with Rougail
------------------------------
We're gonna make the simplest possible example.
.. prerequisites :: Prerequisites
We assume that Rougail's library is installed on your computer (or in a virtual environment).
.. exercise :: Let's make a Hello world
Here is the tree structure we want to have::
workplace
├── dict
│ ├── hello.yml
└── hello.py
- Let's make a :file: `workplace` directory, with a :file: `dict` subfolder.
- First, we need a :term: `dictionary` , so let's make the :file: `hello.yml` file
which is located in the :file: `dict` subfolder, with the following content:
.. code-block :: yaml
:caption: The `hello.yaml` file
---
2024-03-28 09:43:33 +01:00
version: '1.1'
2023-12-17 20:25:53 +01:00
hello:
default: world
- Then we make a :file: `hello.py` in our root :file: `workplace` directory:
.. code-block :: python
:caption: The :file:`hello.py` file
from rougail import Rougail, RougailConfig
RougailConfig['dictionaries_dir'] = ['dict']
rougail = Rougail()
config = rougail.get_config()
print(config.value.get())
.. demo :: Let's run the :file: `hello.py` script
We launch the script:
.. code-block :: bash
python hello.py
And we obtain the following result:
.. code-block :: python
{'rougail.hello': 'world'}
**Congratulations ! You have successfully completed your first Rougail script.**
A "Hello, <name> " sample with a family
------------------------------------------
Let's continuing on our "Hello world" theme and add a :term: `family` container.
.. code-block :: yaml
:caption: the :file:`hello.yml` file
:linenos:
---
2024-03-28 09:43:33 +01:00
version: '1.1'
2023-12-17 20:25:53 +01:00
world:
description: Hello world family container
name:
description: Somebody to say hello
default: rougail
2024-03-05 15:34:08 +01:00
Here, we have a family named `world` .
2023-12-17 20:25:53 +01:00
This family contains a variable named `name`
Again, let's validate this YAML file against Rougail's API:
.. code-block :: bash
python hello.py
We then have the output:
.. code-block :: python
2024-03-05 15:34:08 +01:00
2023-12-17 20:25:53 +01:00
{'rougail.world.name': 'rougail'}