update code to work with new container and disk formats from glance
This commit is contained in:
@@ -96,6 +96,7 @@ flags.DECLARE('network_size', 'nova.network.manager')
|
||||
flags.DECLARE('vlan_start', 'nova.network.manager')
|
||||
flags.DECLARE('vpn_start', 'nova.network.manager')
|
||||
flags.DECLARE('fixed_range_v6', 'nova.network.manager')
|
||||
flags.DECLARE('images_path', 'nova.image.local')
|
||||
flags.DEFINE_flag(flags.HelpFlag())
|
||||
flags.DEFINE_flag(flags.HelpshortFlag())
|
||||
flags.DEFINE_flag(flags.HelpXMLFlag())
|
||||
@@ -743,17 +744,20 @@ class ImageCommands(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.image_service = utils.import_object(FLAGS.image_service)
|
||||
|
||||
def _register(self, image_type, path, owner, name=None,
|
||||
is_public='T', architecture='x86_64',
|
||||
kernel_id=None, ramdisk_id=None):
|
||||
meta = {'type': image_type,
|
||||
'is_public': True,
|
||||
def _register(self, image_type, disk_format, container_format,
|
||||
path, owner, name=None, is_public='T',
|
||||
architecture='x86_64', kernel_id=None, ramdisk_id=None):
|
||||
meta = {'is_public': True,
|
||||
'name': name,
|
||||
'disk_format': disk_format,
|
||||
'container_format': container_format,
|
||||
'properties': {'image_state': 'available',
|
||||
'owner': owner,
|
||||
'type': image_type,
|
||||
'architecture': architecture,
|
||||
'image_location': 'local',
|
||||
'is_public': (is_public == 'T')}}
|
||||
print image_type, meta
|
||||
if kernel_id:
|
||||
meta['properties']['kernel_id'] = int(kernel_id)
|
||||
if ramdisk_id:
|
||||
@@ -781,28 +785,31 @@ class ImageCommands(object):
|
||||
architecture, kernel_id, ramdisk_id)
|
||||
|
||||
def image_register(self, 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,
|
||||
disk_format='ami', container_format='ami'):
|
||||
"""Uploads an image into the image_service
|
||||
arguments: path owner [name] [is_public='T'] [architecture='x86_64']
|
||||
[kernel_id] [ramdisk_id]"""
|
||||
return self._register('machine', path, owner, name, is_public,
|
||||
architecture, kernel_id, ramdisk_id)
|
||||
[kernel_id=None] [ramdisk_id=None]
|
||||
[disk_format='ami'] [container_format='ami']"""
|
||||
return self._register('machine', disk_format, container_format, path,
|
||||
owner, name, is_public, architecture,
|
||||
kernel_id, ramdisk_id)
|
||||
|
||||
def kernel_register(self, path, owner, name=None, is_public='T',
|
||||
architecture='x86_64'):
|
||||
"""Uploads a kernel into the image_service
|
||||
arguments: path owner [name] [is_public='T'] [architecture='x86_64']
|
||||
"""
|
||||
return self._register('kernel', path, owner, name, is_public,
|
||||
architecture)
|
||||
return self._register('kernel', 'aki', 'aki', path, owner, name,
|
||||
is_public, architecture)
|
||||
|
||||
def ramdisk_register(self, path, owner, name=None, is_public='T',
|
||||
architecture='x86_64'):
|
||||
"""Uploads a ramdisk into the image_service
|
||||
arguments: path owner [name] [is_public='T'] [architecture='x86_64']
|
||||
"""
|
||||
return self._register('ramdisk', path, owner, name, is_public,
|
||||
architecture)
|
||||
return self._register('ramdisk', 'ari', 'ari', path, owner, name,
|
||||
is_public, architecture)
|
||||
|
||||
def _lookup(self, old_image_id):
|
||||
try:
|
||||
@@ -813,12 +820,19 @@ class ImageCommands(object):
|
||||
return image['id']
|
||||
|
||||
def _old_to_new(self, old):
|
||||
new = {'type': old['type'],
|
||||
mapping = {'machine': 'ami',
|
||||
'kernel': 'aki',
|
||||
'ramdisk': 'ari'}
|
||||
container_format = mapping[old['type']]
|
||||
disk_format = container_format
|
||||
new = {'disk_format': disk_format,
|
||||
'container_format': container_format,
|
||||
'is_public': True,
|
||||
'name': old['imageId'],
|
||||
'properties': {'image_state': old['imageState'],
|
||||
'owner': old['imageOwnerId'],
|
||||
'architecture': old['architecture'],
|
||||
'type': old['type'],
|
||||
'image_location': old['imageLocation'],
|
||||
'is_public': old['isPublic']}}
|
||||
if old.get('kernelId'):
|
||||
@@ -851,7 +865,8 @@ class ImageCommands(object):
|
||||
# to move the files out of the way before importing
|
||||
# so we aren't writing to the same directory. This
|
||||
# may fail if the dir was a mointpoint.
|
||||
if directory == os.path.abspath(FLAGS.images_path):
|
||||
if (FLAGS.image_service == 'nova.image.local.LocalImageService'
|
||||
and directory == os.path.abspath(FLAGS.images_path)):
|
||||
new_dir = "%s_bak" % directory
|
||||
os.move(directory, new_dir)
|
||||
os.mkdir(directory)
|
||||
|
||||
Reference in New Issue
Block a user