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