summaryrefslogtreecommitdiff
path: root/nova/virt/block_device.py
diff options
context:
space:
mode:
authorMatthew Booth <mbooth@redhat.com>2017-11-26 01:32:07 +0000
committerMatthew Booth <mbooth@redhat.com>2018-01-02 17:29:36 +0000
commit5f1ee5a471e5a7d06b13ea6066b4e78f5d5d658e (patch)
tree5e650bd868174c917ed9242e170a92da48deba1b /nova/virt/block_device.py
parent0c441e636ba9d287909584b6ddf15eab5d479f0e (diff)
downloadnova-5f1ee5a471e5a7d06b13ea6066b4e78f5d5d658e.tar.gz
DriverBlockDevice: make subclasses inherit _proxy_as_attr
This is a minor tidy-up in current code, as it allows volume_id and volume_size to be inherited by all subclasses of DriverVolumeBlockDevice. However, it's primary purpose it to make it cleaner to add uuid to all DriverBlockDevice subclasses in a subsequent patch. Part of bp local-disk-serial-numbers Change-Id: Ifabfaacf8752923493a78248593d2727a8ce4803
Diffstat (limited to 'nova/virt/block_device.py')
-rw-r--r--nova/virt/block_device.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/nova/virt/block_device.py b/nova/virt/block_device.py
index 147d787c3d..1c812cc668 100644
--- a/nova/virt/block_device.py
+++ b/nova/virt/block_device.py
@@ -104,11 +104,15 @@ class DriverBlockDevice(dict):
_fields = set()
_legacy_fields = set()
- _proxy_as_attr = set()
+ _proxy_as_attr_inherited = set()
_update_on_save = {'disk_bus': None,
'device_name': None,
'device_type': None}
+ # A hash containing the combined inherited members of _proxy_as_attr for
+ # each subclass
+ _proxy_as_attr_by_class = {}
+
def __init__(self, bdm):
self.__dict__['_bdm_obj'] = bdm
@@ -118,6 +122,24 @@ class DriverBlockDevice(dict):
self.update({field: None for field in self._fields})
self._transform()
+ @property
+ def _proxy_as_attr(self):
+ # Combine the members of all _proxy_as_attr sets for this class and its
+ # ancestors
+ if self.__class__ not in self._proxy_as_attr_by_class:
+ attr_all = set()
+ for cls in self.__class__.mro():
+ attr_one = getattr(cls, '_proxy_as_attr_inherited', None)
+ if attr_one is not None:
+ attr_all = attr_all | attr_one
+
+ # We don't need to lock here because as long as insertion into a
+ # dict is threadsafe, the only consequence of a race is calculating
+ # the inherited set multiple times.
+ self._proxy_as_attr_by_class[self.__class__] = attr_all
+
+ return self._proxy_as_attr_by_class[self.__class__]
+
def __getattr__(self, name):
if name in self._proxy_as_attr:
return getattr(self._bdm_obj, name)
@@ -228,7 +250,7 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
_valid_source = 'volume'
_valid_destination = 'volume'
- _proxy_as_attr = set(['volume_size', 'volume_id'])
+ _proxy_as_attr_inherited = set(['volume_size', 'volume_id'])
_update_on_save = {'disk_bus': None,
'device_name': 'mount_device',
'device_type': None}
@@ -571,7 +593,7 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
class DriverSnapshotBlockDevice(DriverVolumeBlockDevice):
_valid_source = 'snapshot'
- _proxy_as_attr = set(['volume_size', 'volume_id', 'snapshot_id'])
+ _proxy_as_attr_inherited = set(['snapshot_id'])
def attach(self, context, instance, volume_api,
virt_driver, wait_func=None):
@@ -598,7 +620,7 @@ class DriverSnapshotBlockDevice(DriverVolumeBlockDevice):
class DriverImageBlockDevice(DriverVolumeBlockDevice):
_valid_source = 'image'
- _proxy_as_attr = set(['volume_size', 'volume_id', 'image_id'])
+ _proxy_as_attr_inherited = set(['image_id'])
def attach(self, context, instance, volume_api,
virt_driver, wait_func=None):
@@ -622,7 +644,7 @@ class DriverImageBlockDevice(DriverVolumeBlockDevice):
class DriverBlankBlockDevice(DriverVolumeBlockDevice):
_valid_source = 'blank'
- _proxy_as_attr = set(['volume_size', 'volume_id', 'image_id'])
+ _proxy_as_attr_inherited = set(['image_id'])
def attach(self, context, instance, volume_api,
virt_driver, wait_func=None):