Add volume bootable information to api response
If there is any glance metadata associated with a volume, we'll consider the volume bootable. This will return the information for both /volumes and /detail calls. blueprint list-bootable-volumes Change-Id: Id9dbe5cb648be62fb19bb8bd6a97d8eab05ec25a
This commit is contained in:
parent
3f183070f7
commit
040d9309c5
@ -113,6 +113,11 @@ def _translate_volume_summary_view(context, vol, image_id=None):
|
|||||||
else:
|
else:
|
||||||
d['metadata'] = {}
|
d['metadata'] = {}
|
||||||
|
|
||||||
|
if vol.get('volume_glance_metadata'):
|
||||||
|
d['bootable'] = 'true'
|
||||||
|
else:
|
||||||
|
d['bootable'] = 'false'
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,6 +213,11 @@ class VolumeGlanceMetadata(BASE, CinderBase):
|
|||||||
snapshot_id = Column(String(36), ForeignKey('snapshots.id'))
|
snapshot_id = Column(String(36), ForeignKey('snapshots.id'))
|
||||||
key = Column(String(255))
|
key = Column(String(255))
|
||||||
value = Column(Text)
|
value = Column(Text)
|
||||||
|
volume = relationship(Volume, backref="volume_glance_metadata",
|
||||||
|
foreign_keys=volume_id,
|
||||||
|
primaryjoin='and_('
|
||||||
|
'VolumeGlanceMetadata.volume_id == Volume.id,'
|
||||||
|
'VolumeGlanceMetadata.deleted == False)')
|
||||||
|
|
||||||
|
|
||||||
class Quota(BASE, CinderBase):
|
class Quota(BASE, CinderBase):
|
||||||
|
@ -188,6 +188,7 @@ def stub_volume(id, **kwargs):
|
|||||||
'mountpoint': '/',
|
'mountpoint': '/',
|
||||||
'status': 'fakestatus',
|
'status': 'fakestatus',
|
||||||
'attach_status': 'attached',
|
'attach_status': 'attached',
|
||||||
|
'bootable': 'false',
|
||||||
'name': 'vol name',
|
'name': 'vol name',
|
||||||
'display_name': 'displayname',
|
'display_name': 'displayname',
|
||||||
'display_description': 'displaydesc',
|
'display_description': 'displaydesc',
|
||||||
|
@ -83,6 +83,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'id': '1',
|
'id': '1',
|
||||||
'volume_id': '1'}],
|
'volume_id': '1'}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {},
|
'metadata': {},
|
||||||
@ -140,6 +141,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'id': '1',
|
'id': '1',
|
||||||
'volume_id': '1'}],
|
'volume_id': '1'}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'image_id': 'c905cedb-7281-47e4-8a62-f26bc5fc4c77',
|
'image_id': 'c905cedb-7281-47e4-8a62-f26bc5fc4c77',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
@ -219,6 +221,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'device': '/',
|
'device': '/',
|
||||||
}],
|
}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {},
|
'metadata': {},
|
||||||
@ -247,6 +250,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'device': '/',
|
'device': '/',
|
||||||
}],
|
}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {"qos_max_iops": 2000},
|
'metadata': {"qos_max_iops": 2000},
|
||||||
@ -295,6 +299,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'id': '1',
|
'id': '1',
|
||||||
'volume_id': '1'}],
|
'volume_id': '1'}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {},
|
'metadata': {},
|
||||||
@ -317,6 +322,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'id': '1',
|
'id': '1',
|
||||||
'volume_id': '1'}],
|
'volume_id': '1'}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {},
|
'metadata': {},
|
||||||
@ -398,6 +404,7 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'server_id': 'fakeuuid',
|
'server_id': 'fakeuuid',
|
||||||
'id': '1',
|
'id': '1',
|
||||||
'volume_id': '1'}],
|
'volume_id': '1'}],
|
||||||
|
'bootable': 'false',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {},
|
'metadata': {},
|
||||||
@ -420,6 +427,34 @@ class VolumeApiTest(test.TestCase):
|
|||||||
'availability_zone': 'fakeaz',
|
'availability_zone': 'fakeaz',
|
||||||
'display_name': 'displayname',
|
'display_name': 'displayname',
|
||||||
'attachments': [],
|
'attachments': [],
|
||||||
|
'bootable': 'false',
|
||||||
|
'volume_type': 'vol_type_name',
|
||||||
|
'snapshot_id': None,
|
||||||
|
'metadata': {},
|
||||||
|
'id': '1',
|
||||||
|
'created_at': datetime.datetime(1, 1, 1,
|
||||||
|
1, 1, 1),
|
||||||
|
'size': 1}}
|
||||||
|
self.assertEqual(res_dict, expected)
|
||||||
|
|
||||||
|
def test_volume_show_bootable(self):
|
||||||
|
def stub_volume_get(self, context, volume_id):
|
||||||
|
return (fakes.stub_volume(volume_id,
|
||||||
|
volume_glance_metadata=dict(foo='bar')))
|
||||||
|
|
||||||
|
self.stubs.Set(volume_api.API, 'get', stub_volume_get)
|
||||||
|
|
||||||
|
req = fakes.HTTPRequest.blank('/v1/volumes/1')
|
||||||
|
res_dict = self.controller.show(req, '1')
|
||||||
|
expected = {'volume': {'status': 'fakestatus',
|
||||||
|
'display_description': 'displaydesc',
|
||||||
|
'availability_zone': 'fakeaz',
|
||||||
|
'display_name': 'displayname',
|
||||||
|
'attachments': [{'device': '/',
|
||||||
|
'server_id': 'fakeuuid',
|
||||||
|
'id': '1',
|
||||||
|
'volume_id': '1'}],
|
||||||
|
'bootable': 'true',
|
||||||
'volume_type': 'vol_type_name',
|
'volume_type': 'vol_type_name',
|
||||||
'snapshot_id': None,
|
'snapshot_id': None,
|
||||||
'metadata': {},
|
'metadata': {},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user