Beispiel #1
0
 def test_migrate_live_instance_not_running(self):
     self._test_migrate_live_failed_with_exception(
         exception.InstanceNotRunning(instance_id=""))
Beispiel #2
0
 def snapshot(self, context, instance, name):
     if not instance['name'] in self.instances:
         raise exception.InstanceNotRunning()
Beispiel #3
0
 def snapshot(self, context, instance, name, update_task_state):
     if instance['name'] not in self.instances:
         raise exception.InstanceNotRunning(instance_id=instance['uuid'])
     update_task_state(task_state=task_states.IMAGE_UPLOADING)
Beispiel #4
0
 def snapshot(self, context, instance, image_id, update_task_state):
     if instance.uuid not in self.instances:
         raise exception.InstanceNotRunning(instance_id=instance.uuid)
     update_task_state(task_state=task_states.IMAGE_UPLOADING)
Beispiel #5
0
 def _check_instance_is_running(self):
     if self.instance.power_state != power_state.RUNNING:
         raise exception.InstanceNotRunning(instance_id=self.instance.uuid)
    def perform_vmhandoff(self,
                          context,
                          instance,
                          handoff_url,
                          update_task_state,
                          residue_glance_id=None):
        try:
            if hasattr(self, "_lookup_by_name"):
                # icehouse
                virt_dom = self._lookup_by_name(instance['name'])
            else:
                # kilo
                virt_dom = self._host.get_domain(instance)
        except exception.InstanceNotFound:
            raise exception.InstanceNotRunning(instance_id=instance['uuid'])
        synthesized_vm = self.synthesized_vm_dics.get(instance['uuid'], None)
        if synthesized_vm is None:
            raise exception.InstanceNotRunning(instance_id=instance['uuid'])

        # get the file path for Base VM and VM overlay
        (image_service,
         image_id) = glance.get_remote_image_service(context,
                                                     instance['image_ref'])
        image_meta = image_service.show(context, image_id)
        base_sha256_uuid, memory_snap_id, diskhash_snap_id, memhash_snap_id = \
            self._get_basevm_meta_info(image_meta)
        basedisk_path = self._get_cache_image(context, instance,
                                              image_meta['id'])
        basemem_path = self._get_cache_image(context, instance, memory_snap_id)
        diskhash_path = self._get_cache_image(context, instance,
                                              diskhash_snap_id)
        memhash_path = self._get_cache_image(context, instance,
                                             memhash_snap_id)
        base_vm_paths = [
            basedisk_path, basemem_path, diskhash_path, memhash_path
        ]

        update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD,
                          expected_state=None)
        try:
            residue_filepath = self._handoff_send(base_vm_paths,
                                                  base_sha256_uuid,
                                                  synthesized_vm, handoff_url)
        except handoff.HandoffError as e:
            msg = "failed to perform VM handoff:\n"
            msg += str(e)
            raise exception.ImageNotFound(msg)

        del self.synthesized_vm_dics[instance['uuid']]
        if residue_filepath:
            LOG.info("residue saved at %s" % residue_filepath)
        if residue_filepath and residue_glance_id:
            # export to glance
            (image_service, image_id) = glance.get_remote_image_service(
                context, instance['image_ref'])
            meta_metadata = self._get_snapshot_metadata(
                virt_dom, context, instance, residue_glance_id)
            update_task_state(task_state=task_states.IMAGE_UPLOADING,
                              expected_state=task_states.IMAGE_PENDING_UPLOAD)
            self._update_to_glance(context, image_service, residue_filepath,
                                   residue_glance_id, meta_metadata)
        # clean up
        LOG.info(_("VM residue upload complete"), instance=instance)
        if residue_filepath and os.path.exists(residue_filepath):
            os.remove(residue_filepath)
    def cloudlet_base(self, context, instance, vm_name, disk_meta_id,
                      memory_meta_id, diskhash_meta_id, memoryhash_meta_id,
                      update_task_state):
        """create base vm and save it to glance
        """
        try:
            if hasattr(self, "_lookup_by_name"):
                # icehouse
                virt_dom = self._lookup_by_name(instance['name'])
            else:
                # kilo
                virt_dom = self._host.get_domain(instance)
        except exception.InstanceNotFound:
            raise exception.InstanceNotRunning(instance_id=instance['uuid'])

        # pause VM
        self.pause(instance)

        (image_service,
         image_id) = glance.get_remote_image_service(context,
                                                     instance['image_ref'])

        disk_metadata = self._get_snapshot_metadata(virt_dom, context,
                                                    instance, disk_meta_id)
        mem_metadata = self._get_snapshot_metadata(virt_dom, context, instance,
                                                   memory_meta_id)
        diskhash_metadata = self._get_snapshot_metadata(
            virt_dom, context, instance, diskhash_meta_id)
        memhash_metadata = self._get_snapshot_metadata(virt_dom, context,
                                                       instance,
                                                       memoryhash_meta_id)

        disk_path = libvirt_utils.find_disk(virt_dom)
        source_format = libvirt_utils.get_disk_type(disk_path)
        snapshot_name = uuid.uuid4().hex
        (state, _max_mem, _mem, _cpus, _t) = virt_dom.info()
        state = libvirt_driver.LIBVIRT_POWER_STATE[state]

        # creating base vm requires cold snapshotting
        snapshot_backend = self.image_backend.snapshot(
            disk_path, image_type=source_format)

        LOG.info(_("Beginning cold snapshot process"), instance=instance)
        # not available at icehouse
        # snapshot_backend.snapshot_create()

        update_task_state(task_state=task_states.IMAGE_PENDING_UPLOAD,
                          expected_state=None)
        snapshot_directory = libvirt_driver.CONF.libvirt.snapshots_directory
        fileutils.ensure_tree(snapshot_directory)
        with utils.tempdir(dir=snapshot_directory) as tmpdir:
            try:
                out_path = os.path.join(tmpdir, snapshot_name)
                # At this point, base vm should be "raw" format
                snapshot_backend.snapshot_extract(out_path, "raw")
            finally:
                # snapshotting logic is changed since icehouse.
                #  : cannot find snapshot_create and snapshot_delete.
                # snapshot_extract is replacing these two operations.
                # snapshot_backend.snapshot_delete()
                LOG.info(_("Snapshot extracted, beginning image upload"),
                         instance=instance)

            # generate memory snapshop and hashlist
            basemem_path = os.path.join(tmpdir, snapshot_name + "-mem")
            diskhash_path = os.path.join(tmpdir, snapshot_name + "-disk_hash")
            memhash_path = os.path.join(tmpdir, snapshot_name + "-mem_hash")

            update_task_state(task_state=task_states.IMAGE_UPLOADING,
                              expected_state=task_states.IMAGE_PENDING_UPLOAD)
            synthesis._create_baseVM(self._conn,
                                     virt_dom,
                                     out_path,
                                     basemem_path,
                                     diskhash_path,
                                     memhash_path,
                                     nova_util=libvirt_utils)

            self._update_to_glance(context, image_service, out_path,
                                   disk_meta_id, disk_metadata)
            LOG.info(_("Base disk upload complete"), instance=instance)
            self._update_to_glance(context, image_service, basemem_path,
                                   memory_meta_id, mem_metadata)
            LOG.info(_("Base memory image upload complete"), instance=instance)
            self._update_to_glance(context, image_service, diskhash_path,
                                   diskhash_meta_id, diskhash_metadata)
            LOG.info(_("Base disk upload complete"), instance=instance)
            self._update_to_glance(context, image_service, memhash_path,
                                   memoryhash_meta_id, memhash_metadata)
            LOG.info(_("Base memory image upload complete"), instance=instance)