[WIP] frappy() is now a device
This commit is contained in:
55
commands.py
55
commands.py
@ -36,61 +36,6 @@ def set_se_list():
|
|||||||
fc.set_envlist()
|
fc.set_envlist()
|
||||||
|
|
||||||
|
|
||||||
@usercommand
|
|
||||||
@helparglist('main [, stick [, addons]]')
|
|
||||||
def frappy(*args, main=None, stick=None, addons=None, force=False):
|
|
||||||
"""(re)start frappy server(s) with given configs and load setup if needed
|
|
||||||
|
|
||||||
- without argument: list running frappy servers, restart failed frappy servers
|
|
||||||
- frappy('<cfg>'): if available, the standard stick is added too
|
|
||||||
- frappy(''): the stick is removed too
|
|
||||||
- addons are not changed when not given
|
|
||||||
- frappy(main='<cfg>') # main cfg is changed, but stick is kept
|
|
||||||
- frappy('restart') # restart all frappy servers
|
|
||||||
- frappy(stick='restart') # restart stick frappy server
|
|
||||||
"""
|
|
||||||
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')
|
|
||||||
main = args[0]
|
|
||||||
if len(args) == 1: # special case: main given as single argument
|
|
||||||
if main == 'restart':
|
|
||||||
stick = 'restart'
|
|
||||||
addons = 'restart'
|
|
||||||
elif stick is None: # auto stick
|
|
||||||
if main == '':
|
|
||||||
stick = '' # remove stick with main
|
|
||||||
else:
|
|
||||||
stickcfg = main + 'stick'
|
|
||||||
if FrappyManager().is_cfg(config.instrument, 'stick', stickcfg):
|
|
||||||
# if a default stick is available, start this also
|
|
||||||
stick = stickcfg
|
|
||||||
else:
|
|
||||||
stick = '' # remove stick when main has changed
|
|
||||||
else:
|
|
||||||
if stick is not None:
|
|
||||||
raise TypeError('got multiple values for stick')
|
|
||||||
stick, *alist = args[1:]
|
|
||||||
if alist:
|
|
||||||
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)
|
|
||||||
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')
|
|
||||||
fc.show_config(fc.start_services(main, stick, addons))
|
|
||||||
|
|
||||||
|
|
||||||
@usercommand
|
@usercommand
|
||||||
def frappy_main(*args):
|
def frappy_main(*args):
|
||||||
raise NameError('frappy_main(<cfg>) is no longer avaiable, use frappy(<cfg>) instead')
|
raise NameError('frappy_main(<cfg>) is no longer avaiable, use frappy(<cfg>) instead')
|
||||||
|
75
devices.py
75
devices.py
@ -37,7 +37,7 @@ from nicos.services.daemon.script import RequestError, ScriptRequest
|
|||||||
from nicos.utils.comparestrings import compare
|
from nicos.utils.comparestrings import compare
|
||||||
from nicos.devices.secop.devices import get_attaching_devices
|
from nicos.devices.secop.devices import get_attaching_devices
|
||||||
from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice
|
from nicos.commands.basic import AddSetup, CreateAllDevices, CreateDevice
|
||||||
from servicemanager import FrappyManager
|
from servicemanager import FrappyManager, SeaManager
|
||||||
|
|
||||||
SERVICES = FrappyManager.services
|
SERVICES = FrappyManager.services
|
||||||
|
|
||||||
@ -264,6 +264,55 @@ class FrappyConfig(Device):
|
|||||||
self._cache.put(self, 'config', all_cfg)
|
self._cache.put(self, 'config', all_cfg)
|
||||||
return all_cfg
|
return all_cfg
|
||||||
|
|
||||||
|
def __call__(self, *args, main=None, stick=None, addons=None, force=False):
|
||||||
|
"""(re)start frappy server(s) with given configs and load setup if needed
|
||||||
|
|
||||||
|
- without argument: list running frappy servers, restart failed frappy servers
|
||||||
|
- frappy('<cfg>'): if available, the standard stick is added too
|
||||||
|
- frappy(''): the stick is removed too
|
||||||
|
- addons are not changed when not given
|
||||||
|
- frappy(main='<cfg>') # main cfg is changed, but stick is kept
|
||||||
|
- frappy('restart') # restart all frappy servers
|
||||||
|
- frappy(stick='restart') # restart stick frappy server
|
||||||
|
"""
|
||||||
|
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')
|
||||||
|
main = args[0]
|
||||||
|
if len(args) == 1: # special case: main given as single argument
|
||||||
|
if main == 'restart':
|
||||||
|
stick = 'restart'
|
||||||
|
addons = 'restart'
|
||||||
|
elif stick is None: # auto stick
|
||||||
|
if main == '':
|
||||||
|
stick = '' # remove stick with main
|
||||||
|
else:
|
||||||
|
stickcfg = main + 'stick'
|
||||||
|
if FrappyManager().is_cfg(config.instrument, 'stick', stickcfg):
|
||||||
|
# if a default stick is available, start this also
|
||||||
|
stick = stickcfg
|
||||||
|
else:
|
||||||
|
stick = '' # remove stick when main has changed
|
||||||
|
else:
|
||||||
|
if stick is not None:
|
||||||
|
raise TypeError('got multiple values for stick')
|
||||||
|
stick, *alist = args[1:]
|
||||||
|
if alist:
|
||||||
|
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
|
||||||
|
self.show_config(self.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)
|
||||||
|
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')
|
||||||
|
self.show_config(self.start_services(main, stick, addons))
|
||||||
|
|
||||||
def show_config(self, allcfg):
|
def show_config(self, allcfg):
|
||||||
guess_info = self.to_consider(allcfg)
|
guess_info = self.to_consider(allcfg)
|
||||||
# remove 'frappy_changed()' commands in script queue
|
# remove 'frappy_changed()' commands in script queue
|
||||||
@ -290,7 +339,7 @@ class FrappyConfig(Device):
|
|||||||
if self._servers_loaded:
|
if self._servers_loaded:
|
||||||
return None
|
return None
|
||||||
if self._initial_config is None:
|
if self._initial_config is None:
|
||||||
success = True
|
# we do this only once for all services
|
||||||
fm = FrappyManager()
|
fm = FrappyManager()
|
||||||
running = fm.get_cfg(config.instrument, None)
|
running = fm.get_cfg(config.instrument, None)
|
||||||
cache = self._getCache()
|
cache = self._getCache()
|
||||||
@ -309,25 +358,7 @@ class FrappyConfig(Device):
|
|||||||
cfgs['stick'] = running_stick
|
cfgs['stick'] = running_stick
|
||||||
else:
|
else:
|
||||||
cfgs.pop('stick', None)
|
cfgs.pop('stick', None)
|
||||||
for serv, guess in fm.guess_cfgs(config.instrument, cfgs).items():
|
self._initial_config = fm.propose_cfgs(config.instrument, cfgs)[0]
|
||||||
ok = guess.get('ok', [])
|
|
||||||
for proposed in guess.get('proposed', []):
|
|
||||||
if isinstance(proposed, str): # start only when ambiguous
|
|
||||||
ok.append(proposed)
|
|
||||||
else:
|
|
||||||
success = False
|
|
||||||
if ok:
|
|
||||||
cfgs[serv] = ','.join(ok)
|
|
||||||
if not success:
|
|
||||||
cfgs = {}
|
|
||||||
result = {}
|
|
||||||
for serv, cfg in cfgs.items():
|
|
||||||
runcfg = running.get(serv)
|
|
||||||
if runcfg != cfg:
|
|
||||||
result[serv] = cfg
|
|
||||||
elif runcfg:
|
|
||||||
result[serv] = True # restart not needed as cfg has not changed
|
|
||||||
self._initial_config = result
|
|
||||||
return self._initial_config.get(service)
|
return self._initial_config.get(service)
|
||||||
|
|
||||||
def changed(self):
|
def changed(self):
|
||||||
@ -485,7 +516,7 @@ class FrappyNode(SecNodeDevice, Moveable):
|
|||||||
if mode == SIMULATION or session.sessiontype == POLLER:
|
if mode == SIMULATION or session.sessiontype == POLLER:
|
||||||
super().doInit(mode)
|
super().doInit(mode)
|
||||||
else:
|
else:
|
||||||
fc = session.devices.get('frappy_config')
|
fc = session.devices.get('frappy')
|
||||||
if fc:
|
if fc:
|
||||||
cfg = fc.initial_restart_cfg(self.service)
|
cfg = fc.initial_restart_cfg(self.service)
|
||||||
if isinstance(cfg, str): # may also be None or True
|
if isinstance(cfg, str): # may also be None or True
|
||||||
|
Reference in New Issue
Block a user