def _migrate_disk_files(self, instance, disk_files, destination): local_ips = hostutils.get_local_ips() local_ips.append(hostutils.get_ip()) same_host = destination in local_ips LOG.debug("Destination `%(dest)s` %(local_ips)s", { "dest": destination, "local_ips": local_ips }) instance_basepath = pathutils.instance_basepath(instance) revert_path = pathutils.revert_dir(instance, action=constants.PATH_OVERWRITE) if same_host: destination_path = ("%(path)s%(suffix)s" % { "path": instance_basepath, "suffix": self._SUFFIX }) else: LOG.warning(i18n._LW("Only resize on the same host is supported!")) raise NotImplementedError() # Delete the destination path if already exists pathutils.delete_path(destination_path) # Create the destination path pathutils.create_path(destination_path) try: self._migrate_disk(disk_files[0], destination_path, root_disk=True) for disk_file in disk_files[1:]: self._migrate_disk(disk_file, destination_path) # Remove the instance from the Hypervisor self._vbox_ops.destroy(instance, destroy_disks=False) # Move files to revert path os.rename(instance_basepath, revert_path) if same_host: os.rename(destination_path, instance_basepath) except (OSError, vbox_exc.VBoxException): with excutils.save_and_reraise_exception(): try: self._cleanup_failed_disk_migration( instance_basepath, revert_path, destination_path) except vbox_exc.VBoxException as exc: # Log and ignore this exception LOG.exception(exc)
def _migrate_disk_files(self, instance, disk_files, destination): local_ips = hostutils.get_local_ips() local_ips.append(hostutils.get_ip()) same_host = destination in local_ips LOG.debug("Destination `%(dest)s` %(local_ips)s", {"dest": destination, "local_ips": local_ips}) instance_basepath = pathutils.instance_basepath(instance) revert_path = pathutils.revert_dir( instance, action=constants.PATH_OVERWRITE) if same_host: destination_path = ( "%(path)s%(suffix)s" % {"path": instance_basepath, "suffix": self._SUFFIX}) else: LOG.warning( i18n._LW("Only resize on the same host is supported!")) raise NotImplementedError() # Delete the destination path if already exists pathutils.delete_path(destination_path) # Create the destination path pathutils.create_path(destination_path) try: self._migrate_disk(disk_files[0], destination_path, root_disk=True) for disk_file in disk_files[1:]: self._migrate_disk(disk_file, destination_path) # Remove the instance from the Hypervisor self._vbox_ops.destroy(instance, destroy_disks=False) # Move files to revert path os.rename(instance_basepath, revert_path) if same_host: os.rename(destination_path, instance_basepath) except (OSError, vbox_exc.VBoxException): with excutils.save_and_reraise_exception(): try: self._cleanup_failed_disk_migration( instance_basepath, revert_path, destination_path) except vbox_exc.VBoxException as exc: # Log and ignore this exception LOG.exception(exc)
def confirm_migration(self, migration, instance, network_info): """Confirms a resize, destroying the source VM.""" LOG.debug("`Confirms migration` method called.") revert_path = pathutils.revert_dir(instance) self._remove_disks(revert_path) pathutils.delete_path(revert_path)
def _revert_migration_files(self, instance): instance_basepath = pathutils.instance_basepath(instance) revert_path = pathutils.revert_dir(instance) os.rename(revert_path, instance_basepath)