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 """ pieces = urlparse.urlparse(uri) if pieces.scheme not in SCHEME_TO_CLS_MAP.keys(): raise exception.UnknownScheme(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_store_from_scheme(scheme): """ Given a scheme, return the appropriate store object for handling that scheme """ if scheme not in location.SCHEME_TO_STORE_MAP: raise exception.UnknownScheme(scheme=scheme) return STORES[location.SCHEME_TO_STORE_MAP[scheme]]
def get_from_backend(self, context, location): try: scheme = location[:location.find('/') - 1] if scheme == 'unknown': raise exception.UnknownScheme(scheme=scheme) return self.data[location] except KeyError: raise exception.NotFound()
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 exception.UnknownScheme(scheme=scheme) scheme_info = location.SCHEME_TO_CLS_MAP[scheme] return STORES[scheme_info['store_class']]
def get_store_from_scheme(context, scheme, loc=None, configure=True): """ Given a scheme, return the appropriate store object for handling that scheme. """ if scheme not in location.SCHEME_TO_CLS_MAP: raise exception.UnknownScheme(scheme=scheme) scheme_info = location.SCHEME_TO_CLS_MAP[scheme] store = scheme_info['store_class'](context, loc, configure) return store