Пример #1
0
 def register_image(self, kernel_id, block_device_map, name=None, description=None):
     image = Image()
     image.id = _new_id()
     image.block_device_mapping = block_device_map
     image.state = "available"
     image.name = name
     image.description = description
     self.images[image.id] = image
     return image.id
Пример #2
0
 def register_image(self,
                    kernel_id,
                    block_device_map,
                    name=None,
                    description=None):
     image = Image()
     image.id = 'ami-' + _new_id()
     image.block_device_mapping = block_device_map
     image.state = 'available'
     image.name = name
     image.description = description
     image.virtualization_type = 'paravirtual'
     self.images[image.id] = image
     return image.id
Пример #3
0
 def create_image(self, instance_id, name, **kwargs):
     image = Image()
     image.id = instance_id
     image.block_device_mapping = kwargs['block_device_mapping']
     image.state = 'available'
     image.name = name
     image.description = 'This is a test'
     image.virtualization_type = 'paravirtual'
     image.root_device_name = '/dev/sda1'
     i = self.get_instance(instance_id)
     rdn = image.root_device_name
     # create_image creates this implicitly
     image.block_device_mapping[rdn] = i.block_device_mapping[rdn]
     self.images[image.id] = image
     return image.id
Пример #4
0
 def register_image(self,
                    block_device_map,
                    name=None,
                    description=None):
     image = Image()
     image.id = 'ami-' + new_id()
     image.block_device_mapping = block_device_map
     image.state = 'available'
     image.name = name
     image.description = description
     image.virtualization_type = 'hvm'
     image.root_device_type = 'ebs'
     image.hypervisor = 'xen'
     self.images[image.id] = image
     return image.id
Пример #5
0
 def register_image(self,
                    kernel_id,
                    block_device_map,
                    name=None,
                    description=None):
     image = Image()
     image.id = 'ami-' + new_id()
     image.block_device_mapping = block_device_map
     image.state = 'available'
     image.name = name
     image.description = description
     image.virtualization_type = 'paravirtual'
     image.root_device_type = 'ebs'
     image.hypervisor = 'xen'
     self.images[image.id] = image
     return image.id
Пример #6
0
 def handle_instance_being_bundled(self, instance, do_not_finish=False):
     bundling_tag = instance.tags.get('ec_bundling') or None
     if bundling_tag is None:
         return None
     bucket, bundle_id = bundling_tag.split('/')
     s3_conn = self.get_connection(conn_type='s3')
     k = Key(s3_conn.get_bucket(bucket))
     k.key = bundle_id
     metadata = json.loads(k.get_contents_as_string())
     tasks = self.conn.get_all_bundle_tasks([bundle_id])
     image_id = None
     if do_not_finish and len(tasks) > 0:
         tasks[0].state = 'pending'
     if len(tasks) == 0 or tasks[0].state == 'complete':
         # handle registration
         if metadata['version'] != curr_version:
             self.log_request(
                 _(u"Bundle operation {0} from previous software version will be ignored."
                   ).format(bundle_id))
         else:
             self.log_request(
                 _(u"Registering image from bundle operation {0}").format(
                     bundle_id))
             bdm = self.get_block_device_map(metadata['bdm'])
             image_id = self.conn.register_image(
                 name=metadata['name'],
                 description=metadata['description'],
                 image_location="%s/%s.manifest.xml" %
                 (bucket, metadata['prefix']),
                 virtualization_type=metadata['virt_type'],
                 block_device_map=bdm,
                 kernel_id=metadata['kernel_id'],
                 ramdisk_id=metadata['ramdisk_id'])
             tags = json.loads(metadata['tags'])
             self.conn.create_tags(image_id, tags)
             self.invalidate_images_cache()
         # cleanup metadata
         k.delete()
         self.conn.delete_tags(instance.id, ['ec_bundling'])
         if metadata['version'] != curr_version:
             return None
         else:
             return self.conn.get_all_images(image_ids=[image_id])[0]
     elif tasks[0].state == 'failed':
         # generate error message, need to let user know somehow
         logging.warn("bundle task failed! ")
         # cleanup metadata
         k.delete()
         self.conn.delete_tags(instance.id, ['ec_bundling'])
         return None
     elif tasks[0].state in ['pending', 'bundling', 'storing']:
         # add this into image list
         fakeimage = Image()
         fakeimage.id = _(u'Pending')
         fakeimage.fake_id = 'p' + instance.id
         fakeimage.location = "%s/%s.manifest.xml" % (bucket,
                                                      metadata['prefix'])
         fakeimage.owner_id = ''  # do we need this?
         fakeimage.state = tasks[0].state
         fakeimage.progress = tasks[0].progress
         fakeimage.is_public = False
         fakeimage.name = metadata['name']
         fakeimage.description = metadata['description']
         fakeimage.architecture = metadata['arch']
         fakeimage.platform = 'windows' if metadata[
             'platform'] == 'windows' else None
         fakeimage.type = 'machine'
         fakeimage.root_device_type = 'instance-store'
         fakeimage.root_device_name = '/dev/sda'
         fakeimage.block_device_mapping = {}
         fakeimage.tags = json.loads(metadata['tags'])
         return fakeimage
Пример #7
0
 def handle_instance_being_bundled(self, instance, do_not_finish=False):
     bundling_tag = instance.tags.get('ec_bundling') or None
     if bundling_tag is None:
         return None
     bucket, bundle_id = bundling_tag.split('/')
     s3_conn = self.get_connection(conn_type='s3')
     k = Key(s3_conn.get_bucket(bucket))
     k.key = bundle_id
     metadata = json.loads(k.get_contents_as_string())
     tasks = self.conn.get_all_bundle_tasks([bundle_id])
     image_id = None
     if do_not_finish and len(tasks) > 0:
         tasks[0].state = 'pending'
     if len(tasks) == 0 or tasks[0].state == 'complete':
         # handle registration
         if metadata['version'] != curr_version:
             self.log_request(
                 _(u"Bundle operation {0} from previous software version will be ignored.").format(bundle_id))
         else:
             self.log_request(_(u"Registering image from bundle operation {0}").format(bundle_id))
             bdm = self.get_block_device_map(metadata['bdm'])
             image_id = self.conn.register_image(
                 name=metadata['name'],
                 description=metadata['description'],
                 image_location="%s/%s.manifest.xml" % (bucket, metadata['prefix']),
                 virtualization_type=metadata['virt_type'],
                 block_device_map=bdm,
                 kernel_id=metadata['kernel_id'],
                 ramdisk_id=metadata['ramdisk_id']
             )
             tags = json.loads(metadata['tags'])
             self.conn.create_tags(image_id, tags)
             self.invalidate_images_cache()
         # cleanup metadata
         k.delete()
         self.conn.delete_tags(instance.id, ['ec_bundling'])
         if metadata['version'] != curr_version:
             return None
         else:
             return self.conn.get_all_images(image_ids=[image_id])[0]
     elif tasks[0].state == 'failed':
         # generate error message, need to let user know somehow
         logging.warn("bundle task failed! ")
         # cleanup metadata
         k.delete()
         self.conn.delete_tags(instance.id, ['ec_bundling'])
         return None
     elif tasks[0].state in ['pending', 'bundling', 'storing']:
         # add this into image list
         fakeimage = Image()
         fakeimage.id = _(u'Pending')
         fakeimage.fake_id = 'p' + instance.id
         fakeimage.location = "%s/%s.manifest.xml" % (bucket, metadata['prefix'])
         fakeimage.owner_id = ''  # do we need this?
         fakeimage.state = tasks[0].state
         fakeimage.progress = tasks[0].progress
         fakeimage.is_public = False
         fakeimage.name = metadata['name']
         fakeimage.description = metadata['description']
         fakeimage.architecture = metadata['arch']
         fakeimage.platform = 'windows' if metadata['platform'] == 'windows' else None
         fakeimage.type = 'machine'
         fakeimage.root_device_type = 'instance-store'
         fakeimage.root_device_name = '/dev/sda'
         fakeimage.block_device_mapping = {}
         fakeimage.tags = json.loads(metadata['tags'])
         return fakeimage