fix frappy command
This commit is contained in:
125
commands.py
125
commands.py
@ -66,56 +66,74 @@ def all_info(all_cfg):
|
||||
return 'currently configured: %s' % ', '.join(info)
|
||||
|
||||
|
||||
def frappy_start(service, cfg=None):
|
||||
if service not in SERVICES:
|
||||
raise ValueError('unknown service %s' % service)
|
||||
frappy_config = session.devices.get('frappy_config')
|
||||
# if frappy_config():
|
||||
# frappy_config.remove_aliases()
|
||||
if cfg == '':
|
||||
seaconn = session.devices.get('seaconn')
|
||||
if seaconn and seaconn._attached_secnode:
|
||||
seaconn.communicate('frappy_remove %s' % service)
|
||||
startnode = None
|
||||
all_cfg = {}
|
||||
for srv in SERVICES:
|
||||
nodename = 'se_' + srv
|
||||
secnode = session.devices.get(nodename)
|
||||
def frappy_start(**services):
|
||||
"""start/stop frappy servers
|
||||
|
||||
cfginfo = None if secnode is None else secnode()
|
||||
if srv == service:
|
||||
if cfg is not None:
|
||||
if cfg and not secnode:
|
||||
AddSetup('frappy_' + service)
|
||||
secnode = session.devices[nodename]
|
||||
if cfginfo:
|
||||
secnode('')
|
||||
startnode = secnode
|
||||
cfginfo = cfg
|
||||
elif cfg and cfginfo:
|
||||
# remark: cfg might be a comma separated list of configurations
|
||||
ourcfg = set(cfg.split(','))
|
||||
other = set(cfginfo.split(','))
|
||||
both = other & ourcfg
|
||||
if both:
|
||||
# remove ourcfg from other
|
||||
cfginfo = ','.join(other - ourcfg)
|
||||
# stop other server with the same cfg
|
||||
# or restart with remaining cfgs
|
||||
secnode(cfginfo)
|
||||
all_cfg[srv] = cfginfo
|
||||
if startnode and cfg:
|
||||
startnode(cfg)
|
||||
CreateDevice(str(startnode))
|
||||
if cfg is not None:
|
||||
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('seaconn')
|
||||
if seaconn and seaconn._attached_secnode:
|
||||
seaconn.communicate('frappy_remove %s' % service)
|
||||
used_cfg = {}
|
||||
# check for duplication of cfgs
|
||||
for service in SERVICES:
|
||||
cfginfo = services.get(service)
|
||||
|
||||
all_cfg = {}
|
||||
new_cfg = []
|
||||
remove_cfg = []
|
||||
add_setups = []
|
||||
for service in SERVICES:
|
||||
secnode = session.devices.get('se_' + service)
|
||||
cfginfo = services.get(service)
|
||||
if cfginfo is None:
|
||||
if not secnode:
|
||||
continue
|
||||
cfginfo = secnode() or ''
|
||||
all_cfg[service] = cfginfo
|
||||
else:
|
||||
if cfginfo:
|
||||
new_cfg.append((service, secnode, cfginfo))
|
||||
all_cfg[service] = cfginfo
|
||||
else:
|
||||
remove_cfg.append(secnode)
|
||||
if secnode:
|
||||
secnode('')
|
||||
|
||||
# check cfg is not used twice
|
||||
for cfg in cfginfo.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' % (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)
|
||||
CreateDevice(nodename)
|
||||
cleanup_defunct()
|
||||
CreateAllDevices()
|
||||
if frappy_config:
|
||||
frappy_config.set_envlist()
|
||||
else:
|
||||
applyAliasConfig()
|
||||
if startnode and cfg == '':
|
||||
startnode.disable()
|
||||
if frappy_config:
|
||||
frappy_config.set_envlist()
|
||||
else:
|
||||
applyAliasConfig()
|
||||
for secnode in remove_cfg:
|
||||
secnode.disable()
|
||||
return all_cfg
|
||||
|
||||
|
||||
@ -135,9 +153,7 @@ def frappy(main=None, stick=None, addons=None):
|
||||
- frappy(''): the stick is removed too
|
||||
- addons are not changed when not given!
|
||||
"""
|
||||
all_cfg = {}
|
||||
if main is not None:
|
||||
all_cfg = frappy_start('main', main)
|
||||
if stick is None:
|
||||
if main:
|
||||
stickcfg = main + 'stick'
|
||||
@ -146,10 +162,7 @@ def frappy(main=None, stick=None, addons=None):
|
||||
stick = stickcfg
|
||||
else:
|
||||
stick = ''
|
||||
if stick is not None:
|
||||
all_cfg = frappy_stick('stick', stick)
|
||||
if addons is not None:
|
||||
all_cfg = frappy_stick('addons', addons)
|
||||
all_cfg = frappy_start(main=main, stick=stick, addons=addons)
|
||||
session.log.info(all_info(all_cfg))
|
||||
|
||||
|
||||
@ -161,7 +174,7 @@ def frappy_main(cfg=None):
|
||||
- without argument: list running frappy servers
|
||||
- cfg = "": stop frappy_main server
|
||||
"""
|
||||
session.log.info(all_info(frappy_start('main', cfg)))
|
||||
session.log.info(all_info(frappy_start(main=cfg)))
|
||||
|
||||
|
||||
@usercommand
|
||||
@ -172,7 +185,7 @@ def frappy_stick(cfg=None):
|
||||
- without argument: list running frappy servers
|
||||
- cfg = "": stop frappy_stick server
|
||||
"""
|
||||
session.log.info(all_info(frappy_start('stick', cfg)))
|
||||
session.log.info(all_info(frappy_start(stick=cfg)))
|
||||
|
||||
|
||||
@usercommand
|
||||
@ -183,7 +196,7 @@ def frappy_addons(cfg=None):
|
||||
- without argument: list running frappy servers
|
||||
- cfg = "": stop frappy_addons server
|
||||
"""
|
||||
session.log.info(all_info(frappy_start('addons', cfg)))
|
||||
session.log.info(all_info(frappy_start(addons=cfg)))
|
||||
|
||||
|
||||
@usercommand
|
||||
|
Reference in New Issue
Block a user