Exemple #1
0
def serve_networks():
    """Start the HIL networking server"""
    from hil import model, deferred
    from time import sleep
    config.setup()
    server.init()
    server.register_drivers()
    server.validate_state()
    model.init_db()
    migrations.check_db_schema()

    # Check if config contains usable sleep_time
    if (cfg.has_section('network-daemon')
            and cfg.has_option('network-daemon', 'sleep_time')):
        try:
            sleep_time = cfg.getfloat('network-daemon', 'sleep_time')
        except (ValueError):
            sys.exit("Error: sleep_time set to non-float value")
        if sleep_time <= 0 or sleep_time >= 3600:
            sys.exit("Error: sleep_time not within bounds "
                     "0 < sleep_time < 3600")
        if sleep_time > 60:
            logger.warn('sleep_time greater than 1 minute.')
    else:
        sleep_time = 2

    while True:
        # Empty the journal until it's empty; then delay so we don't tight
        # loop.
        while deferred.apply_networking():
            pass
        sleep(sleep_time)
Exemple #2
0
def config_merge(config_dict):
    """Modify the configuration according to ``config_dict``.

    ``config_dict`` should be a dictionary mapping section names (strings)
    to dictionaries mapping option names within a section (again, strings)
    to their values. If the value of a section, or option is None, that
    section or option is removed. Otherwise, the section is created if it
    does not exist, and any options are set to the specified values.
    """
    for section in config_dict.keys():
        if config_dict[section] is None:
            print('remove section: %r' % section)
            cfg.remove_section(section)
        else:
            if not cfg.has_section(section):
                print('add section: %r' % section)
                cfg.add_section(section)
            for option in config_dict[section].keys():
                if config_dict[section][option] is None:
                    print('remove option: %r' % option)
                    cfg.remove_option(section, option)
                else:
                    assert isinstance(
                        config_dict[section][option],
                        str), ("Passed a non-string value in config!")
                    print('set option: %r' % option)
                    cfg.set(section, option, config_dict[section][option])
Exemple #3
0
def config_merge(config_dict):
    """Modify the configuration according to ``config_dict``.

    ``config_dict`` should be a dictionary mapping section names (strings)
    to dictionaries mapping option names within a section (again, strings)
    to their values. If the value of a section, or option is None, that
    section or option is removed. Otherwise, the section is created if it
    does not exist, and any options are set to the specified values.
    """
    for section in config_dict.keys():
        if config_dict[section] is None:
            print('remove section: %r' % section)
            cfg.remove_section(section)
        else:
            if not cfg.has_section(section):
                print('add section: %r' % section)
                cfg.add_section(section)
            for option in config_dict[section].keys():
                if config_dict[section][option] is None:
                    print('remove option: %r' % option)
                    cfg.remove_option(section, option)
                else:
                    assert isinstance(config_dict[section][option], str), (
                        "Passed a non-string value in config!"
                    )
                    print('set option: %r' % option)
                    cfg.set(section, option, config_dict[section][option])
Exemple #4
0
def setup(*args, **kwargs):
    if not cfg.has_section(__name__):
        logger.error('No section for [%s] in hil.cfg; authentication will '
                     'not work without this. Please add this section and try '
                     'again.', __name__)
        sys.exit(1)
    keystone_cfg = {}
    for key in cfg.options(__name__):
        keystone_cfg[key] = cfg.get(__name__, key)

    # Great job with the API design Openstack! </sarcasm>
    factory = filter_factory(keystone_cfg)
    app.wsgi_app = factory(app.wsgi_app)

    auth.set_auth_backend(KeystoneAuthBackend())
Exemple #5
0
def setup(*args, **kwargs):
    if not cfg.has_section(__name__):
        logger.error(
            'No section for [%s] in hil.cfg; authentication will '
            'not work without this. Please add this section and try '
            'again.', __name__)
        sys.exit(1)
    keystone_cfg = {}
    for key in cfg.options(__name__):
        keystone_cfg[key] = cfg.get(__name__, key)

    # Great job with the API design Openstack! </sarcasm>
    factory = filter_factory(keystone_cfg)
    app.wsgi_app = factory(app.wsgi_app)

    auth.set_auth_backend(KeystoneAuthBackend())