def _migrate_disk_resizing_up(self, context, instance, dest, vm_ref,
                                  sr_path):
        step = make_step_decorator(context,
                                   instance,
                                   self._update_instance_progress,
                                   total_offset=1)
        """
        NOTE(johngarbutt) Understanding how resize up works.

        For resize up, we attempt to minimize the amount of downtime
        for users by copying snapshots of their disks, while their
        VM is still running.

        It is worth noting, that migrating the snapshot, means migrating
        the whole VHD chain up to, but not including, the leaf VHD the VM
        is still writing to.

        Once the snapshots have been migrated, we power down the VM
        and migrate all the disk changes since the snapshots were taken.

        In addition, the snapshots are taken at the latest possible point,
        to help minimize the time it takes to migrate the disk changes
        after the VM has been turned off.

        Before starting to migrate any of the disks, we rename the VM,
        to <current_vm_name>-orig, in case we attempt to migrate the VM
        back onto this host, and so once we have completed the migration
        of the disk, confirm/rollback migrate can work in the usual way.

        If there is a failure at any point, we need to rollback to the
        position we were in before starting to migrate. In particular,
        we need to delete and snapshot VDIs that may have been created,
        and restore the VM back to its original name.
        """

        @step
        def fake_step_to_show_snapshot_complete():
            pass

        @step
        def transfer_immutable_vhds(root_vdi_uuids):
            immutable_root_vdi_uuids = root_vdi_uuids[1:]
            for vhd_num, vdi_uuid in enumerate(immutable_root_vdi_uuids,
                                               start=1):
                vm_utils.migrate_vhd(self._session, instance, vdi_uuid, dest,
                                     sr_path, vhd_num)
            LOG.debug("Migrated root base vhds", instance=instance)

        def _process_ephemeral_chain_recursive(ephemeral_chains,
                                               active_vdi_uuids):
            # This method is called several times, recursively.
            # The first phase snapshots the ephemeral disks, and
            # migrates the read only VHD files.
            # The final call into this method calls
            # power_down_and_transfer_leaf_vhds
            # to turn off the VM and copy the rest of the VHDs.
            number_of_chains = len(ephemeral_chains)
            if number_of_chains == 0:
                # If we get here, we have snapshotted and migrated
                # all the ephemeral disks, so its time to power down
                # and complete the migration of the diffs since the snapshot
                LOG.debug("Migrated all base vhds.", instance=instance)
                return power_down_and_transfer_leaf_vhds(
                            active_root_vdi_uuid,
                            active_vdi_uuids)

            remaining_chains = []
            if 1 > number_of_chains:
                remaining_chains = ephemeral_chains[1:]

            ephemeral_disk_index = len(active_vdi_uuids)
            userdevice = int(DEVICE_EPHEMERAL) + ephemeral_disk_index

            # Here we take a snapshot of the ephemeral disk,
            # and migrate all VHDs in the chain that are not being written to
            # Once that is completed, we call back into this method to either:
            # - migrate any remaining ephemeral disks
            # - or, if all disks are migrated, we power down and complete
            #   the migration but copying the diffs since all the snapshots
            #   were taken
            with vm_utils.snapshot_attached_here(self._session, instance,
                    vm_ref, label, str(userdevice)) as chain_vdi_uuids:

                # remember active vdi, we will migrate these later
                vdi_ref, vm_vdi_rec = vm_utils.get_vdi_for_vm_safely(
                        self._session, vm_ref, str(userdevice))
                active_uuid = vm_vdi_rec['uuid']
                active_vdi_uuids.append(active_uuid)

                # migrate inactive vhds
                inactive_vdi_uuids = chain_vdi_uuids[1:]
                ephemeral_disk_number = ephemeral_disk_index + 1
                for seq_num, vdi_uuid in enumerate(inactive_vdi_uuids,
                                                   start=1):
                    vm_utils.migrate_vhd(self._session, instance, vdi_uuid,
                                         dest, sr_path, seq_num,
                                         ephemeral_disk_number)

                LOG.debug("Read-only migrated for disk: %s", userdevice,
                          instance=instance)
                # This is recursive to simplify the taking and cleaning up
                # of all the ephemeral disk snapshots
                return _process_ephemeral_chain_recursive(remaining_chains,
                                                          active_vdi_uuids)

        @step
        def transfer_ephemeral_disks_then_all_leaf_vdis():
            ephemeral_chains = vm_utils.get_all_vdi_uuids_for_vm(
                    self._session, vm_ref,
                    min_userdevice=int(DEVICE_EPHEMERAL))

            if ephemeral_chains:
                ephemeral_chains = list(ephemeral_chains)
            else:
                ephemeral_chains = []

            _process_ephemeral_chain_recursive(ephemeral_chains, [])

        @step
        def power_down_and_transfer_leaf_vhds(root_vdi_uuid,
                                              ephemeral_vdi_uuids=None):
            self._resize_ensure_vm_is_shutdown(instance, vm_ref)
            if root_vdi_uuid is not None:
                vm_utils.migrate_vhd(self._session, instance, root_vdi_uuid,
                                     dest, sr_path, 0)
            if ephemeral_vdi_uuids:
                for ephemeral_disk_number, ephemeral_vdi_uuid in enumerate(
                            ephemeral_vdi_uuids, start=1):
                    vm_utils.migrate_vhd(self._session, instance,
                                         ephemeral_vdi_uuid, dest,
                                         sr_path, 0, ephemeral_disk_number)

        self._apply_orig_vm_name_label(instance, vm_ref)
        try:
            label = "%s-snapshot" % instance['name']

            if volume_utils.is_booted_from_volume(self._session, vm_ref):
                LOG.debug('Not snapshotting root disk since it is a volume',
                        instance=instance)
                # NOTE(alaski): This is done twice to match the number of
                # defined steps.
                fake_step_to_show_snapshot_complete()
                fake_step_to_show_snapshot_complete()
                # NOTE(alaski): This is set to None to avoid transferring the
                # VHD in power_down_and_transfer_leaf_vhds.
                active_root_vdi_uuid = None
                # snapshot and transfer all ephemeral disks
                # then power down and transfer any diffs since
                # the snapshots were taken
                transfer_ephemeral_disks_then_all_leaf_vdis()
                return

            with vm_utils.snapshot_attached_here(
                    self._session, instance, vm_ref, label) as root_vdi_uuids:
                # NOTE(johngarbutt) snapshot attached here will delete
                # the snapshot if an error occurs
                fake_step_to_show_snapshot_complete()

                # transfer all the non-active VHDs in the root disk chain
                transfer_immutable_vhds(root_vdi_uuids)
                vdi_ref, vm_vdi_rec = vm_utils.get_vdi_for_vm_safely(
                        self._session, vm_ref)
                active_root_vdi_uuid = vm_vdi_rec['uuid']

                # snapshot and transfer all ephemeral disks
                # then power down and transfer any diffs since
                # the snapshots were taken
                transfer_ephemeral_disks_then_all_leaf_vdis()

        except Exception as error:
            LOG.exception(_LE("_migrate_disk_resizing_up failed. "
                              "Restoring orig vm due_to: %s."), error,
                          instance=instance)
            try:
                self._restore_orig_vm_and_cleanup_orphan(instance)
                # TODO(johngarbutt) should also cleanup VHDs at destination
            except Exception as rollback_error:
                LOG.warning(_LW("_migrate_disk_resizing_up failed to "
                                "rollback: %s"), rollback_error,
                            instance=instance)
            raise exception.InstanceFaultRollback(error)
dataset/ETHPy150Open openstack/nova/nova/virt/xenapi/vmops.py/VMOps._migrate_disk_resizing_up/swapped operands of `>`