EC2 DescribeImageAttribute by kernel/ramdisk.

Fixes bug 1026898.

Supports kernel/ramdisk attributes for EC2 DescribeImageAttribute API to
display the ID of the kernel/ramdisk associated with the AMI. And adds
test cases to verify this behavior.

Change-Id: I3ea91b95812dcec349b4ff6dc889645a57975278
This commit is contained in:
MotoKen
2012-07-24 16:27:45 +08:00
parent 9468508efe
commit 7ea6289762
2 changed files with 22 additions and 0 deletions

View File

@@ -1389,10 +1389,26 @@ class CloudController(object):
if result['rootDeviceName'] is None:
result['rootDeviceName'] = block_device.DEFAULT_ROOT_DEV_NAME
def _kernel_attribute(image, result):
kernel_id = image['properties'].get('kernel_id')
if kernel_id:
result['kernel'] = {
'value': ec2utils.image_ec2_id(kernel_id, 'aki')
}
def _ramdisk_attribute(image, result):
ramdisk_id = image['properties'].get('ramdisk_id')
if ramdisk_id:
result['ramdisk'] = {
'value': ec2utils.image_ec2_id(ramdisk_id, 'ari')
}
supported_attributes = {
'blockDeviceMapping': _block_device_mapping_attribute,
'launchPermission': _launch_permission_attribute,
'rootDeviceName': _root_device_name_attribute,
'kernel': _kernel_attribute,
'ramdisk': _ramdisk_attribute,
}
fn = supported_attributes.get(attribute)

View File

@@ -1336,6 +1336,12 @@ class CloudTestCase(test.TestCase):
result = describe_image_attribute(self.context, 'ami-00000001',
'launchPermission')
self.assertEqual([{'group': 'all'}], result['launchPermission'])
result = describe_image_attribute(self.context, 'ami-00000001',
'kernel')
self.assertEqual('aki-00000001', result['kernel']['value'])
result = describe_image_attribute(self.context, 'ami-00000001',
'ramdisk')
self.assertEqual('ari-00000001', result['ramdisk']['value'])
def test_describe_image_attribute_root_device_name(self):
describe_image_attribute = self.cloud.describe_image_attribute