Esempio n. 1
0
    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 get_vnc_console(self, instance):
        """Get connection info for a vnc console."""
        LOG.debug("get_vnc_console called", instance=instance)
        if self.remote_display and self.vrde_module == constants.EXTPACK_VNC:
            host = hostutils.get_ip()
            port = self._get_vrde_port(instance)
            if port:
                LOG.debug("VNC console: %(host)s:%(port)s",
                          {"host": host, "port": port})
                return console_type.ConsoleVNC(host=host, port=port)
            else:
                LOG.warning(i18n._LW("VNC port not found!"), instance=instance)
        else:
            LOG.warning(i18n._LW("VNC console is not available for this"
                                 " instance."),
                        instance=instance)

        raise exception.ConsoleTypeUnavailable(console_type='vnc')
Esempio n. 4
0
    def get_vnc_console(self, instance):
        """Get connection info for a vnc console."""
        LOG.debug("get_vnc_console called", instance=instance)
        if self.remote_display and self.vrde_module == constants.EXTPACK_VNC:
            host = hostutils.get_ip()
            port = self._get_vrde_port(instance)
            if port:
                LOG.debug("VNC console: %(host)s:%(port)s", {
                    "host": host,
                    "port": port
                })
                return console_type.ConsoleVNC(host=host, port=port)
            else:
                LOG.warning(i18n._LW("VNC port not found!"), instance=instance)
        else:
            LOG.warning(i18n._LW("VNC console is not available for this"
                                 " instance."),
                        instance=instance)

        raise exception.ConsoleTypeUnavailable(console_type='vnc')
    def get_rdp_console(self, instance):
        """Get connection info for a rdp console."""
        LOG.debug("get_rdp_console called", instance=instance)
        if self.remote_display and self.vrde_module == constants.EXTPACK_RDP:
            host = hostutils.get_ip()
            access_path = None if self._ports['unique'] else instance.name
            port = self._get_vrde_port(instance)
            if port:
                LOG.debug("RDP console: %(host)s:%(port)s, %(path)s",
                          {"host": host, "port": port, "path": access_path})
                return console_type.ConsoleRDP(
                    host=host, port=port, internal_access_path=access_path)
            else:
                LOG.warning(i18n._LW("RDP port not found."), instance=instance)
        else:
            LOG.warning(i18n._LW("VNC console is not available for this "
                                 "instance."),
                        instance=instance)

        raise exception.ConsoleTypeUnavailable(console_type='rdp')
Esempio n. 6
0
    def get_rdp_console(self, instance):
        """Get connection info for a rdp console."""
        LOG.debug("get_rdp_console called", instance=instance)
        if self.remote_display and self.vrde_module == constants.EXTPACK_RDP:
            host = hostutils.get_ip()
            access_path = None if self._ports['unique'] else instance.name
            port = self._get_vrde_port(instance)
            if port:
                LOG.debug("RDP console: %(host)s:%(port)s, %(path)s", {
                    "host": host,
                    "port": port,
                    "path": access_path
                })
                return console_type.ConsoleRDP(
                    host=host, port=port, internal_access_path=access_path)
            else:
                LOG.warning(i18n._LW("RDP port not found."), instance=instance)
        else:
            LOG.warning(i18n._LW("VNC console is not available for this "
                                 "instance."),
                        instance=instance)

        raise exception.ConsoleTypeUnavailable(console_type='rdp')