On Wed, May 27, 2009 at 11:02:49AM +0100, Guido Trotter wrote:
> On Wed, May 27, 2009 at 10:58 AM, Iustin Pop <[email protected]> wrote:
> >
> > I think that 'reboot -f -n' is similar to, but slightly faster than 
> > 'shutdown
> > -r -n now'.
> >
> >> If we can avoid having to ship a C wrapper it's probably for the best! :)
> >
> > Sorry, I'm confused. My interdiff just uses normal shutdown, I was 
> > semi-joking
> > about the C wrapper.
> >
> > Interdiff updated for reboot -n -f:
> >
> > diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
> > index 1358e54..88c13f4 100644
> > --- a/lib/hypervisor/hv_base.py
> > +++ b/lib/hypervisor/hv_base.py
> > @@ -364,8 +364,14 @@ class BaseHypervisor(object):
> >     """Linux-specific powercycle method.
> >
> >     """
> > -    fd = os.open("/proc/sysrq-trigger", os.O_WRONLY)
> >     try:
> > -      os.write(fd, "b")
> > -    finally:
> > -      fd.close()
> > +      fd = os.open("/proc/sysrq-trigger", os.O_WRONLY)
> > +      try:
> > +        os.write(fd, "b")
> > +      finally:
> > +        fd.close()
> > +    except OSError:
> > +      logging.exception("Can't open the sysrq-trigger file")
> > +      result = utils.RunCmd(["reboot", "-n", "-f"])
> > +      if not result:
> > +        logging.error("Can't run shutdown: %s", result.output)
> >
> 
> Almost-lgtm. You also need to raise an exception here so the xen
> version can catch it and try its own thing!

Why do we need to raise one? The xen version does "finally", so it will get
executed exception or not... I'd rather not raise exceptions, and instead let
the code flow normally.

iustin

Reply via email to