improve frappy server management

- do connect in background when the frappy server is not running
  on startup
This commit is contained in:
2023-09-20 10:02:09 +02:00
parent 1e2721579d
commit ba0f4e62b6
2 changed files with 184 additions and 83 deletions

View File

@@ -22,7 +22,8 @@
from nicos import session, config
from nicos.utils import printTable
from nicos.commands import helparglist, usercommand
from servicemanager import FrappyManager
from .devices import get_frappy_config, all_info
from servicemanager import FrappyManager, SeaManager
SERVICES = FrappyManager.services
@@ -30,8 +31,9 @@ SERVICES = FrappyManager.services
@usercommand
def set_se_list():
frappy_config = session.devices['frappy_config']
frappy_config.set_envlist()
fc = get_frappy_config()
if fc:
fc.set_envlist()
@usercommand
@@ -47,7 +49,11 @@ def frappy(*args, main=None, stick=None, addons=None, force=False):
- frappy('restart') # restart all frappy servers
- frappy(stick='restart') # restart stick frappy server
"""
confirmed = FrappyManager().cfg_from_sea(config.instrument).get('confirmed')
fc = get_frappy_config()
if not fc:
return
stickarg = stick
confirmed = SeaManager().get_cfg(config.instrument, 'sea', True).split('/', 1)[0]
if args:
if main is not None:
raise TypeError('got multiple values for main')
@@ -60,9 +66,8 @@ def frappy(*args, main=None, stick=None, addons=None, force=False):
if main == '':
stick = '' # remove stick with main
else:
allsticks = FrappyManager().all_cfg(config.instrument, 'stick')
stickcfg = main + 'stick'
if stickcfg in allsticks:
if FrappyManager().is_cfg(config.instrument, 'stick', stickcfg):
# if a default stick is available, start this also
stick = stickcfg
else:
@@ -75,12 +80,30 @@ def frappy(*args, main=None, stick=None, addons=None, force=False):
if addons is not None:
raise TypeError('got multiple values for addons')
addons = ','.join(alist)
elif main is None and stick is None and addons is None: # bare frappy() command
fc.show_config(fc.check_services())
return
if confirmed and confirmed != main and main not in (None, 'restart') and not force:
session.log.warning('%r is plugged to the cryostat control rack', confirmed)
session.log.warning('if you are sure, use frappy(..., force=True)', confirmed)
cmd = all_info({'main': main, 'stick': stickarg, 'addons': addons}, '')[:-1] + ', force=True)'
session.log.warning(f'if you are sure, use: %s', cmd)
raise TypeError('refuse to override plugged device')
frappy_config = session.devices['frappy_config']
frappy_config.show_config(*frappy_config.check_or_start(main, stick, addons))
fc.show_config(fc.start_services(main, stick, addons))
@usercommand
def frappy_main(*args):
raise NameError('frappy_main(<cfg>) is no longer avaiable, use frappy(<cfg>) instead')
@usercommand
def frappy_stick(*args):
raise NameError('frappy_stick(<cfg>) is no longer avaiable, use frappy(stick=<cfg>) instead')
@usercommand
def frappy_addons(*args):
raise NameError('frappy_addons(<cfg>) is no longer avaiable, use frappy(addons=<cfg>) instead')
@usercommand
@@ -108,4 +131,6 @@ def frappy_list(service=None):
@usercommand
def frappy_changed():
session.devices['frappy_config'].changed()
fc = get_frappy_config()
if fc:
fc.changed()