def get_store_from_scheme(scheme): """ Given a scheme, return the appropriate store object for handling that scheme. """ if scheme not in location.SCHEME_TO_CLS_MAP: raise exceptions.UnknownScheme(scheme=scheme) scheme_info = location.SCHEME_TO_CLS_MAP[scheme] store = scheme_info['store'] if not store.is_capable(capabilities.BitMasks.DRIVER_REUSABLE): # Driver instance isn't stateless so it can't # be reused safely and need recreation. store_entry = scheme_info['store_entry'] store = _load_store(store.conf, store_entry, invoke_load=True) store.configure() try: scheme_map = {} loc_cls = store.get_store_location_class() for scheme in store.get_schemes(): scheme_map[scheme] = { 'store': store, 'location_class': loc_cls, 'store_entry': store_entry } location.register_scheme_map(scheme_map) except NotImplementedError: scheme_info['store'] = store return store
def create_stores(conf=CONF): """ Registers all store modules and all schemes from the given config. Duplicates are not re-registered. """ store_count = 0 for (store_entry, store_instance) in _load_stores(conf): try: schemes = store_instance.get_schemes() store_instance.configure(re_raise_bsc=False) except NotImplementedError: continue if not schemes: raise exceptions.BackendException('Unable to register store %s. ' 'No schemes associated with it.' % store_entry) else: LOG.debug("Registering store %s with schemes %s", store_entry, schemes) scheme_map = {} loc_cls = store_instance.get_store_location_class() for scheme in schemes: scheme_map[scheme] = { 'store': store_instance, 'location_class': loc_cls, 'store_entry': store_entry } location.register_scheme_map(scheme_map) store_count += 1 return store_count
def register_store_schemes(self, store): schemes = store.get_schemes() scheme_map = {} for scheme in schemes: loc_cls = store.get_store_location_class() scheme_map[scheme] = { 'store': store, 'location_class': loc_cls, } location.register_scheme_map(scheme_map)