summaryrefslogtreecommitdiff
path: root/glance_store/_drivers
diff options
context:
space:
mode:
authorAbhishek Kekane <akekane@redhat.com>2019-05-20 07:58:37 +0000
committerAbhishek Kekane <akekane@redhat.com>2019-06-03 16:16:58 +0000
commitd5dc27e7d389cd00ece53e62f2b1e643ea115fd3 (patch)
treedff7ce52201afd31ac12d6b1d669da084edfc1ac /glance_store/_drivers
parentf92cafed23b1f9a975ee70777e99f67ffd340999 (diff)
downloadglance_store-d5dc27e7d389cd00ece53e62f2b1e643ea115fd3.tar.gz
Add location prefix url to store instance
For updating location metadata with store information to the images which are existed prior to enabling multiple stores, added new public attribute 'url_prefix' to each of the store instance. Implements: blueprint location-uri-prefix Change-Id: Icd760d30e947867c2b5b87f86bbe4b1a4240d214
Diffstat (limited to 'glance_store/_drivers')
-rw-r--r--glance_store/_drivers/cinder.py5
-rw-r--r--glance_store/_drivers/filesystem.py6
-rw-r--r--glance_store/_drivers/http.py10
-rw-r--r--glance_store/_drivers/rbd.py17
-rw-r--r--glance_store/_drivers/sheepdog.py7
-rw-r--r--glance_store/_drivers/swift/store.py55
-rw-r--r--glance_store/_drivers/vmware_datastore.py13
7 files changed, 113 insertions, 0 deletions
diff --git a/glance_store/_drivers/cinder.py b/glance_store/_drivers/cinder.py
index 0b5ac1d..7212e02 100644
--- a/glance_store/_drivers/cinder.py
+++ b/glance_store/_drivers/cinder.py
@@ -435,10 +435,15 @@ class Store(glance_store.driver.Store):
def __init__(self, *args, **kargs):
super(Store, self).__init__(*args, **kargs)
+ if self.backend_group:
+ self._set_url_prefix()
def get_schemes(self):
return ('cinder',)
+ def _set_url_prefix(self):
+ self._url_prefix = "cinder://"
+
def _check_context(self, context, require_tenant=False):
user_overriden = is_user_overriden(self.conf,
backend=self.backend_group)
diff --git a/glance_store/_drivers/filesystem.py b/glance_store/_drivers/filesystem.py
index 4181f9d..f5e7871 100644
--- a/glance_store/_drivers/filesystem.py
+++ b/glance_store/_drivers/filesystem.py
@@ -460,10 +460,16 @@ class Store(glance_store.driver.Store):
reverse=True)
self._create_image_directories(directory_paths)
+ if self.backend_group:
+ self._set_url_prefix()
if meta_file:
self._validate_metadata(meta_file)
+ def _set_url_prefix(self):
+ path = self._find_best_datadir(0)
+ self._url_prefix = "%s://%s" % ('file', path)
+
def _check_directory_paths(self, datadir_path, directory_paths,
priority_paths):
"""
diff --git a/glance_store/_drivers/http.py b/glance_store/_drivers/http.py
index d2a821a..b0b70f5 100644
--- a/glance_store/_drivers/http.py
+++ b/glance_store/_drivers/http.py
@@ -191,6 +191,16 @@ class Store(glance_store.driver.Store):
capabilities.BitMasks.DRIVER_REUSABLE)
OPTIONS = _HTTP_OPTS
+ def __init__(self, *args, **kargs):
+ super(Store, self).__init__(*args, **kargs)
+ if self.backend_group:
+ self._set_url_prefix()
+
+ def _set_url_prefix(self):
+ # NOTE(abhishekk): HTTP store url either starts with http
+ # or https, so default _url_prefix is set to http.
+ self._url_prefix = "http"
+
@capabilities.check
def get(self, location, offset=0, chunk_size=None, context=None):
"""
diff --git a/glance_store/_drivers/rbd.py b/glance_store/_drivers/rbd.py
index 74a80fb..98cb284 100644
--- a/glance_store/_drivers/rbd.py
+++ b/glance_store/_drivers/rbd.py
@@ -319,6 +319,23 @@ class Store(driver.Store):
LOG.error(reason)
raise exceptions.BadStoreConfiguration(store_name='rbd',
reason=reason)
+ if self.backend_group:
+ self._set_url_prefix()
+
+ def _set_url_prefix(self):
+ fsid = None
+ with self.get_connection(conffile=self.conf_file,
+ rados_id=self.user) as conn:
+ if hasattr(conn, 'get_fsid'):
+ fsid = encodeutils.safe_decode(conn.get_fsid())
+
+ if fsid and self.pool:
+ # ensure nothing contains / or any other url-unsafe character
+ safe_fsid = urllib.parse.quote(fsid, '')
+ safe_pool = urllib.parse.quote(self.pool, '')
+ self._url_prefix = "rbd://%s/%s/" % (safe_fsid, safe_pool)
+ else:
+ self._url_prefix = "rbd://"
@capabilities.check
def get(self, location, offset=0, chunk_size=None, context=None):
diff --git a/glance_store/_drivers/sheepdog.py b/glance_store/_drivers/sheepdog.py
index 591efe8..2b1f451 100644
--- a/glance_store/_drivers/sheepdog.py
+++ b/glance_store/_drivers/sheepdog.py
@@ -270,6 +270,10 @@ class Store(glance_store.driver.Store):
def get_schemes(self):
return ('sheepdog',)
+ def _set_url_prefix(self):
+ self._url_prefix = "%s://%s:%s:" % (
+ 'sheepdog', self.addr, self.port)
+
def configure_add(self):
"""
Configure the Store to use the stored configuration options
@@ -304,6 +308,9 @@ class Store(glance_store.driver.Store):
raise exceptions.BadStoreConfiguration(store_name='sheepdog',
reason=reason)
+ if self.backend_group:
+ self._set_url_prefix()
+
@capabilities.check
def get(self, location, offset=0, chunk_size=None, context=None):
"""
diff --git a/glance_store/_drivers/swift/store.py b/glance_store/_drivers/swift/store.py
index 706d352..47c892d 100644
--- a/glance_store/_drivers/swift/store.py
+++ b/glance_store/_drivers/swift/store.py
@@ -1222,6 +1222,9 @@ class BaseStore(driver.Store):
msg = _("There is no Connection Manager implemented for %s class.")
raise NotImplementedError(msg % self.__class__.__name__)
+ def _set_url_prefix(self, context=None):
+ raise NotImplementedError()
+
class SingleTenantStore(BaseStore):
EXAMPLE_URL = "swift://<USER>:<KEY>@<AUTH_ADDRESS>/<CONTAINER>/<FILE>"
@@ -1280,6 +1283,50 @@ class SingleTenantStore(BaseStore):
LOG.error(reason)
raise exceptions.BadStoreConfiguration(store_name="swift",
reason=reason)
+ if self.backend_group:
+ self._set_url_prefix()
+
+ def _get_credstring(self):
+ if self.user and self.key:
+ return '%s:%s' % (urllib.parse.quote(self.user),
+ urllib.parse.quote(self.key))
+ return ''
+
+ def _set_url_prefix(self, context=None):
+ auth_or_store_url = self.auth_address
+ if auth_or_store_url.startswith('http://'):
+ auth_or_store_url = auth_or_store_url[len('http://'):]
+ elif auth_or_store_url.startswith('https://'):
+ auth_or_store_url = auth_or_store_url[len('https://'):]
+
+ credstring = self._get_credstring()
+ auth_or_store_url = auth_or_store_url.strip('/')
+ container = self.container.strip('/')
+
+ if sutils.is_multiple_swift_store_accounts_enabled(
+ self.conf, backend=self.backend_group):
+ include_creds = False
+ else:
+ include_creds = True
+
+ if not include_creds:
+ store = getattr(self.conf,
+ self.backend_group).default_swift_reference
+
+ self._url_prefix = '%s://%s/%s/' % (
+ 'swift+config', store, container)
+ return
+
+ if self.scheme == 'swift+config':
+ if self.ssl_enabled:
+ self.scheme = 'swift+https'
+ else:
+ self.scheme = 'swift+http'
+ if credstring != '':
+ credstring = "%s@" % credstring
+
+ self._url_prefix = '%s://%s%s/%s/' % (
+ self.scheme, credstring, auth_or_store_url, container)
def create_location(self, image_id, context=None):
container_name = self.get_container_name(image_id, self.container)
@@ -1502,6 +1549,11 @@ class MultiTenantStore(BaseStore):
return StoreLocation(specs, self.conf,
backend_group=self.backend_group)
+ def _set_url_prefix(self, context=None):
+ ep = self._get_endpoint(context)
+ self._url_prefix = "%s://%s:%s_" % (
+ self.scheme, ep, self.container)
+
def get_connection(self, location, context=None):
return swiftclient.Connection(
preauthurl=location.swift_url,
@@ -1536,6 +1588,9 @@ class MultiTenantStore(BaseStore):
project_domain_name = default_swift_reference.get(
'project_domain_name')
+ if self.backend_group:
+ self._set_url_prefix(context=context)
+
# create client for multitenant user(trustor)
trustor_auth = ks_identity.V3Token(auth_url=auth_address,
token=context.auth_token,
diff --git a/glance_store/_drivers/vmware_datastore.py b/glance_store/_drivers/vmware_datastore.py
index 76a9edd..9ca691e 100644
--- a/glance_store/_drivers/vmware_datastore.py
+++ b/glance_store/_drivers/vmware_datastore.py
@@ -515,6 +515,19 @@ class Store(glance_store.Store):
store_conf = self.conf.glance_store
self.store_image_dir = store_conf.vmware_store_image_dir
+ if self.backend_group:
+ self._set_url_prefix()
+
+ def _set_url_prefix(self):
+ path = os.path.join(DS_URL_PREFIX,
+ self.store_image_dir)
+
+ if netutils.is_valid_ipv6(self.server_host):
+ self._url_prefix = '%s://[%s]%s' % (self.scheme,
+ self.server_host, path)
+ else:
+ self._url_prefix = '%s://%s%s' % (self.scheme,
+ self.server_host, path)
def select_datastore(self, image_size):
"""Select a datastore with free space larger than image size."""