98 lines
2.1 KiB
Markdown
98 lines
2.1 KiB
Markdown
# Exemples de calcule
|
|
|
|
## Calculer les noms de modèle à généré à partir d'une variable
|
|
|
|
Créeons deux variables multiples, une pour accueillir la liste des éléments du nom variable (ici `zones_list`), la seconde étant le nom du fichier calculé (ici `netwokd_configurations`) :
|
|
|
|
```xml
|
|
<variables>
|
|
<variable name="zones_list" type="string" multi="True">
|
|
<value>zone1</value>
|
|
<value>zone2</value>
|
|
<value>zone3</value>
|
|
</variable>
|
|
<variable name="netwokd_configurations" type="filename" multi="True" hidden="True"/>
|
|
</variables>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
variables:
|
|
- variable:
|
|
name: zones_list
|
|
type: string
|
|
multi: true
|
|
value:
|
|
- text: 'zone1'
|
|
- text: 'zone2'
|
|
- text: 'zone3'
|
|
- variable:
|
|
name: netwokd_configurations
|
|
type: filename
|
|
multi: true
|
|
hidden: true
|
|
```
|
|
|
|
Calculons la valeur de la seconde variable à partir de la première :
|
|
|
|
```xml
|
|
<constraints>
|
|
<fill name="calc_value">
|
|
<param>/systemd/network/10-</param>
|
|
<param type="variable">zones_list</param>
|
|
<param>-risotto.network</param>
|
|
<param name="join"></param>
|
|
<param name="multi" type="boolean">True</param>
|
|
<target>netwokd_configurations</target>
|
|
</fill>
|
|
</constraints>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
constraints:
|
|
- fill:
|
|
- name: calc_value
|
|
param:
|
|
- text: /systemd/network/10-
|
|
- type: variable
|
|
text: zones_list
|
|
- text: -risotto.network
|
|
- name: join
|
|
- name: multi
|
|
type: boolean
|
|
text: true
|
|
target:
|
|
- text: netwokd_configurations
|
|
```
|
|
|
|
Le contenu de la variable `netwokd_configurations` sera alors :
|
|
|
|
- /systemd/netword/10-zone1/risotto.network
|
|
- /systemd/netword/10-zone2/risotto.network
|
|
- /systemd/netword/10-zone3/risotto.network
|
|
|
|
Enfin déclarer une balise file en utilisant ces deux variables :
|
|
|
|
```xml
|
|
<services>
|
|
<service name="systemd-networkd">
|
|
<file file_type="variable" source="network" variable="zones_list">netwokd_configurations</file>
|
|
</service>
|
|
</services>
|
|
```
|
|
|
|
En YAML :
|
|
|
|
```yml
|
|
services:
|
|
- service:
|
|
- name: systemd-networkd
|
|
file:
|
|
- file_type: variable
|
|
source: network
|
|
variable: zones_list
|
|
text: netwokd_configurations
|
|
```
|