Add two attributes for cinder volume

Add 'encrypted' and 'attachments' attributes for cinder
volume resource.

Change-Id: I920f97d196e5f4bed7bc8186b7d12157ee25edea
This commit is contained in:
huangtianhua 2014-09-23 12:04:37 +08:00
parent a0b89b9a1c
commit c38a2a0282
2 changed files with 14 additions and 3 deletions

View File

@ -458,10 +458,12 @@ class CinderVolume(Volume):
AVAILABILITY_ZONE_ATTR, SIZE_ATTR, SNAPSHOT_ID_ATTR, DISPLAY_NAME,
DISPLAY_DESCRIPTION, VOLUME_TYPE_ATTR, METADATA_ATTR,
SOURCE_VOLID_ATTR, STATUS, CREATED_AT, BOOTABLE, METADATA_VALUES_ATTR,
ENCRYPTED_ATTR, ATTACHMENTS,
) = (
'availability_zone', 'size', 'snapshot_id', 'display_name',
'display_description', 'volume_type', 'metadata',
'source_volid', 'status', 'created_at', 'bootable', 'metadata_values',
'encrypted', 'attachments',
)
properties_schema = {
@ -564,6 +566,12 @@ class CinderVolume(Volume):
METADATA_VALUES_ATTR: attributes.Schema(
_('Key/value pairs associated with the volume in raw dict form.')
),
ENCRYPTED_ATTR: attributes.Schema(
_('Boolean indicating if the volume is encrypted or not.')
),
ATTACHMENTS: attributes.Schema(
_('The list of attachments of the volume.')
),
}
_volume_creating_status = ['creating', 'restoring-backup', 'downloading']
@ -596,9 +604,9 @@ class CinderVolume(Volume):
def _resolve_attribute(self, name):
vol = self.cinder().volumes.get(self.resource_id)
if name == 'metadata':
if name == self.METADATA_ATTR:
return unicode(json.dumps(vol.metadata))
elif name == 'metadata_values':
elif name == self.METADATA_VALUES_ATTR:
return vol.metadata
return unicode(getattr(vol, name))

View File

@ -816,7 +816,8 @@ class CinderVolumeTest(BaseVolumeTest):
display_description='desc', volume_type='lvm',
metadata={'key': 'value'}, source_volid=None,
status='available', bootable=False,
created_at='2013-02-25T02:40:21.000000')
created_at='2013-02-25T02:40:21.000000',
encrypted=False, attachments=[])
stack_name = 'test_volume_stack'
self._mock_create_volume(fv, stack_name)
@ -842,6 +843,8 @@ class CinderVolumeTest(BaseVolumeTest):
self.assertEqual(u'2013-02-25T02:40:21.000000',
rsrc.FnGetAtt('created_at'))
self.assertEqual(u'False', rsrc.FnGetAtt('bootable'))
self.assertEqual(u'False', rsrc.FnGetAtt('encrypted'))
self.assertEqual(u'[]', rsrc.FnGetAtt('attachments'))
error = self.assertRaises(exception.InvalidTemplateAttribute,
rsrc.FnGetAtt, 'unknown')
self.assertEqual(