virt-manager

changeset 1617:fc1360e7ded9

Attempt to 'fake' reboot if it isn't supported

We do this by attempting vm.shutdown(), followed by a vm.start() when
the vm actually stops. Any manual 'shutdown' or 'destroy' call will undo
the reboot command, similar to how xen acts (on RHEL5 at least).
author Cole Robinson <crobinso@redhat.com>
date Wed Mar 17 16:41:50 2010 -0400 (2010-03-17)
parents 91818a16657c
children c2cbba74520f
files src/virtManager/domain.py src/virtManager/engine.py
line diff
     1.1 --- a/src/virtManager/domain.py	Wed Mar 17 08:49:06 2010 +0000
     1.2 +++ b/src/virtManager/domain.py	Wed Mar 17 16:41:50 2010 -0400
     1.3 @@ -1178,6 +1178,8 @@
     1.4          self.toggle_sample_network_traffic()
     1.5          self.toggle_sample_disk_io()
     1.6  
     1.7 +        self.reboot_listener = None
     1.8 +
     1.9          # Determine available XML flags (older libvirt versions will error
    1.10          # out if passed SECURE_XML, INACTIVE_XML, etc)
    1.11          (self._inactive_xml_flags,
    1.12 @@ -1231,7 +1233,47 @@
    1.13      def disk_write_rate(self):
    1.14          return self._get_record_helper("diskWrRate")
    1.15  
    1.16 +    def _unregister_reboot_listener(self):
    1.17 +        if self.reboot_listener == None:
    1.18 +            return
    1.19 +
    1.20 +        try:
    1.21 +            self.disconnect(self.reboot_listener)
    1.22 +            self.reboot_listener = None
    1.23 +        except:
    1.24 +            pass
    1.25 +
    1.26 +    def manual_reboot(self):
    1.27 +        # Attempt a manual reboot via 'shutdown' followed by startup
    1.28 +        def reboot_listener(vm, ignore1, ignore2, self):
    1.29 +            if vm.is_crashed():
    1.30 +                # Abandon reboot plans
    1.31 +                self.reboot_listener = None
    1.32 +                return True
    1.33 +
    1.34 +            if not vm.is_shutoff():
    1.35 +                # Not shutoff, continue waiting
    1.36 +                return
    1.37 +
    1.38 +            try:
    1.39 +                logging.debug("Fake reboot detected shutdown. Restarting VM")
    1.40 +                vm.startup()
    1.41 +            except:
    1.42 +                logging.exception("Fake reboot startup failed")
    1.43 +
    1.44 +            self.reboot_listener = None
    1.45 +            return True
    1.46 +
    1.47 +        self._unregister_reboot_listener()
    1.48 +
    1.49 +        # Request a shutdown
    1.50 +        self.shutdown()
    1.51 +
    1.52 +        self.reboot_listener = util.connect_opt_out(self, "status-changed",
    1.53 +                                                    reboot_listener, self)
    1.54 +
    1.55      def shutdown(self):
    1.56 +        self._unregister_reboot_listener()
    1.57          self._backend.shutdown()
    1.58          self._update_status()
    1.59  
    1.60 @@ -1265,7 +1307,9 @@
    1.61          self._update_status()
    1.62  
    1.63      def destroy(self):
    1.64 +        self._unregister_reboot_listener()
    1.65          self._backend.destroy()
    1.66 +        self._update_status()
    1.67  
    1.68      def interfaceStats(self, device):
    1.69          return self._backend.interfaceStats(device)
     2.1 --- a/src/virtManager/engine.py	Wed Mar 17 08:49:06 2010 +0000
     2.2 +++ b/src/virtManager/engine.py	Wed Mar 17 16:41:50 2010 -0400
     2.3 @@ -834,10 +834,30 @@
     2.4              self.config.set_confirm_poweroff(not skip_prompt)
     2.5  
     2.6          logging.debug("Rebooting vm '%s'." % vm.get_name())
     2.7 +        no_support = False
     2.8 +        reboot_err = None
     2.9          try:
    2.10              vm.reboot()
    2.11 -        except Exception, e:
    2.12 -            self.err.show_err(_("Error shutting down domain: %s" % str(e)),
    2.13 +        except Exception, reboot_err:
    2.14 +            no_support = virtinst.support.is_error_nosupport(reboot_err)
    2.15 +            if not no_support:
    2.16 +                self.err.show_err(_("Error rebooting domain: %s" %
    2.17 +                                  str(reboot_err)),
    2.18 +                                  "".join(traceback.format_exc()))
    2.19 +
    2.20 +        if not no_support:
    2.21 +            return
    2.22 +
    2.23 +        # Reboot isn't supported. Let's try to emulate it
    2.24 +        logging.debug("Hypervisor doesn't support reboot, let's fake it")
    2.25 +        try:
    2.26 +            vm.manual_reboot()
    2.27 +        except:
    2.28 +            logging.exception("Could not fake a reboot")
    2.29 +
    2.30 +            # Raise the original error message
    2.31 +            self.err.show_err(_("Error rebooting domain: %s" %
    2.32 +                              str(reboot_err)),
    2.33                                "".join(traceback.format_exc()))
    2.34  
    2.35      def migrate_domain(self, uri, uuid):