From 37993add1089f594aca394063d3333c6afd40084 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 25 Feb 2020 08:33:00 +0100 Subject: [PATCH] readd std server configuration --- README.md | 1 + .../config.configuration.server.get.yml | 4 ++ src/risotto/services/config/config.py | 64 +++++++++++++++---- src/risotto/services/session/session.py | 4 +- src/risotto/services/session/storage.py | 2 +- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 113d645..1e41c95 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ S=xxxxxxxxxxxxxxxxxxxxxx ./script/cucchiaiata session.server.stop -s $S -a # Generate configuration +./script/cucchiaiata config.configuration.server.deploy -s test ./script/cucchiaiata template.generate -s test # OpenSSH diff --git a/messages/v1/messages/config.configuration.server.get.yml b/messages/v1/messages/config.configuration.server.get.yml index a2b35f7..92e5049 100644 --- a/messages/v1/messages/config.configuration.server.get.yml +++ b/messages/v1/messages/config.configuration.server.get.yml @@ -12,6 +12,10 @@ parameters: ref: Server.ServerName shortarg: s description: Nom du serveur. + deployed: + type: Boolean + description: Configuration de type déployée. + default: true response: type: ConfigConfiguration diff --git a/src/risotto/services/config/config.py b/src/risotto/services/config/config.py index 9144555..0356207 100644 --- a/src/risotto/services/config/config.py +++ b/src/risotto/services/config/config.py @@ -163,7 +163,6 @@ class Risotto(Controller): msg) # do link - # mix = await servermodel_parent.config.get('m_v_' + str(servermodel_parent_id)) try: await servermodel_parent.config.add(self.servermodel[servermodel_id]) except Exception as err: @@ -228,6 +227,10 @@ class Risotto(Controller): server_id, server_name, mixconfig), + 'server_to_deploy': await self.build_config(f'std_{server_id}', + server_id, + server_name, + mixconfig), 'funcs_file': self.get_funcs_filename(server_servermodel_id)} async def build_config(self, @@ -263,12 +266,11 @@ class Risotto(Controller): @register('v1.server.deleted') async def server_deleted(self, server_id: int) -> None: - # delete config to it's parents - config = self.server[server_id]['server'] - for parent in await config.config.parents(): - await parent.config.pop(await config.session.id()) - await config.session.reset() - # delete mixconfig + 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()) + await config.session.reset() del self.server[server_id] @register('v1.servermodel.created') @@ -309,7 +311,6 @@ class Risotto(Controller): await mixconfig.config.pop(await child.session.id()) for parent in await mixconfig.config.parents(): await parent.config.pop(await mixconfig.session.id()) - await mixconfig.session.reset() return children @register('v1.servermodel.updated') @@ -347,7 +348,8 @@ class Risotto(Controller): @register('v1.config.configuration.server.get') async def get_configuration(self, risotto_context: Context, - server_name: str) -> dict: + server_name: str, + deployed: bool) -> dict: server = await self.call('v1.server.describe', risotto_context, server_name=server_name) @@ -359,17 +361,57 @@ class Risotto(Controller): msg) raise CallError(msg) - server = self.server[server_id]['server'] + if deployed: + server = self.server[server_id]['server'] + else: + server = self.server[server_id]['server_to_deploy'] await server.property.read_only() try: configuration = await server.value.dict(fullpath=True, leader_to_list=True) except: - msg = _(f'No configuration available for server {server_id}') + if deployed: + msg = _(f'No configuration available for server {server_id}') + else: + msg = _(f'No undeployed configuration available for server {server_id}') await log.error_msg(risotto_context, None, msg) raise CallError(msg) return {'server_name': server_name, + 'deployed': deployed, 'configuration': configuration} + + @register('v1.config.configuration.server.deploy') + async def deploy_configuration(self, + risotto_context: Context, + server_name: str) -> Dict: + """Copy values, permissions, permissives from config 'to deploy' to active config + """ + server = await self.call('v1.server.describe', + risotto_context, + server_name=server_name) + server_id = server['server_id'] + # FIXME is server_to_deploy working? + config = self.server[server_id]['server'] + config_std = self.server[server_id]['server_to_deploy'] + + # when deploy, calculate force_store_value + ro = await 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') + rw = frozenset(list(rw) + ['force_store_value']) + await config_std.property.setdefault(rw, 'read_write', 'append') + await 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()) + + return {'server_id': server_id, + 'server_name': server_name, + 'deployed': True} diff --git a/src/risotto/services/session/session.py b/src/risotto/services/session/session.py index db336fc..2b27efe 100644 --- a/src/risotto/services/session/session.py +++ b/src/risotto/services/session/session.py @@ -79,7 +79,7 @@ class Risotto(Controller): if not server or server['server_id'] not in config_module.server: raise Exception(_(f'cannot find server with name {server_name}')) id = server['server_id'] - config = config_module.server[id]['server'] + config = config_module.server[id]['server_to_deploy'] storage = self.get_storage('server') @@ -287,7 +287,7 @@ class Risotto(Controller): id_ = session['id'] config_module = dispatcher.get_service('config') if type == 'server': - config = config_module.server[id_]['server'] + config = config_module.server[id_]['server_to_deploy'] else: config = config_module.servermodel[id_] if save: diff --git a/src/risotto/services/session/storage.py b/src/risotto/services/session/storage.py index 0c2b8be..fe71432 100644 --- a/src/risotto/services/session/storage.py +++ b/src/risotto/services/session/storage.py @@ -124,7 +124,7 @@ class Storage(object): class StorageServer(Storage): def get_config_name(self, server_id: int): - return f's_{server_id}' + return f'std_{server_id}' async def set_owner(self, config: Config,