Python oslo_config.cfg.DuplicateOptError() Examples

The following are 5 code examples of oslo_config.cfg.DuplicateOptError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oslo_config.cfg , or try the search function .
Example #1
Source File: driver.py    From glance_store with Apache License 2.0 6 votes vote down vote up
def __init__(self, conf, backend=None):
        """
        Initialize the Store
        """

        super(Store, self).__init__()

        self.conf = conf
        self.backend_group = backend
        self.store_location_class = None
        self._url_prefix = None

        try:
            if self.OPTIONS is not None:
                group = 'glance_store'
                if self.backend_group:
                    group = self.backend_group
                    if self.MULTI_BACKEND_OPTIONS is not None:
                        self.conf.register_opts(
                            self.MULTI_BACKEND_OPTIONS, group=group)

                self.conf.register_opts(self.OPTIONS, group=group)
        except cfg.DuplicateOptError:
            pass 
Example #2
Source File: test_migration_key_manager.py    From castellan with Apache License 2.0 5 votes vote down vote up
def _create_key_manager(self):
        self.fixed_key = '1' * 64
        try:
            self.conf.register_opt(cfg.StrOpt('fixed_key'),
                                   group='key_manager')
        except cfg.DuplicateOptError:
            pass
        self.conf.set_override('fixed_key',
                               self.fixed_key,
                               group='key_manager')
        return key_manager.API(self.conf) 
Example #3
Source File: store.py    From glance_store with Apache License 2.0 5 votes vote down vote up
def Store(conf, backend=None):
    group = 'glance_store'
    if backend:
        group = backend
        multi_tenant = getattr(conf, backend).swift_store_multi_tenant
        default_store = conf.glance_store.default_backend
    else:
        default_store = conf.glance_store.default_store
        multi_tenant = conf.glance_store.swift_store_multi_tenant

    # NOTE(dharinic): Multi-tenant store cannot work with swift config
    if multi_tenant:
        if (default_store == 'swift+config' or
                sutils.is_multiple_swift_store_accounts_enabled(
                    conf, backend=backend)):
            msg = _("Swift multi-tenant store cannot be configured to "
                    "work with swift+config. The options "
                    "'swift_store_multi_tenant' and "
                    "'swift_store_config_file' are mutually exclusive. "
                    "If you inted to use multi-tenant swift store, please "
                    "make sure that you have not set a swift configuration "
                    "file with the 'swift_store_config_file' option.")
            raise exceptions.BadStoreConfiguration(store_name="swift",
                                                   reason=msg)
    try:
        conf.register_opts(_SWIFT_OPTS + sutils.swift_opts +
                           buffered.BUFFERING_OPTS, group=group)
    except cfg.DuplicateOptError:
        pass

    if multi_tenant:
        return MultiTenantStore(conf, backend=backend)
    return SingleTenantStore(conf, backend=backend) 
Example #4
Source File: configuration.py    From cyborg with Apache License 2.0 5 votes vote down vote up
def _safe_register(self, opt, group):
        try:
            CONF.register_opt(opt, group=group)
        except cfg.DuplicateOptError:
            pass  # If it's already registered ignore it 
Example #5
Source File: migration.py    From castellan with Apache License 2.0 4 votes vote down vote up
def handle_migration(conf, key_mgr):
    try:
        conf.register_opt(cfg.StrOpt('fixed_key'), group='key_manager')
    except cfg.DuplicateOptError:
        pass

    if conf.key_manager.fixed_key is not None and \
       not conf.key_manager.backend.endswith('ConfKeyManager'):

        LOG.warning("Using MigrationKeyManager to provide support for legacy"
                    " fixed_key encryption")

        class MigrationKeyManager(type(key_mgr)):
            def __init__(self, configuration):
                self.fixed_key = configuration.key_manager.fixed_key
                self.fixed_key_id = '00000000-0000-0000-0000-000000000000'
                super(MigrationKeyManager, self).__init__(configuration)

            def get(self, context, managed_object_id):
                if managed_object_id == self.fixed_key_id:
                    LOG.debug("Processing request for secret associated"
                              " with fixed_key key ID")

                    if context is None:
                        raise exception.Forbidden()

                    key_bytes = bytes(binascii.unhexlify(self.fixed_key))
                    secret = symmetric_key.SymmetricKey('AES',
                                                        len(key_bytes) * 8,
                                                        key_bytes)
                else:
                    secret = super(MigrationKeyManager, self).get(
                        context, managed_object_id)
                return secret

            def delete(self, context, managed_object_id):
                if managed_object_id == self.fixed_key_id:
                    LOG.debug("Not deleting key associated with"
                              " fixed_key key ID")

                    if context is None:
                        raise exception.Forbidden()
                else:
                    super(MigrationKeyManager, self).delete(context,
                                                            managed_object_id)

        key_mgr = MigrationKeyManager(configuration=conf)

    return key_mgr