From b978489695c88ad4baa2d5d5b2906b5af465b9c2 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 12 Sep 2023 13:19:52 +0200 Subject: [PATCH] improve frappy() command - only informational effect without arguments - consider also cfg from sea - on nicos restart, frappy nodes look also for sea device --- commands.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/commands.py b/commands.py index b635278..9b5d1cd 100644 --- a/commands.py +++ b/commands.py @@ -29,6 +29,83 @@ from servicemanager import FrappyManager, SeaManager SERVICES = FrappyManager.services +def all_info(all_cfg, prefix='currently configured: '): + info = [] + addkwd = False + for srv in SERVICES: + cfginfo = all_cfg.get(srv) + if cfginfo is None: + addkwd = True + elif addkwd: + info.append('%s=%r' % (srv, cfginfo)) + else: + info.append(repr(cfginfo)) + return f"{prefix}frappy({', '.join(info)})" + + +def frappy_start(**services): + """start/stop frappy servers + + for example: frappy_start(main='xy', stick='') + - restart main server with cfg='xy' + - stop stick server + - do not touch addons server + + in addition, if a newly given cfg is already used on a running server, + this cfg is removed from the server (remark: cfg might be a comma separated list) + """ + frappy_config = session.devices.get('frappy_config') + for service in SERVICES: + if services.get(service) == '': + seaconn = session.devices.get(f'se_sea_{service}') + if seaconn and seaconn._attached_secnode: + seaconn.communicate('frappy_remove %s' % service) + used_cfg = {} + all_cfg = {} + new_cfg = [] + remove_cfg = [] + for service in reversed(SERVICES): + secnode = session.devices.get('se_' + service) + cfginfo = services.get(service) + if cfginfo is not None: + if cfginfo: + new_cfg.append((service, secnode, cfginfo)) + else: + remove_cfg.append(secnode) + if secnode: + secnode('') + if secnode: + all_cfg[service] = secnode.get_info() + + # check cfg is not used twice + for cfg in (cfginfo or '').split(','): + cfg = cfg.strip() + if cfg: + prev = used_cfg.get(cfg) + if prev: + raise ValueError('%r can not be used in both %s and %s' % (cfg, prev, service)) + used_cfg[cfg] = service + + if new_cfg: + for service, secnode, cfginfo in new_cfg: + nodename = 'se_' + service + if not secnode: + AddSetup('frappy_' + service) + secnode = session.devices[nodename] + secnode(cfginfo) + all_cfg[service] = secnode.get_info() + CreateDevice(nodename) + cleanup_defunct() + CreateAllDevices() + if frappy_config: + frappy_config.set_envlist() + else: + applyAliasConfig() + for secnode in remove_cfg: + secnode.disable() + return all_cfg + + @usercommand def set_se_list(): fc = get_frappy_config()