direct-io.hg

changeset 14378:192bee4b09a6

Added Xen-API support to xm shutdown.

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Mar 14 20:27:57 2007 +0000 (2007-03-14)
parents 817647aff01f
children 460dac5742cf
files tools/python/xen/xm/shutdown.py
line diff
     1.1 --- a/tools/python/xen/xm/shutdown.py	Wed Mar 14 14:18:51 2007 -0700
     1.2 +++ b/tools/python/xen/xm/shutdown.py	Wed Mar 14 20:27:57 2007 +0000
     1.3 @@ -21,7 +21,8 @@ import time
     1.4  
     1.5  from xen.xend import sxp
     1.6  from opts import *
     1.7 -from main import server
     1.8 +from main import server, serverType, SERVER_XEN_API, get_single_vm
     1.9 +from xen.xend.XendAPIConstants import *
    1.10  
    1.11  gopts = Opts(use="""[options] [DOM]
    1.12  
    1.13 @@ -49,6 +50,9 @@ gopts.opt('reboot', short='R',
    1.14            use='Shutdown and reboot.')
    1.15  
    1.16  def wait_reboot(opts, doms, rcs):
    1.17 +    if serverType == SERVER_XEN_API:
    1.18 +	    opts.err("Cannot wait for reboot w/ XenAPI (yet)")
    1.19 +
    1.20      while doms:
    1.21          alive = server.xend.domains(0)
    1.22          reboot = []
    1.23 @@ -68,7 +72,12 @@ def wait_reboot(opts, doms, rcs):
    1.24  
    1.25  def wait_shutdown(opts, doms):
    1.26      while doms:
    1.27 -        alive = server.xend.domains(0)
    1.28 +        if serverType == SERVER_XEN_API:
    1.29 +		    alive = [dom for dom in server.xenapi.VM.get_all()
    1.30 +                     if server.xenapi.VM.get_power_state(dom) ==
    1.31 +                     XEN_API_VM_POWER_STATE[XEN_API_VM_POWER_STATE_RUNNING]]
    1.32 +        else:
    1.33 +            alive = server.xend.domains(0)
    1.34          dead = []
    1.35          for d in doms:
    1.36              if d in alive: continue
    1.37 @@ -82,8 +91,16 @@ def wait_shutdown(opts, doms):
    1.38  def shutdown(opts, doms, mode, wait):
    1.39      rcs = {}
    1.40      for d in doms:
    1.41 -        rcs[d] = server.xend.domain.getRestartCount(d)
    1.42 -        server.xend.domain.shutdown(d, mode)
    1.43 +		if serverType == SERVER_XEN_API:
    1.44 +			if mode == 'halt':
    1.45 +				server.xenapi.VM.clean_shutdown(d)
    1.46 +			if mode == 'reboot':
    1.47 +				server.xenapi.VM.clean_reboot(d)
    1.48 +			if mode == 'poweroff':
    1.49 +				server.xenapi.VM.clean_shutdown(d)				
    1.50 +		else:
    1.51 +			rcs[d] = server.xend.domain.getRestartCount(d)
    1.52 +			server.xend.domain.shutdown(d, mode)
    1.53  
    1.54      if wait:
    1.55          if mode == 'reboot':
    1.56 @@ -103,9 +120,13 @@ def shutdown_mode(opts):
    1.57          return 'poweroff'
    1.58  
    1.59  def main_all(opts, args):
    1.60 -    doms = server.xend.domains(0)
    1.61 -    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
    1.62 -    doms.remove(dom0_name)
    1.63 +    if serverType == SERVER_XEN_API:
    1.64 +        doms = [dom for dom in server.xenapi.VM.get_all()
    1.65 +                if not server.xenapi.VM.get_is_control_domain(dom)]
    1.66 +    else:
    1.67 +        doms = server.xend.domains(0)
    1.68 +        dom0_name = sxp.child_value(server.xend.domain(0), 'name')
    1.69 +        doms.remove(dom0_name)
    1.70      mode = shutdown_mode(opts)  
    1.71      shutdown(opts, doms, mode, opts.vals.wait)
    1.72  
    1.73 @@ -113,6 +134,8 @@ def main_dom(opts, args):
    1.74      if len(args) == 0: opts.err('No domain parameter given')
    1.75      if len(args) >  1: opts.err('No multiple domain parameters allowed')
    1.76      dom = args[0]
    1.77 +    if serverType == SERVER_XEN_API:
    1.78 +		dom = get_single_vm(dom)
    1.79      mode = shutdown_mode(opts)  
    1.80      shutdown(opts, [ dom ], mode, opts.vals.wait)
    1.81