ia64/xen-unstable

view tools/python/xen/xm/shutdown.py @ 10595:40e1a7749208

[XM] When two or more domain parameters are given, the xm reboot
command doesn't give a command error. This problem is also
included in the xm shutdown command.

This patch checks on domain parameter. If two or more domain
parameters are given, the command error occurs.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Jun 29 14:25:35 2006 +0100 (2006-06-29)
parents 5c9c44fc1c39
children 88dc1ae16d2b
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.xend import sxp
26 from xen.xm.opts import *
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(0)
57 dom0_name = sxp.child_value(server.xend.domain(0), 'name')
58 for x in [dom0_name, DOM0_ID]:
59 if x in doms:
60 if opts.vals.all:
61 doms.remove(x)
62 else:
63 opts.err("Can't specify Domain-0")
64 for d in doms:
65 server.xend.domain.shutdown(d, mode)
66 if wait:
67 while doms:
68 alive = server.xend.domains(0)
69 dead = []
70 for d in doms:
71 if d in alive: continue
72 dead.append(d)
73 for d in dead:
74 opts.info("Domain %s terminated" % d)
75 doms.remove(d)
76 time.sleep(1)
77 opts.info("All domains terminated")
79 def shutdown_mode(opts):
80 if opts.vals.halt and opts.vals.reboot:
81 opts.err("Can't specify halt and reboot")
83 if opts.vals.halt:
84 return 'halt'
85 elif opts.vals.reboot:
86 return 'reboot'
87 else:
88 return 'poweroff'
90 def main_all(opts, args):
91 mode = shutdown_mode(opts)
92 shutdown(opts, None, mode, opts.vals.wait)
94 def main_dom(opts, args):
95 if len(args) == 0: opts.err('No domain parameter given')
96 if len(args) > 1: opts.err('No multiple domain parameters allowed')
97 dom = args[0]
98 mode = shutdown_mode(opts)
99 shutdown(opts, [ dom ], mode, opts.vals.wait)
101 def main(argv):
102 opts = gopts
103 args = opts.parse(argv)
104 if opts.vals.help:
105 opts.usage()
106 return
107 if opts.vals.all:
108 main_all(opts, args)
109 else:
110 main_dom(opts, args)