From 7757912b55a0d423615c409b7d4ad0a1d177d361 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 21 Feb 2020 16:08:31 +0100 Subject: [PATCH] do not ask release_id --- README.md | 65 ++++++++++++---- .../v1/messages/applicationservice.create.yml | 5 -- .../messages/applicationservice.describe.yml | 11 ++- src/risotto/config.py | 2 - .../applicationservice/applicationservice.py | 78 +++++++++++++++---- src/risotto/services/config/config.py | 5 +- .../services/servermodel/servermodel.py | 17 ++-- src/risotto/services/source/source.py | 23 +----- src/risotto/services/template/template.py | 3 +- src/risotto/services/uri/uri.py | 2 - 10 files changed, 139 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index fbb2007..8bbe5fa 100644 --- a/README.md +++ b/README.md @@ -53,16 +53,58 @@ drop table value; drop table property; drop table permissive; drop table informa ./script/cucchiaiata applicationservice.dataset.updated -s eole -r last ./script/cucchiaiata servermodel.dataset.updated -s eole -r last -# Create a server -./script/cucchiaiata server.create -s test -d description -m eolebase -n eole -r last +# Create a new user and set role 'server_rw' for this server +./script/cucchiaiata user.create -l gnunux -n gnunux -s gnunux +./script/cucchiaiata user.role.create -u gnunux -n 'server_rw' -a 'Server.ServerName' -v test + +# Heritage +## ACA +./script/cucchiaiata servermodel.create -n aca -d Aca -p eolebase -s eole -r last +./script/cucchiaiata session.servermodel.start -s aca +S=xxxxxxxxxxxxxxxxxxxxxx +### verif +./script/cucchiaiata session.servermodel.get -s $S -n creole.reseau.unbound_route_address +./script/cucchiaiata session.servermodel.get -s $S -n creole.reseau.unbound_domain_name +./script/cucchiaiata session.servermodel.get -s $S -n creole.serveur_dns.unbound_local_zones +./script/cucchiaiata session.servermodel.get -s $S -n creole.reseau.unbound_ip_address_cidr + +./script/cucchiaiata session.servermodel.configure -s $S --creole.reseau.unbound_route_address 192.168.1.2 +./script/cucchiaiata session.servermodel.configure -s $S --creole.serveur_dns.unbound_allowed_client_cidr 192.168.1.0/24 +./script/cucchiaiata session.servermodel.stop -s $S -a + +## etab1 +./script/cucchiaiata servermodel.create -n etab1 -d "Etab 1" -p aca -s internal -r last +./script/cucchiaiata session.servermodel.start -s etab1 +S=xxxxxxxxxxxxxxxxxxxxxx +./script/cucchiaiata session.servermodel.configure -s $S --creole.reseau.unbound_domain_name test.cadoles.com +./script/cucchiaiata session.servermodel.stop -s $S -a + +## unbound +./script/cucchiaiata servermodel.create -n unbound -d "generic unbound configuration" -p eolebase -s eole -r last +./script/cucchiaiata session.servermodel.start -s unbound +S=xxxxxxxxxxxxxxxxxxxxxx +./script/cucchiaiata session.servermodel.configure -s $S --creole.serveur_dns.unbound_local_zones cadoles.com +./script/cucchiaiata session.servermodel.filter -s $S -n unbound +./script/cucchiaiata session.servermodel.configure -s $S --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.hostname_cadoles_com toto titi +./script/cucchiaiata session.servermodel.configure -s $S --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.ip_cadoles_com 0 192.168.1.25 +./script/cucchiaiata session.servermodel.configure -s $S --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.type_cadoles_com 1 CNAME +./script/cucchiaiata session.servermodel.configure -s $S --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.cname_cadoles_com 1 toto.cadoles.com +./script/cucchiaiata session.servermodel.stop -s $S -a + +## unbound_etab1 +./script/cucchiaiata servermodel.create -n unbound_etab1 -d "unbound configuration for etab1" -p etab1 unbound -s internal -r last + +### verif +./script/cucchiaiata session.servermodel.start -s unbound_etab1 +S=xxxxxxxxxxxxxxxxxxxxxx +XXXXX + +# Create a server +./script/cucchiaiata server.create -s test -d description -m unbound_etab1 -n internal -r last -# Configure the server ./script/cucchiaiata session.server.start -s test S=xxxxxxxxxxxxxxxxxxxxxx -./script/cucchiaiata session.server.configure -s $S --creole.reseau.unbound_ip_address_cidr 192.168.1.1/24 --creole.reseau.unbound_route_address 192.168.1.2 --creole.serveur_dns.unbound_allowed_client_cidr 192.168.1.0/24 --creole.serveur_dns.unbound_local_zones cadoles.com -./script/cucchiaiata session.server.configure -s $S --creole.reseau.unbound_domain_name test.cadoles.com -./script/cucchiaiata session.server.filter -s $S -n unbound -./script/cucchiaiata session.server.configure -s $S --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.hostname_cadoles_com toto titi --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.ip_cadoles_com 0 192.168.1.25 --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.type_cadoles_com 1 CNAME --unbound.unbound_zone_cadoles_com.hostname_cadoles_com.cname_cadoles_com 1 toto.cadoles.com +./script/cucchiaiata session.server.configure -s $S --creole.reseau.unbound_ip_address_cidr 192.168.1.1/24 ./script/cucchiaiata session.server.validate -s $S ./script/cucchiaiata session.server.stop -s $S -a @@ -70,11 +112,6 @@ S=xxxxxxxxxxxxxxxxxxxxxx ./script/cucchiaiata config.configuration.server.deploy -s test ./script/cucchiaiata template.generate -s test -# Create a new user and set role 'server_rw' for this server -./script/cucchiaiata user.create -l gnunux -n gnunux -s gnunux -./script/cucchiaiata user.role.create -u gnunux -n 'server_rw' -a 'Server.ServerName' -v test -# Heritage -./script/cucchiaiata servermodel.create -n aca -d Aca -p eolebase -s eole -r last -./script/cucchiaiata session.servermodel.start -s aca -./script/cucchiaiata session.servermodel.configure -s $S --creole.reseau.unbound_domain_name test.cadoles.com +# OpenSSH: +./script/cucchiaiata server.create -s test -d description -m eolebase -n internal -r last diff --git a/messages/v1/messages/applicationservice.create.yml b/messages/v1/messages/applicationservice.create.yml index ab95b6b..de7b99a 100644 --- a/messages/v1/messages/applicationservice.create.yml +++ b/messages/v1/messages/applicationservice.create.yml @@ -22,11 +22,6 @@ parameters: 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 diff --git a/messages/v1/messages/applicationservice.describe.yml b/messages/v1/messages/applicationservice.describe.yml index ac4bd3d..2a3efeb 100644 --- a/messages/v1/messages/applicationservice.describe.yml +++ b/messages/v1/messages/applicationservice.describe.yml @@ -12,11 +12,16 @@ parameters: shortarg: n description: | Nom du service applicatif à créer. - release_id: - type: Number + source_name: + type: String + shortarg: s + description: | + Nom de la source. + release_distribution: + type: String shortarg: r description: | - Identifiant de la version associée au service applicatif. + Version associée au service applicatif. response: type: ApplicationService diff --git a/src/risotto/config.py b/src/risotto/config.py index 086f5c1..3482828 100644 --- a/src/risotto/config.py +++ b/src/risotto/config.py @@ -3,7 +3,6 @@ INTERNAL_USER = 'internal' CONFIGURATION_DIR = 'configurations' TEMPLATE_DIR = 'templates' TMP_DIR = 'tmp' -ROUGAIL_DTD_PATH = '../rougail/data/creole.dtd' DEFAULT_USER = 'Anonymous' DEFAULT_DSN = 'postgres:///risotto?host=/var/run/postgresql/&user=risotto' DEFAULT_TIRAMISU_DSN = 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu' @@ -23,7 +22,6 @@ def get_config(): 'debug': True, 'internal_user': 'internal', 'check_role': True, - 'rougail_dtd_path': '../rougail/data/creole.dtd', 'admin_user': DEFAULT_USER}, 'source': {'root_path': '/srv/seed'}, 'cache': {'root_path': '/var/cache/risotto'}, diff --git a/src/risotto/services/applicationservice/applicationservice.py b/src/risotto/services/applicationservice/applicationservice.py index 27bbcf2..aadd54f 100644 --- a/src/risotto/services/applicationservice/applicationservice.py +++ b/src/risotto/services/applicationservice/applicationservice.py @@ -15,6 +15,21 @@ class Risotto(Controller): def __init__(self, test: bool) -> None: self.source_root_path = get_config().get('source').get('root_path') + self.internal_source_name = get_config()['servermodel']['internal_source'] + self.internal_distribution_name = get_config()['servermodel']['internal_distribution'] + + async def on_join(self, + risotto_context: Context) -> None: + internal_source = await self.call('v1.source.create', + risotto_context, + source_name=self.internal_source_name, + source_url='none') + internal_release = await self.call('v1.source.release.create', + risotto_context, + source_name=self.internal_source_name, + release_name='none', + release_distribution=self.internal_distribution_name) + self.internal_release_id = internal_release['release_id'] async def _applicationservice_create(self, risotto_context: Context, @@ -35,30 +50,51 @@ class Risotto(Controller): 'applicationservice_release_id': release_id, 'applicationservice_id': applicationservice_id} + @register('v1.applicationservice.dependency.add') + async def applicationservice_dependency_add(self, + risotto_context: Context, + applicationservice_name: str, + applicationservice_dependency: str, + source_name: str, + release_distribution: str) -> Dict: + release = await self.call('v1.source.release.describe', + risotto_context, + source_name=source_name, + release_distribution=release_distribution) + as_descr = await self._applicationservice_describe(risotto_context, + applicationservice_name, + self.internal_release_id) + dependency_descr = await self._applicationservice_describe(risotto_context, + dependency, + release['release_id']) + as_descr['applicationservice_dependencies'].append(dependency_descr['applicationservice_id']) + sql = "UPDATE ApplicationService SET ApplicationServiceDependencies = $1 WHERE ApplicationServiceId = $2" + await risotto_context.connection.execute(sql, + as_descr['applicationservice_dependencies'], + as_descr['applicationserviceid']) + return as_descr + + @register('v1.applicationservice.create') async def applicationservice_create(self, risotto_context: Context, applicationservice_name: str, applicationservice_description: str, - applicationservice_dependencies: List[int], - release_id: int) -> Dict: + applicationservice_dependencies: List[int]) -> Dict: return await self._applicationservice_create(risotto_context, applicationservice_name, applicationservice_description, applicationservice_dependencies, - release_id) + self.internal_release_id) @register('v1.applicationservice.dataset.updated') 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', + release = await self.call('v1.source.release.describe', risotto_context, - source_id=source['source_id'], + source_name=source_name, release_distribution=release_distribution) applicationservice_path = join(self.source_root_path, source_name, @@ -81,7 +117,7 @@ class Risotto(Controller): 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'): @@ -104,11 +140,10 @@ class Risotto(Controller): raise Exception(_(f'unknown service with ID {applicationservice_id}')) return dict(applicationservice) - @register('v1.applicationservice.describe') - async def applicationservice_describe(self, - risotto_context: Context, - applicationservice_name, - release_id): + 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 @@ -119,3 +154,18 @@ class Risotto(Controller): if applicationservice is None: raise Exception(_(f'unknown service {applicationservice_name} in release ID {release_id}')) return dict(applicationservice) + + + @register('v1.applicationservice.describe') + async def applicationservice_describe(self, + risotto_context: Context, + applicationservice_name, + source_name, + release_distribution): + release = await self.call('v1.source.release.describe', + risotto_context, + source_name=source_name, + release_distribution=release_distribution) + return await self._applicationservice_describe(risotto_context, + applicationservice_name, + release['release_id']) diff --git a/src/risotto/services/config/config.py b/src/risotto/services/config/config.py index 6fcf2bb..5f0559f 100644 --- a/src/risotto/services/config/config.py +++ b/src/risotto/services/config/config.py @@ -7,10 +7,11 @@ from typing import Dict, List from tiramisu import Storage, delete_session, MetaConfig, MixConfig from rougail import load as rougail_load +from rougail.config import dtdfilename from ...controller import Controller from ...register import register -from ...config import ROUGAIL_DTD_PATH, get_config +from ...config import get_config from ...context import Context from ...utils import _ from ...error import CallError, RegistrationError @@ -110,7 +111,7 @@ class Risotto(Controller): # build tiramisu's session ID session_id = f'v_{servermodel_id}' optiondescription = rougail_load(xmlroot, - ROUGAIL_DTD_PATH, + dtdfilename, funcs_file) # build servermodel metaconfig (v_xxx.m_v_xxx) diff --git a/src/risotto/services/servermodel/servermodel.py b/src/risotto/services/servermodel/servermodel.py index 319d836..12a9562 100644 --- a/src/risotto/services/servermodel/servermodel.py +++ b/src/risotto/services/servermodel/servermodel.py @@ -5,6 +5,7 @@ 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 _ @@ -69,7 +70,6 @@ class Risotto(Controller): as_names_str = '", "'.join(as_names) await log.info(risotto_context, _(f'gen funcs for "{servermodel_name}" with application services "{as_names_str}"')) - #eolobj = CreoleObjSpace(get_config()['global']['rougail_dtd_path']) async def servermodel_gen_schema(self, servermodel_name: str, @@ -107,7 +107,7 @@ class Risotto(Controller): continue as_names.add(applicationservice_name) extras.append((namespace, [extra_dir])) - eolobj = CreoleObjSpace(get_config()['global']['rougail_dtd_path']) + eolobj = CreoleObjSpace(dtdfilename) as_names_str = '", "'.join(as_names) await log.info(risotto_context, _(f'gen schema for "{servermodel_name}" with application services "{as_names_str}"')) @@ -178,8 +178,7 @@ class Risotto(Controller): risotto_context, applicationservice_name=as_name, applicationservice_description=as_description, - applicationservice_dependencies=dependencies, - release_id=self.internal_release_id) + applicationservice_dependencies=dependencies) applicationservice_id = applicationservice['applicationservice_id'] servermodel_id = await risotto_context.connection.fetchval(servermodel_insert, servermodel_name, @@ -244,12 +243,9 @@ class Risotto(Controller): 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', + release = await self.call('v1.source.release.describe', risotto_context, - source_id=source['source_id'], + source_name=source_name, release_distribution=release_distribution) release_id = release['release_id'] servermodel_path = join(self.source_root_path, @@ -294,7 +290,8 @@ class Risotto(Controller): applicationservice = await self.call('v1.applicationservice.describe', risotto_context, applicationservice_name=depend, - release_id=release_id) + source_name=source_name, + release_distribution=release_distribution) dependencies.append(applicationservice['applicationservice_id']) sm_name = servermodel_description['name'] sm_description = servermodel_description['description'] diff --git a/src/risotto/services/source/source.py b/src/risotto/services/source/source.py index 35cbc25..d12b88e 100644 --- a/src/risotto/services/source/source.py +++ b/src/risotto/services/source/source.py @@ -122,10 +122,10 @@ class Risotto(Controller): return [dict(r) for r in result] @register('v1.source.release.describe') - async def release_list(self, - risotto_context, - source_name: str, - release_distribution: str) -> Dict: + async def release_describe(self, + risotto_context, + source_name: str, + 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 Source.SourceName=$1 AND Source.SourceId=Release.ReleaseSourceId AND Release.ReleaseDistribution=$2""" @@ -148,18 +148,3 @@ class Risotto(Controller): if not result: raise Exception(_(f'unknown release id {release_id}')) return dict(result) - - @register('v1.source.release.get_by_distribution') - 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) diff --git a/src/risotto/services/template/template.py b/src/risotto/services/template/template.py index 7fcb931..8189d9e 100644 --- a/src/risotto/services/template/template.py +++ b/src/risotto/services/template/template.py @@ -60,6 +60,7 @@ class Risotto(Controller): templates_dir, tmp_dir, configurations_dir) - del meta + del meta, config + # FIXME del session ! return {'server_name': server_name, 'template_dir': configurations_dir} diff --git a/src/risotto/services/uri/uri.py b/src/risotto/services/uri/uri.py index d5fcfe8..da7ae93 100644 --- a/src/risotto/services/uri/uri.py +++ b/src/risotto/services/uri/uri.py @@ -53,8 +53,6 @@ class Risotto(Controller): '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._uri_role_join(risotto_context,