Fixes issues with describe instances due to improperly set metadata.

* Removes image['properties']['type']
 * Uses image['container_format'] to key display of type and create ec2 ids.
 * Defaults to 'ami' if container_format cannot be deduced. This allows
   bare images to show up in describe instances and be launched even though they
   are not officially in 'ami' format.
 * Changes nova-manage register to set proper container format
 * Fixes tests
 * Fixes _do_get_kernel_and_ramdisk in openstack api to only try to get them if it is a true 'ami'
 * Replaces 'owner_id' with 'project_id' since that is expected by glance code
 * Moves the filtering scheme to base image service so all services filter the same way
This commit is contained in:
Vishvananda Ishaya
2011-04-08 00:32:34 +00:00
committed by Tarmac

View File

@@ -894,20 +894,17 @@ class ImageCommands(object):
def __init__(self, *args, **kwargs):
self.image_service = utils.import_object(FLAGS.image_service)
def _register(self, image_type, disk_format, container_format,
def _register(self, container_format, disk_format,
path, owner, name=None, is_public='T',
architecture='x86_64', kernel_id=None, ramdisk_id=None):
meta = {'is_public': True,
meta = {'is_public': (is_public == 'T'),
'name': name,
'disk_format': disk_format,
'container_format': container_format,
'disk_format': disk_format,
'properties': {'image_state': 'available',
'owner_id': owner,
'type': image_type,
'project_id': owner,
'architecture': architecture,
'image_location': 'local',
'is_public': (is_public == 'T')}}
print image_type, meta
'image_location': 'local'}}
if kernel_id:
meta['properties']['kernel_id'] = int(kernel_id)
if ramdisk_id:
@@ -932,16 +929,18 @@ class ImageCommands(object):
ramdisk_id = self.ramdisk_register(ramdisk, owner, None,
is_public, architecture)
self.image_register(image, owner, name, is_public,
architecture, kernel_id, ramdisk_id)
architecture, 'ami', 'ami',
kernel_id, ramdisk_id)
def image_register(self, path, owner, name=None, is_public='T',
architecture='x86_64', kernel_id=None, ramdisk_id=None,
disk_format='ami', container_format='ami'):
architecture='x86_64', container_format='bare',
disk_format='raw', kernel_id=None, ramdisk_id=None):
"""Uploads an image into the image_service
arguments: path owner [name] [is_public='T'] [architecture='x86_64']
[container_format='bare'] [disk_format='raw']
[kernel_id=None] [ramdisk_id=None]
[disk_format='ami'] [container_format='ami']"""
return self._register('machine', disk_format, container_format, path,
"""
return self._register(container_format, disk_format, path,
owner, name, is_public, architecture,
kernel_id, ramdisk_id)
@@ -950,7 +949,7 @@ class ImageCommands(object):
"""Uploads a kernel into the image_service
arguments: path owner [name] [is_public='T'] [architecture='x86_64']
"""
return self._register('kernel', 'aki', 'aki', path, owner, name,
return self._register('aki', 'aki', path, owner, name,
is_public, architecture)
def ramdisk_register(self, path, owner, name=None, is_public='T',
@@ -958,7 +957,7 @@ class ImageCommands(object):
"""Uploads a ramdisk into the image_service
arguments: path owner [name] [is_public='T'] [architecture='x86_64']
"""
return self._register('ramdisk', 'ari', 'ari', path, owner, name,
return self._register('ari', 'ari', path, owner, name,
is_public, architecture)
def _lookup(self, old_image_id):
@@ -975,16 +974,17 @@ class ImageCommands(object):
'ramdisk': 'ari'}
container_format = mapping[old['type']]
disk_format = container_format
if container_format == 'ami' and not old.get('kernelId'):
container_format = 'bare'
disk_format = 'raw'
new = {'disk_format': disk_format,
'container_format': container_format,
'is_public': True,
'is_public': old['isPublic'],
'name': old['imageId'],
'properties': {'image_state': old['imageState'],
'owner_id': old['imageOwnerId'],
'project_id': old['imageOwnerId'],
'architecture': old['architecture'],
'type': old['type'],
'image_location': old['imageLocation'],
'is_public': old['isPublic']}}
'image_location': old['imageLocation']}}
if old.get('kernelId'):
new['properties']['kernel_id'] = self._lookup(old['kernelId'])
if old.get('ramdiskId'):