def get_location_from_uri_and_backend(uri, backend, conf=CONF): """Extract backend location from a URI. Given a URI, return a Location object that has had an appropriate store parse the URI. :param uri: A URI that could come from the end-user in the Location attribute/header. :param backend: A backend name for the store. :param conf: The global configuration. Example URIs: https://user:[email protected]:80/images/some-id http://example.com/123456 swift://example.com/container/obj-id swift://user:account:[email protected]/container/obj-id swift+http://user:account:[email protected]/container/obj-id file:///var/lib/glance/images/1 cinder://volume-id """ pieces = urllib.parse.urlparse(uri) if pieces.scheme not in SCHEME_TO_CLS_BACKEND_MAP.keys(): raise exceptions.UnknownScheme(scheme=pieces.scheme) try: scheme_info = SCHEME_TO_CLS_BACKEND_MAP[pieces.scheme][backend] except KeyError: raise exceptions.UnknownScheme(scheme=backend) return Location(pieces.scheme, scheme_info['location_class'], conf, uri=uri, backend=backend)
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 get_location_from_uri(uri): """ Given a URI, return a Location object that has had an appropriate store parse the URI. :param uri: A URI that could come from the end-user in the Location attribute/header Example URIs: https://user:[email protected]:80/images/some-id http://images.oracle.com/123456 swift://example.com/container/obj-id swift://user:account:[email protected]/container/obj-id swift+http://user:account:[email protected]/container/obj-id s3://accesskey:[email protected]/bucket/key-id s3+https://accesskey:[email protected]/bucket/key-id file:///var/lib/glance/images/1 cinder://volume-id """ pieces = urlparse.urlparse(uri) if pieces.scheme not in SCHEME_TO_CLS_MAP.keys(): raise exceptions.UnknownScheme(scheme=pieces.scheme) scheme_info = SCHEME_TO_CLS_MAP[pieces.scheme] return Location(pieces.scheme, uri=uri, store_location_class=scheme_info['location_class'])
def get_location_from_uri(uri, conf=CONF): """ Given a URI, return a Location object that has had an appropriate store parse the URI. :param uri: A URI that could come from the end-user in the Location attribute/header. :param conf: The global configuration. Example URIs: https://user:[email protected]:80/images/some-id http://images.oracle.com/123456 swift://example.com/container/obj-id swift://user:account:[email protected]/container/obj-id swift+http://user:account:[email protected]/container/obj-id file:///var/lib/glance/images/1 cinder://volume-id """ pieces = urllib.parse.urlparse(uri) #先自url中取出scheme,检查scheme是否在keys中,如果不在,直接报错 if pieces.scheme not in SCHEME_TO_CLS_MAP.keys(): raise exceptions.UnknownScheme(scheme=pieces.scheme) scheme_info = SCHEME_TO_CLS_MAP[pieces.scheme] return Location(pieces.scheme, scheme_info['location_class'], conf, uri=uri)
def get_store_from_store_identifier(store_identifier): """Determine backing store from identifier. Given a store identifier, return the appropriate store object for handling that scheme. """ scheme_map = {} enabled_backends = CONF.enabled_backends try: scheme = enabled_backends[store_identifier] except KeyError: msg = _("Store for identifier %s not found") % store_identifier raise exceptions.UnknownScheme(msg) if scheme not in location.SCHEME_TO_CLS_BACKEND_MAP: raise exceptions.UnknownScheme(scheme=scheme) scheme_info = location.SCHEME_TO_CLS_BACKEND_MAP[scheme][store_identifier] 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_multi_store(store.conf, store_entry, invoke_load=True, backend=store_identifier) store.configure() try: loc_cls = store.get_store_location_class() for new_scheme in store.get_schemes(): if new_scheme not in scheme_map: scheme_map[new_scheme] = {} scheme_map[new_scheme][store_identifier] = { 'store': store, 'location_class': loc_cls, 'store_entry': store_entry } location.register_scheme_backend_map(scheme_map) except NotImplementedError: scheme_info['store'] = store return store
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] return scheme_info['store']