def setup(ttl=None): if not is_enabled('lm'): raise FunctionFailed('LM PLC is not enabled') if ttl: try: ttl = float(ttl) except: raise InvalidParameter('ttl is not a number') eva.registry.key_set_field('config/lm/main', 'plc/cache-remote-state', ttl) restart_controller('lm')
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 remove(controller=None): if controller not in ['uc', 'lm', 'sfa']: raise InvalidParameter if not is_enabled(controller): raise FunctionFailed(f'{controller} is not enebled') for field in [ 'ssl-listen', 'ssl-module', 'ssl-cert', 'ssl-key', 'ssl-chain', 'ssl-force-redirect' ]: eva.registry.key_delete_field(f'config/{controller}/main', f'webapi/{field}') restart_controller(controller)
def setup(smtp=None, default_from=None, ssl=None, tls=None, login=None, password=None): if not smtp: raise InvalidParameter if not default_from: default_from = f'eva@{platform.node()}' config = {'smtp': smtp, 'from': default_from} config['ssl'] = val_to_boolean(ssl) or False config['tls'] = val_to_boolean(tls) or False config['login'] = str(login) if login else None config['password'] = str(password) if password else None eva.registry.key_set('config/common/mailer', config) for c in ['uc', 'lm', 'sfa']: if is_enabled(c): restart_controller(c)
def setup(controller=None, cert=None, key=None, listen=None, module=None, chain=None, redirect=None, http=None): if controller not in ['uc', 'lm', 'sfa']: raise InvalidParameter if not is_enabled(controller): raise FunctionFailed(f'{controller} is not enebled') if listen is None or ':' not in listen: raise InvalidParameter if http and ':' not in http: raise InvalidParameter if module is None: module = 'builtin' if module not in ['builtin', 'pyopenssl']: raise InvalidParameter if module == 'pyopenssl': append_python_libraries(['pyopenssl==20.0.1']) if redirect is not None: redirect = val_to_boolean(redirect) if redirect is None: raise InvalidParameter for f in [cert, key]: check_file(f) if chain: check_file(chain) cfg = f'config/{controller}/main' eva.registry.key_set_field(cfg, 'webapi/ssl-listen', listen) eva.registry.key_set_field(cfg, 'webapi/ssl-cert', cert) eva.registry.key_set_field(cfg, 'webapi/ssl-key', key) if http: eva.registry.key_set_field(cfg, 'webapi/listen', http) if module: eva.registry.key_set_field(cfg, 'webapi/ssl-module', module) if chain: eva.registry.key_set_field(cfg, 'webapi/ssl-chain', chain) if redirect is not None: eva.registry.key_set_field(cfg, 'webapi/ssl-force-redirect', redirect) restart_controller(controller)
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(host=None, domain=None, key_prefix='', ca=None, cache_time=None, cache_first=False): if not is_enabled('sfa'): raise FunctionFailed('SFA is not enabled') if not host: raise InvalidParameter if cache_time: try: cache_time = int(cache_time) except: raise InvalidParameter('cache_time is not a number') if OS_LIKE == 'debian': install_system_packages(['libsasl2-dev', 'libldap2-dev', 'libssl-dev']) elif OS_LIKE == 'fedora': install_system_packages(['openldap-devel', 'openssl-devel']) elif OS_LIKE == 'alpine': install_system_packages(['openldap-dev']) with open('/usr/lib/libldap_r.so', 'w') as fh: fh.write('INPUT ( libldap.so )') else: raise UnsupportedOS append_python_libraries(python_libs) config = {'host': host} if domain: config['domain'] = domain if key_prefix: config['key-prefix'] = key_prefix if ca: config['ca'] = ca if cache_time and cache_time > 0: config['cache-time'] = cache_time if val_to_boolean(cache_first): config['cache-first'] = True eva.registry.key_set_field('config/sfa/main', 'msad', config) restart_controller('sfa')
def remove(): if not is_enabled('lm'): raise FunctionFailed('LM PLC is not enabled') eva.registry.key_delete_field('config/lm/main', 'plc/cache-remote-state') restart_controller('lm')
def remove(): if not is_enabled('sfa'): raise FunctionFailed('SFA is not enabled') eva.registry.key_delete_field('config/sfa/main', 'msad') remove_python_libraries(python_libs) restart_controller('sfa')
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)