Compare commits
4 Commits
1e223e7b57
...
master
Author | SHA1 | Date | |
---|---|---|---|
8a7cf24cd6 | |||
669782cd35 | |||
4acd5d5a7f | |||
533ad2551f |
33
README.md
33
README.md
@ -11,27 +11,20 @@ Accéder à un message :
|
||||
wget http://localhost:8080/v1/config.session.server.start
|
||||
```
|
||||
|
||||
Démarrer un serveur LemonLDAP de test
|
||||
```
|
||||
docker pull coudot/lemonldap-ng
|
||||
echo "127.0.0.1 auth.example.com manager.example.com test1.example.com test2.example.com" >> /etc/hosts
|
||||
docker run -d --add-host reload.example.com:127.0.0.1 -p 80:80 coudot/lemonldap-ng
|
||||
```
|
||||
[Documentation WIKI cadoles](https://doku.cadoles.com/dokuwiki/doku.php?id=documentation:risotto) n'est qu'un liens vers la doc officiel (pour le moment) [dans la forge](https://forge.cadoles.com/Infra/eole-risotto/wiki)
|
||||
|
||||
Démarrer un serveur postgresql de test
|
||||
```
|
||||
podman pull docker.io/library/postgres:11-alpine
|
||||
podman run -dt -p 5432:5432 postgres:11-alpine
|
||||
**branche :**
|
||||
|
||||
psql -U postgres -h localhost -c "CREATE ROLE risotto WITH LOGIN PASSWORD 'risotto';"
|
||||
psql -U postgres -h localhost -c "CREATE DATABASE risotto;"
|
||||
psql -U postgres -h localhost -c "GRANT ALL ON DATABASE risotto TO risotto;"
|
||||
psql -U postgres -h localhost -c "CREATE EXTENSION hstore;" risotto
|
||||
```
|
||||
master
|
||||
|
||||
Gestion de la base de données avec Sqitch
|
||||
develop
|
||||
|
||||
```
|
||||
cpanm --quiet --notest App::Sqitch
|
||||
sqitch init risotto --uri https://forge.cadoles.com/Infra/risotto --engine pg
|
||||
```
|
||||
dist/risotto/risotto-2.7.1/develop : pour faire des paquets
|
||||
|
||||
dist/risotto/risotto-2.8.0/develop : pour faire des paquets
|
||||
|
||||
docker : n'est pas a jour
|
||||
|
||||
feature/service_servermodel :
|
||||
|
||||
jwt :
|
||||
|
@ -1,33 +0,0 @@
|
||||
---
|
||||
uri: applicationservice.create
|
||||
|
||||
description: |
|
||||
Créé un service applicatif.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
applicationservice_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: |
|
||||
Nom du service applicatif à créer.
|
||||
applicationservice_description:
|
||||
type: String
|
||||
shortarg: d
|
||||
description: |
|
||||
Description du service applicatif à créer.
|
||||
applicationservice_dependencies:
|
||||
type: '[]Number'
|
||||
shortarg: a
|
||||
description: ID des services applicatif donc dépendant le service applicatif.
|
||||
default: []
|
||||
release_id:
|
||||
type: Number
|
||||
shortarg: r
|
||||
description: |
|
||||
Identifiant de la version associée au service applicatif.
|
||||
|
||||
response:
|
||||
type: ApplicationService
|
||||
description: Informations sur le service applicatif créé.
|
@ -1,20 +0,0 @@
|
||||
uri: applicationservice.dataset.updated
|
||||
|
||||
description: |
|
||||
Les services applicatifs sont mis à jour.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
shortarg: s
|
||||
description: Nom de la source.
|
||||
release_distribution:
|
||||
type: String
|
||||
shortarg: r
|
||||
description: Distribution de la source.
|
||||
|
||||
response:
|
||||
type: ReturnStatus
|
||||
description: Code de retour sur l’injection des services applicatifs en base.
|
@ -1,23 +0,0 @@
|
||||
---
|
||||
uri: applicationservice.describe
|
||||
|
||||
description: |
|
||||
Décrit un service applicatif.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
applicationservice_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: |
|
||||
Nom du service applicatif à créer.
|
||||
release_id:
|
||||
type: Number
|
||||
shortarg: r
|
||||
description: |
|
||||
Identifiant de la version associée au service applicatif.
|
||||
|
||||
response:
|
||||
type: ApplicationService
|
||||
description: Informations sur le service applicatif.
|
@ -1,34 +0,0 @@
|
||||
---
|
||||
uri: applicationservice.get_by_id
|
||||
|
||||
description: |
|
||||
Retourne un service applicatif suivant l'identifiant.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
applicationservice_id:
|
||||
type: Number
|
||||
shortarg: i
|
||||
description: |
|
||||
ID du service applicatif à créer.
|
||||
|
||||
response:
|
||||
type: ApplicationService
|
||||
description: Informations sur le service applicatif créé.
|
||||
|
||||
errors:
|
||||
- uri: servermodel.create.error.database_not_available
|
||||
- uri: servermodel.create.error.duplicate_servermodel
|
||||
- uri: servermodel.create.error.invalid_parentservermodel_id
|
||||
- uri: servermodel.create.error.invalid_source_id
|
||||
- uri: servermodel.create.error.unknown_parentservermodel_id
|
||||
- uri: servermodel.create.error.unknown_source_id
|
||||
- uri: servermodel.create.error.servermodelname_not_provided
|
||||
|
||||
related:
|
||||
- servermodel.list
|
||||
- servermodel.describe
|
||||
- servermodel.update
|
||||
- servermodel.delete
|
||||
- servermodel.event
|
@ -4,8 +4,14 @@ uri: config.configuration.server.deploy
|
||||
description: |
|
||||
Déployer la configuration d'un serveur.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: config-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -4,8 +4,14 @@ uri: config.configuration.server.get
|
||||
description: |
|
||||
Récupère le contenu de la configuration.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: false
|
||||
|
||||
domain: config-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -4,8 +4,14 @@ uri: config.configuration.server.updated
|
||||
description: |
|
||||
Une configuration de serveur a été mise à jour.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: config-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
54
messages/v1/messages/old/server.create.yml
Normal file
54
messages/v1/messages/old/server.create.yml
Normal file
@ -0,0 +1,54 @@
|
||||
---
|
||||
uri: server.create
|
||||
|
||||
description: |
|
||||
Crée un serveur.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client server.create -s MonJoliServeur -d "un bien joli serveur" -m 1 -p MyPassPhrase
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: server-domain
|
||||
|
||||
parameters:
|
||||
servername:
|
||||
type: String
|
||||
shortarg: s
|
||||
description: |
|
||||
Nom du serveur.
|
||||
serverdescription:
|
||||
type: String
|
||||
shortarg: d
|
||||
description: |
|
||||
Description du serveur.
|
||||
servermodelid:
|
||||
type: Number
|
||||
shortarg: m
|
||||
ref: Servermodel.ServermodelId
|
||||
description: |
|
||||
Identifiant du modèle de serveur.
|
||||
serverpassphrase:
|
||||
type: String
|
||||
shortarg: p
|
||||
description: |
|
||||
Phrase secrète de la clef privé.
|
||||
|
||||
response:
|
||||
type: Server
|
||||
description: Description du serveur créé.
|
||||
|
||||
errors:
|
||||
- uri: server.error.database-not-available
|
||||
- uri: server.error.db-connection
|
||||
- uri: server.error.invalid-servermodel-id
|
||||
- uri: server.error.unknown-servermodel-id
|
||||
- uri: server.error.servername-not-provided
|
||||
|
||||
related:
|
||||
- server.list
|
||||
- server.describe
|
||||
- server.update
|
||||
- server.delete
|
49
messages/v1/messages/old/server.describe.yml
Normal file
49
messages/v1/messages/old/server.describe.yml
Normal file
@ -0,0 +1,49 @@
|
||||
---
|
||||
uri: server.describe
|
||||
|
||||
description: |
|
||||
Retourne les attributs détaillés d’un serveur.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client server.describe -s 1
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: server-domain
|
||||
|
||||
parameters:
|
||||
serverid:
|
||||
type: Number
|
||||
ref: Server.ServerId
|
||||
description: Identifiant du serveur.
|
||||
shortarg: s
|
||||
configuration:
|
||||
type: Boolean
|
||||
description: Inclure les valeurs de configuration.
|
||||
default: false
|
||||
environment:
|
||||
type: Boolean
|
||||
description: Inclure les variables d'environement.
|
||||
default: false
|
||||
peering:
|
||||
type: Boolean
|
||||
description: Inclure la clé d'appairage.
|
||||
default: false
|
||||
|
||||
response:
|
||||
type: ServerDescribe
|
||||
description: Description du serveur.
|
||||
|
||||
errors:
|
||||
- uri: server.error.database-not-available
|
||||
- uri: server.error.db-connection
|
||||
- uri: server.error.invalid-server-id
|
||||
- uri: server.error.unknown-server-id
|
||||
|
||||
related:
|
||||
- server.list
|
||||
- server.create
|
||||
- server.update
|
||||
- server.delete
|
@ -1,32 +0,0 @@
|
||||
---
|
||||
uri: servermodel.describe
|
||||
|
||||
description: |
|
||||
Retourne les attributs détaillés d'un modèle de serveur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
parameters:
|
||||
servermodel_id:
|
||||
type: Number
|
||||
shortarg: s
|
||||
description: Identifiant du modèle de serveur à récupérer.
|
||||
ref: Servermodel.ServermodelId
|
||||
|
||||
response:
|
||||
type: Servermodel
|
||||
description: Description du modèle de serveur.
|
||||
|
||||
errors:
|
||||
- uri: servermodel.describe.error.database_not_available
|
||||
- uri: servermodel.describe.error.invalid_servermodel_id
|
||||
- uri: servermodel.describe.error.unknown_servermodel_id
|
||||
|
||||
related:
|
||||
- servermodel.list
|
||||
- servermodel.create
|
||||
- servermodel.update
|
||||
- servermodel.delete
|
||||
- servermodel.event
|
18
messages/v1/messages/old/servermodel.source.list.yml
Normal file
18
messages/v1/messages/old/servermodel.source.list.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
uri: servermodel.source.list
|
||||
|
||||
description: |
|
||||
Retourne la liste des sources.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client servermodel.source.list
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
response:
|
||||
type: '[]Dict'
|
||||
description: Liste des sources disponibles.
|
@ -1,25 +0,0 @@
|
||||
---
|
||||
uri: server.create
|
||||
|
||||
description: Crée un serveur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
server_name:
|
||||
type: String
|
||||
shortarg: s
|
||||
description: Nom du serveur.
|
||||
server_description:
|
||||
type: String
|
||||
shortarg: d
|
||||
description: Description du serveur.
|
||||
server_servermodel_id:
|
||||
type: Number
|
||||
shortarg: m
|
||||
ref: Servermodel.ServermodelId
|
||||
description: Identifiant du modèle de serveur.
|
||||
|
||||
response:
|
||||
type: Server
|
||||
description: Description du serveur créé.
|
@ -5,6 +5,10 @@ description: Un serveur a été créé.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: server-domain
|
||||
|
||||
parameters:
|
||||
type: Server
|
||||
description: Description du serveur.
|
||||
|
@ -1,11 +1,17 @@
|
||||
---
|
||||
uri: server.deleted
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
description: |
|
||||
Un serveur a été supprimé.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: server-domain
|
||||
|
||||
parameters:
|
||||
server_id:
|
||||
type: Number
|
||||
|
@ -1,16 +0,0 @@
|
||||
---
|
||||
uri: server.describe
|
||||
|
||||
description: Retourne les attributs détaillés d’un serveur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
server_name:
|
||||
type: String
|
||||
ref: Server.ServerName
|
||||
description: Nom du serveur.
|
||||
|
||||
response:
|
||||
type: Server
|
||||
description: Description du serveur.
|
@ -4,8 +4,15 @@ uri: server.list
|
||||
description: |
|
||||
Liste les serveurs disponibles.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client server.list
|
||||
|
||||
public: true
|
||||
|
||||
pattern: rpc
|
||||
|
||||
domain: server-domain
|
||||
|
||||
response:
|
||||
type: '[]Server'
|
||||
description: Retourne la liste des serveurs.
|
||||
|
@ -5,6 +5,10 @@ description: Des modèles de serveur ont été créés.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
type: Servermodel
|
||||
description: Informations sur les modèles de serveur créés.
|
||||
|
@ -1,20 +0,0 @@
|
||||
uri: servermodel.dataset.updated
|
||||
|
||||
description: |
|
||||
Initialise la table pour les modèles de serveur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
shortarg: s
|
||||
description: Nom de la source.
|
||||
release_distribution:
|
||||
type: String
|
||||
shortarg: r
|
||||
description: Distribution de la version.
|
||||
|
||||
response:
|
||||
type: ReturnStatus
|
||||
description: Code de retour sur l’injection des modèles de serveur en base.
|
67
messages/v1/messages/servermodel.describe.yml
Normal file
67
messages/v1/messages/servermodel.describe.yml
Normal file
@ -0,0 +1,67 @@
|
||||
---
|
||||
uri: servermodel.describe
|
||||
|
||||
description: |
|
||||
Retourne les attributs détaillés d'un modèle de serveur.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client servermodel.describe -s 1
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
servermodelid:
|
||||
type: Number
|
||||
shortarg: s
|
||||
description: Identifiant du modèle de serveur à récupérer.
|
||||
ref: Servermodel.ServermodelId
|
||||
inheritance:
|
||||
type: Boolean
|
||||
shortarg: i
|
||||
description: Inclure les données héritées des modèles de serveur parents.
|
||||
default: true
|
||||
resolvdepends:
|
||||
type: Boolean
|
||||
shortarg: r
|
||||
description: Résoudre les dépendances de services.
|
||||
default: true
|
||||
schema:
|
||||
type: Boolean
|
||||
shortarg: c
|
||||
description: Inclure le schema de configuration (réaggrège les données provenant du datasource).
|
||||
default: false
|
||||
probes:
|
||||
type: Boolean
|
||||
shortarg: p
|
||||
description: Inclure les informations sur les sondes de la configuration.
|
||||
default: false
|
||||
creolefuncs:
|
||||
type: Boolean
|
||||
shortarg: o
|
||||
description: Inclure les fonctions Creole.
|
||||
default: false
|
||||
conffiles:
|
||||
type: Boolean
|
||||
shortarg: f
|
||||
description: Inclure les fichier creole au format tar encodé en base64
|
||||
default: false
|
||||
|
||||
response:
|
||||
type: Servermodel
|
||||
description: Description du modèle de serveur.
|
||||
|
||||
errors:
|
||||
- uri: servermodel.describe.error.database_not_available
|
||||
- uri: servermodel.describe.error.invalid_servermodel_id
|
||||
- uri: servermodel.describe.error.unknown_servermodel_id
|
||||
|
||||
related:
|
||||
- servermodel.list
|
||||
- servermodel.create
|
||||
- servermodel.update
|
||||
- servermodel.delete
|
||||
- servermodel.event
|
@ -1,17 +0,0 @@
|
||||
---
|
||||
uri: servermodel.get_by_id
|
||||
|
||||
description: Retourne les attributs détaillés d'un modèle de serveur suivant son identifiant.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
servermodel_id:
|
||||
type: Number
|
||||
shortarg: s
|
||||
description: Identifiant du modèle de serveur à récupérer.
|
||||
ref: Servermodel.ServermodelId
|
||||
|
||||
response:
|
||||
type: Servermodel
|
||||
description: Description du modèle de serveur.
|
@ -4,10 +4,17 @@ uri: servermodel.list
|
||||
description: |
|
||||
Retourne la liste des modèles de serveur disponibles.
|
||||
|
||||
sampleuse: |
|
||||
zephir-client servermodel.list
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
sourceid:
|
||||
type: Number
|
||||
shortarg: s
|
||||
description: |
|
||||
@ -17,3 +24,13 @@ parameters:
|
||||
response:
|
||||
type: '[]Servermodel'
|
||||
description: Liste des modèles de serveur disponibles.
|
||||
|
||||
errors:
|
||||
- uri: servermodel.list.error.database_not_available
|
||||
|
||||
related:
|
||||
- servermodel.describe
|
||||
- servermodel.create
|
||||
- servermodel.update
|
||||
- servermodel.delete
|
||||
- servermodel.event
|
||||
|
@ -5,6 +5,10 @@ description: Des modèles de serveur ont été modifiés.
|
||||
|
||||
pattern: event
|
||||
|
||||
public: false
|
||||
|
||||
domain: servermodel-domain
|
||||
|
||||
parameters:
|
||||
type: 'Servermodel'
|
||||
description: Informations sur les modèles de serveur modifiés.
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
response:
|
||||
type: '[]Session'
|
||||
description: |
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
id:
|
||||
type: Number
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
type: String
|
||||
|
@ -5,6 +5,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
response:
|
||||
type: '[]Session'
|
||||
description: |
|
||||
|
@ -5,6 +5,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
id:
|
||||
type: Number
|
||||
|
@ -5,6 +5,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -6,6 +6,10 @@ description: |
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: session-domain
|
||||
|
||||
parameters:
|
||||
session_id:
|
||||
ref: Config.SessionId
|
||||
|
@ -1,23 +0,0 @@
|
||||
---
|
||||
uri: source.create
|
||||
|
||||
description: |
|
||||
Créer une source.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: |
|
||||
Nom de la source.
|
||||
source_url:
|
||||
type: String
|
||||
shortarg: u
|
||||
description: |
|
||||
URL de téléchargement de la source.
|
||||
|
||||
response:
|
||||
type: 'Source'
|
||||
description: Information sur la source.
|
@ -1,20 +0,0 @@
|
||||
uri: source.dataset.update
|
||||
|
||||
description: |
|
||||
Initialise la table pour les versions.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
shortarg: s
|
||||
description: ID de la source.
|
||||
release_name:
|
||||
type: String
|
||||
shortarg: r
|
||||
description: Nom de la version.
|
||||
|
||||
response:
|
||||
type: Release
|
||||
description: Informations sur la version injectée en base.
|
@ -1,18 +0,0 @@
|
||||
---
|
||||
uri: source.describe
|
||||
|
||||
description: |
|
||||
Retourne une source.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: |
|
||||
Nom de la source.
|
||||
|
||||
response:
|
||||
type: 'Source'
|
||||
description: Information sur la source.
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
uri: source.list
|
||||
|
||||
description: |
|
||||
Retourne la liste des sources.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
type: '[]Source'
|
||||
description: Liste des sources disponibles.
|
@ -1,27 +0,0 @@
|
||||
---
|
||||
uri: source.release.create
|
||||
|
||||
description: |
|
||||
Créer une version.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
shortarg: i
|
||||
description: ID de la source.
|
||||
release_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: |
|
||||
Nom de la version.
|
||||
release_distribution:
|
||||
type: String
|
||||
shortarg: d
|
||||
description: |
|
||||
Distribution de la version.
|
||||
|
||||
response:
|
||||
type: 'Release'
|
||||
description: Information sur la version.
|
@ -1,22 +0,0 @@
|
||||
---
|
||||
uri: source.release.get_by_distribution
|
||||
|
||||
description: |
|
||||
Retourne version suivant le nom de la distribution.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
source_id:
|
||||
type: Number
|
||||
shortarg: s
|
||||
description: ID de la source.
|
||||
release_distribution:
|
||||
type: String
|
||||
shortarg: r
|
||||
description: Distribution de la version.
|
||||
|
||||
response:
|
||||
type: 'Release'
|
||||
description: La version disponibles.
|
||||
|
@ -1,17 +0,0 @@
|
||||
---
|
||||
uri: source.release.get_by_id
|
||||
|
||||
description: |
|
||||
Retourne version suivant l'identifiant.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
release_id:
|
||||
type: Number
|
||||
shortarg: r
|
||||
description: ID de la version.
|
||||
|
||||
response:
|
||||
type: 'Release'
|
||||
description: La version disponibles.
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
uri: source.release.list
|
||||
|
||||
description: |
|
||||
Retourne la liste des versions.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
type: '[]Release'
|
||||
description: Liste des versions disponibles.
|
@ -4,15 +4,21 @@ uri: template.generate
|
||||
description: |
|
||||
Génère et récupère les templates générés.
|
||||
|
||||
sampleuse: ~
|
||||
|
||||
pattern: rpc
|
||||
|
||||
public: true
|
||||
|
||||
domain: template-domain
|
||||
|
||||
parameters:
|
||||
server_name:
|
||||
type: String
|
||||
ref: Server.ServerName
|
||||
server_id:
|
||||
type: Number
|
||||
ref: Server.ServerId
|
||||
shortarg: s
|
||||
description: |
|
||||
Nom du serveur.
|
||||
Identifiant du serveur.
|
||||
|
||||
response:
|
||||
type: Template
|
||||
|
@ -1,22 +0,0 @@
|
||||
---
|
||||
uri: uri.role.join
|
||||
|
||||
description: Crée un rôle utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
role_name:
|
||||
type: String
|
||||
shortarg: r
|
||||
description: Nom du rôle.
|
||||
ref: User.RoleName
|
||||
uri_name:
|
||||
type: String
|
||||
shortarg: u
|
||||
description: Nom du message.
|
||||
|
||||
response:
|
||||
type: URIRole
|
||||
description: Association de rôle créé.
|
||||
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
uri: uri.role.list
|
||||
|
||||
description: Liste des associations d'URI et de rôle.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
type: '[]URIRole'
|
||||
description: Liste des associations.
|
||||
|
@ -1,25 +0,0 @@
|
||||
---
|
||||
uri: user.create
|
||||
|
||||
description: Crée un utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur.
|
||||
ref: User.Login
|
||||
user_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: Nom de l'utilisateur.
|
||||
user_surname:
|
||||
type: String
|
||||
shortarg: s
|
||||
description: Nom de famille de l'utilisateur.
|
||||
|
||||
response:
|
||||
type: User
|
||||
description: Description de l'utilisateur créé.
|
@ -1,18 +0,0 @@
|
||||
---
|
||||
uri: user.delete
|
||||
|
||||
description: Supprimer un utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur.
|
||||
ref: User.Login
|
||||
|
||||
response:
|
||||
type: User
|
||||
description: Description de l'utilisateur supprimé.
|
||||
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
uri: user.list
|
||||
|
||||
description: |
|
||||
Liste les utilisateurs disponibles.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
response:
|
||||
type: '[]User'
|
||||
description: Retourne la liste des utilisateurs.
|
@ -1,32 +0,0 @@
|
||||
---
|
||||
uri: user.role.create
|
||||
|
||||
description: Crée un rôle utilisateur.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur.
|
||||
ref: User.UserLogin
|
||||
role_name:
|
||||
type: String
|
||||
shortarg: n
|
||||
description: Nom du rôle.
|
||||
ref: User.RoleName
|
||||
role_attribute:
|
||||
type: String
|
||||
shortarg: a
|
||||
description: Attribut contrôlé.
|
||||
default: null
|
||||
role_attribute_value:
|
||||
type: String
|
||||
shortarg: v
|
||||
description: Valeur de l'attribut contrôlé.
|
||||
default: null
|
||||
|
||||
response:
|
||||
type: Role
|
||||
description: Description du rôle créé.
|
@ -1,19 +0,0 @@
|
||||
---
|
||||
uri: user.role.list
|
||||
|
||||
description: |
|
||||
Liste les rôles disponibles.
|
||||
|
||||
pattern: rpc
|
||||
|
||||
parameters:
|
||||
user_login:
|
||||
type: String
|
||||
shortarg: l
|
||||
description: Login de l'utilisateur associé.
|
||||
ref: User.RoleName
|
||||
default: null
|
||||
|
||||
response:
|
||||
type: '[]Role'
|
||||
description: Retourne la liste des rôles.
|
@ -1,28 +0,0 @@
|
||||
---
|
||||
title: ApplicationService
|
||||
type: object
|
||||
description: Description d'un modèle de serveur.
|
||||
properties:
|
||||
applicationservice_id:
|
||||
type: number
|
||||
description: ID du service applicatif.
|
||||
applicationservice_name:
|
||||
type: string
|
||||
description: Nom du service applicatif.
|
||||
applicationservice_description:
|
||||
type: string
|
||||
description: Description du service applicatif.
|
||||
applicationservice_release_id:
|
||||
type: number
|
||||
ref: Version.ReleaseId
|
||||
description: Version du service applicatif.
|
||||
applicationservice_dependencies:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
description: Liste des services applicatifs déclarés en dépendance de ce service applicatif.
|
||||
|
||||
required:
|
||||
- applicationservice_id
|
||||
- applicationservice_name
|
||||
- applicationservice_release_id
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
title: ReturnStatus
|
||||
type: object
|
||||
description: Résultat d’une commande.
|
||||
properties:
|
||||
retcode:
|
||||
type: number
|
||||
description: Code de retour de la commande.
|
||||
returns:
|
||||
type: string
|
||||
description: Retour de la commande.
|
||||
required:
|
||||
- retcode
|
||||
- returns
|
@ -1,28 +0,0 @@
|
||||
---
|
||||
title: Release
|
||||
type: object
|
||||
description: Description de la version.
|
||||
properties:
|
||||
release_id:
|
||||
type: number
|
||||
description: Identifiant de la version.
|
||||
release_name:
|
||||
type: string
|
||||
description: Le nom de la version.
|
||||
release_distribution:
|
||||
type: string
|
||||
description: Le nom de la distribution de la version.
|
||||
source_url:
|
||||
type: string
|
||||
description: URL de la source.
|
||||
ref: Source.ReleaseId
|
||||
source_name:
|
||||
type: string
|
||||
description: Le nom de la source.
|
||||
required:
|
||||
- release_id
|
||||
- release_name
|
||||
- release_distribution
|
||||
- source_name
|
||||
- source_url
|
||||
|
@ -1,26 +0,0 @@
|
||||
---
|
||||
title: Role
|
||||
type: object
|
||||
description: Description du rôle.
|
||||
properties:
|
||||
role_id:
|
||||
type: number
|
||||
description: Identifiant de l'utilisateur.
|
||||
ref: User.RoleUserId
|
||||
user_login:
|
||||
type: string
|
||||
description: Login du l'utilisateur.
|
||||
ref: User.Login
|
||||
role_name:
|
||||
type: string
|
||||
description: Nom du rôle.
|
||||
role_attribute:
|
||||
type: string
|
||||
description: Nom de l'utilisateur.
|
||||
role_attribute_value:
|
||||
type: string
|
||||
description: Valeur de l'attribut contrôlé.
|
||||
|
||||
required:
|
||||
- role_id
|
||||
- role_name
|
44
messages/v1/types/server.describe.yml
Normal file
44
messages/v1/types/server.describe.yml
Normal file
@ -0,0 +1,44 @@
|
||||
---
|
||||
title: ServerDescribe
|
||||
type: object
|
||||
description: Description du serveur.
|
||||
properties:
|
||||
serverid:
|
||||
type: number
|
||||
description: Identifiant du serveur.
|
||||
ref: Server.ServerId
|
||||
servername:
|
||||
type: string
|
||||
description: Nom du serveur.
|
||||
serverdescription:
|
||||
type: string
|
||||
description: Description du serveur.
|
||||
servermodelid:
|
||||
type: number
|
||||
description: Identifiant du modèle de serveur.
|
||||
ref: Servermodel.ServermodelId
|
||||
zoneid:
|
||||
type: number
|
||||
description: Identifiant de la zone.
|
||||
ref: Zone.ZoneId
|
||||
machineid:
|
||||
type: number
|
||||
description: Identifiant de la machine.
|
||||
ref: Zone.MachineId
|
||||
configuration:
|
||||
type: file
|
||||
description: Valeurs de configuration.
|
||||
serverenvironment:
|
||||
type: object
|
||||
description: Variables d'environnement du serveur.
|
||||
peering:
|
||||
type: object
|
||||
description: Clé d'appairage.
|
||||
lastpeerconnection:
|
||||
type: string
|
||||
description: Timestamp de la dernière connexion avec le serveur.
|
||||
required:
|
||||
- serverid
|
||||
- servername
|
||||
- serverdescription
|
||||
- servermodelid
|
@ -7,18 +7,33 @@ properties:
|
||||
type: number
|
||||
description: Identifiant du serveur.
|
||||
ref: Server.ServerId
|
||||
server_name:
|
||||
servername:
|
||||
type: string
|
||||
description: Nom du serveur.
|
||||
server_description:
|
||||
serverdescription:
|
||||
type: string
|
||||
description: Description du serveur.
|
||||
server_servermodel_id:
|
||||
servermodelid:
|
||||
type: number
|
||||
description: Identifiant du modèle de serveur.
|
||||
ref: Servermodel.ServermodelId
|
||||
zoneid:
|
||||
type: number
|
||||
description: Identifiant de la zone.
|
||||
ref: Zone.ZoneId
|
||||
machineid:
|
||||
type: number
|
||||
description: Identifiant de la machine.
|
||||
ref: Zone.MachineId
|
||||
automation:
|
||||
type: string
|
||||
description: Moteur d'exécution.
|
||||
ref: Server.automation
|
||||
lastpeerconnection:
|
||||
type: string
|
||||
description: Timestamp de la dernière connexion avec le serveur.
|
||||
required:
|
||||
- server_id
|
||||
- server_name
|
||||
- server_description
|
||||
- server_servermodel_id
|
||||
- servername
|
||||
- serverdescription
|
||||
- servermodelid
|
||||
|
@ -3,16 +3,16 @@ title: ServermodelSource
|
||||
type: object
|
||||
description: Description de la source.
|
||||
properties:
|
||||
source_id:
|
||||
sourceid:
|
||||
type: number
|
||||
description: ID de la source.
|
||||
source_name:
|
||||
sourcename:
|
||||
type: string
|
||||
description: Nom de la source.
|
||||
source_url:
|
||||
sourceurl:
|
||||
type: string
|
||||
description: URL de la source.
|
||||
required:
|
||||
- source_id
|
||||
- source_name
|
||||
- source_url
|
||||
- sourceid
|
||||
- sourcename
|
||||
- sourceurl
|
||||
|
@ -3,28 +3,55 @@ title: Servermodel
|
||||
type: object
|
||||
description: Description d'un modèle de serveur.
|
||||
properties:
|
||||
servermodel_id:
|
||||
servermodelid:
|
||||
type: number
|
||||
description: ID du modèle de serveur.
|
||||
ref: Servermodel.ServermodelId
|
||||
servermodel_name:
|
||||
servermodelname:
|
||||
type: string
|
||||
description: Nom du modèle de serveur.
|
||||
servermodel_description:
|
||||
servermodeldescription:
|
||||
type: string
|
||||
description: Description du modèle de serveur.
|
||||
servermodel_parents_id:
|
||||
servermodelparentsid:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
ref: Servermodel.ServermodelId
|
||||
description: ID du modèle de serveur parent.
|
||||
release_id:
|
||||
subreleaseid:
|
||||
type: number
|
||||
ref: Servermodel.SubreleaseId
|
||||
description: Version du modèle de serveur.
|
||||
subreleasename:
|
||||
type: string
|
||||
ref: SubRelease.SubReleaseName
|
||||
description: Nom de la sous-version.
|
||||
sourceid:
|
||||
type: number
|
||||
ref: ServermodelId.SourceId
|
||||
description: ID de la sous-version.
|
||||
services:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
description: Liste des services applicatifs déclarés pour ce modèle de serveur.
|
||||
schema:
|
||||
type: string
|
||||
description: Contenu du schema.
|
||||
probes:
|
||||
type: string
|
||||
description: Informations sur les sondes.
|
||||
creolefuncs:
|
||||
type: string
|
||||
description: Fonctions Creole.
|
||||
conffiles:
|
||||
type: string
|
||||
description: Fichiers creole au format tar encodé base64
|
||||
required:
|
||||
- servermodel_id
|
||||
- servermodel_name
|
||||
- servermodel_description
|
||||
- release_id
|
||||
- servermodelid
|
||||
- servermodelname
|
||||
- servermodeldescription
|
||||
- servermodelsubreleaseid
|
||||
- sourceid
|
||||
- subreleasename
|
||||
|
@ -1,20 +0,0 @@
|
||||
---
|
||||
title: Source
|
||||
type: object
|
||||
description: Description d'un source.
|
||||
properties:
|
||||
source_id:
|
||||
type: number
|
||||
description: ID de la source.
|
||||
ref: Source.SourceId
|
||||
source_name:
|
||||
type: string
|
||||
description: Nom de la source.
|
||||
source_url:
|
||||
type: string
|
||||
description: URL de téléchargement de la source.
|
||||
|
||||
required:
|
||||
- source_id
|
||||
- source_name
|
||||
- source_url
|
@ -1,15 +0,0 @@
|
||||
---
|
||||
title: URIRole
|
||||
type: object
|
||||
description: Description de l'assication du message et du rôle.
|
||||
properties:
|
||||
role_name:
|
||||
type: string
|
||||
description: Nom du rôle
|
||||
ref: User.RoleName
|
||||
uri_name:
|
||||
type: string
|
||||
description: Nom du message
|
||||
required:
|
||||
- role_name
|
||||
- uri_name
|
@ -1,24 +0,0 @@
|
||||
---
|
||||
title: User
|
||||
type: object
|
||||
description: Description de l'utilisateur.
|
||||
properties:
|
||||
user_id:
|
||||
type: number
|
||||
description: Identifiant de l'utilisateur.
|
||||
ref: User.UserId
|
||||
user_login:
|
||||
type: string
|
||||
description: Login de l'utilisateur.
|
||||
user_name:
|
||||
type: string
|
||||
description: Nom de l'utilisateur.
|
||||
user_surname:
|
||||
type: string
|
||||
description: Nom de famille de l'utilisateur.
|
||||
|
||||
required:
|
||||
- user_id
|
||||
- user_login
|
||||
- user_name
|
||||
- user_surname
|
@ -1,20 +0,0 @@
|
||||
---
|
||||
title: UserRole
|
||||
type: object
|
||||
description: Description de l'association du rôle et de l'utilisateur.
|
||||
properties:
|
||||
user_role_id:
|
||||
type: number
|
||||
description: Identifiant de l'association.
|
||||
ref: User.UserRoleId
|
||||
user_login:
|
||||
type: string
|
||||
description: Login de l'utilisateur.
|
||||
role_name:
|
||||
type: string
|
||||
description: Nom du rôle.
|
||||
|
||||
required:
|
||||
- user_role_id
|
||||
- user_login
|
||||
- role_name
|
BIN
schema-tira.jpg
Normal file
BIN
schema-tira.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 86 KiB |
@ -1,97 +0,0 @@
|
||||
import asyncpg
|
||||
import asyncio
|
||||
from risotto.config import get_config
|
||||
|
||||
VERSION_INIT = """
|
||||
-- Création de la table Source
|
||||
CREATE TABLE Source (
|
||||
SourceId SERIAL PRIMARY KEY,
|
||||
SourceName VARCHAR(255) NOT NULL UNIQUE,
|
||||
SourceURL TEXT
|
||||
);
|
||||
|
||||
-- Création de la table Release
|
||||
CREATE TABLE Release (
|
||||
ReleaseId SERIAL PRIMARY KEY,
|
||||
ReleaseName VARCHAR(255) NOT NULL,
|
||||
ReleaseSourceId INTEGER NOT NULL,
|
||||
ReleaseDistribution VARCHAR(20) CONSTRAINT releasedistribution_choice CHECK (ReleaseDistribution IN ('last', 'n-1', 'n-2')),
|
||||
UNIQUE (ReleaseName, ReleaseSourceId),
|
||||
UNIQUE (ReleaseDistribution, ReleaseSourceId),
|
||||
FOREIGN KEY (ReleaseSourceId) REFERENCES Source(SourceId)
|
||||
);
|
||||
|
||||
|
||||
-- Création de la table Servermodel
|
||||
CREATE TABLE Servermodel (
|
||||
ServermodelId SERIAL PRIMARY KEY,
|
||||
ServermodelName VARCHAR(255) NOT NULL,
|
||||
ServermodelDescription VARCHAR(255) NOT NULL,
|
||||
ServermodelParentsId INTEGER [] DEFAULT '{}',
|
||||
ServermodelReleaseId INTEGER NOT NULL,
|
||||
ServermodelApplicationServiceId INTEGER NOT NULL,
|
||||
ServermodelUsers hstore,
|
||||
UNIQUE (ServermodelName, ServermodelReleaseId)
|
||||
);
|
||||
|
||||
-- Création de la table ApplicationService
|
||||
CREATE TABLE ApplicationService (
|
||||
ApplicationServiceId SERIAL PRIMARY KEY,
|
||||
ApplicationServiceName VARCHAR(255) NOT NULL,
|
||||
ApplicationServiceDescription VARCHAR(255) NOT NULL,
|
||||
ApplicationServiceReleaseId INTEGER NOT NULL,
|
||||
ApplicationServiceDependencies JSON,
|
||||
UNIQUE (ApplicationServiceName, ApplicationServiceReleaseId)
|
||||
);
|
||||
|
||||
-- Server table creation
|
||||
CREATE TABLE Server (
|
||||
ServerId SERIAL PRIMARY KEY,
|
||||
ServerName VARCHAR(255) NOT NULL UNIQUE,
|
||||
ServerDescription VARCHAR(255) NOT NULL,
|
||||
ServerServermodelId INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- User, Role and ACL table creation
|
||||
|
||||
CREATE TABLE RisottoUser (
|
||||
UserId SERIAL PRIMARY KEY,
|
||||
UserLogin VARCHAR(100) NOT NULL UNIQUE,
|
||||
UserName VARCHAR(100) NOT NULL,
|
||||
UserSurname VARCHAR(100) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE UserRole (
|
||||
RoleId SERIAL PRIMARY KEY,
|
||||
RoleUserId INTEGER NOT NULL,
|
||||
RoleName VARCHAR(255) NOT NULL,
|
||||
RoleAttribute VARCHAR(255),
|
||||
RoleAttributeValue VARCHAR(255),
|
||||
FOREIGN KEY (RoleUserId) REFERENCES RisottoUser(UserId)
|
||||
);
|
||||
|
||||
CREATE TABLE URI (
|
||||
URIId SERIAL PRIMARY KEY,
|
||||
URIName VARCHAR(255) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE RoleURI (
|
||||
RoleName VARCHAR(255) NOT NULL,
|
||||
URIId INTEGER NOT NULL,
|
||||
FOREIGN KEY (URIId) REFERENCES URI(URIId),
|
||||
PRIMARY KEY (RoleName, URIId)
|
||||
);
|
||||
|
||||
"""
|
||||
|
||||
async def main():
|
||||
db_conf = get_config().get('database')
|
||||
pool = await asyncpg.create_pool(database=db_conf.get('dbname'), user=db_conf.get('user'))
|
||||
async with pool.acquire() as connection:
|
||||
async with connection.transaction():
|
||||
returns = await connection.execute(VERSION_INIT)
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.run_until_complete(main())
|
||||
# asyncio.run(main())
|
@ -1,32 +1,10 @@
|
||||
HTTP_PORT = 8080
|
||||
MESSAGE_ROOT_PATH = 'messages'
|
||||
DEBUG = True
|
||||
ROOT_CACHE_DIR = 'cache'
|
||||
DEBUG = False
|
||||
DATABASE_DIR = 'database'
|
||||
INTERNAL_USER = 'internal'
|
||||
CONFIGURATION_DIR = 'configurations'
|
||||
TEMPLATE_DIR = 'templates'
|
||||
TMP_DIR = 'tmp'
|
||||
ROUGAIL_DTD_PATH = '../rougail/data/creole.dtd'
|
||||
POSTGRESQL_ADDRESS = '192.168.56.106'
|
||||
POSTGRESQL_PORT = 5432
|
||||
|
||||
import os
|
||||
from pathlib import PurePosixPath
|
||||
CURRENT_PATH = PurePosixPath(__file__)
|
||||
|
||||
def get_config():
|
||||
return {'database': {'host': 'localhost',
|
||||
'port': 5432,
|
||||
'dbname': 'risotto',
|
||||
'user': 'risotto',
|
||||
'password': 'risotto',
|
||||
},
|
||||
'http_server': {'port': 8080},
|
||||
'global': {'message_root_path': CURRENT_PATH.parents[2] / 'messages',
|
||||
'debug': DEBUG,
|
||||
'internal_user': 'internal',
|
||||
'check_role': False,
|
||||
'rougail_dtd_path': '../rougail/data/creole.dtd'},
|
||||
'source': {'root_path': '/srv/seed'},
|
||||
'cache': {'root_path': '/var/cache/risotto'}
|
||||
}
|
||||
|
@ -5,10 +5,6 @@ from .context import Context
|
||||
class Controller:
|
||||
"""Common controller used to add a service in Risotto
|
||||
"""
|
||||
def __init__(self,
|
||||
test: bool):
|
||||
pass
|
||||
|
||||
async def call(self,
|
||||
uri: str,
|
||||
risotto_context: Context,
|
||||
|
@ -2,20 +2,26 @@ from tiramisu import Config
|
||||
from traceback import print_exc
|
||||
from copy import copy
|
||||
from typing import Dict, Callable
|
||||
from json import dumps, loads
|
||||
|
||||
from .utils import _
|
||||
from .error import CallError, NotAllowedError
|
||||
from .logger import log
|
||||
from .config import DEBUG
|
||||
from .config import get_config
|
||||
from .context import Context
|
||||
from . import register
|
||||
import asyncpg
|
||||
|
||||
|
||||
class CallDispatcher:
|
||||
async def valid_call_returns(self,
|
||||
def valid_public_function(self,
|
||||
risotto_context: Context,
|
||||
kwargs: Dict,
|
||||
public_only: bool):
|
||||
if public_only and not self.messages[risotto_context.version][risotto_context.message]['public']:
|
||||
msg = _(f'the message {risotto_context.message} is private')
|
||||
log.error_msg(risotto_context, kwargs, msg)
|
||||
raise NotAllowedError(msg)
|
||||
|
||||
def valid_call_returns(self,
|
||||
risotto_context: Context,
|
||||
returns: Dict,
|
||||
kwargs: Dict):
|
||||
@ -29,7 +35,6 @@ class CallDispatcher:
|
||||
raise CallError(str(err))
|
||||
else:
|
||||
if not isinstance(returns, dict):
|
||||
log.error_msg(risotto_context, kwargs, returns)
|
||||
err = _(f'function {module_name}.{function_name} has to return a dict')
|
||||
log.error_msg(risotto_context, kwargs, err)
|
||||
raise CallError(str(err))
|
||||
@ -38,12 +43,11 @@ class CallDispatcher:
|
||||
raise Exception('hu?')
|
||||
else:
|
||||
for ret in returns:
|
||||
config = await Config(response,
|
||||
display_name=lambda self, dyn_name: self.impl_getname())
|
||||
await config.property.read_write()
|
||||
config = Config(response, display_name=lambda self, dyn_name: self.impl_getname())
|
||||
config.property.read_write()
|
||||
try:
|
||||
for key, value in ret.items():
|
||||
await config.option(key).value.set(value)
|
||||
config.option(key).value.set(value)
|
||||
except AttributeError:
|
||||
err = _(f'function {module_name}.{function_name} return the unknown parameter "{key}"')
|
||||
log.error_msg(risotto_context, kwargs, err)
|
||||
@ -52,13 +56,13 @@ class CallDispatcher:
|
||||
err = _(f'function {module_name}.{function_name} return the parameter "{key}" with an unvalid value "{value}"')
|
||||
log.error_msg(risotto_context, kwargs, err)
|
||||
raise CallError(str(err))
|
||||
await config.property.read_only()
|
||||
mandatories = await config.value.mandatory()
|
||||
config.property.read_only()
|
||||
mandatories = list(config.value.mandatory())
|
||||
if mandatories:
|
||||
mand = [mand.split('.')[-1] for mand in mandatories]
|
||||
raise ValueError(_(f'missing parameters in response: {mand} in message "{risotto_context.message}"'))
|
||||
try:
|
||||
await config.value.dict()
|
||||
config.value.dict()
|
||||
except Exception as err:
|
||||
err = _(f'function {module_name}.{function_name} return an invalid response {err}')
|
||||
log.error_msg(risotto_context, kwargs, err)
|
||||
@ -68,7 +72,7 @@ class CallDispatcher:
|
||||
version: str,
|
||||
message: str,
|
||||
old_risotto_context: Context,
|
||||
check_role: bool=False,
|
||||
public_only: bool=False,
|
||||
**kwargs):
|
||||
""" execute the function associate with specified uri
|
||||
arguments are validate before
|
||||
@ -77,44 +81,31 @@ class CallDispatcher:
|
||||
version,
|
||||
message,
|
||||
'rpc')
|
||||
self.valid_public_function(risotto_context,
|
||||
kwargs,
|
||||
public_only)
|
||||
self.check_message_type(risotto_context,
|
||||
kwargs)
|
||||
try:
|
||||
kw = await self.load_kwargs_to_config(risotto_context,
|
||||
f'{version}.{message}',
|
||||
kwargs,
|
||||
check_role)
|
||||
function_obj = self.messages[version][message]
|
||||
risotto_context.function = function_obj['function']
|
||||
if function_obj['risotto_context']:
|
||||
tiramisu_config = self.load_kwargs_to_config(risotto_context,
|
||||
kwargs)
|
||||
obj = self.messages[version][message]
|
||||
kw = tiramisu_config.option(message).value.dict()
|
||||
risotto_context.function = obj['function']
|
||||
if obj['risotto_context']:
|
||||
kw['risotto_context'] = risotto_context
|
||||
# do not start a new database connection
|
||||
if function_obj['database'] and hasattr(old_risotto_context, 'connection'):
|
||||
risotto_context.connection = old_risotto_context.connection
|
||||
if function_obj['database'] and not hasattr(risotto_context, 'connection'):
|
||||
async with self.pool.acquire() as connection:
|
||||
await connection.set_type_codec(
|
||||
'json',
|
||||
encoder=dumps,
|
||||
decoder=loads,
|
||||
schema='pg_catalog'
|
||||
)
|
||||
risotto_context.connection = connection
|
||||
async with connection.transaction():
|
||||
returns = await risotto_context.function(self.injected_self[function_obj['module']], **kw)
|
||||
else:
|
||||
returns = await risotto_context.function(self.injected_self[function_obj['module']], **kw)
|
||||
returns = await risotto_context.function(self.injected_self[obj['module']], **kw)
|
||||
except CallError as err:
|
||||
raise err
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
if DEBUG:
|
||||
print_exc()
|
||||
log.error_msg(risotto_context,
|
||||
kwargs,
|
||||
err)
|
||||
raise CallError(str(err))
|
||||
# valid returns
|
||||
await self.valid_call_returns(risotto_context,
|
||||
self.valid_call_returns(risotto_context,
|
||||
returns,
|
||||
kwargs)
|
||||
# log the success
|
||||
@ -122,8 +113,8 @@ class CallDispatcher:
|
||||
kwargs,
|
||||
_(f'returns {returns}'))
|
||||
# notification
|
||||
if function_obj.get('notification'):
|
||||
notif_version, notif_message = function_obj['notification'].split('.', 1)
|
||||
if obj.get('notification'):
|
||||
notif_version, notif_message = obj['notification'].split('.', 1)
|
||||
if not isinstance(returns, list):
|
||||
send_returns = [returns]
|
||||
else:
|
||||
@ -137,12 +128,7 @@ class CallDispatcher:
|
||||
|
||||
|
||||
class PublishDispatcher:
|
||||
async def publish(self,
|
||||
version: str,
|
||||
message: str,
|
||||
old_risotto_context: Context,
|
||||
check_role: bool=False,
|
||||
**kwargs) -> None:
|
||||
async def publish(self, version, message, old_risotto_context, public_only=False, **kwargs):
|
||||
risotto_context = self.build_new_context(old_risotto_context,
|
||||
version,
|
||||
message,
|
||||
@ -150,8 +136,9 @@ class PublishDispatcher:
|
||||
self.check_message_type(risotto_context,
|
||||
kwargs)
|
||||
try:
|
||||
config_arguments = await self.load_kwargs_to_config(risotto_context,
|
||||
config = self.load_kwargs_to_config(risotto_context,
|
||||
kwargs)
|
||||
config_arguments = config.option(message).value.dict()
|
||||
except CallError as err:
|
||||
return
|
||||
except Exception as err:
|
||||
@ -176,20 +163,6 @@ class PublishDispatcher:
|
||||
if function_obj['risotto_context']:
|
||||
kw['risotto_context'] = risotto_context
|
||||
# send event
|
||||
if function_obj['database'] and hasattr(old_risotto_context, 'connection'):
|
||||
risotto_context.connection = old_risotto_context.connection
|
||||
if function_obj['database'] and not hasattr(risotto_context, 'connection'):
|
||||
async with self.pool.acquire() as connection:
|
||||
await connection.set_type_codec(
|
||||
'json',
|
||||
encoder=dumps,
|
||||
decoder=loads,
|
||||
schema='pg_catalog'
|
||||
)
|
||||
risotto_context.connection = connection
|
||||
async with connection.transaction():
|
||||
returns = await function(self.injected_self[function_obj['module']], **kw)
|
||||
else:
|
||||
returns = await function(self.injected_self[function_obj['module']], **kw)
|
||||
except Exception as err:
|
||||
if DEBUG:
|
||||
@ -237,91 +210,38 @@ class Dispatcher(register.RegisterDispatcher, CallDispatcher, PublishDispatcher)
|
||||
log.error_msg(risotto_context, kwargs, msg)
|
||||
raise CallError(msg)
|
||||
|
||||
async def load_kwargs_to_config(self,
|
||||
def load_kwargs_to_config(self,
|
||||
risotto_context: Context,
|
||||
uri: str,
|
||||
kwargs: Dict,
|
||||
check_role: bool):
|
||||
kwargs: Dict):
|
||||
""" create a new Config et set values to it
|
||||
"""
|
||||
# create a new config
|
||||
config = await Config(self.option)
|
||||
await config.property.read_write()
|
||||
config = Config(self.option)
|
||||
config.property.read_write()
|
||||
# set message's option
|
||||
await config.option('message').value.set(risotto_context.message)
|
||||
config.option('message').value.set(risotto_context.message)
|
||||
# store values
|
||||
subconfig = config.option(risotto_context.message)
|
||||
for key, value in kwargs.items():
|
||||
try:
|
||||
await subconfig.option(key).value.set(value)
|
||||
subconfig.option(key).value.set(value)
|
||||
except AttributeError:
|
||||
if DEBUG:
|
||||
print_exc()
|
||||
raise ValueError(_(f'unknown parameter in "{uri}": "{key}"'))
|
||||
raise AttributeError(_(f'unknown parameter "{key}"'))
|
||||
# check mandatories options
|
||||
if check_role and get_config().get('global').get('check_role'):
|
||||
await self.check_role(subconfig,
|
||||
risotto_context.username,
|
||||
uri)
|
||||
await config.property.read_only()
|
||||
mandatories = await config.value.mandatory()
|
||||
config.property.read_only()
|
||||
mandatories = list(config.value.mandatory())
|
||||
if mandatories:
|
||||
mand = [mand.split('.')[-1] for mand in mandatories]
|
||||
raise ValueError(_(f'missing parameters in "{uri}": {mand}'))
|
||||
# return complete an validated kwargs
|
||||
return await subconfig.value.dict()
|
||||
raise ValueError(_(f'missing parameters: {mand}'))
|
||||
# return the config
|
||||
return config
|
||||
|
||||
def get_service(self,
|
||||
name: str):
|
||||
return self.injected_self[name]
|
||||
|
||||
async def check_role(self,
|
||||
config: Config,
|
||||
user_login: str,
|
||||
uri: str) -> None:
|
||||
async with self.pool.acquire() as connection:
|
||||
async with connection.transaction():
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT UserId
|
||||
FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
'''
|
||||
user_id = await connection.fetchval(sql,
|
||||
user_login)
|
||||
if user_id is None:
|
||||
raise NotAllowedError(_(f"You ({user_login}) don't have any account in this application"))
|
||||
|
||||
# Get all references for this message
|
||||
refs = {}
|
||||
for option in await config.list('all'):
|
||||
ref = await option.information.get('ref')
|
||||
if ref:
|
||||
refs[ref] = str(await option.value.get())
|
||||
|
||||
# Check role
|
||||
select_role_uri = '''
|
||||
SELECT RoleName
|
||||
FROM URI, RoleURI
|
||||
WHERE URI.URIName = $1 AND RoleURI.URIId = URI.URIId
|
||||
'''
|
||||
select_role_user = '''
|
||||
SELECT RoleAttribute, RoleAttributeValue
|
||||
FROM UserRole
|
||||
WHERE RoleUserId = $1 AND RoleName = $2
|
||||
'''
|
||||
for uri_role in await connection.fetch(select_role_uri,
|
||||
uri):
|
||||
for user_role in await connection.fetch(select_role_user,
|
||||
user_id,
|
||||
uri_role['rolename']):
|
||||
if not user_role['roleattribute']:
|
||||
return
|
||||
if user_role['roleattribute'] in refs and \
|
||||
user_role['roleattributevalue'] == refs[user_role['roleattribute']]:
|
||||
return
|
||||
raise NotAllowedError(_(f'You ({user_login}) don\'t have any authorisation to access to "{uri}"'))
|
||||
|
||||
|
||||
dispatcher = Dispatcher()
|
||||
register.dispatcher = dispatcher
|
||||
|
@ -8,7 +8,3 @@ class CallError(Exception):
|
||||
|
||||
class NotAllowedError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ExecutionError(Exception):
|
||||
pass
|
||||
|
@ -61,24 +61,19 @@ class extra_route_handler:
|
||||
|
||||
|
||||
async def handle(request):
|
||||
version, message = request.match_info.get_info()['path'].rsplit('/', 2)[-2:]
|
||||
version, uri = request.match_info.get_info()['path'].rsplit('/', 2)[-2:]
|
||||
risotto_context = create_context(request)
|
||||
kwargs = await request.json()
|
||||
try:
|
||||
pattern = dispatcher.messages[version][message]['pattern']
|
||||
if pattern == 'rpc':
|
||||
method = dispatcher.call
|
||||
else:
|
||||
method = dispatcher.publish
|
||||
text = await method(version,
|
||||
message,
|
||||
text = await dispatcher.call(version,
|
||||
uri,
|
||||
risotto_context,
|
||||
check_role=True,
|
||||
public_only=True,
|
||||
**kwargs)
|
||||
except NotAllowedError as err:
|
||||
raise HTTPNotFound(reason=str(err))
|
||||
except CallError as err:
|
||||
raise HTTPBadRequest(reason=str(err).replace('\n', ' '))
|
||||
raise HTTPBadRequest(reason=str(err))
|
||||
except Exception as err:
|
||||
if DEBUG:
|
||||
print_exc()
|
||||
@ -89,9 +84,10 @@ async def handle(request):
|
||||
async def api(request, risotto_context):
|
||||
global tiramisu
|
||||
if not tiramisu:
|
||||
config = await Config(get_messages(load_shortarg=True)[1])
|
||||
await config.property.read_write()
|
||||
tiramisu = await config.option.dict(remotable='none')
|
||||
config = Config(get_messages(load_shortarg=True,
|
||||
only_public=True)[1])
|
||||
config.property.read_write()
|
||||
tiramisu = config.option.dict(remotable='none')
|
||||
return tiramisu
|
||||
|
||||
|
||||
@ -106,14 +102,16 @@ async def get_app(loop):
|
||||
load_services()
|
||||
app = Application(loop=loop)
|
||||
routes = []
|
||||
await dispatcher.load()
|
||||
for version, messages in dispatcher.messages.items():
|
||||
print()
|
||||
print(_('======== Registered messages ========'))
|
||||
for message in messages:
|
||||
web_message = f'/api/{version}/{message}'
|
||||
if dispatcher.messages[version][message]['public']:
|
||||
print(f' - {web_message}')
|
||||
else:
|
||||
pattern = dispatcher.messages[version][message]['pattern']
|
||||
print(f' - {web_message} ({pattern})')
|
||||
print(f' - {web_message} (private {pattern})')
|
||||
routes.append(post(web_message, handle))
|
||||
print()
|
||||
print(_('======== Registered extra routes ========'))
|
||||
|
@ -53,10 +53,5 @@ class Logger:
|
||||
if DEBUG:
|
||||
print(tmsg)
|
||||
|
||||
def info(self,
|
||||
msg):
|
||||
if DEBUG:
|
||||
print(msg)
|
||||
|
||||
|
||||
log = Logger()
|
||||
|
@ -3,16 +3,15 @@ from os.path import join, basename, dirname
|
||||
from glob import glob
|
||||
|
||||
from tiramisu import StrOption, IntOption, BoolOption, ChoiceOption, OptionDescription, SymLinkOption, \
|
||||
Calculation, Params, ParamOption, ParamValue, calc_value, calc_value_property_help, \
|
||||
Config, Calculation, Params, ParamOption, ParamValue, calc_value, calc_value_property_help, \
|
||||
groups, Option
|
||||
|
||||
from yaml import load, SafeLoader
|
||||
from os import listdir
|
||||
from os.path import isfile
|
||||
from ..config import get_config
|
||||
from ..config import MESSAGE_ROOT_PATH
|
||||
from ..utils import _
|
||||
|
||||
MESSAGE_ROOT_PATH = get_config().get('global').get('message_root_path')
|
||||
|
||||
groups.addgroup('message')
|
||||
|
||||
@ -43,25 +42,33 @@ class MessageDefinition:
|
||||
__slots__ = ('version',
|
||||
'uri',
|
||||
'description',
|
||||
'sampleuse',
|
||||
'domain',
|
||||
'parameters',
|
||||
'public',
|
||||
'errors',
|
||||
'pattern',
|
||||
'related',
|
||||
'response')
|
||||
|
||||
def __init__(self, raw_def, message):
|
||||
def __init__(self, raw_def):
|
||||
# default value for non mandatory key
|
||||
self.version = u''
|
||||
self.parameters = OrderedDict()
|
||||
self.public = False
|
||||
self.errors = []
|
||||
self.related = []
|
||||
self.response = None
|
||||
self.sampleuse = None
|
||||
|
||||
# loads yaml information into object
|
||||
for key, value in raw_def.items():
|
||||
if isinstance(value, str):
|
||||
value = value.strip()
|
||||
if key == 'pattern':
|
||||
if key == 'public':
|
||||
if not isinstance(value, bool):
|
||||
raise ValueError(_("{} must be a boolean, not {}").format(key, value))
|
||||
elif key == 'pattern':
|
||||
if value not in ['rpc', 'event', 'error']:
|
||||
raise Exception(_('unknown pattern {}').format(value))
|
||||
elif key == 'parameters':
|
||||
@ -81,8 +88,9 @@ class MessageDefinition:
|
||||
getattr(self, key)
|
||||
except AttributeError:
|
||||
raise Exception(_('mandatory key not set {} message').format(key))
|
||||
if self.uri != message:
|
||||
raise Exception(_(f'yaml file name "{message}.yml" does not match uri "{self.uri}"'))
|
||||
# message with pattern = error must be public
|
||||
if self.public is False and self.pattern == 'error':
|
||||
raise Exception(_('Error message must be public : {}').format(self.uri))
|
||||
|
||||
|
||||
class ParameterDefinition:
|
||||
@ -209,8 +217,8 @@ def _parse_parameters(raw_defs):
|
||||
return parameters
|
||||
|
||||
|
||||
def parse_definition(filecontent: bytes, message: str):
|
||||
return MessageDefinition(load(filecontent, Loader=SafeLoader), message)
|
||||
def parse_definition(filename: str):
|
||||
return MessageDefinition(load(filename, Loader=SafeLoader))
|
||||
|
||||
def is_message_defined(uri):
|
||||
version, message = split_message_uri(uri)
|
||||
@ -223,7 +231,7 @@ def get_message(uri):
|
||||
version, message = split_message_uri(uri)
|
||||
path = get_message_file_path(version, message)
|
||||
with open(path, "r") as message_file:
|
||||
message_content = parse_definition(message_file.read(), message)
|
||||
message_content = parse_definition(message_file.read())
|
||||
message_content.version = version
|
||||
return message_content
|
||||
except Exception as err:
|
||||
@ -432,19 +440,16 @@ def _get_option(name,
|
||||
kwargs['multi'] = True
|
||||
type_ = type_[2:]
|
||||
if type_ == 'Dict':
|
||||
obj = DictOption(**kwargs)
|
||||
return DictOption(**kwargs)
|
||||
elif type_ == 'String':
|
||||
obj = StrOption(**kwargs)
|
||||
return StrOption(**kwargs)
|
||||
elif type_ == 'Any':
|
||||
obj = AnyOption(**kwargs)
|
||||
return AnyOption(**kwargs)
|
||||
elif 'Number' in type_ or type_ == 'ID' or type_ == 'Integer':
|
||||
obj = IntOption(**kwargs)
|
||||
return IntOption(**kwargs)
|
||||
elif type_ == 'Boolean':
|
||||
obj = BoolOption(**kwargs)
|
||||
else:
|
||||
return BoolOption(**kwargs)
|
||||
raise Exception('unsupported type {} in {}'.format(type_, file_path))
|
||||
obj.impl_set_information('ref', arg.ref)
|
||||
return obj
|
||||
|
||||
|
||||
def _parse_args(message_def,
|
||||
@ -458,15 +463,11 @@ def _parse_args(message_def,
|
||||
"""
|
||||
new_options = OrderedDict()
|
||||
for name, arg in message_def.parameters.items():
|
||||
#new_options[name] = arg
|
||||
# if arg.ref:
|
||||
# needs.setdefault(message_def.uri, {}).setdefault(arg.ref, []).append(name)
|
||||
#for name, arg in new_options.items():
|
||||
current_opt = _get_option(name,
|
||||
arg,
|
||||
file_path,
|
||||
select_option,
|
||||
optiondescription)
|
||||
new_options[name] = arg
|
||||
if arg.ref:
|
||||
needs.setdefault(message_def.uri, {}).setdefault(arg.ref, []).append(name)
|
||||
for name, arg in new_options.items():
|
||||
current_opt = _get_option(name, arg, file_path, select_option, optiondescription)
|
||||
options.append(current_opt)
|
||||
if hasattr(arg, 'shortarg') and arg.shortarg and load_shortarg:
|
||||
options.append(SymLinkOption(arg.shortarg, current_opt))
|
||||
@ -477,7 +478,13 @@ def _parse_responses(message_def,
|
||||
"""build option with returns
|
||||
"""
|
||||
if message_def.response.parameters is None:
|
||||
raise Exception('uri "{}" did not returned any valid parameters.'.format(message_def.uri))
|
||||
raise Exception('not implemented yet')
|
||||
#name = 'response'
|
||||
#keys['']['columns'][name] = {'description': message_def.response.description,
|
||||
# 'type': message_def.response.type}
|
||||
#responses = {}
|
||||
#responses['keys'] = keys
|
||||
#return responses
|
||||
|
||||
options = []
|
||||
names = []
|
||||
@ -499,7 +506,7 @@ def _parse_responses(message_def,
|
||||
# FIXME
|
||||
'File': StrOption}.get(type_)
|
||||
if not option:
|
||||
raise Exception(f'unknown param type {obj.type} in responses of message {message_def.uri}')
|
||||
raise Exception(f'unknown param type {obj.type}')
|
||||
if hasattr(obj, 'default'):
|
||||
kwargs['default'] = obj.default
|
||||
else:
|
||||
@ -573,7 +580,7 @@ def _get_root_option(select_option, optiondescriptions):
|
||||
return OptionDescription('root', 'root', options_obj)
|
||||
|
||||
|
||||
def get_messages(load_shortarg=False):
|
||||
def get_messages(load_shortarg=False, only_public=False):
|
||||
"""generate description from yml files
|
||||
"""
|
||||
optiondescriptions = OrderedDict()
|
||||
@ -584,7 +591,8 @@ def get_messages(load_shortarg=False):
|
||||
messages.sort()
|
||||
for message_name in messages:
|
||||
message_def = get_message(message_name)
|
||||
if message_def.pattern not in ['rpc', 'event']:
|
||||
if message_def.pattern not in ['rpc', 'event'] or \
|
||||
(not message_def.public and only_public):
|
||||
continue
|
||||
optiondescriptions_name.append(message_def.uri)
|
||||
optiondescriptions_name.sort()
|
||||
@ -594,9 +602,11 @@ def get_messages(load_shortarg=False):
|
||||
properties=frozenset(['mandatory', 'positional']))
|
||||
for message_name in messages:
|
||||
message_def = get_message(message_name)
|
||||
if message_def.pattern not in ['rpc', 'event']:
|
||||
if message_def.pattern not in ['rpc', 'event'] or \
|
||||
(not message_def.public and only_public):
|
||||
continue
|
||||
optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern}
|
||||
optiondescriptions_info[message_def.uri] = {'pattern': message_def.pattern,
|
||||
'public': message_def.public}
|
||||
if message_def.pattern == 'rpc':
|
||||
optiondescriptions_info[message_def.uri]['response'] = _parse_responses(message_def,
|
||||
message_name)
|
||||
@ -612,4 +622,12 @@ def get_messages(load_shortarg=False):
|
||||
load_shortarg)
|
||||
|
||||
root = _get_root_option(select_option, optiondescriptions)
|
||||
try:
|
||||
config = Config(root)
|
||||
except Exception as err:
|
||||
raise Exception('error when generating root optiondescription: {}'.format(err))
|
||||
|
||||
config.property.read_write()
|
||||
# config.property.add('demoting_error_warning')
|
||||
# return needs, responses, config
|
||||
return optiondescriptions_info, root
|
||||
|
@ -1,18 +1,15 @@
|
||||
from tiramisu import Config
|
||||
from inspect import signature
|
||||
from typing import Callable, Optional
|
||||
import asyncpg
|
||||
|
||||
from .utils import undefined, _
|
||||
from .error import RegistrationError
|
||||
from .message import get_messages
|
||||
from .context import Context
|
||||
from .config import INTERNAL_USER, get_config
|
||||
from .config import INTERNAL_USER
|
||||
|
||||
|
||||
def register(uris: str,
|
||||
notification: str=undefined,
|
||||
database: bool=False):
|
||||
notification: str=undefined):
|
||||
""" Decorator to register function to the dispatcher
|
||||
"""
|
||||
if not isinstance(uris, list):
|
||||
@ -24,7 +21,6 @@ def register(uris: str,
|
||||
dispatcher.set_function(version,
|
||||
message,
|
||||
notification,
|
||||
database,
|
||||
function)
|
||||
return decorator
|
||||
|
||||
@ -33,8 +29,6 @@ class RegisterDispatcher:
|
||||
def __init__(self):
|
||||
# reference to instanciate module (to inject self in method): {"module_name": instance_of_module}
|
||||
self.injected_self = {}
|
||||
# postgresql pool
|
||||
self.pool = None
|
||||
# list of uris with informations: {"v1": {"module_name.xxxxx": yyyyyy}}
|
||||
self.messages = {}
|
||||
# load tiramisu objects
|
||||
@ -51,22 +45,22 @@ class RegisterDispatcher:
|
||||
first_argument_index = 1
|
||||
return [param.name for param in list(signature(function).parameters.values())[first_argument_index:]]
|
||||
|
||||
async def valid_rpc_params(self,
|
||||
def valid_rpc_params(self,
|
||||
version: str,
|
||||
message: str,
|
||||
function: Callable,
|
||||
module_name: str):
|
||||
""" parameters function must have strictly all arguments with the correct name
|
||||
"""
|
||||
async def get_message_args():
|
||||
def get_message_args():
|
||||
# load config
|
||||
config = await Config(self.option)
|
||||
await config.property.read_write()
|
||||
config = Config(self.option)
|
||||
config.property.read_write()
|
||||
# set message to the uri name
|
||||
await config.option('message').value.set(message)
|
||||
config.option('message').value.set(message)
|
||||
# get message argument
|
||||
dico = await config.option(message).value.dict()
|
||||
return set(dico.keys())
|
||||
subconfig = config.option(message)
|
||||
return set(config.option(message).value.dict().keys())
|
||||
|
||||
def get_function_args():
|
||||
function_args = self.get_function_args(function)
|
||||
@ -76,7 +70,7 @@ class RegisterDispatcher:
|
||||
return set(function_args)
|
||||
|
||||
# get message arguments
|
||||
message_args = await get_message_args()
|
||||
message_args = get_message_args()
|
||||
# get function arguments
|
||||
function_args = get_function_args()
|
||||
# compare message arguments with function parameter
|
||||
@ -94,22 +88,22 @@ class RegisterDispatcher:
|
||||
msg = _(' and ').join(msg)
|
||||
raise RegistrationError(_(f'error with {module_name}.{function_name} arguments: {msg}'))
|
||||
|
||||
async def valid_event_params(self,
|
||||
def valid_event_params(self,
|
||||
version: str,
|
||||
message: str,
|
||||
function: Callable,
|
||||
module_name: str):
|
||||
""" parameters function validation for event messages
|
||||
"""
|
||||
async def get_message_args():
|
||||
def get_message_args():
|
||||
# load config
|
||||
config = await Config(self.option)
|
||||
await config.property.read_write()
|
||||
config = Config(self.option)
|
||||
config.property.read_write()
|
||||
# set message to the message name
|
||||
await config.option('message').value.set(message)
|
||||
config.option('message').value.set(message)
|
||||
# get message argument
|
||||
dico = await config.option(message).value.dict()
|
||||
return set(dico.keys())
|
||||
subconfig = config.option(message)
|
||||
return set(config.option(message).value.dict().keys())
|
||||
|
||||
def get_function_args():
|
||||
function_args = self.get_function_args(function)
|
||||
@ -119,7 +113,7 @@ class RegisterDispatcher:
|
||||
return set(function_args)
|
||||
|
||||
# get message arguments
|
||||
message_args = await get_message_args()
|
||||
message_args = get_message_args()
|
||||
# get function arguments
|
||||
function_args = get_function_args()
|
||||
# compare message arguments with function parameter
|
||||
@ -135,7 +129,6 @@ class RegisterDispatcher:
|
||||
version: str,
|
||||
message: str,
|
||||
notification: str,
|
||||
database: bool,
|
||||
function: Callable):
|
||||
""" register a function to an URI
|
||||
URI is a message
|
||||
@ -163,11 +156,18 @@ class RegisterDispatcher:
|
||||
if 'function' in self.messages[version][message]:
|
||||
raise RegistrationError(_(f'uri {version}.{message} already registered'))
|
||||
|
||||
# check notification
|
||||
# valid function's arguments
|
||||
if self.messages[version][message]['pattern'] == 'rpc':
|
||||
if notification is undefined:
|
||||
function_name = function.__name__
|
||||
raise RegistrationError(_(f'notification is mandatory when registered "{message}" with "{module_name}.{function_name}" even if you set None'))
|
||||
valid_params = self.valid_rpc_params
|
||||
else:
|
||||
valid_params = self.valid_event_params
|
||||
valid_params(version,
|
||||
message,
|
||||
function,
|
||||
module_name)
|
||||
|
||||
# register
|
||||
if self.messages[version][message]['pattern'] == 'rpc':
|
||||
@ -180,7 +180,6 @@ class RegisterDispatcher:
|
||||
function,
|
||||
function_args,
|
||||
inject_risotto_context,
|
||||
database,
|
||||
notification)
|
||||
|
||||
def register_rpc(self,
|
||||
@ -190,13 +189,11 @@ class RegisterDispatcher:
|
||||
function: Callable,
|
||||
function_args: list,
|
||||
inject_risotto_context: bool,
|
||||
database: bool,
|
||||
notification: Optional[str]):
|
||||
self.messages[version][message]['module'] = module_name
|
||||
self.messages[version][message]['function'] = function
|
||||
self.messages[version][message]['arguments'] = function_args
|
||||
self.messages[version][message]['risotto_context'] = inject_risotto_context
|
||||
self.messages[version][message]['database'] = database
|
||||
if notification:
|
||||
self.messages[version][message]['notification'] = notification
|
||||
|
||||
@ -207,7 +204,6 @@ class RegisterDispatcher:
|
||||
function: Callable,
|
||||
function_args: list,
|
||||
inject_risotto_context: bool,
|
||||
database: bool,
|
||||
notification: Optional[str]):
|
||||
if 'functions' not in self.messages[version][message]:
|
||||
self.messages[version][message]['functions'] = []
|
||||
@ -215,17 +211,16 @@ class RegisterDispatcher:
|
||||
dico = {'module': module_name,
|
||||
'function': function,
|
||||
'arguments': function_args,
|
||||
'database': database,
|
||||
'risotto_context': inject_risotto_context}
|
||||
if notification and notification is not undefined:
|
||||
dico['notification'] = notification
|
||||
self.messages[version][message]['functions'].append(dico)
|
||||
|
||||
def set_module(self, module_name, module, test):
|
||||
def set_module(self, module_name, module):
|
||||
""" register and instanciate a new module
|
||||
"""
|
||||
try:
|
||||
self.injected_self[module_name] = module.Risotto(test)
|
||||
self.injected_self[module_name] = module.Risotto()
|
||||
except AttributeError as err:
|
||||
raise RegistrationError(_(f'unable to register the module {module_name}, this module must have Risotto class'))
|
||||
|
||||
@ -236,9 +231,6 @@ class RegisterDispatcher:
|
||||
for version, messages in self.messages.items():
|
||||
for message, message_obj in messages.items():
|
||||
if not 'functions' in message_obj and not 'function' in message_obj:
|
||||
if message_obj['pattern'] == 'event':
|
||||
print(f'{message} prêche dans le désert')
|
||||
else:
|
||||
missing_messages.append(message)
|
||||
if missing_messages:
|
||||
raise RegistrationError(_(f'missing uri {missing_messages}'))
|
||||
@ -250,39 +242,3 @@ class RegisterDispatcher:
|
||||
risotto_context.paths.append(f'{module_name}.on_join')
|
||||
risotto_context.type = None
|
||||
await module.on_join(risotto_context)
|
||||
|
||||
async def insert_message(self,
|
||||
connection,
|
||||
uri):
|
||||
sql = """INSERT INTO URI(URIName) VALUES ($1)
|
||||
ON CONFLICT (URIName) DO NOTHING
|
||||
"""
|
||||
await connection.fetchval(sql,
|
||||
uri)
|
||||
|
||||
async def load(self):
|
||||
# valid function's arguments
|
||||
db_conf = get_config().get('database')
|
||||
self.pool = await asyncpg.create_pool(database=db_conf.get('dbname'), user=db_conf.get('user'))
|
||||
async with self.pool.acquire() as connection:
|
||||
async with connection.transaction():
|
||||
for version, messages in self.messages.items():
|
||||
for message, message_infos in messages.items():
|
||||
if message_infos['pattern'] == 'rpc':
|
||||
module_name = message_infos['module']
|
||||
function = message_infos['function']
|
||||
await self.valid_rpc_params(version,
|
||||
message,
|
||||
function,
|
||||
module_name)
|
||||
else:
|
||||
if 'functions' in message_infos:
|
||||
for function_infos in message_infos['functions']:
|
||||
module_name = function_infos['module']
|
||||
function = function_infos['function']
|
||||
await self.valid_event_params(version,
|
||||
message,
|
||||
function,
|
||||
module_name)
|
||||
await self.insert_message(connection,
|
||||
f'{version}.{message}')
|
||||
|
@ -5,8 +5,7 @@ from ..dispatcher import dispatcher
|
||||
|
||||
|
||||
def load_services(modules=None,
|
||||
validate: bool=True,
|
||||
test: bool=False):
|
||||
validate: bool=True):
|
||||
abs_here = dirname(abspath(__file__))
|
||||
here = basename(abs_here)
|
||||
module = basename(dirname(abs_here))
|
||||
@ -15,6 +14,6 @@ def load_services(modules=None,
|
||||
for filename in modules:
|
||||
absfilename = join(abs_here, filename)
|
||||
if isdir(absfilename) and isfile(join(absfilename, '__init__.py')):
|
||||
dispatcher.set_module(filename, import_module(f'.{here}.{filename}', module), test)
|
||||
dispatcher.set_module(filename, import_module(f'.{here}.{filename}', module))
|
||||
if validate:
|
||||
dispatcher.validate()
|
||||
|
@ -1 +0,0 @@
|
||||
from .applicationservice import Risotto
|
@ -1,121 +0,0 @@
|
||||
from os import listdir
|
||||
from os.path import join
|
||||
from traceback import print_exc
|
||||
from yaml import load, SafeLoader
|
||||
from typing import Dict, List
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...config import get_config
|
||||
from ...error import ExecutionError
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
class Risotto(Controller):
|
||||
def __init__(self,
|
||||
test: bool) -> None:
|
||||
self.source_root_path = get_config().get('source').get('root_path')
|
||||
|
||||
async def _applicationservice_create(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_name: str,
|
||||
applicationservice_description: str,
|
||||
applicationservice_dependencies: List[int],
|
||||
release_id: int) -> Dict:
|
||||
applicationservice_update_query = """INSERT INTO ApplicationService(ApplicationServiceName, ApplicationServiceDescription, ApplicationServiceDependencies, ApplicationServiceReleaseId) VALUES ($1,$2,$3,$4)
|
||||
RETURNING ApplicationServiceId
|
||||
"""
|
||||
applicationservice_id = await risotto_context.connection.fetchval(applicationservice_update_query,
|
||||
applicationservice_name,
|
||||
applicationservice_description,
|
||||
applicationservice_dependencies,
|
||||
release_id)
|
||||
return {'applicationservice_name': applicationservice_name,
|
||||
'applicationservice_description': applicationservice_description,
|
||||
'applicationservice_release_id': release_id,
|
||||
'applicationservice_id': applicationservice_id}
|
||||
|
||||
@register('v1.applicationservice.create', None, database=True)
|
||||
async def applicationservice_create(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_name: str,
|
||||
applicationservice_description: str,
|
||||
applicationservice_dependencies: List[int],
|
||||
release_id: int) -> Dict:
|
||||
return await self._applicationservice_create(risotto_context,
|
||||
applicationservice_name,
|
||||
applicationservice_description,
|
||||
applicationservice_dependencies,
|
||||
release_id)
|
||||
|
||||
@register('v1.applicationservice.dataset.updated', None, database=True)
|
||||
async def applicationservice_update(self,
|
||||
risotto_context: Context,
|
||||
source_name: str,
|
||||
release_distribution: str) -> Dict:
|
||||
source = await self.call('v1.source.describe',
|
||||
risotto_context,
|
||||
source_name=source_name)
|
||||
release = await self.call('v1.source.release.get_by_distribution',
|
||||
risotto_context,
|
||||
source_id=source['source_id'],
|
||||
release_distribution=release_distribution)
|
||||
applicationservice_path = join(self.source_root_path,
|
||||
source_name,
|
||||
release['release_name'],
|
||||
'applicationservice')
|
||||
release_id = release['release_id']
|
||||
for service in listdir(applicationservice_path):
|
||||
try:
|
||||
applicationservice_description_path = join(applicationservice_path,
|
||||
service,
|
||||
'applicationservice.yml')
|
||||
with open(applicationservice_description_path, 'r') as applicationservice_yml:
|
||||
applicationservice_description = load(applicationservice_yml,
|
||||
Loader=SafeLoader)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f'Error while reading {applicationservice_description_path}: {err}'))
|
||||
try:
|
||||
await self._applicationservice_create(risotto_context,
|
||||
applicationservice_description['name'],
|
||||
applicationservice_description['description'],
|
||||
[], # FIXME dependencies
|
||||
release_id)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f"Error while injecting application service {applicationservice_description['name']} in database: {err}"))
|
||||
return {'retcode': 0,
|
||||
'returns': _('Application Services successfully loaded')}
|
||||
|
||||
@register('v1.applicationservice.get_by_id', None, database=True)
|
||||
async def applicationservice_get_by_id(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_id: int) -> Dict:
|
||||
applicationservice_query = """
|
||||
SELECT ApplicationServiceId as applicationservice_id, ApplicationServiceName as applicationservice_name, ApplicationServiceDependencies as applicationservice_dependencies, ApplicationServiceReleaseId as applicationservice_release_id
|
||||
FROM applicationservice
|
||||
WHERE applicationserviceid=$1"""
|
||||
applicationservice = await risotto_context.connection.fetchrow(applicationservice_query,
|
||||
applicationservice_id)
|
||||
if applicationservice is None:
|
||||
raise Exception(_(f'unknown service with ID {applicationservice_id}'))
|
||||
return dict(applicationservice)
|
||||
|
||||
@register('v1.applicationservice.describe', None, database=True)
|
||||
async def applicationservice_describe(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_name,
|
||||
release_id):
|
||||
applicationservice_query = """
|
||||
SELECT ApplicationServiceId as applicationservice_id, ApplicationServiceName as applicationservice_name, ApplicationServiceDependencies as applicationservice_dependencies, ApplicationServiceReleaseId as applicationservice_release_id
|
||||
FROM ApplicationService
|
||||
WHERE ApplicationServiceName=$1 AND ApplicationServiceReleaseId=$2"""
|
||||
applicationservice = await risotto_context.connection.fetchrow(applicationservice_query,
|
||||
applicationservice_name,
|
||||
release_id)
|
||||
if applicationservice is None:
|
||||
raise Exception(_(f'unknown service {applicationservice_name} in release ID {release_id}'))
|
||||
return dict(applicationservice)
|
@ -10,7 +10,7 @@ from rougail import load as rougail_load
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...config import DATABASE_DIR, DEBUG, ROUGAIL_DTD_PATH, get_config
|
||||
from ...config import ROOT_CACHE_DIR, DATABASE_DIR, DEBUG, ROUGAIL_DTD_PATH
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
from ...error import CallError, RegistrationError
|
||||
@ -18,19 +18,15 @@ from ...logger import log
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
servermodel = {}
|
||||
server = {}
|
||||
|
||||
def __init__(self,
|
||||
test) -> None:
|
||||
global conf_storage
|
||||
self.cache_root_path = join(get_config().get('cache').get('root_path'), 'servermodel')
|
||||
for dirname in [self.cache_root_path, DATABASE_DIR]:
|
||||
def __init__(self) -> None:
|
||||
for dirname in [ROOT_CACHE_DIR, DATABASE_DIR]:
|
||||
if not isdir(dirname):
|
||||
raise RegistrationError(_(f'unable to find the cache dir "{dirname}"'))
|
||||
if not test:
|
||||
self.save_storage = Storage(engine='sqlite3', dir_database=DATABASE_DIR)
|
||||
self.servermodel = {}
|
||||
self.server = {}
|
||||
super().__init__(test)
|
||||
super().__init__()
|
||||
|
||||
async def on_join(self,
|
||||
risotto_context: Context) -> None:
|
||||
@ -53,92 +49,114 @@ class Risotto(Controller):
|
||||
for servermodel in servermodels:
|
||||
try:
|
||||
await self.load_servermodel(risotto_context,
|
||||
servermodel['servermodel_id'],
|
||||
servermodel['servermodel_name'])
|
||||
servermodel['servermodelid'],
|
||||
servermodel['servermodelname'])
|
||||
except CallError as err:
|
||||
pass
|
||||
|
||||
# do link to this servermodel
|
||||
for servermodel in servermodels:
|
||||
if 'servermodel_parents_id' in servermodel:
|
||||
for servermodelparentid in servermodel['servermodel_parents_id']:
|
||||
await self.servermodel_legacy(risotto_context,
|
||||
servermodel['servermodel_name'],
|
||||
servermodel['servermodel_id'],
|
||||
if 'servermodelparentsid' in servermodel:
|
||||
for servermodelparentid in servermodel['servermodelparentsid']:
|
||||
self.servermodel_legacy(risotto_context,
|
||||
servermodel['servermodelname'],
|
||||
servermodel['servermodelid'],
|
||||
servermodelparentid)
|
||||
|
||||
def get_funcs_filename(self,
|
||||
servermodel_id: int):
|
||||
return join(self.cache_root_path, str(servermodel_id), "funcs.py")
|
||||
servermodelid: int):
|
||||
return join(ROOT_CACHE_DIR, str(servermodelid)+".creolefuncs")
|
||||
|
||||
|
||||
|
||||
async def load_servermodel(self,
|
||||
risotto_context: Context,
|
||||
servermodel_id: int,
|
||||
servermodel_name: str) -> None:
|
||||
servermodelid: int,
|
||||
servermodelname: str) -> None:
|
||||
""" Loads a servermodel
|
||||
"""
|
||||
cache_file = join(self.cache_root_path, str(servermodel_id), "dictionaries.xml")
|
||||
funcs_file = self.get_funcs_filename(servermodel_id)
|
||||
cache_file = join(ROOT_CACHE_DIR, str(servermodelid)+".xml")
|
||||
funcs_file = self.get_funcs_filename(servermodelid)
|
||||
log.info_msg(risotto_context,
|
||||
None,
|
||||
f'Load servermodel {servermodel_name} ({servermodel_id})')
|
||||
f'Load servermodel {servermodelname} ({servermodelid})')
|
||||
|
||||
# use file in cache
|
||||
with open(cache_file) as fileio:
|
||||
# use file in cache if found, otherwise retrieve it in servermodel context
|
||||
if isfile(cache_file):
|
||||
fileio = open(cache_file)
|
||||
else:
|
||||
servermodel = await self.call('v1.servermodel.describe',
|
||||
risotto_context,
|
||||
servermodelid=servermodelid,
|
||||
inheritance=False,
|
||||
resolvdepends=False,
|
||||
schema=True,
|
||||
creolefuncs=True)
|
||||
fileio = BytesIO()
|
||||
fileio.write(servermodel['schema'].encode())
|
||||
fileio.seek(0)
|
||||
|
||||
with open(cache_file, 'w') as cache:
|
||||
cache.write(servermodel['schema'])
|
||||
with open(funcs_file, 'w') as cache:
|
||||
cache.write(servermodel['creolefuncs'])
|
||||
del servermodel
|
||||
|
||||
# loads tiramisu config and store it
|
||||
xmlroot = parse(fileio).getroot()
|
||||
self.servermodel[servermodel_id] = await self.build_metaconfig(servermodel_id,
|
||||
servermodel_name,
|
||||
self.servermodel[servermodelid] = self.build_metaconfig(servermodelid,
|
||||
servermodelname,
|
||||
xmlroot,
|
||||
funcs_file)
|
||||
|
||||
async def build_metaconfig(self,
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
def build_metaconfig(self,
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
xmlroot: str,
|
||||
funcs_file: str) -> MetaConfig:
|
||||
""" Build metaconfig for a servermodel
|
||||
"""
|
||||
# build tiramisu's session ID
|
||||
session_id = f'v_{servermodel_id}'
|
||||
session_id = f'v_{servermodelid}'
|
||||
optiondescription = rougail_load(xmlroot,
|
||||
ROUGAIL_DTD_PATH,
|
||||
funcs_file)
|
||||
|
||||
# build servermodel metaconfig (v_xxx.m_v_xxx)
|
||||
metaconfig = await MetaConfig([],
|
||||
metaconfig = MetaConfig([],
|
||||
optiondescription=optiondescription,
|
||||
persistent=True,
|
||||
session_id=session_id,
|
||||
storage=self.save_storage)
|
||||
mixconfig = await MixConfig(children=[],
|
||||
mixconfig = MixConfig(children=[],
|
||||
optiondescription=optiondescription,
|
||||
persistent=True,
|
||||
session_id='m_' + session_id,
|
||||
storage=self.save_storage)
|
||||
await metaconfig.config.add(mixconfig)
|
||||
metaconfig.config.add(mixconfig)
|
||||
|
||||
# change default rights
|
||||
ro_origin = await metaconfig.property.getdefault('read_only', 'append')
|
||||
ro_origin = metaconfig.property.getdefault('read_only', 'append')
|
||||
ro_append = frozenset(ro_origin - {'force_store_value'})
|
||||
rw_origin = await metaconfig.property.getdefault('read_write', 'append')
|
||||
rw_origin = metaconfig.property.getdefault('read_write', 'append')
|
||||
rw_append = frozenset(rw_origin - {'force_store_value'})
|
||||
await metaconfig.property.setdefault(ro_append, 'read_only', 'append')
|
||||
await metaconfig.property.setdefault(rw_append, 'read_write', 'append')
|
||||
metaconfig.property.setdefault(ro_append, 'read_only', 'append')
|
||||
metaconfig.property.setdefault(rw_append, 'read_write', 'append')
|
||||
|
||||
await metaconfig.property.read_only()
|
||||
await metaconfig.permissive.add('basic')
|
||||
await metaconfig.permissive.add('normal')
|
||||
await metaconfig.permissive.add('expert')
|
||||
metaconfig.property.read_only()
|
||||
metaconfig.permissive.add('basic')
|
||||
metaconfig.permissive.add('normal')
|
||||
metaconfig.permissive.add('expert')
|
||||
|
||||
# set informtion and owner
|
||||
await metaconfig.owner.set('v_{}'.format(servermodel_name))
|
||||
await metaconfig.information.set('servermodel_id', servermodel_id)
|
||||
await metaconfig.information.set('servermodel_name', servermodel_name)
|
||||
metaconfig.owner.set('v_{}'.format(servermodelname))
|
||||
metaconfig.information.set('servermodel_id', servermodelid)
|
||||
metaconfig.information.set('servermodel_name', servermodelname)
|
||||
|
||||
# return configuration
|
||||
return metaconfig
|
||||
|
||||
async def servermodel_legacy(self,
|
||||
def servermodel_legacy(self,
|
||||
risotto_context: Context,
|
||||
servermodel_name: str,
|
||||
servermodel_id: int,
|
||||
@ -155,7 +173,7 @@ class Risotto(Controller):
|
||||
msg)
|
||||
return
|
||||
servermodel_parent = self.servermodel[servermodel_parent_id]
|
||||
servermodel_parent_name = await servermodel_parent.information.get('servermodel_name')
|
||||
servermodel_parent_name = servermodel_parent.information.get('servermodel_name')
|
||||
if DEBUG:
|
||||
msg = _(f'Create legacy of servermodel {servermodel_name} ({servermodel_id}) with parent {servermodel_parent_name} ({servermodel_parent_id})')
|
||||
log.info_msg(risotto_context,
|
||||
@ -163,9 +181,9 @@ class Risotto(Controller):
|
||||
msg)
|
||||
|
||||
# do link
|
||||
mix = await servermodel_parent.config.get('m_v_' + str(servermodel_parent_id))
|
||||
mix = servermodel_parent.config.get('m_v_' + str(servermodel_parent_id))
|
||||
try:
|
||||
await mix.config.add(self.servermodel[servermodel_id])
|
||||
mix.config.add(self.servermodel[servermodel_id])
|
||||
except Exception as err:
|
||||
if DEBUG:
|
||||
log.error_msg(risotto_context,
|
||||
@ -185,34 +203,34 @@ class Risotto(Controller):
|
||||
# loads servers
|
||||
for server in servers:
|
||||
try:
|
||||
await self.load_server(risotto_context,
|
||||
self.load_server(risotto_context,
|
||||
server['server_id'],
|
||||
server['server_name'],
|
||||
server['server_servermodel_id'])
|
||||
server['servername'],
|
||||
server['servermodelid'])
|
||||
except Exception as err:
|
||||
if DEBUG:
|
||||
print_exc()
|
||||
server_name = server['server_name']
|
||||
servername = server['servername']
|
||||
server_id = server['server_id']
|
||||
msg = _(f'unable to load server {server_name} ({server_id}): {err}')
|
||||
msg = _(f'unable to load server {servername} ({server_id}): {err}')
|
||||
log.error_msg(risotto_context,
|
||||
None,
|
||||
msg)
|
||||
|
||||
async def load_server(self,
|
||||
def load_server(self,
|
||||
risotto_context: Context,
|
||||
server_id: int,
|
||||
server_name: str,
|
||||
server_servermodel_id: int) -> None:
|
||||
servername: str,
|
||||
servermodelid: int) -> None:
|
||||
""" Loads a server
|
||||
"""
|
||||
if server_id in self.server:
|
||||
return
|
||||
log.info_msg(risotto_context,
|
||||
None,
|
||||
f'Load server {server_name} ({server_id})')
|
||||
if not server_servermodel_id in self.servermodel:
|
||||
msg = f'unable to find servermodel with id {server_servermodel_id}'
|
||||
f'Load server {servername} ({server_id})')
|
||||
if not servermodelid in self.servermodel:
|
||||
msg = f'unable to find servermodel with id {servermodelid}'
|
||||
log.error_msg(risotto_context,
|
||||
None,
|
||||
msg)
|
||||
@ -222,47 +240,47 @@ class Risotto(Controller):
|
||||
session_id = f's_{server_id}'
|
||||
|
||||
# get the servermodel's metaconfig
|
||||
metaconfig = self.servermodel[server_servermodel_id]
|
||||
metaconfig = self.servermodel[servermodelid]
|
||||
|
||||
# create server configuration and server 'to deploy' configuration and store it
|
||||
self.server[server_id] = {'server': await self.build_config(session_id,
|
||||
self.server[server_id] = {'server': self.build_config(session_id,
|
||||
server_id,
|
||||
server_name,
|
||||
servername,
|
||||
metaconfig),
|
||||
'server_to_deploy': await self.build_config(f'std_{server_id}',
|
||||
'server_to_deploy': self.build_config(f'std_{server_id}',
|
||||
server_id,
|
||||
server_name,
|
||||
servername,
|
||||
metaconfig),
|
||||
'funcs_file': self.get_funcs_filename(server_servermodel_id)}
|
||||
'funcs_file': self.get_funcs_filename(servermodelid)}
|
||||
|
||||
async def build_config(self,
|
||||
def build_config(self,
|
||||
session_id: str,
|
||||
server_id: int,
|
||||
server_name: str,
|
||||
servername: str,
|
||||
metaconfig: MetaConfig) -> None:
|
||||
""" build server's config
|
||||
"""
|
||||
config = await metaconfig.config.new(session_id,
|
||||
config = metaconfig.config.new(session_id,
|
||||
storage=self.save_storage,
|
||||
persistent=True)
|
||||
await config.information.set('server_id', server_id)
|
||||
await config.information.set('server_name', server_name)
|
||||
await config.owner.set(server_name)
|
||||
await config.property.read_only()
|
||||
config.information.set('server_id', server_id)
|
||||
config.information.set('server_name', servername)
|
||||
config.owner.set(servername)
|
||||
config.property.read_only()
|
||||
return config
|
||||
|
||||
@register('v1.server.created')
|
||||
async def server_created(self,
|
||||
risotto_context: Context,
|
||||
server_id: int,
|
||||
server_name: str,
|
||||
server_servermodel_id: int) -> None:
|
||||
servername: str,
|
||||
servermodelid: int) -> None:
|
||||
""" Loads server's configuration when a new server is created
|
||||
"""
|
||||
await self.load_server(risotto_context,
|
||||
self.load_server(risotto_context,
|
||||
server_id,
|
||||
server_name,
|
||||
server_servermodel_id)
|
||||
servername,
|
||||
servermodelid)
|
||||
|
||||
@register('v1.server.deleted')
|
||||
async def server_deleted(self,
|
||||
@ -270,99 +288,99 @@ class Risotto(Controller):
|
||||
# delete config to it's parents
|
||||
for server_type in ['server', 'server_to_deploy']:
|
||||
config = self.server[server_id]['server']
|
||||
for parent in await config.config.parents():
|
||||
await parent.config.pop(await config.config.name())
|
||||
for parent in config.config.parents():
|
||||
parent.config.pop(config.config.name())
|
||||
delete_session(storage=self.save_storage,
|
||||
session_id=await config.config.name())
|
||||
session_id=config.config.name())
|
||||
# delete metaconfig
|
||||
del self.server[server_id]
|
||||
|
||||
@register('v1.servermodel.created')
|
||||
async def servermodel_created(self,
|
||||
risotto_context: Context,
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
servermodel_parents_id: List[int]) -> None:
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodelparentsid: List[int]) -> None:
|
||||
""" when servermodels are created, load it and do link
|
||||
"""
|
||||
await self.load_and_link_servermodel(risotto_context,
|
||||
servermodel_id,
|
||||
servermodel_name,
|
||||
servermodel_parents_id)
|
||||
servermodelid,
|
||||
servermodelname,
|
||||
servermodelparentsid)
|
||||
|
||||
|
||||
async def load_and_link_servermodel(self,
|
||||
risotto_context: Context,
|
||||
servermodel_id: int,
|
||||
servermodel_name: str,
|
||||
servermodel_parents_id: List[int]) -> None:
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodelparentsid: List[int]) -> None:
|
||||
await self.load_servermodel(risotto_context,
|
||||
servermodel_id,
|
||||
servermodel_name)
|
||||
if servermodel_parents_id is not None:
|
||||
for servermodelparentid in servermodel_parents_id:
|
||||
await self.servermodel_legacy(risotto_context,
|
||||
servermodel_name,
|
||||
servermodel_id,
|
||||
servermodelid,
|
||||
servermodelname)
|
||||
if servermodelparentsid is not None:
|
||||
for servermodelparentid in servermodelparentsid:
|
||||
self.servermodel_legacy(risotto_context,
|
||||
servermodelname,
|
||||
servermodelid,
|
||||
servermodelparentid)
|
||||
|
||||
async def servermodel_delete(self,
|
||||
servermodel_id: int) -> List[MetaConfig]:
|
||||
metaconfig = self.servermodel.pop(servermodel_id)
|
||||
mixconfig = await metaconfig.config.list()[0]
|
||||
def servermodel_delete(self,
|
||||
servermodelid: int) -> List[MetaConfig]:
|
||||
metaconfig = self.servermodel.pop(servermodelid)
|
||||
mixconfig = next(metaconfig.config.list())
|
||||
children = []
|
||||
for child in await mixconfig.config.list():
|
||||
for child in mixconfig.config.list():
|
||||
children.append(child)
|
||||
await mixconfig.config.pop(await child.config.name())
|
||||
await metaconfig.config.pop(await mixconfig.config.name())
|
||||
mixconfig.config.pop(child.config.name())
|
||||
metaconfig.config.pop(mixconfig.config.name())
|
||||
delete_session(storage=self.save_storage,
|
||||
session_id=await mixconfig.config.name())
|
||||
session_id=mixconfig.config.name())
|
||||
del mixconfig
|
||||
for parent in await metaconfig.config.parents():
|
||||
await parent.config.pop(await metaconfig.config.name())
|
||||
for parent in metaconfig.config.parents():
|
||||
parent.config.pop(metaconfig.config.name())
|
||||
delete_session(storage=self.save_storage,
|
||||
session_id=await metaconfig.config.name())
|
||||
session_id=metaconfig.config.name())
|
||||
return children
|
||||
#
|
||||
# @register('v1.servermodel.updated')
|
||||
# async def servermodel_updated(self,
|
||||
# risotto_context: Context,
|
||||
# servermodel_id: int,
|
||||
# servermodel_name: str,
|
||||
# servermodel_parents_id: List[int]) -> None:
|
||||
# log.info_msg(risotto_context,
|
||||
# None,
|
||||
# f'Reload servermodel {servermodel_name} ({servermodel_id})')
|
||||
# # unlink cache to force download new aggregated file
|
||||
# cache_file = join(self.cache_root_path, str(servermodel_id)+".xml")
|
||||
# if isfile(cache_file):
|
||||
# unlink(cache_file)
|
||||
#
|
||||
# # store all informations
|
||||
# if servermodel_id in self.servermodel:
|
||||
# old_values = await self.servermodel[servermodel_id].value.exportation()
|
||||
# old_permissives = await self.servermodel[servermodel_id].permissive.exportation()
|
||||
# old_properties = await self.servermodel[servermodel_id].property.exportation()
|
||||
# children = await self.servermodel_delete(servermodel_id)
|
||||
# else:
|
||||
# old_values = None
|
||||
#
|
||||
# # create new one
|
||||
# await self.load_and_link_servermodel(risotto_context,
|
||||
# servermodel_id,
|
||||
# servermodel_name,
|
||||
# servermodel_parents_id)
|
||||
#
|
||||
# # migrates informations
|
||||
# if old_values is not None:
|
||||
# await self.servermodel[servermodel_id].value.importation(old_values)
|
||||
# await self.servermodel[servermodel_id].permissive.importation(old_permissives)
|
||||
# await self.servermodel[servermodel_id].property.importation(old_properties)
|
||||
# for child in children:
|
||||
# await self.servermodel_legacy(risotto_context,
|
||||
# await child.information.get('servermodel_name'),
|
||||
# await child.information.get('servermodel_id'),
|
||||
# servermodel_id)
|
||||
|
||||
@register('v1.servermodel.updated')
|
||||
async def servermodel_updated(self,
|
||||
risotto_context: Context,
|
||||
servermodelid: int,
|
||||
servermodelname: str,
|
||||
servermodelparentsid: List[int]) -> None:
|
||||
log.info_msg(risotto_context,
|
||||
None,
|
||||
f'Reload servermodel {servermodelname} ({servermodelid})')
|
||||
# unlink cache to force download new aggregated file
|
||||
cache_file = join(ROOT_CACHE_DIR, str(servermodelid)+".xml")
|
||||
if isfile(cache_file):
|
||||
unlink(cache_file)
|
||||
|
||||
# store all informations
|
||||
if servermodelid in self.servermodel:
|
||||
old_values = self.servermodel[servermodelid].value.exportation()
|
||||
old_permissives = self.servermodel[servermodelid].permissive.exportation()
|
||||
old_properties = self.servermodel[servermodelid].property.exportation()
|
||||
children = self.servermodel_delete(servermodelid)
|
||||
else:
|
||||
old_values = None
|
||||
|
||||
# create new one
|
||||
await self.load_and_link_servermodel(risotto_context,
|
||||
servermodelid,
|
||||
servermodelname,
|
||||
servermodelparentsid)
|
||||
|
||||
# migrates informations
|
||||
if old_values is not None:
|
||||
self.servermodel[servermodelid].value.importation(old_values)
|
||||
self.servermodel[servermodelid].permissive.importation(old_permissives)
|
||||
self.servermodel[servermodelid].property.importation(old_properties)
|
||||
for child in children:
|
||||
self.servermodel_legacy(risotto_context,
|
||||
child.information.get('servermodel_name'),
|
||||
child.information.get('servermodel_id'),
|
||||
servermodelid)
|
||||
|
||||
@register('v1.config.configuration.server.get', None)
|
||||
async def get_configuration(self,
|
||||
@ -380,9 +398,9 @@ class Risotto(Controller):
|
||||
else:
|
||||
server = self.server[server_id]['server_to_deploy']
|
||||
|
||||
await server.property.read_only()
|
||||
server.property.read_only()
|
||||
try:
|
||||
configuration = await server.value.dict(fullpath=True)
|
||||
configuration = server.value.dict(fullpath=True)
|
||||
except:
|
||||
if deployed:
|
||||
msg = _(f'No configuration available for server {server_id}')
|
||||
@ -405,19 +423,19 @@ class Risotto(Controller):
|
||||
config_std = self.server[server_id]['server_to_deploy']
|
||||
|
||||
# when deploy, calculate force_store_value
|
||||
ro = await config_std.property.getdefault('read_only', 'append')
|
||||
ro = config_std.property.getdefault('read_only', 'append')
|
||||
if 'force_store_value' not in ro:
|
||||
ro = frozenset(list(ro) + ['force_store_value'])
|
||||
await config_std.property.setdefault(ro, 'read_only', 'append')
|
||||
rw = await config_std.property.getdefault('read_write', 'append')
|
||||
config_std.property.setdefault(ro, 'read_only', 'append')
|
||||
rw = config_std.property.getdefault('read_write', 'append')
|
||||
rw = frozenset(list(rw) + ['force_store_value'])
|
||||
await config_std.property.setdefault(rw, 'read_write', 'append')
|
||||
await config_std.property.add('force_store_value')
|
||||
config_std.property.setdefault(rw, 'read_write', 'append')
|
||||
config_std.property.add('force_store_value')
|
||||
|
||||
# copy informations from server 'to deploy' configuration to server configuration
|
||||
await config.value.importation(await config_std.value.exportation())
|
||||
await config.permissive.importation(await config_std.permissive.exportation())
|
||||
await config.property.importation(await config_std.property.exportation())
|
||||
config.value.importation(config_std.value.exportation())
|
||||
config.permissive.importation(config_std.permissive.exportation())
|
||||
config.property.importation(config_std.property.exportation())
|
||||
|
||||
return {'server_id': server_id,
|
||||
'deployed': True}
|
||||
|
@ -1,56 +1,8 @@
|
||||
from typing import Dict
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.server.list', None, database=True)
|
||||
async def server_list(self,
|
||||
risotto_context: Context) -> Dict:
|
||||
sql = '''
|
||||
SELECT ServerId as server_id, ServerName as server_name, ServerDescription as server_description, ServerServermodelId as server_servermodel_id
|
||||
FROM Server
|
||||
'''
|
||||
servers = await risotto_context.connection.fetch(sql)
|
||||
return [dict(r) for r in servers]
|
||||
|
||||
@register('v1.server.create', 'v1.server.created', database=True)
|
||||
async def server_create(self,
|
||||
risotto_context: Context,
|
||||
server_name: str,
|
||||
server_description: str,
|
||||
server_servermodel_id: int) -> Dict:
|
||||
|
||||
await self.call('v1.servermodel.get_by_id',
|
||||
risotto_context,
|
||||
servermodel_id=server_servermodel_id)
|
||||
server_insert = """INSERT INTO Server(ServerName, ServerDescription, ServerServermodelId)
|
||||
VALUES ($1,$2,$3)
|
||||
RETURNING ServerId
|
||||
"""
|
||||
server_id = await risotto_context.connection.fetchval(server_insert,
|
||||
server_name,
|
||||
server_description,
|
||||
server_servermodel_id)
|
||||
return {'server_id': server_id,
|
||||
'server_name': server_name,
|
||||
'server_description': server_description,
|
||||
'server_servermodel_id': server_servermodel_id}
|
||||
|
||||
@register('v1.server.describe', None, database=True)
|
||||
async def server_describe(self,
|
||||
risotto_context: Context,
|
||||
server_name: str) -> Dict:
|
||||
sql = '''
|
||||
SELECT ServerId as server_id, ServerName as server_name, ServerDescription as server_description, ServerServermodelId as server_servermodel_id
|
||||
FROM Server
|
||||
WHERE ServerName = $1
|
||||
'''
|
||||
server = await risotto_context.connection.fetchrow(sql,
|
||||
server_name)
|
||||
if not server:
|
||||
raise Exception(_(f'unable to find server with name {server_name}'))
|
||||
return dict(server)
|
||||
@register('v1.server.list', None)
|
||||
async def server_list(self):
|
||||
return [{'server_id': 1, 'servername': 'one', 'serverdescription': 'the first', 'servermodelid': 1}]
|
||||
|
@ -1,393 +1,65 @@
|
||||
from shutil import rmtree, copyfile
|
||||
from os import listdir, makedirs
|
||||
from os.path import join, isdir, isfile
|
||||
from yaml import load, SafeLoader
|
||||
from traceback import print_exc
|
||||
from typing import Dict, List, Optional
|
||||
from rougail import CreoleObjSpace
|
||||
from rougail.config import dtdfilename
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...utils import _
|
||||
from ...context import Context
|
||||
from ...config import get_config
|
||||
from ...error import ExecutionError
|
||||
from ...logger import log
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
def __init__(self,
|
||||
test: bool) -> None:
|
||||
self.source_root_path = get_config().get('source').get('root_path')
|
||||
self.cache_root_path = join(get_config().get('cache').get('root_path'), 'servermodel')
|
||||
if not isdir(self.cache_root_path):
|
||||
makedirs(join(self.cache_root_path))
|
||||
@register('v1.servermodel.list', None)
|
||||
async def servermodel_list(self, sourceid):
|
||||
return [{'servermodelid': 1,
|
||||
'servermodelname': 'name',
|
||||
'subreleasename': 'name',
|
||||
'sourceid': 1,
|
||||
'servermodeldescription': 'description'}]
|
||||
|
||||
async def on_join(self,
|
||||
risotto_context: Context) -> None:
|
||||
internal_source = await self.call('v1.source.create',
|
||||
risotto_context,
|
||||
source_name='internal',
|
||||
source_url='none')
|
||||
internal_release = await self.call('v1.source.release.create',
|
||||
risotto_context,
|
||||
source_id=internal_source['source_id'],
|
||||
release_name='none',
|
||||
release_distribution='stable')
|
||||
self.internal_release_id = internal_release['release_id']
|
||||
|
||||
def servermodel_gen_funcs(self,
|
||||
servermodel_name: str,
|
||||
servermodel_id: int,
|
||||
dependencies: Dict,
|
||||
release_cache: Dict) -> None:
|
||||
as_names = []
|
||||
dest_file = self.get_servermodel_cache(servermodel_id, 'funcs.py')
|
||||
with open(dest_file, 'wb') as funcs:
|
||||
funcs.write(b'from tiramisu import valid_network_netmask, valid_ip_netmask, valid_broadcast, valid_in_network, valid_not_equal as valid_differ, valid_not_equal, calc_value\n\n')
|
||||
for applicationservice_id, applicationservice_infos in dependencies.items():
|
||||
applicationservice_name, as_release_id = applicationservice_infos
|
||||
path = join(self.source_root_path,
|
||||
release_cache[as_release_id]['source_name'],
|
||||
release_cache[as_release_id]['release_name'],
|
||||
'applicationservice',
|
||||
applicationservice_name,
|
||||
'funcs')
|
||||
if isdir(path):
|
||||
as_names.append(applicationservice_name)
|
||||
for fil in listdir(path):
|
||||
if not fil.endswith('.py'):
|
||||
continue
|
||||
fil_path = join(path, fil)
|
||||
with open(fil_path, 'rb') as fh:
|
||||
funcs.write(f'# {fil_path}\n'.encode())
|
||||
funcs.write(fh.read())
|
||||
funcs.write(b'\n')
|
||||
|
||||
as_names_str = '", "'.join(as_names)
|
||||
log.info(_(f'gen funcs for "{servermodel_name}" with application services "{as_names_str}"'))
|
||||
eolobj = CreoleObjSpace(dtdfilename)
|
||||
|
||||
def servermodel_gen_schema(self,
|
||||
servermodel_name: str,
|
||||
servermodel_id: int,
|
||||
dependencies: Dict,
|
||||
release_cache: Dict) -> None:
|
||||
paths = []
|
||||
extras = []
|
||||
as_names = set()
|
||||
for applicationservice_id, applicationservice_infos in dependencies.items():
|
||||
applicationservice_name, as_release_id = applicationservice_infos
|
||||
# load creole dictionaries
|
||||
path = join(self.source_root_path,
|
||||
release_cache[as_release_id]['source_name'],
|
||||
release_cache[as_release_id]['release_name'],
|
||||
'applicationservice',
|
||||
applicationservice_name,
|
||||
'dictionaries')
|
||||
if isdir(path):
|
||||
as_names.add(applicationservice_name)
|
||||
paths.append(path)
|
||||
|
||||
# load extra dictionaries
|
||||
path = join(self.source_root_path,
|
||||
release_cache[as_release_id]['source_name'],
|
||||
release_cache[as_release_id]['release_name'],
|
||||
'applicationservice',
|
||||
applicationservice_name,
|
||||
'extras')
|
||||
if isdir(path):
|
||||
for namespace in listdir(path):
|
||||
extra_dir = join(path, namespace)
|
||||
if not isdir(extra_dir):
|
||||
continue
|
||||
as_names.add(applicationservice_name)
|
||||
extras.append((namespace, [extra_dir]))
|
||||
eolobj = CreoleObjSpace(dtdfilename)
|
||||
as_names_str = '", "'.join(as_names)
|
||||
log.info(_(f'gen schema for "{servermodel_name}" with application services "{as_names_str}"'))
|
||||
eolobj.create_or_populate_from_xml('creole', paths)
|
||||
for extra in extras:
|
||||
eolobj.create_or_populate_from_xml(extra[0], extra[1])
|
||||
# FIXME extra
|
||||
funcs_file = self.get_servermodel_cache(servermodel_id, 'funcs.py')
|
||||
eolobj.space_visitor(funcs_file)
|
||||
dest_dir = self.get_servermodel_cache(servermodel_id, 'dictionaries.xml')
|
||||
eolobj.save(dest_dir)
|
||||
|
||||
def get_servermodel_cache(self,
|
||||
servermodel_id: int,
|
||||
subdir: Optional[str]=None) -> str:
|
||||
if subdir:
|
||||
return join(self.cache_root_path, str(servermodel_id), subdir)
|
||||
return join(self.cache_root_path, str(servermodel_id))
|
||||
|
||||
def servermodel_copy_templates(self,
|
||||
servermodel_name: str,
|
||||
servermodel_id: int,
|
||||
dependencies: Dict,
|
||||
release_cache: Dict) -> None:
|
||||
as_names = []
|
||||
dest_dir = self.get_servermodel_cache(servermodel_id, 'templates')
|
||||
makedirs(dest_dir)
|
||||
for applicationservice_id, applicationservice_infos in dependencies.items():
|
||||
applicationservice_name, as_release_id = applicationservice_infos
|
||||
path = join(self.source_root_path,
|
||||
release_cache[as_release_id]['source_name'],
|
||||
release_cache[as_release_id]['release_name'],
|
||||
'applicationservice',
|
||||
applicationservice_name,
|
||||
'templates')
|
||||
if isdir(path):
|
||||
for template in listdir(path):
|
||||
template_path = join(dest_dir, template)
|
||||
if isfile(template_path):
|
||||
as_names_str = '", "'.join(as_names)
|
||||
raise Exception(_(f'duplicate "{template}" when copying template from "{applicationservice_name}" to "{dest_dir}" for servermodel "{servermodel_name}" (previous application services was "{as_names_str}"'))
|
||||
copyfile(join(path, template), template_path)
|
||||
as_names.append(applicationservice_name)
|
||||
as_names_str = '", "'.join(as_names)
|
||||
log.info(_(f'copy templates for "{servermodel_name}" with application services "{as_names_str}"'))
|
||||
|
||||
async def _servermodel_create(self,
|
||||
risotto_context: Context,
|
||||
servermodel_name: str,
|
||||
servermodel_description: str,
|
||||
servermodel_parents_id: List[int],
|
||||
dependencies: List[int],
|
||||
release_id: int,
|
||||
release_cache: Dict=None) -> Dict:
|
||||
servermodel_update = """INSERT INTO Servermodel(ServermodelName, ServermodelDescription, ServermodelParentsId, ServermodelReleaseId, ServermodelApplicationServiceId)
|
||||
VALUES ($1,$2,$3,$4,$5)
|
||||
RETURNING ServermodelId
|
||||
"""
|
||||
as_name = f"local_{servermodel_name}"
|
||||
as_description = f'local application service for {servermodel_name}'
|
||||
applicationservice = await self.call('v1.applicationservice.create',
|
||||
risotto_context,
|
||||
applicationservice_name=as_name,
|
||||
applicationservice_description=as_description,
|
||||
applicationservice_dependencies=dependencies,
|
||||
release_id=self.internal_release_id)
|
||||
applicationservice_id = applicationservice['applicationservice_id']
|
||||
servermodel_id = await risotto_context.connection.fetchval(servermodel_update,
|
||||
servermodel_name,
|
||||
servermodel_description,
|
||||
servermodel_parents_id,
|
||||
release_id,
|
||||
applicationservice_id)
|
||||
dest_dir = self.get_servermodel_cache(servermodel_id)
|
||||
if isdir(dest_dir):
|
||||
rmtree(dest_dir)
|
||||
makedirs(dest_dir)
|
||||
# get all dependencies for this application service
|
||||
dependencies = await self.get_applicationservices(risotto_context,
|
||||
applicationservice_id)
|
||||
# build cache to have all release informations
|
||||
if release_cache is None:
|
||||
release_cache = {}
|
||||
for applicationservice_id, applicationservice_infos in dependencies.items():
|
||||
applicationservice_name, as_release_id = applicationservice_infos
|
||||
if as_release_id not in release_cache:
|
||||
release_cache[as_release_id] = await self.call('v1.source.release.get_by_id',
|
||||
risotto_context,
|
||||
release_id=as_release_id)
|
||||
|
||||
self.servermodel_gen_funcs(servermodel_name,
|
||||
servermodel_id,
|
||||
dependencies,
|
||||
release_cache)
|
||||
self.servermodel_gen_schema(servermodel_name,
|
||||
servermodel_id,
|
||||
dependencies,
|
||||
release_cache)
|
||||
self.servermodel_copy_templates(servermodel_name,
|
||||
servermodel_id,
|
||||
dependencies,
|
||||
release_cache)
|
||||
sm_dict = {'servermodel_name': servermodel_name,
|
||||
'servermodel_description': servermodel_description,
|
||||
'servermodel_parents_id': servermodel_parents_id,
|
||||
'release_id': release_id,
|
||||
'servermodel_id': servermodel_id}
|
||||
await self.publish('v1.servermodel.created',
|
||||
risotto_context,
|
||||
**sm_dict)
|
||||
return sm_dict
|
||||
|
||||
def parse_parents(self,
|
||||
servermodels: Dict,
|
||||
servermodel: Dict,
|
||||
parents: List=None) -> List:
|
||||
if parents is None:
|
||||
parents = [servermodel['name']]
|
||||
parent = servermodel['parent']
|
||||
if parent in servermodels:
|
||||
parents.append(parent)
|
||||
self.parse_parents(servermodels, servermodels[parent], parents)
|
||||
return parents
|
||||
|
||||
async def get_servermodel_id_by_name(self,
|
||||
risotto_context: Context,
|
||||
servermodel_name: str,
|
||||
release_id: int):
|
||||
sql = 'SELECT ServermodelId as servermodel_id FROM Servermodel WHERE ServermodelName = $1 AND ServermodelReleaseId = $2',
|
||||
return await risotto_context.connection.fetchval(sql,
|
||||
servermodel_name,
|
||||
release_id)['servermodel_id']
|
||||
|
||||
@register('v1.servermodel.dataset.updated', None, database=True)
|
||||
async def servermodel_update(self,
|
||||
risotto_context: Context,
|
||||
source_name: str,
|
||||
release_distribution: int):
|
||||
source = await self.call('v1.source.describe',
|
||||
risotto_context,
|
||||
source_name=source_name)
|
||||
release = await self.call('v1.source.release.get_by_distribution',
|
||||
risotto_context,
|
||||
source_id=source['source_id'],
|
||||
release_distribution=release_distribution)
|
||||
release_id = release['release_id']
|
||||
servermodel_path = join(self.source_root_path,
|
||||
source_name,
|
||||
release['release_name'],
|
||||
'servermodel')
|
||||
servermodels = {}
|
||||
for servermodel in listdir(servermodel_path):
|
||||
if not servermodel.endswith('.yml'):
|
||||
continue
|
||||
servermodel_description_path = join(servermodel_path, servermodel)
|
||||
try:
|
||||
with open(servermodel_description_path, 'r') as servermodel_yml:
|
||||
servermodel_description = load(servermodel_yml,
|
||||
Loader=SafeLoader)
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f'Error while reading {servermodel_description_path}: {err}'))
|
||||
servermodels[servermodel_description['name']] = servermodel_description
|
||||
servermodels[servermodel_description['name']]['done'] = False
|
||||
|
||||
release_cache = {release['release_id']: release}
|
||||
for servermodel in servermodels.values():
|
||||
if not servermodel['done']:
|
||||
# parent needs to create before child, so retrieve all parents
|
||||
parents = self.parse_parents(servermodels,
|
||||
servermodel)
|
||||
parents.reverse()
|
||||
servermodelparent_id = []
|
||||
for new_servermodel in parents:
|
||||
if not servermodels[new_servermodel]['done']:
|
||||
servermodel_description = servermodels[new_servermodel]
|
||||
parent = servermodel_description['parent']
|
||||
if not servermodelparent_id and parent is not None:
|
||||
# parent is a str, so get ID
|
||||
servermodelparent_id = [await self.get_servermodel_id_by_name(risotto_context,
|
||||
parent,
|
||||
release_id)]
|
||||
# link application service with this servermodel
|
||||
dependencies = []
|
||||
for depend in servermodels[new_servermodel]['applicationservices']:
|
||||
applicationservice = await self.call('v1.applicationservice.describe',
|
||||
risotto_context,
|
||||
applicationservice_name=depend,
|
||||
release_id=release_id)
|
||||
dependencies.append(applicationservice['applicationservice_id'])
|
||||
sm_name = servermodel_description['name']
|
||||
sm_description = servermodel_description['description']
|
||||
try:
|
||||
servermodel_ob = await self._servermodel_create(risotto_context,
|
||||
sm_name,
|
||||
sm_description,
|
||||
servermodelparent_id,
|
||||
dependencies,
|
||||
release_id,
|
||||
release_cache)
|
||||
servermodel_id = servermodel_ob['servermodel_id']
|
||||
except Exception as err:
|
||||
if get_config().get('global').get('debug'):
|
||||
print_exc()
|
||||
raise ExecutionError(_(f"Error while injecting servermodel {sm_name} in database: {err}"))
|
||||
servermodelparent_id = [servermodel_id]
|
||||
servermodel_description['done'] = True
|
||||
return {'retcode': 0, 'returns': _('Servermodels successfully loaded')}
|
||||
|
||||
@register('v1.servermodel.list', None, database=True)
|
||||
async def servermodel_list(self,
|
||||
risotto_context: Context,
|
||||
source_id: int):
|
||||
sql = '''
|
||||
SELECT ServermodelId as servermodel_id, ServermodelName as servermodel_name, ServermodelDescription as servermodel_description, ServermodelParentsId as servermodel_parents_id, ServermodelReleaseId as release_id
|
||||
FROM Servermodel
|
||||
'''
|
||||
servermodels = await risotto_context.connection.fetch(sql)
|
||||
return [dict(r) for r in servermodels]
|
||||
|
||||
@register('v1.servermodel.get_by_id', None, database=True)
|
||||
async def servermodel_get_by_id(self,
|
||||
risotto_context: Context,
|
||||
servermodel_id: int):
|
||||
sql = '''
|
||||
SELECT ServermodelId as servermodel_id, ServermodelName as servermodel_name, ServermodelDescription as servermodel_description, ServermodelParentsId as servermodel_parents_id, ServermodelReleaseId as release_id
|
||||
FROM Servermodel
|
||||
WHERE ServermodelId=$1
|
||||
'''
|
||||
servermodel = await risotto_context.connection.fetchrow(sql,
|
||||
servermodel_id)
|
||||
if not servermodel:
|
||||
raise Exception(_(f'{servermodel_id} is not a valid ID for a servermodel'))
|
||||
return dict(servermodel)
|
||||
|
||||
async def _parse_depends(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_id: int,
|
||||
or_depends: list,
|
||||
ids: list) -> None:
|
||||
applicationservice = await self.call('v1.applicationservice.get_by_id',
|
||||
risotto_context,
|
||||
applicationservice_id=applicationservice_id)
|
||||
ids[applicationservice_id] = (applicationservice['applicationservice_name'],
|
||||
applicationservice['applicationservice_release_id'])
|
||||
for depend in applicationservice['applicationservice_dependencies']:
|
||||
if isinstance(depend, dict):
|
||||
or_depends.append(depend['or'])
|
||||
elif depend not in ids:
|
||||
await self._parse_depends(risotto_context,
|
||||
depend,
|
||||
or_depends,
|
||||
ids)
|
||||
|
||||
async def _parse_or_depends(self,
|
||||
risotto_context: Context,
|
||||
or_depends: list,
|
||||
ids: list) -> None:
|
||||
new_or_depends = []
|
||||
set_ids = set(ids)
|
||||
for or_depend in or_depends:
|
||||
if not set(or_depend) & set_ids:
|
||||
applicationservice_id= or_depend[0]
|
||||
await self._parse_depends(risotto_context,
|
||||
applicationservice_id,
|
||||
new_or_depends,
|
||||
ids)
|
||||
if new_or_depends:
|
||||
await self._parse_or_depends(risotto_context,
|
||||
new_or_depends,
|
||||
ids)
|
||||
|
||||
async def get_applicationservices(self,
|
||||
risotto_context: Context,
|
||||
applicationservice_id: int) -> list:
|
||||
"""Return consolidated dependencies or raise.
|
||||
"""
|
||||
or_depends = []
|
||||
ids = {}
|
||||
await self._parse_depends(risotto_context,
|
||||
applicationservice_id,
|
||||
or_depends,
|
||||
ids)
|
||||
await self._parse_or_depends(risotto_context,
|
||||
or_depends,
|
||||
ids)
|
||||
return ids
|
||||
@register('v1.servermodel.describe', None)
|
||||
async def servermodel_describe(self, inheritance, creolefuncs, servermodelid, schema, conffiles, resolvdepends, probes):
|
||||
schema = """<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="name" type="string">
|
||||
<value>/etc/mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="general" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
<leader doc="master" name="master">
|
||||
<property>normal</property>
|
||||
<variable doc="master" multi="True" name="master" type="string"/>
|
||||
<variable doc="slave1" multi="True" name="slave1" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
<variable doc="slave2" multi="True" name="slave2" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
</leader>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>"""
|
||||
return {'servermodelid': 1, 'servermodelname': 'name', 'servermodeldescription': 'description', 'subreleasename': 'name', 'sourceid': 1, 'schema': schema, 'creolefuncs': ''}
|
||||
|
@ -9,6 +9,7 @@ from ...http import register as register_http
|
||||
from ...config import DEBUG
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
from ...error import CallError
|
||||
from .storage import storage_server, storage_servermodel
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
@ -16,8 +17,7 @@ from ...dispatcher import dispatcher
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
def __init__(self,
|
||||
test):
|
||||
def __init__(self):
|
||||
self.modify_storage = Storage(engine='dictionary')
|
||||
|
||||
def get_storage(self,
|
||||
@ -85,21 +85,20 @@ class Risotto(Controller):
|
||||
|
||||
# check if a session already exists
|
||||
sessions = storage.get_sessions()
|
||||
for sess_id, session in sessions.items():
|
||||
if session['id'] == id:
|
||||
if session['username'] == risotto_context.username:
|
||||
for session in sessions.values():
|
||||
if sess['id'] == id:
|
||||
if sess['username'] == risotto_context.username:
|
||||
# same user so returns it
|
||||
return self.format_session(sess_id,
|
||||
session)
|
||||
return self.format_session(session['session_id'], session)
|
||||
else:
|
||||
raise Exception(_(f'{username} already edits this configuration'))
|
||||
raise CallError(_(f'{username} already edits this configuration'))
|
||||
|
||||
# create a new session
|
||||
while True:
|
||||
session_id = 'z' + hexlify(urandom(23)).decode()
|
||||
if not session_id in sessions:
|
||||
break
|
||||
await storage.add_session(session_id,
|
||||
storage.add_session(session_id,
|
||||
config,
|
||||
id,
|
||||
risotto_context.username,
|
||||
@ -135,11 +134,11 @@ class Risotto(Controller):
|
||||
namespace)
|
||||
if mode is not None:
|
||||
if mode not in ('basic', 'normal', 'expert'):
|
||||
raise Exception(f'unknown mode {mode}')
|
||||
await storage.set_config_mode(session_id,
|
||||
raise CallError(f'unknown mode {mode}')
|
||||
storage.set_config_mode(session_id,
|
||||
mode)
|
||||
if debug is not None:
|
||||
await storage.set_config_debug(session_id,
|
||||
storage.set_config_debug(session_id,
|
||||
debug)
|
||||
return self.get_session_informations(risotto_context,
|
||||
session_id,
|
||||
@ -159,23 +158,21 @@ class Risotto(Controller):
|
||||
session_id,
|
||||
type)
|
||||
# if multi and not follower the value is in fact in value_multi
|
||||
# FIXME option = session['option'].option(name).option
|
||||
option = session['config'].option(name).option
|
||||
if await option.ismulti() and not await option.isfollower():
|
||||
option = session['option'].option(name).option
|
||||
if option.ismulti() and not option.isfollower():
|
||||
value = value_multi
|
||||
#FIXME namespace = session['namespace']
|
||||
#FIXME update = {'name': f'{namespace}.{name}',
|
||||
update = {'name': name,
|
||||
namespace = session['namespace']
|
||||
update = {'name': f'{namespace}.{name}',
|
||||
'action': action,
|
||||
'value': value}
|
||||
if index is not None:
|
||||
update['index'] = index
|
||||
updates = {'updates': [update]}
|
||||
ret = await session['option'].updates(updates)
|
||||
ret = session['option'].updates(updates)
|
||||
if update['name'] in ret:
|
||||
for val in ret[update['name']][index]:
|
||||
if isinstance(val, ValueError):
|
||||
raise Exception(val)
|
||||
raise CallError(val)
|
||||
ret = {'session_id': session_id,
|
||||
'name': name}
|
||||
if index is not None:
|
||||
@ -191,23 +188,19 @@ class Risotto(Controller):
|
||||
session_id,
|
||||
type)
|
||||
try:
|
||||
await session['config'].forcepermissive.option(session['namespace']).value.dict()
|
||||
session['config'].forcepermissive.option(session['namespace']).value.dict()
|
||||
except Exception as err:
|
||||
raise Exception(str(err))
|
||||
raise CallError(str(err))
|
||||
if type == 'server':
|
||||
config = session['config']
|
||||
await config.property.read_only()
|
||||
mandatories = list(await config.value.mandatory())
|
||||
await config.property.read_write()
|
||||
mandatories = list(session['config'].forcepermissive.value.mandatory())
|
||||
if mandatories:
|
||||
# FIXME mandatories = [mandatory.split('.', 1)[1] for mandatory in mandatories]
|
||||
if len(mandatories) == 1:
|
||||
mandatories = mandatories[0]
|
||||
msg = _(f'the parameter "--{mandatories}" is mandatory')
|
||||
msg = _('the parameter "--{mandatories}" is mandatory')
|
||||
else:
|
||||
mandatories = '", "--'.join(mandatories)
|
||||
msg = _(f'parameters "--{mandatories}" are mandatories')
|
||||
raise Exception(msg)
|
||||
msg = _('parameters "{mandatories}" are mandatories')
|
||||
raise CallError(msg)
|
||||
return self.format_session(session_id,
|
||||
session)
|
||||
|
||||
@ -222,11 +215,9 @@ class Risotto(Controller):
|
||||
type)
|
||||
info = self.format_session(session_id, session)
|
||||
if name is not None:
|
||||
content = {name: await session['config'].option(name).value.get()}
|
||||
info['content'] = {name: session['option'].option(name).value.get()}
|
||||
else:
|
||||
content = await session['option'].value.dict(fullpath=True,
|
||||
leader_to_list=True)
|
||||
info['content'] = content
|
||||
info['content'] = session['option'].value.dict()
|
||||
return info
|
||||
|
||||
@register(['v1.session.server.stop', 'v1.session.servermodel.stop'], None)
|
||||
@ -246,8 +237,8 @@ class Risotto(Controller):
|
||||
config = config_module.servermodel[id_]
|
||||
if save:
|
||||
modif_config = session['config']
|
||||
await config.value.importation(await modif_config.value.exportation())
|
||||
await config.permissive.importation(await modif_config.permissive.exportation())
|
||||
config.value.importation(modif_config.value.exportation())
|
||||
config.permissive.importation(modif_config.permissive.exportation())
|
||||
storage.del_session(session_id)
|
||||
return self.format_session(session_id, session)
|
||||
|
||||
@ -258,7 +249,7 @@ class Risotto(Controller):
|
||||
session_id: str) -> Dict:
|
||||
session = storage_server.get_session(session_id,
|
||||
risotto_context.username)
|
||||
return await session['option'].dict(remotable='all')
|
||||
return session['option'].dict(remotable='all')
|
||||
|
||||
@register_http('v1', '/config/servermodel/{session_id}')
|
||||
async def get_servermodel_api(self,
|
||||
@ -267,4 +258,4 @@ class Risotto(Controller):
|
||||
session_id: str) -> Dict:
|
||||
session = storage_servermodel.get_session(session_id,
|
||||
risotto_context.username)
|
||||
return await session['option'].dict(remotable='all')
|
||||
return session['option'].dict(remotable='all')
|
||||
|
@ -15,7 +15,7 @@ class Storage(object):
|
||||
def __init__(self):
|
||||
self.sessions = {}
|
||||
|
||||
async def add_session(self,
|
||||
def add_session(self,
|
||||
session_id: int,
|
||||
orig_config: Config,
|
||||
server_id: int,
|
||||
@ -26,7 +26,7 @@ class Storage(object):
|
||||
config_id = f'{prefix_id}{config_name}'
|
||||
|
||||
# copy Config and all it's parents
|
||||
meta = await orig_config.config.deepcopy(session_id=config_id,
|
||||
meta = orig_config.config.deepcopy(session_id=config_id,
|
||||
storage=config_storage,
|
||||
metaconfig_prefix=prefix_id)
|
||||
|
||||
@ -34,7 +34,7 @@ class Storage(object):
|
||||
config = meta
|
||||
while True:
|
||||
try:
|
||||
children = list(await config.config.list())
|
||||
children = list(config.config.list())
|
||||
if not children:
|
||||
# it's an empty metaconfig
|
||||
break
|
||||
@ -42,9 +42,9 @@ class Storage(object):
|
||||
except:
|
||||
# it's a config, so no "list" method
|
||||
break
|
||||
await config.property.read_write()
|
||||
config.property.read_write()
|
||||
# set the default owner
|
||||
await self.set_owner(config,
|
||||
self.set_owner(config,
|
||||
username)
|
||||
|
||||
# store it
|
||||
@ -54,14 +54,14 @@ class Storage(object):
|
||||
'id': server_id,
|
||||
'timestamp': int(time.time()),
|
||||
'username': username}
|
||||
await self.set_config_mode(session_id,
|
||||
self.set_config_mode(session_id,
|
||||
'normal')
|
||||
await self.set_config_debug(session_id,
|
||||
self.set_config_debug(session_id,
|
||||
False)
|
||||
self.set_namespace(session_id,
|
||||
'creole')
|
||||
|
||||
async def set_config_mode(self,
|
||||
def set_config_mode(self,
|
||||
id: int,
|
||||
mode: str):
|
||||
""" Define which edition mode to select
|
||||
@ -69,19 +69,19 @@ class Storage(object):
|
||||
config = self.sessions[id]['config']
|
||||
for mode_level in modes.values():
|
||||
if modes[mode] < mode_level:
|
||||
await config.property.add(mode_level.name)
|
||||
config.property.add(mode_level.name)
|
||||
else:
|
||||
await config.property.pop(mode_level.name)
|
||||
config.property.pop(mode_level.name)
|
||||
self.sessions[id]['mode'] = mode
|
||||
|
||||
async def set_config_debug(self, id_, is_debug):
|
||||
def set_config_debug(self, id_, is_debug):
|
||||
""" Enable/Disable debug mode
|
||||
"""
|
||||
config = self.sessions[id_]['config']
|
||||
if is_debug:
|
||||
await config.property.pop('hidden')
|
||||
config.property.pop('hidden')
|
||||
else:
|
||||
await config.property.add('hidden')
|
||||
config.property.add('hidden')
|
||||
self.sessions[id_]['debug'] = is_debug
|
||||
|
||||
def set_namespace(self,
|
||||
@ -97,7 +97,7 @@ class Storage(object):
|
||||
session_id: int,
|
||||
username: str) -> Dict:
|
||||
if session_id not in self.sessions:
|
||||
raise Exception(f'the session "{session_id}" not exists')
|
||||
raise Exception(f'the session {id} not exists')
|
||||
session = self.sessions[session_id]
|
||||
if username != session['username']:
|
||||
raise NotAllowedError()
|
||||
@ -113,10 +113,10 @@ class StorageServer(Storage):
|
||||
server_id: int):
|
||||
return f'std_{server_id}'
|
||||
|
||||
async def set_owner(self,
|
||||
def set_owner(self,
|
||||
config: Config,
|
||||
username: str):
|
||||
await config.owner.set(username)
|
||||
config.owner.set(username)
|
||||
|
||||
|
||||
class StorageServermodel(Storage):
|
||||
@ -124,10 +124,10 @@ class StorageServermodel(Storage):
|
||||
server_id: int):
|
||||
return f'v_{server_id}'
|
||||
|
||||
async def set_owner(self,
|
||||
def set_owner(self,
|
||||
config: Config,
|
||||
username: str):
|
||||
await config.owner.set('servermodel_' + username)
|
||||
config.owner.set('servermodel_' + username)
|
||||
|
||||
|
||||
storage_server = StorageServer()
|
||||
|
@ -1 +0,0 @@
|
||||
from .source import Risotto
|
@ -1,145 +0,0 @@
|
||||
from typing import Dict, List
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...context import Context
|
||||
import requests
|
||||
import yaml
|
||||
import os
|
||||
from ...utils import _
|
||||
from ...config import get_config
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.source.create', None, database=True)
|
||||
async def source_create(self,
|
||||
risotto_context: Context,
|
||||
source_name: str,
|
||||
source_url: str) -> Dict:
|
||||
source_upsert = """INSERT INTO Source(SourceName, SourceURL) VALUES ($1, $2)
|
||||
ON CONFLICT (SourceName) DO UPDATE SET SourceURL = $2
|
||||
RETURNING SourceId
|
||||
"""
|
||||
# If given url is not 'none' (a.k.a internal source)
|
||||
# Look for file releases.yml at given url
|
||||
# If such a file exists, consider source a valid one and create source in database.
|
||||
if source_url != 'none':
|
||||
try:
|
||||
releases = yaml.load(requests.get(source_url.rstrip('/') + '/releases.yml').content, Loader=yaml.SafeLoader)
|
||||
except requests.exceptions.ConnectionError as err:
|
||||
raise Exception(_('Invalid URL'))
|
||||
except yaml.scanner.ScannerError as err:
|
||||
raise Exception(_('Invalid releases.yml file'))
|
||||
except:
|
||||
raise Exception(_('Invalid source'))
|
||||
else:
|
||||
releases = {'1.0.0': {'distribution': 'last'}}
|
||||
os.makedirs(os.path.join(get_config().get('source').get('root_path'), source_name), exist_ok=True)
|
||||
with open(os.path.join(get_config().get('source').get('root_path'), source_name, 'releases.yml'), 'w') as release_file:
|
||||
yaml.dump(releases, release_file)
|
||||
source_id = await risotto_context.connection.fetchval(source_upsert,
|
||||
source_name,
|
||||
source_url)
|
||||
return {'source_name': source_name,
|
||||
'source_url': source_url,
|
||||
'source_id': source_id}
|
||||
|
||||
@register('v1.source.describe', None, database=True)
|
||||
async def source_describe(self,
|
||||
risotto_context: Context,
|
||||
source_name: str) -> Dict:
|
||||
source_get = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
|
||||
FROM Source
|
||||
WHERE SourceName = $1
|
||||
"""
|
||||
source = await risotto_context.connection.fetchrow(source_get,
|
||||
source_name)
|
||||
if not source:
|
||||
raise Exception(_(f'unknown source with name {source_name}'))
|
||||
return dict(source)
|
||||
|
||||
@register('v1.source.list', None, database=True)
|
||||
async def source_list(self,
|
||||
risotto_context: Context) -> List[Dict]:
|
||||
source_list = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
|
||||
FROM Source
|
||||
"""
|
||||
result = await risotto_context.connection.fetch(source_list)
|
||||
return [dict(r) for r in result]
|
||||
|
||||
@register('v1.source.dataset.update', None, database=True)
|
||||
async def version_update(self,
|
||||
risotto_context: Context,
|
||||
source_id: int,
|
||||
release_name: str):
|
||||
# source.release.create is an upsert, do not using it
|
||||
release_insert = """INSERT INTO Release(ReleaseName, ReleaseSourceId) VALUES ($1, $2)
|
||||
RETURNING ReleaseId
|
||||
"""
|
||||
release_id = await risotto_context.connection.fetchval(release_insert,
|
||||
release_name,
|
||||
source_id)
|
||||
return {'release_id': release_id,
|
||||
'release_name': release_name}
|
||||
|
||||
@register('v1.source.release.create', None, database=True)
|
||||
async def source_release_create(self,
|
||||
risotto_context: Context,
|
||||
source_id: int,
|
||||
release_name: str,
|
||||
release_distribution: str) -> Dict:
|
||||
source_get = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url
|
||||
FROM Source
|
||||
WHERE SourceId = $1
|
||||
"""
|
||||
release_upsert = """INSERT INTO Release(ReleaseName, ReleaseSourceId, ReleaseDistribution) VALUES ($1, $2, $3)
|
||||
ON CONFLICT (ReleaseName, ReleaseSourceId) DO UPDATE SET ReleaseName = $1
|
||||
RETURNING ReleaseId
|
||||
"""
|
||||
source = dict(await risotto_context.connection.fetchrow(source_get,
|
||||
source_id))
|
||||
release_id = await risotto_context.connection.fetchval(release_upsert,
|
||||
release_name,
|
||||
source_id,
|
||||
release_distribution)
|
||||
del source['source_id']
|
||||
source['release_id'] = release_id
|
||||
source['release_name'] = release_name
|
||||
source['release_distribution'] = release_distribution
|
||||
return source
|
||||
|
||||
@register('v1.source.release.list', None, database=True)
|
||||
async def release_list(self,
|
||||
risotto_context):
|
||||
release_query = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name, ReleaseDistribution as release_distribution
|
||||
FROM Release, Source
|
||||
WHERE Source.SourceId=Release.ReleaseSourceId"""
|
||||
result = await risotto_context.connection.fetch(release_query)
|
||||
return [dict(r) for r in result]
|
||||
|
||||
@register('v1.source.release.get_by_id', None, database=True)
|
||||
async def release_get_by_id(self,
|
||||
risotto_context: Context,
|
||||
release_id: int) -> Dict:
|
||||
release_query = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name, ReleaseDistribution as release_distribution
|
||||
FROM Release, Source
|
||||
WHERE Release.ReleaseId = $1 AND Source.SourceId = Release.ReleaseSourceId"""
|
||||
result = await risotto_context.connection.fetchrow(release_query,
|
||||
release_id)
|
||||
if not result:
|
||||
raise Exception(_(f'unknown release id {release_id}'))
|
||||
return dict(result)
|
||||
|
||||
@register('v1.source.release.get_by_distribution', None, database=True)
|
||||
async def release_get_by_distribution(self,
|
||||
risotto_context: Context,
|
||||
source_id: int,
|
||||
release_distribution: str) -> Dict:
|
||||
release_query = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name, ReleaseDistribution as release_distribution
|
||||
FROM Release, Source
|
||||
WHERE Release.ReleaseSourceId = $1 AND Release.ReleaseDistribution = $2 AND Source.SourceId = Release.ReleaseSourceId"""
|
||||
result = await risotto_context.connection.fetchrow(release_query,
|
||||
source_id,
|
||||
release_distribution)
|
||||
if not result:
|
||||
raise Exception(_(f'unknown distribution {release_distribution} with source {source_id}'))
|
||||
return dict(result)
|
@ -1,31 +1,21 @@
|
||||
from os import mkdir
|
||||
from os.path import isdir, join
|
||||
from shutil import rmtree
|
||||
from typing import Dict
|
||||
from rougail.template import generate
|
||||
from tiramisu import Storage
|
||||
from ...config import CONFIGURATION_DIR, TMP_DIR, get_config
|
||||
from ...config import ROOT_CACHE_DIR, CONFIGURATION_DIR, TEMPLATE_DIR, TMP_DIR
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...dispatcher import dispatcher
|
||||
from ...utils import _
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
def __init__(self,
|
||||
test: bool) -> None:
|
||||
def __init__(self):
|
||||
self.storage = Storage(engine='dictionary')
|
||||
self.cache_root_path = join(get_config().get('cache').get('root_path'), 'servermodel')
|
||||
|
||||
@register('v1.template.generate', None)
|
||||
async def template_get(self,
|
||||
risotto_context,
|
||||
server_name: str) -> Dict:
|
||||
server = await self.call('v1.server.describe',
|
||||
risotto_context,
|
||||
server_name=server_name)
|
||||
server_id = server['server_id']
|
||||
servermodel_id = server['server_servermodel_id']
|
||||
server_id: int):
|
||||
config_module = dispatcher.get_service('config')
|
||||
server = config_module.server[server_id]
|
||||
config = meta = server['server'].config.deepcopy(storage=self.storage)
|
||||
@ -38,6 +28,7 @@ class Risotto(Controller):
|
||||
config = children[0]
|
||||
else:
|
||||
break
|
||||
print(config.value.dict())
|
||||
configurations_dir = join(CONFIGURATION_DIR,
|
||||
str(server_id))
|
||||
if isdir(configurations_dir):
|
||||
@ -47,7 +38,7 @@ class Risotto(Controller):
|
||||
if isdir(tmp_dir):
|
||||
rmtree(tmp_dir)
|
||||
mkdir(tmp_dir)
|
||||
templates_dir = join(self.cache_root_path, str(servermodel_id), 'templates')
|
||||
templates_dir = join(TEMPLATE_DIR, str(server_id))
|
||||
generate(config,
|
||||
server['funcs_file'],
|
||||
templates_dir,
|
||||
|
@ -1 +0,0 @@
|
||||
from .uri import Risotto
|
@ -1,100 +0,0 @@
|
||||
from typing import Dict, List
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
async def on_join(self,
|
||||
risotto_context):
|
||||
for uri in ['v1.applicationservice.create',
|
||||
'v1.applicationservice.dataset.updated',
|
||||
'v1.server.create',
|
||||
'v1.servermodel.dataset.updated',
|
||||
'v1.session.server.start',
|
||||
'v1.source.create',
|
||||
'v1.source.dataset.update',
|
||||
'v1.source.release.create',
|
||||
'v1.template.generate',
|
||||
'v1.uri.role.join',
|
||||
'v1.uri.role.list',
|
||||
'v1.user.create',
|
||||
'v1.user.delete',
|
||||
'v1.user.list',
|
||||
'v1.user.role.create',
|
||||
'v1.user.role.list']:
|
||||
try:
|
||||
await self.call('v1.uri.role.join',
|
||||
risotto_context,
|
||||
role_name='administrator',
|
||||
uri_name=uri)
|
||||
except:
|
||||
pass
|
||||
for uri in ['v1.applicationservice.describe',
|
||||
'v1.applicationservice.get_by_id',
|
||||
'v1.server.describe',
|
||||
'v1.server.list',
|
||||
'v1.servermodel.list',
|
||||
'v1.session.server.configure',
|
||||
'v1.session.server.filter',
|
||||
'v1.session.server.get',
|
||||
'v1.session.server.list',
|
||||
'v1.session.servermodel.configure',
|
||||
'v1.session.servermodel.filter',
|
||||
'v1.session.servermodel.get',
|
||||
'v1.session.servermodel.list',
|
||||
'v1.session.servermodel.start',
|
||||
'v1.session.servermodel.stop',
|
||||
'v1.session.servermodel.validate',
|
||||
'v1.session.server.stop',
|
||||
'v1.session.server.validate',
|
||||
'v1.source.describe',
|
||||
'v1.source.list',
|
||||
'v1.source.release.get_by_distribution',
|
||||
'v1.source.release.get_by_id',
|
||||
'v1.source.release.list']:
|
||||
try:
|
||||
await self.call('v1.uri.role.join',
|
||||
risotto_context,
|
||||
role_name='all',
|
||||
uri_name=uri)
|
||||
except:
|
||||
pass
|
||||
|
||||
@register('v1.uri.role.join', None, database=True)
|
||||
async def uri_role_join(self,
|
||||
risotto_context: Context,
|
||||
role_name: str,
|
||||
uri_name: str) -> Dict:
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT URIId
|
||||
FROM URI
|
||||
WHERE URIName = $1
|
||||
'''
|
||||
uri_id = await risotto_context.connection.fetchval(sql,
|
||||
uri_name)
|
||||
if uri_id is None:
|
||||
raise Exception(_(f'unable to find message {uri_name}'))
|
||||
sql = '''
|
||||
INSERT INTO RoleURI(RoleName, URIId)
|
||||
VALUES ($1,$2)
|
||||
ON CONFLICT DO NOTHING
|
||||
'''
|
||||
uri_id = await risotto_context.connection.fetchrow(sql,
|
||||
role_name,
|
||||
uri_id)
|
||||
return {'role_name': role_name,
|
||||
'uri_name': uri_name}
|
||||
|
||||
@register('v1.uri.role.list', None, database=True)
|
||||
async def uri_role_list(self,
|
||||
risotto_context: Context) -> List[Dict]:
|
||||
sql = '''
|
||||
SELECT RoleName as role_name, URI.URIName as uri
|
||||
FROM RoleURI, URI
|
||||
WHERE RoleURI.URIId = URI.URIId
|
||||
'''
|
||||
return [dict(r) for r in await risotto_context.connection.fetch(sql)]
|
@ -1 +0,0 @@
|
||||
from .user import Risotto
|
@ -1,147 +0,0 @@
|
||||
from typing import Dict, Optional
|
||||
|
||||
from ...controller import Controller
|
||||
from ...register import register
|
||||
from ...context import Context
|
||||
from ...utils import _
|
||||
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.user.create', None, database=True)
|
||||
async def user_create(self,
|
||||
risotto_context: Context,
|
||||
user_login: str,
|
||||
user_name: str,
|
||||
user_surname: str) -> Dict:
|
||||
user_insert = """INSERT INTO RisottoUser(UserLogin, UserName, UserSurname)
|
||||
VALUES ($1,$2,$3)
|
||||
RETURNING UserId
|
||||
"""
|
||||
user_id = await risotto_context.connection.fetchval(user_insert,
|
||||
user_login,
|
||||
user_name,
|
||||
user_surname)
|
||||
await self.call('v1.user.role.create',
|
||||
risotto_context,
|
||||
user_login=user_login,
|
||||
role_name='all')
|
||||
return {'user_id': user_id,
|
||||
'user_login': user_login,
|
||||
'user_name': user_name,
|
||||
'user_surname': user_surname}
|
||||
|
||||
@register('v1.user.list', None, database=True)
|
||||
async def user_list(self,
|
||||
risotto_context: Context) -> Dict:
|
||||
sql = '''
|
||||
SELECT UserId as user_id, UserLogin as user_login, UserName as user_name, UserSurname as user_surname
|
||||
FROM RisottoUser
|
||||
'''
|
||||
users = await risotto_context.connection.fetch(sql)
|
||||
return [dict(r) for r in users]
|
||||
|
||||
@register('v1.user.delete', None, database=True)
|
||||
async def user_delete(self,
|
||||
risotto_context: Context,
|
||||
user_login: str) -> Dict:
|
||||
sql = '''
|
||||
DELETE FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
RETURNING UserId as user_id, UserLogin as user_login, UserName as user_name, UserSurname as user_surname
|
||||
'''
|
||||
user = await risotto_context.connection.fetchrow(sql,
|
||||
user_login)
|
||||
if user is None:
|
||||
raise Exception(_(f'unable to find user {user_login}'))
|
||||
return dict(user)
|
||||
|
||||
@register('v1.user.role.create', None, database=True)
|
||||
async def user_role_create(self,
|
||||
risotto_context: Context,
|
||||
user_login: str,
|
||||
role_name: str,
|
||||
role_attribute: str,
|
||||
role_attribute_value: str) -> Dict:
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT UserId
|
||||
FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
'''
|
||||
user_id = await risotto_context.connection.fetchval(sql,
|
||||
user_login)
|
||||
if user_id is None:
|
||||
raise Exception(_(f'unable to find user {user_login}'))
|
||||
sql = '''INSERT INTO UserRole(RoleUserId, RoleName, RoleAttribute, RoleAttributeValue)
|
||||
VALUES($1,$2,$3,$4)
|
||||
RETURNING RoleId
|
||||
'''
|
||||
role_id = await risotto_context.connection.fetchval(sql,
|
||||
user_id,
|
||||
role_name,
|
||||
role_attribute,
|
||||
role_attribute_value)
|
||||
return {'role_id': role_id,
|
||||
'user_login': user_login,
|
||||
'role_name': role_name,
|
||||
'role_attribute': role_attribute,
|
||||
'role_attribute_value': role_attribute_value}
|
||||
|
||||
@register('v1.user.role.list', None, database=True)
|
||||
async def user_role_list(self,
|
||||
risotto_context: Context,
|
||||
user_login: Optional[str]) -> Dict:
|
||||
if not user_login:
|
||||
sql = '''
|
||||
SELECT RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value, RisottoUser.UserLogin as user_login
|
||||
FROM UserRole, RisottoUser
|
||||
WHERE UserRole.RoleUserId = RisottoUser.UserId
|
||||
'''
|
||||
roles = await risotto_context.connection.fetch(sql)
|
||||
else:
|
||||
# Verify if user exists and get ID
|
||||
sql = '''
|
||||
SELECT UserId
|
||||
FROM RisottoUser
|
||||
WHERE UserLogin = $1
|
||||
'''
|
||||
user_id = await risotto_context.connection.fetchval(sql,
|
||||
user_login)
|
||||
if user_id is None:
|
||||
raise Exception(_(f'unable to find user {user_login}'))
|
||||
sql = '''
|
||||
SELECT RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value, RisottoUser.UserLogin as user_login
|
||||
FROM UserRole, RisottoUser
|
||||
WHERE UserRole.RoleUserId = RisottoUser.UserId AND UserRole.RoleUserId = $1
|
||||
'''
|
||||
roles = await risotto_context.connection.fetch(sql,
|
||||
user_id)
|
||||
return [dict(r) for r in roles]
|
||||
#
|
||||
# FIXME comment savoir quel role il faut supprimer ? avec attribut ou juste l'ID ?
|
||||
# @register('v1.user.role.delete', None, database=True)
|
||||
# async def user_role_delete(self,
|
||||
# risotto_context: Context,
|
||||
# user_login: str,
|
||||
# role_name: str) -> Dict:
|
||||
# # Verify if user exists and get ID
|
||||
# sql = '''
|
||||
# SELECT UserId
|
||||
# FROM RisottoUser
|
||||
# WHERE UserLogin = $1
|
||||
# '''
|
||||
# user_id = await risotto_context.connection.fetchval(sql,
|
||||
# user_login)
|
||||
# if user_id is None:
|
||||
# raise Exception(_(f'unable to find user {user_login}'))
|
||||
# sql = '''
|
||||
# DELETE FROM RisottoRole
|
||||
# WHERE RoleName = $1 AND UserId = $2
|
||||
# RETURNING RoleId as role_id, RoleName as role_name, RoleAttribute as role_attribute, RoleAttributeValue as role_attribute_value
|
||||
# '''
|
||||
# role = await risotto_context.connection.fetchrow(sql,
|
||||
# role_name,
|
||||
# user_id)
|
||||
# if role is None:
|
||||
# raise Exception(_(f'unable to find role {role_name}'))
|
||||
# return dict(role)
|
@ -1,50 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="name" type="string">
|
||||
<value>/etc/mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="general" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
<leader doc="master" name="master">
|
||||
<property>normal</property>
|
||||
<variable doc="master" multi="True" name="master" type="string"/>
|
||||
<variable doc="slave1" multi="True" name="slave1" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
<variable doc="slave2" multi="True" name="slave2" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
</leader>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>
|
@ -1,50 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="name" type="string">
|
||||
<value>/etc/mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="general" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
<leader doc="master" name="master">
|
||||
<property>normal</property>
|
||||
<variable doc="master" multi="True" name="master" type="string"/>
|
||||
<variable doc="slave1" multi="True" name="slave1" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
<variable doc="slave2" multi="True" name="slave2" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
</leader>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>
|
@ -1,50 +0,0 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="name" type="string">
|
||||
<value>/etc/mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="general" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
<leader doc="master" name="master">
|
||||
<property>normal</property>
|
||||
<variable doc="master" multi="True" name="master" type="string"/>
|
||||
<variable doc="slave1" multi="True" name="slave1" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
<variable doc="slave2" multi="True" name="slave2" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
</leader>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>
|
@ -5,4 +5,4 @@ from risotto.register import register
|
||||
class Risotto(Controller):
|
||||
@register('v1.server.list', None)
|
||||
async def server_list(self):
|
||||
return [{'server_id': 3, 'server_name': 'one', 'server_description': 'the first', 'server_servermodel_id': 1}]
|
||||
return [{'server_id': 3, 'servername': 'one', 'serverdescription': 'the first', 'servermodelid': 1}]
|
||||
|
@ -3,13 +3,69 @@ from risotto.register import register
|
||||
|
||||
class Risotto(Controller):
|
||||
@register('v1.servermodel.list', None)
|
||||
async def servermodel_list(self, source_id):
|
||||
return [{'servermodel_id': 1,
|
||||
'servermodel_name': 'name1',
|
||||
'release_id': 1,
|
||||
'servermodel_description': 'description1'},
|
||||
{'servermodel_id': 2,
|
||||
'servermodel_name': 'name2',
|
||||
'release_id': 2,
|
||||
'servermodel_description': 'description2',
|
||||
'servermodel_parents_id': [1]}]
|
||||
async def servermodel_list(self, sourceid):
|
||||
return [{'servermodelid': 1,
|
||||
'servermodelname': 'name1',
|
||||
'subreleasename': 'name1',
|
||||
'sourceid': 1,
|
||||
'servermodeldescription': 'description1'},
|
||||
{'servermodelid': 2,
|
||||
'servermodelname': 'name2',
|
||||
'subreleasename': 'name2',
|
||||
'sourceid': 2,
|
||||
'servermodeldescription': 'description2',
|
||||
'servermodelparentsid': [1]}]
|
||||
|
||||
@register('v1.servermodel.describe', None)
|
||||
async def servermodel_describe(self, inheritance, creolefuncs, servermodelid, schema, conffiles, resolvdepends, probes):
|
||||
schema = """<?xml version='1.0' encoding='UTF-8'?>
|
||||
<creole>
|
||||
<family name="containers">
|
||||
<family name="container0" doc="test">
|
||||
<family doc="files" name="files">
|
||||
<family doc="file0" name="file0">
|
||||
<variable doc="" multi="False" name="mkdir" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="name" type="string">
|
||||
<value>/etc/mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="rm" type="boolean">
|
||||
<value>False</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="source" type="string">
|
||||
<value>mailname</value>
|
||||
</variable>
|
||||
<variable doc="" multi="False" name="activate" type="boolean">
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
</family>
|
||||
<property>basic</property>
|
||||
</family>
|
||||
</family>
|
||||
<family doc="" name="creole">
|
||||
<family doc="general" name="general">
|
||||
<property>normal</property>
|
||||
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
|
||||
<choice type="string">oui</choice>
|
||||
<choice type="string">non</choice>
|
||||
<property>mandatory</property>
|
||||
<property>normal</property>
|
||||
<value type="string">non</value>
|
||||
</variable>
|
||||
<leader doc="master" name="master">
|
||||
<property>normal</property>
|
||||
<variable doc="master" multi="True" name="master" type="string"/>
|
||||
<variable doc="slave1" multi="True" name="slave1" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
<variable doc="slave2" multi="True" name="slave2" type="string">
|
||||
<property>normal</property>
|
||||
</variable>
|
||||
</leader>
|
||||
</family>
|
||||
<separators/>
|
||||
</family>
|
||||
</creole>"""
|
||||
return {'servermodelid': 1, 'servermodelname': 'name', 'servermodeldescription': 'description', 'subreleasename': 'name', 'sourceid': 1, 'schema': schema, 'creolefuncs': ''}
|
||||
|
@ -1,5 +0,0 @@
|
||||
from tiramisu import Storage
|
||||
from risotto.config import DATABASE_DIR
|
||||
|
||||
|
||||
STORAGE = Storage(engine='sqlite3', dir_database=DATABASE_DIR, name='test')
|
@ -1,20 +1,20 @@
|
||||
from importlib import import_module
|
||||
import pytest
|
||||
from tiramisu import list_sessions, delete_session
|
||||
from tiramisu import Storage, list_sessions, delete_session
|
||||
|
||||
from .storage import STORAGE
|
||||
from risotto.context import Context
|
||||
from risotto.services import load_services
|
||||
from risotto.dispatcher import dispatcher
|
||||
from risotto.config import DATABASE_DIR
|
||||
|
||||
|
||||
def setup_module(module):
|
||||
load_services(['config'],
|
||||
validate=False)
|
||||
config_module = dispatcher.get_service('config')
|
||||
config_module.save_storage = STORAGE
|
||||
dispatcher.set_module('server', import_module(f'.server', 'fake_services'), True)
|
||||
dispatcher.set_module('servermodel', import_module(f'.servermodel', 'fake_services'), True)
|
||||
config_module.save_storage = Storage(engine='sqlite3', dir_database=DATABASE_DIR, name='test')
|
||||
dispatcher.set_module('server', import_module(f'.server', 'fake_services'))
|
||||
dispatcher.set_module('servermodel', import_module(f'.servermodel', 'fake_services'))
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
@ -45,19 +45,17 @@ async def test_on_join():
|
||||
assert config_module.server == {}
|
||||
#
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
assert list(config_module.servermodel.keys()) == [1, 2]
|
||||
assert list(config_module.server) == [3]
|
||||
assert set(config_module.server[3]) == {'server', 'server_to_deploy', 'funcs_file'}
|
||||
assert config_module.server[3]['funcs_file'] == 'tests/data/1/funcs.py'
|
||||
assert config_module.server[3]['funcs_file'] == 'cache/1.creolefuncs'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_server_created():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
assert list(config_module.server) == [3]
|
||||
@ -65,19 +63,18 @@ async def test_server_created():
|
||||
'server.created',
|
||||
fake_context,
|
||||
server_id=4,
|
||||
server_name='name3',
|
||||
server_description='description3',
|
||||
server_servermodel_id=2)
|
||||
servername='name3',
|
||||
serverdescription='description3',
|
||||
servermodelid=2)
|
||||
assert list(config_module.server) == [3, 4]
|
||||
assert set(config_module.server[4]) == {'server', 'server_to_deploy', 'funcs_file'}
|
||||
assert config_module.server[4]['funcs_file'] == 'tests/data/2/funcs.py'
|
||||
assert config_module.server[4]['funcs_file'] == 'cache/2.creolefuncs'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_server_deleted():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
assert list(config_module.server) == [3]
|
||||
@ -85,9 +82,9 @@ async def test_server_deleted():
|
||||
'server.created',
|
||||
fake_context,
|
||||
server_id=4,
|
||||
server_name='name4',
|
||||
server_description='description4',
|
||||
server_servermodel_id=2)
|
||||
servername='name4',
|
||||
serverdescription='description4',
|
||||
servermodelid=2)
|
||||
assert list(config_module.server) == [3, 4]
|
||||
await dispatcher.publish('v1',
|
||||
'server.deleted',
|
||||
@ -100,7 +97,6 @@ async def test_server_deleted():
|
||||
async def test_servermodel_created():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
assert list(config_module.servermodel) == [1, 2]
|
||||
@ -109,186 +105,187 @@ async def test_servermodel_created():
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.created',
|
||||
fake_context,
|
||||
servermodel_id=3,
|
||||
servermodel_description='name3',
|
||||
release_id=1,
|
||||
servermodel_name='name3')
|
||||
servermodelid=3,
|
||||
servermodeldescription='name3',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodelname='name3')
|
||||
assert list(config_module.servermodel) == [1, 2, 3]
|
||||
assert not list(await config_module.servermodel[3].config.parents())
|
||||
assert not list(config_module.servermodel[3].config.parents())
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_servermodel_herited_created():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
assert list(config_module.servermodel) == [1, 2]
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.created',
|
||||
fake_context,
|
||||
servermodel_id=3,
|
||||
servermodel_name='name3',
|
||||
release_id=1,
|
||||
servermodel_description='name3',
|
||||
servermodel_parents_id=[1])
|
||||
servermodelid=3,
|
||||
servermodelname='name3',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name3',
|
||||
servermodelparentsid=[1])
|
||||
assert list(config_module.servermodel) == [1, 2, 3]
|
||||
assert len(list(await config_module.servermodel[3].config.parents())) == 1
|
||||
assert len(list(config_module.servermodel[3].config.parents())) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_servermodel_multi_herited_created():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
assert list(config_module.servermodel) == [1, 2]
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.created',
|
||||
fake_context,
|
||||
servermodel_id=3,
|
||||
servermodel_name='name3',
|
||||
release_id=1,
|
||||
servermodel_description='name3',
|
||||
servermodel_parents_id=[1, 2])
|
||||
servermodelid=3,
|
||||
servermodelname='name3',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name3',
|
||||
servermodelparentsid=[1, 2])
|
||||
assert list(config_module.servermodel) == [1, 2, 3]
|
||||
assert len(list(await config_module.servermodel[3].config.parents())) == 2
|
||||
assert len(list(config_module.servermodel[3].config.parents())) == 2
|
||||
|
||||
|
||||
#@pytest.mark.asyncio
|
||||
#async def test_servermodel_updated_not_exists():
|
||||
# config_module = dispatcher.get_service('config')
|
||||
# fake_context = get_fake_context('config')
|
||||
# config_module.cache_root_path = 'tests/data'
|
||||
# await config_module.on_join(fake_context)
|
||||
# #
|
||||
# assert list(config_module.servermodel) == [1, 2]
|
||||
# await dispatcher.publish('v1',
|
||||
# 'servermodel.updated',
|
||||
# fake_context,
|
||||
# servermodel_id=3,
|
||||
# servermodel_name='name3',
|
||||
# release_id=1,
|
||||
# servermodel_description='name3',
|
||||
# servermodel_parents_id=[1, 2])
|
||||
# assert list(config_module.servermodel) == [1, 2, 3]
|
||||
# assert len(list(await config_module.servermodel[3].config.parents())) == 2
|
||||
@pytest.mark.asyncio
|
||||
async def test_servermodel_updated_not_exists():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
assert list(config_module.servermodel) == [1, 2]
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.updated',
|
||||
fake_context,
|
||||
servermodelid=3,
|
||||
servermodelname='name3',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name3',
|
||||
servermodelparentsid=[1, 2])
|
||||
assert list(config_module.servermodel) == [1, 2, 3]
|
||||
assert len(list(config_module.servermodel[3].config.parents())) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_servermodel_updated1():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_servermodel_updated1():
|
||||
# config_module = dispatcher.get_service('config')
|
||||
# fake_context = get_fake_context('config')
|
||||
# config_module.cache_root_path = 'tests/data'
|
||||
# await config_module.on_join(fake_context)
|
||||
# #
|
||||
# assert list(config_module.servermodel) == [1, 2]
|
||||
# metaconfig1 = config_module.servermodel[1]
|
||||
# metaconfig2 = config_module.servermodel[2]
|
||||
# mixconfig1 = (await metaconfig1.config.list())[0]
|
||||
# mixconfig2 = (await metaconfig2.config.list())[0]
|
||||
# assert len(list(await metaconfig1.config.parents())) == 0
|
||||
# assert len(list(await metaconfig2.config.parents())) == 1
|
||||
# assert len(list(await mixconfig1.config.list())) == 1
|
||||
# assert len(list(await mixconfig2.config.list())) == 0
|
||||
# #
|
||||
# await dispatcher.publish('v1',
|
||||
# 'servermodel.updated',
|
||||
# fake_context,
|
||||
# servermodel_id=1,
|
||||
# servermodel_name='name1-1',
|
||||
# release_id=1,
|
||||
# servermodel_description='name1-1')
|
||||
# assert set(config_module.servermodel) == {1, 2}
|
||||
# assert config_module.servermodel[1].information.get('servermodel_name') == 'name1-1'
|
||||
# assert metaconfig1 != config_module.servermodel[1]
|
||||
# assert metaconfig2 == config_module.servermodel[2]
|
||||
# metaconfig1 = config_module.servermodel[1]
|
||||
# assert mixconfig1 != next(metaconfig1.config.list())
|
||||
# mixconfig1 = next(metaconfig1.config.list())
|
||||
# #
|
||||
# assert len(list(await metaconfig1.config.parents())) == 0
|
||||
# assert len(list(await metaconfig2.config.parents())) == 1
|
||||
# assert len(list(await mixconfig1.config.list())) == 1
|
||||
# assert len(list(await mixconfig2.config.list())) == 0
|
||||
assert list(config_module.servermodel) == [1, 2]
|
||||
metaconfig1 = config_module.servermodel[1]
|
||||
metaconfig2 = config_module.servermodel[2]
|
||||
mixconfig1 = next(metaconfig1.config.list())
|
||||
mixconfig2 = next(metaconfig2.config.list())
|
||||
assert len(list(metaconfig1.config.parents())) == 0
|
||||
assert len(list(metaconfig2.config.parents())) == 1
|
||||
assert len(list(mixconfig1.config.list())) == 1
|
||||
assert len(list(mixconfig2.config.list())) == 0
|
||||
#
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.updated',
|
||||
fake_context,
|
||||
servermodelid=1,
|
||||
servermodelname='name1-1',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name1-1')
|
||||
assert set(config_module.servermodel) == {1, 2}
|
||||
assert config_module.servermodel[1].information.get('servermodel_name') == 'name1-1'
|
||||
assert metaconfig1 != config_module.servermodel[1]
|
||||
assert metaconfig2 == config_module.servermodel[2]
|
||||
metaconfig1 = config_module.servermodel[1]
|
||||
assert mixconfig1 != next(metaconfig1.config.list())
|
||||
mixconfig1 = next(metaconfig1.config.list())
|
||||
#
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_servermodel_updated2():
|
||||
# config_module = dispatcher.get_service('config')
|
||||
# fake_context = get_fake_context('config')
|
||||
# config_module.cache_root_path = 'tests/data'
|
||||
# await config_module.on_join(fake_context)
|
||||
# # create a new servermodel
|
||||
# assert list(config_module.servermodel) == [1, 2]
|
||||
# mixconfig1 = next(config_module.servermodel[1].config.list())
|
||||
# mixconfig2 = next(config_module.servermodel[2].config.list())
|
||||
# assert len(list(mixconfig1.config.list())) == 1
|
||||
# assert len(list(mixconfig2.config.list())) == 0
|
||||
# await dispatcher.publish('v1',
|
||||
# 'servermodel.created',
|
||||
# fake_context,
|
||||
# servermodel_id=3,
|
||||
# servermodel_name='name3',
|
||||
# release_id=1,
|
||||
# servermodel_description='name3',
|
||||
# servermodel_parents_id=[1])
|
||||
# assert list(config_module.servermodel) == [1, 2, 3]
|
||||
# assert len(list(await config_module.servermodel[3].config.parents())) == 1
|
||||
# assert await config_module.servermodel[3].information.get('servermodel_name') == 'name3'
|
||||
# assert len(list(await mixconfig1.config.list())) == 2
|
||||
# assert len(list(await mixconfig2.config.list())) == 0
|
||||
# #
|
||||
# await dispatcher.publish('v1',
|
||||
# 'servermodel.updated',
|
||||
# fake_context,
|
||||
# servermodel_id=3,
|
||||
# servermodel_name='name3-1',
|
||||
# release_id=1,
|
||||
# servermodel_description='name3-1',
|
||||
# servermodel_parents_id=[1, 2])
|
||||
# assert list(config_module.servermodel) == [1, 2, 3]
|
||||
# assert config_module.servermodel[3].information.get('servermodel_name') == 'name3-1'
|
||||
# assert len(list(mixconfig1.config.list())) == 2
|
||||
# assert len(list(mixconfig2.config.list())) == 1
|
||||
assert len(list(metaconfig1.config.parents())) == 0
|
||||
assert len(list(metaconfig2.config.parents())) == 1
|
||||
assert len(list(mixconfig1.config.list())) == 1
|
||||
assert len(list(mixconfig2.config.list())) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_servermodel_updated2():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
await config_module.on_join(fake_context)
|
||||
# create a new servermodel
|
||||
assert list(config_module.servermodel) == [1, 2]
|
||||
mixconfig1 = next(config_module.servermodel[1].config.list())
|
||||
mixconfig2 = next(config_module.servermodel[2].config.list())
|
||||
assert len(list(mixconfig1.config.list())) == 1
|
||||
assert len(list(mixconfig2.config.list())) == 0
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.created',
|
||||
fake_context,
|
||||
servermodelid=3,
|
||||
servermodelname='name3',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name3',
|
||||
servermodelparentsid=[1])
|
||||
assert list(config_module.servermodel) == [1, 2, 3]
|
||||
assert len(list(config_module.servermodel[3].config.parents())) == 1
|
||||
assert config_module.servermodel[3].information.get('servermodel_name') == 'name3'
|
||||
assert len(list(mixconfig1.config.list())) == 2
|
||||
assert len(list(mixconfig2.config.list())) == 0
|
||||
#
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.updated',
|
||||
fake_context,
|
||||
servermodelid=3,
|
||||
servermodelname='name3-1',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name3-1',
|
||||
servermodelparentsid=[1, 2])
|
||||
assert list(config_module.servermodel) == [1, 2, 3]
|
||||
assert config_module.servermodel[3].information.get('servermodel_name') == 'name3-1'
|
||||
assert len(list(mixconfig1.config.list())) == 2
|
||||
assert len(list(mixconfig2.config.list())) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_servermodel_updated_config():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_servermodel_updated_config():
|
||||
# config_module = dispatcher.get_service('config')
|
||||
# fake_context = get_fake_context('config')
|
||||
# config_module.cache_root_path = 'tests/data'
|
||||
# await config_module.on_join(fake_context)
|
||||
# #
|
||||
# config_module.servermodel[1].property.read_write()
|
||||
# assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
# config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.set('oui')
|
||||
# assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
# #
|
||||
# await dispatcher.publish('v1',
|
||||
# 'servermodel.updated',
|
||||
# fake_context,
|
||||
# servermodel_id=1,
|
||||
# servermodel_name='name1-1',
|
||||
# release_id=1,
|
||||
# servermodel_description='name1-1')
|
||||
# assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
config_module.servermodel[1].property.read_write()
|
||||
assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.set('oui')
|
||||
assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
#
|
||||
await dispatcher.publish('v1',
|
||||
'servermodel.updated',
|
||||
fake_context,
|
||||
servermodelid=1,
|
||||
servermodelname='name1-1',
|
||||
subreleasename='2.7.0',
|
||||
sourceid=1,
|
||||
servermodeldescription='name1-1')
|
||||
assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_server_configuration_get():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
await config_module.server[3]['server_to_deploy'].property.read_write()
|
||||
assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.set('oui')
|
||||
assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert await config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
config_module.server[3]['server_to_deploy'].property.read_write()
|
||||
assert config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.set('oui')
|
||||
assert config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
#
|
||||
values = await dispatcher.call('v1',
|
||||
'config.configuration.server.get',
|
||||
@ -322,17 +319,16 @@ async def test_server_configuration_get():
|
||||
async def test_config_deployed():
|
||||
config_module = dispatcher.get_service('config')
|
||||
fake_context = get_fake_context('config')
|
||||
config_module.cache_root_path = 'tests/data'
|
||||
await config_module.on_join(fake_context)
|
||||
#
|
||||
await config_module.server[3]['server_to_deploy'].property.read_write()
|
||||
assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.set('oui')
|
||||
assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert await config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
config_module.server[3]['server_to_deploy'].property.read_write()
|
||||
assert config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.set('oui')
|
||||
assert config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
|
||||
values = await dispatcher.publish('v1',
|
||||
'config.configuration.server.deploy',
|
||||
fake_context,
|
||||
server_id=3)
|
||||
assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert await config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
assert config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user