def remove(node=None): if not node: raise InvalidParameter controllers = get_controllers(node) for c in controllers: print(c) cli_call('sfa', f'controller set {c} masterkey -y', return_result=True)
def remove(): need_restart = False try: cli_call(f'ns uc', f'destroy lurp_local_lm', return_result=True) need_restart = True except: print_warn('UC notifier lurp_local_lm was not setup') try: cli_call(f'ns uc', f'destroy lurp_local_sfa', return_result=True) need_restart = True except: print_warn('UC notifier lurp_local_sfa was not setup') if need_restart and is_enabled('uc'): restart_controller('uc') try: cli_call(f'ns lm', f'destroy lurp_local_sfa', return_result=True) except: print_warn('LM notifier lurp_local_sfa was not setup') if is_enabled('lm'): eva.registry.key_delete_field('config/lm/main', 'lurp') restart_controller('lm') if is_enabled('uc'): sysname = eva_jcmd('uc', 'test')['system'] cli_call('lm', f'controller set uc/{sysname} ws_state_events 1 -y', return_result=True) if is_enabled('sfa'): eva.registry.key_delete_field('config/sfa/main', 'lurp') restart_controller('sfa') for c in ['uc', 'lm']: if is_enabled(c): sysname = eva_jcmd(c, 'test')['system'] cli_call('sfa', f'controller set {c}/{sysname} ws_state_events 1 -y', return_result=True)
def remove(id=None): if not id: id = 'eva_1' for c in ['uc', 'lm']: if is_enabled(c): print(f'{c.upper()}...') try: cli_call(f'ns {c}', f'destroy {id}', return_result=True) restart_controller(c) except: print_warn(f'unable to destroy {id} notifier for {c}')
def setup(key=None): if not key: raise InvalidParameter data = cli_call('', 'server status', return_result=True) changed = False for c, v in data.items(): if v: print(f'Changing default key for {c}') cli_call(c, f'key set default key {key} -y', return_result=True) changed = True if changed: restart_controller()
def setup(node=None, key=None): if not node or not key: raise InvalidParameter controllers = get_controllers(node) if not controllers: from eva.features import print_warn print_warn('no candidates found') return for c in controllers: print(c) cli_call('sfa', f'controller set {c} masterkey {key} -y', return_result=True) cli_call('sfa', f'controller ma-test {c}', return_result=True)
def setup(host=None, id=None, ca=None, cert=None, key=None, retain=None, announce=None, proto=None, socket_buf_size=None): if proto is None: proto = 'mqtt' elif proto not in ['mqtt', 'psrt']: raise InvalidParameter(f'Invalid protocol: {proto}') check_cmd = dir_eva + f'/sbin/check-{proto}' if proto == 'psrt': retain = False if retain is None else val_to_boolean(retain) else: retain = True if retain is None else val_to_boolean(retain) announce = 30 if announce is None else float(announce) if not id: id = 'eva_1' if '/' in host: _host, space = host.rsplit('/', 1) else: _host = host space = None batch = [f'create {id} {proto}:{_host}{(" -s " + space) if space else ""}'] if ca: batch.append(f'set {id} ca_certs {ca}') check_cmd += f' --cafile {ca}' if cert: if proto == 'psrt': print_warn('cert/key auth no supported by psrt') else: batch.append(f'set {id} certfile {ca}') check_cmd += f' --cert {cert}' if key and proto != 'psrt': if proto == 'psrt': print_warn('cert/key auth no supported by psrt') else: batch.append(f'set {id} keyfile {ca}') check_cmd += f' --key {key}' check_cmd += f' {host}' exec_shell(check_cmd, passthru=True) if retain and proto == 'psrt': print_warn('retain not supported by psrt') if proto == 'mqtt': batch.append(f'set {id} retain_enabled {retain}') if socket_buf_size: if proto == 'psrt': batch.append(f'set {id} socket_buf_size {socket_buf_size}') else: print_warn('socket_buf_size supported by psrt only') if proto == 'mqtt': batch.append(f'set {id} retain_enabled {retain}') batch.append(f'test {id}') batch.append(f'subscribe state {id} -p "#" -g "#"') batch.append(f'subscribe server {id}') batch.append(f'set {id} api_enabled 1') batch.append(f'set {id} announce_interval {announce}') batch.append(f'enable {id}') for c in ['uc', 'lm']: if is_enabled(c): print(f'{c.upper()}...') for b in batch: cli_call(f'ns {c}', b, return_result=True) restart_controller(c)
def setup(buffer=None): if is_enabled('uc'): if is_enabled('lm'): nid = 'lurp_local_lm' cli_call(f'ns uc', f'create {nid} udp:127.0.0.1:8911', return_result=True) cli_call(f'ns uc', f'set {nid} max_frame_size 65000', return_result=True) cli_call(f'ns uc', f'subscribe state {nid} -p "#" -g "#"', return_result=True) cli_call(f'ns uc', f'enable {nid} -p "#" -g "#"', return_result=True) if is_enabled('sfa'): nid = 'lurp_local_sfa' cli_call(f'ns uc', f'create {nid} udp:127.0.0.1:8921', return_result=True) cli_call(f'ns uc', f'set {nid} max_frame_size 65000', return_result=True) cli_call(f'ns uc', f'subscribe state {nid} -p "#" -g "#"', return_result=True) cli_call(f'ns uc', f'enable {nid} -p "#" -g "#"', return_result=True) restart_controller('uc') if buffer: buf = int(buffer) if buf <= 1024: raise ValueError('Buffer too small') buf_cfg = {'buffer': buf} else: buf_cfg = {} if is_enabled('lm'): cfg = {'listen': '127.0.0.1:8911'} cfg.update(buf_cfg) eva.registry.key_set_field('config/lm/main', 'lurp', cfg) if is_enabled('sfa'): nid = 'lurp_local_sfa' cli_call(f'ns lm', f'create {nid} udp:127.0.0.1:8921', return_result=True) cli_call(f'ns lm', f'set {nid} max_frame_size 65000', return_result=True) cli_call(f'ns lm', f'subscribe state {nid} -p "#" -g "#"', return_result=True) cli_call(f'ns lm', f'enable {nid} -p "#" -g "#"', return_result=True) restart_controller('lm') if is_enabled('uc'): sysname = eva_jcmd('uc', 'test')['system'] cli_call('lm', f'controller set uc/{sysname} ws_state_events 0 -y', return_result=True) if is_enabled('sfa'): cfg = {'listen': '127.0.0.1:8921'} cfg.update(buf_cfg) eva.registry.key_set_field('config/sfa/main', 'lurp', cfg) restart_controller('sfa') for c in ['uc', 'lm']: if is_enabled(c): sysname = eva_jcmd(c, 'test')['system'] cli_call('sfa', f'controller set {c}/{sysname} ws_state_events 0 -y', return_result=True)