diff options
author | Zhi Yan Liu <zhiyanl@cn.ibm.com> | 2014-11-21 22:05:49 +0800 |
---|---|---|
committer | Zhi Yan Liu <zhiyanl@cn.ibm.com> | 2015-02-08 12:41:47 +0800 |
commit | 138875b7c3051a4f92616df56bffb8c91e669d88 (patch) | |
tree | 2e767e83d4d7bd61bc23a45b0e88c1c21c75903f /glance_store/driver.py | |
parent | 36e293b5d5322c15cb612356616357e2df2c6f52 (diff) | |
download | glance_store-138875b7c3051a4f92616df56bffb8c91e669d88.tar.gz |
Add capabilities to storage driver
Storage capabilities is used to indicate the static and dynamic ability
of the storage driver object based on current driver implementation or
particular driver configuration and backend status.
Use storage capabilities glance_store can do more proper operations on
backend to support upper layer request, like to enable or disable add()
function to glance, or if allow glance reuse driver instance for all
request according to whether the driver and/or backend is stateless.
This patch implemented some initial capabilities for existing drivers,
and change the foundational code to make them be aware. Mainly it
contains:
1. Implemented essential code to enable driver capabilities, adding
necessary capabilities.
2. Added a generic checker on necessary storage operations, to make sure
the capabilities of the driver are capable of handling requested
operation. We can enhance the check logic as needed easily in future.
3. Added a callback based schedule logic to update dynamic capabilities
of store when operator enabled it by a option.
4. Refactoring on existing disablement logic on driver add() interface,
to use consistent capabilities way to handle it, removed add_disabled().
5. Therefor the related exception conversion logic for other interfaces
are redundant, due to now we can raise proper exception directly from
the checker.
6. Added the logic to recreate drive object if the storage and/or driver
isn't stateless.
Few minor changes need to be added to Glance side:
Change Ibbc85b6bc2ea98c564d316db2874d7df5aac32a6 .
docImpact
Implements: blueprint store-capabilities
Change-Id: Iedf0d4f829e46ca64c3f4fc6a7dfee54d9b0605b
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
Diffstat (limited to 'glance_store/driver.py')
-rw-r--r-- | glance_store/driver.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/glance_store/driver.py b/glance_store/driver.py index d1d28f8..b7680a6 100644 --- a/glance_store/driver.py +++ b/glance_store/driver.py @@ -21,14 +21,16 @@ import logging from oslo.config import cfg from oslo.utils import importutils +from glance_store import capabilities from glance_store.common import utils from glance_store import exceptions -from glance_store.i18n import _ +from glance_store import i18n +_ = i18n._ LOG = logging.getLogger(__name__) -class Store(object): +class Store(capabilities.StoreCapability): OPTIONS = None READ_CHUNKSIZE = 16 * (1024 * 1024) # 16M @@ -38,6 +40,9 @@ class Store(object): """ Initialize the Store """ + + super(Store, self).__init__() + self.conf = conf self.store_location_class = None @@ -55,21 +60,23 @@ class Store(object): def configure(self): """ - Configure the Store to use the stored configuration options + Configure the store to use the stored configuration options + and initialize capabilities based on current configuration. + Any store that needs special configuration should implement this method. """ try: self.configure_add() - self.add = getattr(self, '_add', self.add) except exceptions.BadStoreConfiguration as e: - self._add = self.add - self.add = self.add_disabled + self.unset_capabilities(capabilities.WRITE_ACCESS) msg = (_(u"Failed to configure store correctly: %s " "Disabling add method.") % utils.exception_to_str(e)) LOG.warn(msg) + self.update_capabilities() + def get_schemes(self): """ Returns a tuple of schemes which this store can handle. @@ -96,6 +103,7 @@ class Store(object): """ # NOTE(flaper87): This should probably go away + @capabilities.check def get(self, location, offset=0, chunk_size=None, context=None): """ Takes a `glance_store.location.Location` object that indicates @@ -119,14 +127,7 @@ class Store(object): """ raise NotImplementedError - def add_disabled(self, *args, **kwargs): - """ - Add method that raises an exception because the Store was - not able to be configured properly and therefore the add() - method would error out. - """ - raise exceptions.StoreAddDisabled - + @capabilities.check def add(self, image_id, image_file, image_size, context=None): """ Stores an image file with supplied identifier to the backend @@ -144,6 +145,7 @@ class Store(object): """ raise NotImplementedError + @capabilities.check def delete(self, location, context=None): """ Takes a `glance_store.location.Location` object that indicates |