Skip to content

Commit

Permalink
EC2 DescribeImageAttribute by kernel/ramdisk.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
motokentsai committed Jul 25, 2012
1 parent 9468508 commit 7ea6289
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nova/api/ec2/cloud.py
Expand Up @@ -1389,10 +1389,26 @@ def _root_device_name_attribute(image, result):
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)
Expand Down
6 changes: 6 additions & 0 deletions nova/tests/api/ec2/test_cloud.py
Expand Up @@ -1336,6 +1336,12 @@ def fake_detail(self, context, **kwargs):
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
Expand Down

0 comments on commit 7ea6289

Please sign in to comment.