diff -r 8e55c5c11475 tools/python/xen/xm/shutdown.py --- a/tools/python/xen/xm/shutdown.py Wed Jul 05 18:48:41 2006 +0100 +++ b/tools/python/xen/xm/shutdown.py Fri Jul 07 01:03:55 2006 +0900 @@ -22,8 +22,6 @@ from xen.xend.XendClient import server from xen.xend.XendClient import server from xen.xend import sxp from xen.xm.opts import * - -DOM0_ID = '0' gopts = Opts(use="""[options] [DOM] @@ -51,14 +49,6 @@ gopts.opt('reboot', short='R', use='Shutdown and reboot.') def shutdown(opts, doms, mode, wait): - if doms == None: doms = server.xend.domains(0) - dom0_name = sxp.child_value(server.xend.domain(0), 'name') - for x in [dom0_name, DOM0_ID]: - if x in doms: - if opts.vals.all: - doms.remove(x) - else: - opts.err("Can't specify Domain-0") for d in doms: server.xend.domain.shutdown(d, mode) if wait: @@ -86,13 +76,42 @@ def shutdown_mode(opts): return 'poweroff' def main_all(opts, args): + doms = server.xend.domains(0) + dom0_name = sxp.child_value(server.xend.domain(0), 'name') + + doms.remove(dom0_name) + mode = shutdown_mode(opts) - shutdown(opts, None, mode, opts.vals.wait) + shutdown(opts, doms, mode, opts.vals.wait) def main_dom(opts, args): if len(args) == 0: opts.err('No domain parameter given') if len(args) > 1: opts.err('No multiple domain parameters allowed') dom = args[0] + + doms = server.xend.domains(0) + dom0_name = sxp.child_value(server.xend.domain(0), 'name') + + # We confirm whether the domain of the specified domain name exists. + dom_exist = 0 + for d in doms: + if d == dom: + if d == dom0_name: opts.err("Can't specify Domain-0") + dom_exist = 1 + break + + # If the domain of the specified domain name doesn't exist, + # we assume that domain ID was specified. + if not dom_exist: + # If character strings are all '0', + # we assume that Domain-0 was specified. + all_zero = 1 + for s in dom: + if s != '0': + all_zero = 0 + break + if all_zero: opts.err("Can't specify Domain-0") + mode = shutdown_mode(opts) shutdown(opts, [ dom ], mode, opts.vals.wait)