Beispiel #1
0
def setup(python_lib_only=None):
    if python_lib_only is not None:
        python_lib_only = val_to_boolean(python_lib_only)
    if not python_lib_only:
        if OS_ID in ['rhel', 'centos']:
            raise UnsupportedOS(kb='KB00003')
        elif OS_LIKE == 'debian':
            install_system_packages(['libow-dev'])
        elif OS_LIKE == 'fedora':
            install_system_packages(['owfs-libs', 'owfs-devel'])
        else:
            if not Path('/usr/include/owcapi.h').exists() and not Path(
                    '/usr/local/include/owcapi.h').exists():
                build_system_package(
                    src=
                    'https://github.com/owfs/owfs/releases/download/v3.2p4/owfs-3.2p4.tar.gz',
                    sha256=
                    'af0a5035f3f3df876ca15aea13486bfed6b3ef5409dee016db0be67755c35fcc',
                    tdir='owfs-3.2p4',
                    configure_args=[
                        '--prefix=/usr', '--disable-owtcl', '--disable-owphp',
                        '--disable-owpython', '--disable-zero',
                        '--disable-owshell', '--disable-owhttpd',
                        '--disable-owftpd', '--disable-owserver',
                        '--disable-owperl', '--disable-owtap',
                        '--disable-owmon', '--disable-owexternal'
                    ],
                    update_ld=True)
    append_python_libraries(python_libs)
Beispiel #2
0
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)
Beispiel #3
0
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()
Beispiel #4
0
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)
Beispiel #5
0
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')
Beispiel #6
0
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')
Beispiel #7
0
def setup(mods=False):
    mods = val_to_boolean(mods)
    append_python_libraries(python_libraries)

    if mods:
        download_phis(phis)
Beispiel #8
0
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)