diff options
author | Abhishek Kekane <akekane@redhat.com> | 2018-06-08 09:50:32 +0000 |
---|---|---|
committer | Abhishek Kekane <akekane@redhat.com> | 2018-07-15 15:10:27 +0000 |
commit | 87114c8ec70364f2690fdec875180657002c33ab (patch) | |
tree | 08bb660555bb8e19c5655c71ca28634cb0a07dfd /glance_store/location.py | |
parent | d50ab63e138d58ef96b302fc1a1cf56923a26c76 (diff) | |
download | glance_store-87114c8ec70364f2690fdec875180657002c33ab.tar.gz |
Enable multi store support for glance
Added supporting logic to configure, manage and use multiple stores
of the same or different type/scheme. Added new config option
'default_backend' which will be used to specifiy default store
to which image will be stored.
Added support for file and rbd store. The default behavior is
maintained for backward compatibility.
DocImpact
Partial-Implements: bp multi-store
Change-Id: I1f2e8fa61d6dfecd8395a1f894f74ec5bcb5573c
Diffstat (limited to 'glance_store/location.py')
-rw-r--r-- | glance_store/location.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/glance_store/location.py b/glance_store/location.py index 4212768..4084179 100644 --- a/glance_store/location.py +++ b/glance_store/location.py @@ -49,6 +49,7 @@ CONF = cfg.CONF LOG = logging.getLogger(__name__) SCHEME_TO_CLS_MAP = {} +SCHEME_TO_CLS_BACKEND_MAP = {} def get_location_from_uri(uri, conf=CONF): @@ -62,7 +63,7 @@ def get_location_from_uri(uri, conf=CONF): Example URIs: https://user:pass@example.com:80/images/some-id - http://images.oracle.com/123456 + http://example.com/123456 swift://example.com/container/obj-id swift://user:account:pass@authurl.com/container/obj-id swift+http://user:account:pass@authurl.com/container/obj-id @@ -77,6 +78,56 @@ def get_location_from_uri(uri, conf=CONF): conf, uri=uri) +def get_location_from_uri_and_backend(uri, backend, 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 backend: A backend name for the store. + :param conf: The global configuration. + + Example URIs: + https://user:pass@example.com:80/images/some-id + http://example.com/123456 + swift://example.com/container/obj-id + swift://user:account:pass@authurl.com/container/obj-id + swift+http://user:account:pass@authurl.com/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) + + +def register_scheme_backend_map(scheme_map): + """ + Given a mapping of 'scheme' to store_name, adds the mapping to the + known list of schemes. + + This function overrides existing stores. + """ + + for (k, v) in scheme_map.items(): + if k not in SCHEME_TO_CLS_BACKEND_MAP: + SCHEME_TO_CLS_BACKEND_MAP[k] = {} + + LOG.debug("Registering scheme %s with %s", k, v) + for key, value in v.items(): + SCHEME_TO_CLS_BACKEND_MAP[k][key] = value + + def register_scheme_map(scheme_map): """ Given a mapping of 'scheme' to store_name, adds the mapping to the |