summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Andrews <anotherjesse@gmail.com>2010-07-14 21:26:10 -0500
committerJesse Andrews <anotherjesse@gmail.com>2010-07-14 21:26:10 -0500
commit6bed8cde37af2614367f2ecb45bbc43d412ccd4c (patch)
tree73a6b5d28e7d91cb8951e59e330f6bcb0afca3c8
parent02fa700c4595344287a66ccbcca7510f0f4071af (diff)
downloadnova-6bed8cde37af2614367f2ecb45bbc43d412ccd4c.tar.gz
nova-6bed8cde37af2614367f2ecb45bbc43d412ccd4c.tar.xz
nova-6bed8cde37af2614367f2ecb45bbc43d412ccd4c.zip
work on importing images
-rw-r--r--nova/endpoint/cloud.py21
-rw-r--r--nova/objectstore/handler.py4
-rw-r--r--nova/objectstore/image.py64
-rw-r--r--nova/tests/objectstore_unittest.py2
4 files changed, 81 insertions, 10 deletions
diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py
index 9dccc24dc..32c7cbce0 100644
--- a/nova/endpoint/cloud.py
+++ b/nova/endpoint/cloud.py
@@ -514,6 +514,18 @@ class CloudController(object):
# vpn image is private so it doesn't show up on lists
if kwargs['image_id'] != FLAGS.vpn_image_id:
image = self._get_image(context, kwargs['image_id'])
+
+ # FIXME(ja): if image is cloudpipe, this breaks
+
+ # get defaults from imagestore
+ image_id = image['imageId']
+ kernel_id = image.get('kernelId', None)
+ ramdisk_id = image.get('ramdiskId', None)
+
+ # API parameters overrides of defaults
+ kernel_id = kwargs.get('kernel_id', kernel_id)
+ ramdisk_id = kwargs.get('ramdisk_id', ramdisk_id)
+
logging.debug("Going to run instances...")
reservation_id = utils.generate_uid('r')
launch_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
@@ -534,12 +546,9 @@ class CloudController(object):
bridge_name = net['bridge_name']
for num in range(int(kwargs['max_count'])):
inst = self.instdir.new()
- # TODO(ja): add ari, aki
- inst['image_id'] = kwargs['image_id']
- if 'kernel_id' in kwargs:
- inst['kernel_id'] = kwargs['kernel_id']
- if 'ramdisk_id' in kwargs:
- inst['ramdisk_id'] = kwargs['ramdisk_id']
+ inst['image_id'] = image_id
+ inst['kernel_id'] = kernel_id
+ inst['ramdisk_id'] = ramdisk_id
inst['user_data'] = kwargs.get('user_data', '')
inst['instance_type'] = kwargs.get('instance_type', 'm1.small')
inst['reservation_id'] = reservation_id
diff --git a/nova/objectstore/handler.py b/nova/objectstore/handler.py
index 462ad90b1..2482f6fea 100644
--- a/nova/objectstore/handler.py
+++ b/nova/objectstore/handler.py
@@ -286,8 +286,8 @@ class ImageHandler(BaseRequestHandler):
if not bucket_object.is_authorized(self.context):
raise web.HTTPError(403)
- p = multiprocessing.Process(target=image.Image.create,args=
- (image_id, image_location, self.context))
+ p = multiprocessing.Process(target=image.Image.register_aws_image,
+ args=(image_id, image_location, self.context))
p.start()
self.finish()
diff --git a/nova/objectstore/image.py b/nova/objectstore/image.py
index dc4667ec2..4de41ea96 100644
--- a/nova/objectstore/image.py
+++ b/nova/objectstore/image.py
@@ -100,7 +100,69 @@ class Image(object):
return json.load(f)
@staticmethod
- def create(image_id, image_location, context):
+ def add(src, description, kernel=None, ramdisk=None, public=True):
+ """adds an image to imagestore
+
+ @type src: str
+ @param src: location of the partition image on disk
+
+ @type description: str
+ @param description: string describing the image contents
+
+ @type kernel: bool or str
+ @param kernel: either TRUE meaning this partition is a kernel image or
+ a string of the image id for the kernel
+
+ @type ramdisk: bool or str
+ @param ramdisk: either TRUE meaning this partition is a ramdisk image or
+ a string of the image id for the ramdisk
+
+
+ @type public: bool
+ @param public: determine if this is a public image or private
+
+ @rtype: str
+ @return: a string with the image id
+ """
+
+ image_type = 'machine'
+ image_id = utils.generate_uid('ami')
+
+ if kernel is True:
+ image_type = 'kernel'
+ image_id = utils.generate_uid('aki')
+ if ramdisk is True:
+ image_type = 'ramdisk'
+ image_id = utils.generate_uid('ari')
+
+ image_path = os.path.join(FLAGS.images_path, image_id)
+ os.makedirs(image_path)
+
+ shutil.copyfile(src, os.path.join(image_path, 'image'))
+
+ info = {
+ 'imageId': image_id,
+ 'imageLocation': description,
+ 'imageOwnerId': 'system',
+ 'isPublic': public,
+ 'architecture': 'x86_64',
+ 'type': image_type,
+ 'state': 'available'
+ }
+
+ if type(kernel) is str and len(kernel) > 0:
+ info['kernelId'] = kernel
+
+ if type(ramdisk) is str and len(ramdisk) > 0:
+ info['ramdiskId'] = ramdisk
+
+ with open(os.path.join(image_path, 'info.json'), "w") as f:
+ json.dump(info, f)
+
+ return image_id
+
+ @staticmethod
+ def register_aws_image(image_id, image_location, context):
image_path = os.path.join(FLAGS.images_path, image_id)
os.makedirs(image_path)
diff --git a/nova/tests/objectstore_unittest.py b/nova/tests/objectstore_unittest.py
index cee567c8b..ddd455a73 100644
--- a/nova/tests/objectstore_unittest.py
+++ b/nova/tests/objectstore_unittest.py
@@ -155,7 +155,7 @@ class ObjectStoreTestCase(test.BaseTestCase):
bucket[os.path.basename(path)] = open(path, 'rb').read()
# register an image
- objectstore.image.Image.create('i-testing', 'image_bucket/1mb.manifest.xml', self.context)
+ objectstore.image.Image.register_aws_image('i-testing', 'image_bucket/1mb.manifest.xml', self.context)
# verify image
my_img = objectstore.image.Image('i-testing')