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(from_scratch=False): from_scratch = val_to_boolean(from_scratch) if from_scratch: from eva.features import print_warn print_warn('Removing Python virtual environment') print('Removing venv...') # check to avoid rm at root if dir_eva: exec_shell(f'rm -rf {dir_eva}/python3') else: raise RuntimeError('EVA directory not detected') rebuild_python_venv()
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 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 setup(name=None, rename_only=None): if not name: raise InvalidParameter if rename_only is not None: rename_only = val_to_boolean(rename_only) current_name = eva.registry.SYSTEM_NAME try: eva.registry.db.key_get(key=f'eva3/{current_name}/config/venv') except Exception as e: raise FunctionFailed(f'Unable to setup registry config: {e}') if not rename_only: print('Stopping controllers...') for c in ['sfa', 'lm', 'uc']: if is_enabled(c): stop_controller(c) if name != current_name: print('Setting local inter-connection for UC...') for c in ['lm', 'sfa']: if is_enabled(c): try: with eva.registry.key_as_dict( f'data/{c}/remote_uc/{current_name}') as k: if not k.data: raise KeyError k.get('id') k.set('id', name) k.set('full_id', f'uc/{name}') k.set('oid', f'remote_uc:uc/{name}') eva.registry.db.key_rename( key=f'eva3/{current_name}' f'/data/{c}/remote_uc/{current_name}', dst_key=f'eva3/{current_name}/data/{c}/remote_uc/{name}' ) except KeyError: pass print('Setting local inter-connection for LM PLC...') if is_enabled('sfa'): try: with eva.registry.key_as_dict( f'data/sfa/remote_lm/{current_name}') as k: if not k.data: raise KeyError k.set('id', name) k.set('full_id', f'lm/{name}') k.set('oid', f'remote_lm:lm/{name}') eva.registry.db.key_rename( key=f'eva3/{current_name}/data' f'/sfa/remote_lm/{current_name}', dst_key=f'eva3/{current_name}/data/sfa/remote_lm/{name}') except KeyError: pass print('Renaming schema keys...') eva.registry.db.key_rename(key=f'.schema/eva3/{current_name}', dst_key=f'.schema/eva3/{name}') print('Renaming node keys...') eva.registry.db.key_rename(key=f'eva3/{current_name}', dst_key=f'eva3/{name}') print('Setting new name in etc/eva_config ...') with ShellConfigFile('eva_config', init_if_missing=True) as cf: cf.set('SYSTEM_NAME', name) eva.registry.SYSTEM_NAME = current_name if not rename_only: print('Starting controllers back...') for c in ['uc', 'lm', 'sfa']: if is_enabled(c): start_controller(c) print() print_warn(f'Local node renamed to "{name}"') print_warn('If eva-shell is running in the interactive mode, ' 'it is recommended to restart the session')
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)