Ejemplo n.º 1
0
def dynamic_conf(uri, options):
    """Given metadata, yields a dynamic configuration.

    :param uri: pool location
    :type uri: six.text_type
    :param options: additional pool metadata
    :type options: dict
    :returns: Configuration object suitable for constructing storage
              drivers
    :rtype: oslo.config.cfg.ConfigOpts
    """
    # NOTE(cpp-cabrera): make it *very* clear to data storage
    # drivers that we are operating in a dynamic mode.
    general_opts = utils.dict_to_conf({'dynamic': True})

    # NOTE(cpp-cabrera): parse general opts: 'drivers'
    storage_type = six.moves.urllib_parse.urlparse(uri).scheme
    driver_opts = utils.dict_to_conf({'storage': storage_type})

    # NOTE(cpp-cabrera): parse storage-specific opts:
    # 'drivers:storage:{type}'
    storage_opts = utils.dict_to_conf({'uri': uri, 'options': options})
    storage_group = u'drivers:storage:%s' % storage_type

    # NOTE(cpp-cabrera): register those options!
    conf = cfg.ConfigOpts()
    conf.register_opts(general_opts)
    conf.register_opts(driver_opts, group=u'drivers')
    conf.register_opts(storage_opts, group=storage_group)
    return conf
Ejemplo n.º 2
0
def dynamic_conf(uri, options):
    """Given metadata, yields a dynamic configuration.

    :param uri: pool location
    :type uri: six.text_type
    :param options: additional pool metadata
    :type options: dict
    :returns: Configuration object suitable for constructing storage
              drivers
    :rtype: oslo.config.cfg.ConfigOpts
    """
    # NOTE(cpp-cabrera): make it *very* clear to data storage
    # drivers that we are operating in a dynamic mode.
    general_opts = utils.dict_to_conf({'dynamic': True})

    # NOTE(cpp-cabrera): parse general opts: 'drivers'
    storage_type = six.moves.urllib_parse.urlparse(uri).scheme
    driver_opts = utils.dict_to_conf({'storage': storage_type})

    # NOTE(cpp-cabrera): parse storage-specific opts:
    # 'drivers:storage:{type}'
    storage_opts = utils.dict_to_conf({'uri': uri, 'options': options})
    storage_group = u'drivers:storage:%s' % storage_type

    # NOTE(cpp-cabrera): register those options!
    conf = cfg.ConfigOpts()
    conf.register_opts(general_opts)
    conf.register_opts(driver_opts, group=u'drivers')
    conf.register_opts(storage_opts, group=storage_group)
    return conf
Ejemplo n.º 3
0
def dynamic_conf(uri, options, conf=None):
    """Given metadata, yields a dynamic configuration.

    :param uri: pool location
    :type uri: six.text_type
    :param options: additional pool metadata
    :type options: dict
    :param conf: Optional conf object to copy
    :type conf: `oslo_config.cfg.ConfigOpts`
    :returns: Configuration object suitable for constructing storage
              drivers
    :rtype: oslo_config.cfg.ConfigOpts
    """
    storage_type = six.moves.urllib_parse.urlparse(uri).scheme

    # NOTE(cpp-cabrera): parse storage-specific opts:
    # 'drivers:storage:{type}'
    options['uri'] = uri
    storage_opts = utils.dict_to_conf(options)
    storage_group = u'drivers:message_store:%s' % storage_type

    # NOTE(cpp-cabrera): register those options!
    if conf is None:
        conf = cfg.ConfigOpts()
    else:
        conf_wrap = configuration.Configuration(conf)
        conf = copy.copy(conf_wrap)

    if storage_group not in conf:
        conf.register_opts(storage_opts, group=storage_group)

    if 'drivers' not in conf:
        # NOTE(cpp-cabrera): parse general opts: 'drivers'
        driver_opts = utils.dict_to_conf({'message_store': storage_type})
        conf.register_opts(driver_opts, group=u'drivers')

    conf.set_override('message_store',
                      storage_type,
                      'drivers',
                      enforce_type=True)

    for opt in options:
        if opt in conf[storage_group]:
            conf.set_override(opt,
                              options[opt],
                              group=storage_group,
                              enforce_type=True)
    return conf
Ejemplo n.º 4
0
def dynamic_conf(uri, options, conf=None):
    """Given metadata, yields a dynamic configuration.

    :param uri: pool location
    :type uri: six.text_type
    :param options: additional pool metadata
    :type options: dict
    :param conf: Optional conf object to copy
    :type conf: `oslo_config.cfg.ConfigOpts`
    :returns: Configuration object suitable for constructing storage
              drivers
    :rtype: oslo_config.cfg.ConfigOpts
    """
    storage_type = six.moves.urllib_parse.urlparse(uri).scheme

    # NOTE(cpp-cabrera): parse storage-specific opts:
    # 'drivers:storage:{type}'
    options['uri'] = uri
    storage_opts = utils.dict_to_conf(options)
    storage_group = u'drivers:message_store:%s' % storage_type

    # NOTE(cpp-cabrera): register those options!
    if conf is None:
        conf = cfg.ConfigOpts()
    else:
        conf = copy.copy(conf)

    if storage_group not in conf:
        conf.register_opts(storage_opts,
                           group=storage_group)

    if 'drivers' not in conf:
        # NOTE(cpp-cabrera): parse general opts: 'drivers'
        driver_opts = utils.dict_to_conf({'message_store': storage_type})
        conf.register_opts(driver_opts, group=u'drivers')

    conf.set_override('message_store', storage_type, 'drivers',
                      enforce_type=True)

    for opt in options:
        if opt in conf[storage_group]:
            conf.set_override(opt, options[opt], group=storage_group,
                              enforce_type=True)
    return conf