2023-12-17 20:25:53 +01:00
Getting started
====================
What is a consistency handling system ?
------------------------------------------------
2024-10-14 19:17:44 +02:00
.. questions ::
"OK, I have understood that the Rougail stuff enables me to take advantage of :xref: `tiramisu` .
But what is all this for?
What is exactly a consistency handling system?
And again, what is this :xref: `tiramisu` library used for?"
2023-12-17 20:25:53 +01:00
2024-10-14 19:17:44 +02:00
*Answer* : Well, now we explain what this :xref: `tiramisu` library is, and how we are using it.
2023-12-17 20:25:53 +01:00
.. glossary ::
Tiramisu
2024-10-14 19:17:44 +02:00
:xref: `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* .
2024-10-14 19:17:44 +02:00
Here is the :xref: `tiramisu library` .
2023-12-17 20:25:53 +01:00
In the Rougail scope, we call it :term: `variable` \ s and :term: `families` .
2024-10-21 19:50:26 +02:00
In Rougail, the families and variables are located in the :term: `structure files <dictionaries>` .
2023-12-17 20:25:53 +01:00
And this is what we are going to explain in this page.
2024-10-21 19:50:26 +02:00
The structure files
2023-12-17 20:25:53 +01:00
---------------------
.. glossary ::
2024-10-21 19:50:26 +02:00
structure file
2023-12-17 20:25:53 +01:00
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.
2024-10-21 19:50:26 +02:00
A dictionary file is a structure file, we call a dictionary a structure file.
2023-12-17 20:25:53 +01:00
.. image :: images/schema.png
2024-01-23 10:57:01 +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-01-23 10:57:01 +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
2024-10-21 19:50:26 +02:00
Once the structure files are loaded by Rougail, we find all the power of the :term: `Tiramisu` configuration management tool.
2023-12-17 20:25:53 +01:00
2024-10-21 19:50:26 +02:00
The YAML structure files 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).
2024-10-14 19:17:44 +02:00
.. todo :: parler de jinja https://jinja.palletsprojects.com
Here is an empty rougail dictionary YAML file
2024-10-28 15:29:11 +01:00
.. extinclude :: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_000/firefox/00-proxy.yml
2024-10-14 22:51:05 +02:00
:linenos:
:language: yaml
2024-10-15 07:31:31 +02:00
:caption: An empty rougail dictionnary file. It's a YAML format.
:name: RougailDictionaryEmptyFile
2024-10-14 19:17:44 +02:00
2024-10-28 15:29:11 +01:00
..
---
version: 1.1
:download: `source file <https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_000/firefox/00-proxy.yml>`
2024-10-14 19:17:44 +02:00
2024-10-15 09:20:01 +02:00
You can see that there is just a `version` specification.
2023-12-17 20:25:53 +01:00
2024-10-15 09:20:01 +02:00
.. glossary ::
2023-12-17 20:25:53 +01:00
2024-10-15 09:20:01 +02:00
version
The version is here a Rougail YAML dictionary version format.
It is set in the beginning of a YAML dictionary, or globaly in the Rougail settings
for example from the command line
2023-12-17 20:25:53 +01:00
2024-10-15 09:20:01 +02:00
.. note :: You can set the format in the Rougail command line tool like this:
2023-12-17 20:25:53 +01:00
2024-10-15 09:20:01 +02:00
.. code-block :: bash
foo@bar:~$ rougail -v 1.1
2023-12-17 20:25:53 +01:00
The variables
-----------------
2024-10-21 19:50:26 +02:00
Here is a :term: `structure file <dictionary>` example with a variable into it:
2024-10-15 09:20:01 +02:00
2024-10-28 15:29:11 +01:00
.. extinclude :: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_010/firefox/00-proxy.yml
2024-10-15 09:20:01 +02:00
:linenos:
:language: yaml
:caption: A rougail dictionnary file with a variable named `proxy_mode`. It's the Rougail YAML dictionary format.
:name: RougailDictionaryFirstVariable
2024-10-28 15:29:11 +01:00
..
---
proxy_mode:
:download: `source file <https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_010/firefox/00-proxy.yml>`
2024-10-15 09:20:01 +02:00
2024-10-21 19:50:26 +02:00
Here we declare a **variable** named `proxy_mode` without a default value.
2024-10-15 09:20:01 +02:00
A variable can be defined with no default value at all.
2024-10-15 15:50:01 +02:00
Here is the same variable with a description label:
2024-10-28 15:29:11 +01:00
.. extinclude :: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_011/firefox/00-proxy.yml
2024-10-15 15:50:01 +02:00
:linenos:
:language: yaml
:caption: A rougail dictionnary file with a variable named `proxy_mode`, with a description.
:name: RougailDictionaryFirstVariableDescription
2024-10-28 15:29:11 +01:00
..
---
proxy_mode:
description: Configure Proxy Access to the Internet
2024-10-15 15:50:01 +02:00
2024-10-28 15:29:11 +01:00
The same with a default value:
2024-10-15 15:50:01 +02:00
2024-10-28 15:29:11 +01:00
.. extinclude :: https://forge.cloud.silique.fr/stove/rougail-tutorials/raw/tag/v1.1_012/firefox/00-proxy.yml
2024-10-15 15:50:01 +02:00
:linenos:
:language: yaml
:caption: A rougail dictionnary file with a variable named `proxy_mode`, with a default value.
:name: RougailDictionaryFirstVariableDefault
2024-10-28 15:29:11 +01:00
..
---
proxy_mode:
description: Configure Proxy Access to the Internet
default: No proxy
2023-12-17 20:25:53 +01:00
variable
2024-10-15 09:20:01 +02:00
A variable is a declaration unit that represents a business domain metaphor,
2024-01-23 10:57:01 +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-10-15 15:50:01 +02:00
.. todo :: définir une variable avec une description, un type, l'inférence de type,
les notations condensées,
une family sans variable doit avoir un type: family,
2024-01-23 10:57:01 +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-10-15 09:20:01 +02:00
**and** the relations 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
2024-10-15 16:55:01 +02:00
We assume that Rougail's library is installed on your computer (or in a virtual environment).
2023-12-17 20:25:53 +01:00
2024-10-15 16:55:01 +02:00
.. exercise :: Hello world's workshop
2023-12-17 20:25:53 +01:00
2024-10-15 16:55:01 +02:00
Here is the tree structure we want to have::
2023-12-17 20:25:53 +01:00
2024-10-15 16:55:01 +02:00
workplace
├── dict
│ ├── hello.yml
└── hello.py
2023-12-17 20:25:53 +01:00
- 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
2024-10-21 15:42:52 +02:00
.. todo :: mettre un appel à la CLI pour lancer le truc
2023-12-17 20:25:53 +01:00
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-01-23 10:57:01 +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-01-23 10:57:01 +01:00
2023-12-17 20:25:53 +01:00
{'rougail.world.name': 'rougail'}
2024-10-14 19:17:44 +02:00