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