ia64/xen-unstable

view tools/python/xen/xm/shutdown.py @ 7175:c70829a6edac

Remove the reason code from the destroy action -- the reason is only of value
on a graceful shutdown. Clarify the semantic difference between poweroff and
halt (we use halt to mean 'shutdown and stop' and poweroff to mean 'shutdown
and do whatever the configured behaviour is').

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Tue Oct 04 00:57:34 2005 +0100 (2005-10-04)
parents 06d84bf87159
children dee321bf18e9
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 #============================================================================
18 """Domain shutdown.
19 """
20 import string
21 import sys
22 import time
24 from xen.xend.XendClient import server
25 from xen.xm.opts import *
27 DOM0_NAME = 'Domain-0'
28 DOM0_ID = '0'
30 gopts = Opts(use="""[options] [DOM]
32 Shutdown one or more domains gracefully.
33 """)
35 gopts.opt('help', short='h',
36 fn=set_true, default=0,
37 use="Print this help.")
39 gopts.opt('all', short='a',
40 fn=set_true, default=0,
41 use="Shutdown all domains.")
43 gopts.opt('wait', short='w',
44 fn=set_true, default=0,
45 use='Wait for shutdown to complete.')
47 gopts.opt('halt', short='H',
48 fn=set_true, default=0,
49 use='Shutdown without reboot.')
51 gopts.opt('reboot', short='R',
52 fn=set_true, default=0,
53 use='Shutdown and reboot.')
55 def shutdown(opts, doms, mode, wait):
56 if doms == None: doms = server.xend_domains()
57 for x in [DOM0_NAME, DOM0_ID]:
58 if x in doms:
59 doms.remove(x)
60 for d in doms:
61 server.xend_domain_shutdown(d, mode)
62 if wait:
63 while doms:
64 alive = server.xend_domains()
65 dead = []
66 for d in doms:
67 if d in alive: continue
68 dead.append(d)
69 for d in dead:
70 opts.info("Domain %s terminated" % d)
71 doms.remove(d)
72 time.sleep(1)
73 opts.info("All domains terminated")
75 def shutdown_mode(opts):
76 if opts.vals.halt and opts.vals.reboot:
77 opts.err("Can't specify halt and reboot")
79 if opts.vals.halt:
80 return 'halt'
81 elif opts.vals.reboot:
82 return 'reboot'
83 else:
84 return 'poweroff'
86 def main_all(opts, args):
87 mode = shutdown_mode(opts)
88 shutdown(opts, None, mode, opts.vals.wait)
90 def main_dom(opts, args):
91 if len(args) < 1: opts.err('Missing domain')
92 dom = args[0]
93 mode = shutdown_mode(opts)
94 shutdown(opts, [ dom ], mode, opts.vals.wait)
96 def main(argv):
97 opts = gopts
98 args = opts.parse(argv)
99 if opts.vals.help:
100 opts.usage()
101 return
102 if opts.vals.all:
103 main_all(opts, args)
104 else:
105 main_dom(opts, args)