From: Sean Dague Subject: [PATCH] rework xen/xm/main.py to be more straight forward Date: Mon, 1 Aug 2005 15:22:16 -0400 Message-ID: <20050801192216.GA5974@underhill.no-ip.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0054681239==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: xen-tools@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============0054681239== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="LZvS9be/3tNcYl/X" Content-Disposition: inline --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The following patch is a major restructuring of main.py to be more straight forward, and remove as much code as possible. It does a number of things: * It implements the standardized options proposed via my RFC for xm * It restructures the calling of these functions to be function pointers out of a dictionary, instead of subclasses found through inspection * It consolidates all help info, making it easier to see that the help screen looks consistent across commands * It moves object importing into the functions that require them only, allowing commands like "xm help" to be runable as non root * It adds command aliasing to provide backwards compatibility with many commands (i.e. xm balloon) * It provides more useful error messages is most fail cases * It implements a short help by default (which takes < 24 screen lines) as requested by Mark W at OLS * It attempts to trap more exceptions than before and provide useful errors based on them (this requires more testing) It also has the added benefit of dropping the total size of main.py from 935 lines to 694 lines. This patch makes no changes to any other elements of xen/xm, and works with all other objects and libraries as is. Signed-off-by: Sean Dague Diffstat output: main.py | 1471 ++++++++++++++++++++++++++---------------------------------= ----- 1 files changed, 615 insertions(+), 856 deletions(-) --- xen-unstable.hg/tools/python/xen/xm/main.py 2005-07-29 15:35:02.0000000= 00 -0400 +++ xen-unstable.sean/tools/python/xen/xm/main.py 2005-08-01 14:57:23.00000= 0000 -0400 @@ -1,27 +1,115 @@ -# Copyright (C) 2004 Mike Wray +# (C) Copyright IBM Corp. 2005 +# Copyright (C) 2004 Mike Wray +# +# Authors: +# Sean Dague +# Mike Wray +# +# This software may be used and distributed according to the terms +# of the GNU General Public License v2. Full details on license +# terms and conditions are included with this distribution + """Grand unified management application for Xen. """ import os import os.path import sys +import re from getopt import getopt import socket import warnings warnings.filterwarnings('ignore', category=3DFutureWarning) - from xen.xend import PrettyPrint from xen.xend import sxp -# this is a nasty place to stick this in, but required because -# log file access is set up via a 5 deep import chain. This -# ensures the user sees a useful message instead of a stack trace -if os.getuid() !=3D 0: - print "xm requires root access to execute, please try again as root" - sys.exit(1) - -from xen.xend.XendClient import XendError, server -from xen.xend.XendClient import main as xend_client_main -from xen.xm import create, destroy, migrate, shutdown, sysrq from xen.xm.opts import * +shorthelp =3D """Usage: xm [args] + Control, list, and manipulate Xen guest instances + +xm common subcommands: + console attach to console of DomId + create create a domain based on Config File + destroy terminate a domain immediately + help display this message + list [DomId, ...] list information about domains + mem-max set the maximum memory reservation for a domain + mem-set adjust the current memory usage for a domain + migrate migrate a domain to another machine + pause pause execution of a domain + reboot reboot a domain + restore create a domain from a saved state file + save save domain state (and config) to file + shutdown shutdown a domain + unpause unpause a paused domain + +For a complete list of subcommands run 'xm help --long' +For more help on xm see the xm(1) man page +For more help on xm create, see the xmdomain.cfg(5) man page""" + +longhelp =3D """Usage: xm [args] + Control, list, and manipulate Xen guest instances + +xm full list of subcommands: + + Console Commands: + console attach to console of DomId + console-list list available consoles + + Domain Commands: + create create a domain + cpus-set set which cpus a VCPU can use.=20 + cpus-list get the list of cpus for a VCPU + destroy terminate a domain immediately + domid convert a domain name to a domain id + domname convert a domain id to a domain name + list list information about domains + mem-max set domain maximum memory limit + mem-set set the domain's memory dynamically + migrate migrate a domain to another machine + pause pause execution of a domain + reboot [-w|-a] reboot a domain + restore create a domain from a saved state file + save save domain state (and config) to file + shutdown [-w|-a] shutdown a domain + sysrq send a sysrq to a domain + unpause unpause a paused domain + vcpu-enable disable VCPU in a domain + vcpu-disable enable VCPU in a domain + vcpu-list get the list of VCPUs for a domain + + Xen Host Commands: + dmesg [--clear] read or clear Xen's message buffer + info get information about the xen host + log print the xend log + + Scheduler Commands: + bvt set BVT scheduler parameters + bvt_ctxallow set the BVT scheduler context switch allowan= ce + sedf set simple EDF parameters + + Virtual Device Commands: + block-create [BackDomId] + Create a new virtual block device=20 + block-destroy Destroy a domain's virtual block device + block-list List virtual block devices for a domain + block-refresh Refresh a virtual block device for a do= main + network-limit + Limit the transmission rate of a virtual network interface + network-list List virtual network interfaces for a d= omain + +For a short list of subcommands run 'xm help' +For more help on xm see the xm(1) man page +For more help on xm create, see the xmdomain.cfg(5) man page""" + +#################################################################### +# +# Utility functions +# +#################################################################### + +def arg_check(args,num,name): + if len(args) < num: + err("'xm %s' requires %s argument(s)!\n" % (name, num)) + usage(name) =20 def unit(c): if not c.isalpha(): @@ -48,724 +136,342 @@ else: return value * (base / dst_base) =20 -class Group: +def err(msg): + print >>sys.stderr, "Error:", msg =20 - name =3D "" - info =3D "" +def handle_xend_error(cmd, dom, ex): + error =3D str(ex) + if error =3D=3D "Not found" and dom !=3D None: + err("Domain '%s' not found when running 'xm %s'" % (dom, cmd)) + sys.exit(1) + else: + raise ex =20 - def __init__(self, xm): - self.xm =3D xm - self.progs =3D {} - - def addprog(self, prog): - self.progs[prog.name] =3D prog - - def getprog(self, name): - return self.progs.get(name) - - def proglist(self): - kl =3D self.progs.keys() - kl.sort() - return [ self.getprog(k) for k in kl ] - - def help(self, args): - if self.info: - print=20 - print self.info - print - else: - print - =20 - def shortHelp(self, args): - self.help(args) - for p in self.proglist(): - p.shortHelp(args) - -class Prog: - """Base class for sub-programs. - """ - - """Program group it belongs to""" - group =3D 'all' - """Program name.""" - name =3D '??' - """Short program info.""" - info =3D '' - - def __init__(self, xm): - self.xm =3D xm - - def err(self, msg): - self.xm.err(msg) =20 - def help(self, args): - self.shortHelp(args) +######################################################################### +# +# Main xm functions +# +######################################################################### + +def xm_create(args): + from xen.xm import create + # ugly hack because the opt parser apparently wants + # the subcommand name just to throw it away! + args.insert(0,"bogus") + create.main(args) =20 - def shortHelp(self, args): - print "%-14s %s" % (self.name, self.info) +def xm_save(args): + arg_check(args,2,"save") =20 - def main(self, args): - """Program main entry point. - """ - pass - - -class ProgUnknown(Prog): - - name =3D 'unknown' - info =3D '' + dom =3D args[0] # TODO: should check if this exists + savefile =3D os.path.abspath(args[1]) =20 - def help(self, args): - self.xm.err("Unknown command: %s\nTry '%s help' for more informati= on." - % (args[0], self.xm.name)) - - main =3D help - -class Xm: - """Main application. - """ - - def __init__(self): - self.name =3D 'xm' - self.unknown =3D ProgUnknown(self) - self.progs =3D {} - self.groups =3D {} - - def err(self, msg): - print >>sys.stderr, "Error:", msg - sys.exit(1) - - def main(self, args): - try: - self.main_call(args) - except socket.error, ex: - print >>sys.stderr, ex - self.err("Error connecting to xend, is xend running?") - except XendError, ex: - self.err(str(ex)) - - def main_call(self, args): - """Main entry point. Dispatches to the progs. - """ - self.name =3D args[0] - if len(args) < 2: - args.append('help') - help =3D self.helparg(args) - p =3D self.getprog(args[1], self.unknown) - if help or len(args) < 2:=20 - p.help(args[1:]) - else: - p.main(args[1:]) + from xen.xend.XendClient import server + server.xend_domain_save(dom, savefile) + =20 +def xm_restore(args): + arg_check(args,1,"restore") =20 - def helparg(self, args): - for a in args: - if a in ['-h', '--help']: - return 1 - return 0 + savefile =3D os.path.abspath(args[0]) =20 - def prog(self, pklass): - """Add a sub-program. + from xen.xend.XendClient import server + info =3D server.xend_domain_restore(savefile) + PrettyPrint.prettyprint(info) + id =3D sxp.child_value(info, 'id') + if id is not None: + server.xend_domain_unpause(id) + +def xm_migrate(args): + # TODO: arg_check + from xen.xm import migrate + # ugly hack because the opt parser apparently wants + # the subcommand name just to throw it away! + args.insert(0,"bogus") + migrate.main(args) + +def xm_list(args): + use_long =3D 0 + show_vcpus =3D 0 + (options, params) =3D getopt(args, 'lv', ['long','vcpus']) + =20 + n =3D len(params) + for (k, v) in options: + if k in ['-l', '--long']: + use_long =3D 1 + if k in ['-v', '--vcpus']: + show_vcpus =3D 1 + + domsinfo =3D [] + from xen.xend.XendClient import server + if n =3D=3D 0: + doms =3D server.xend_domains() + doms.sort() + else: + doms =3D params + for dom in doms: + info =3D server.xend_domain(dom) + domsinfo.append(parse_doms_info(info)) + =20 + if use_long: + # this actually seems like a bad idea, as it just dumps sexp out + PrettyPrint.prettyprint(info) + elif show_vcpus: + xm_show_vcpus(domsinfo) + else: + xm_brief_list(domsinfo) =20 - pklass program class (Prog subclass) - """ - p =3D pklass(self) - self.progs[p.name] =3D p - self.getgroup(p.group).addprog(p) - return p - - def getprog(self, name, val=3DNone): - """Get a sub-program. - name Name of the sub-program (or optionally, an unambiguous - prefix of its name) - val Default return value if no (unique) match is found - """ - - match =3D None - for progname in self.progs.keys(): - if progname =3D=3D name: - match =3D progname - break - if progname.startswith(name): - if not match: - match =3D progname - else: - return val # name is ambiguous - bail out - - return self.progs.get(match, val) - - def group(self, klass): - g =3D klass(self) - self.groups[g.name] =3D g - return g - - def getgroup(self, name): - return self.groups[name] - - def grouplist(self): - kl =3D self.groups.keys() - kl.sort() - return [ self.getgroup(k) for k in kl ] +def parse_doms_info(info): + dominfo =3D {} + dominfo['dom'] =3D int(sxp.child_value(info, 'id', '-1')) + dominfo['name'] =3D sxp.child_value(info, 'name', '??') + dominfo['mem'] =3D int(sxp.child_value(info, 'memory', '0')) + dominfo['cpu'] =3D str(sxp.child_value(info, 'cpu', '0')) + dominfo['vcpus'] =3D int(sxp.child_value(info, 'vcpus', '0')) + # if there is more than 1 cpu, the value doesn't mean much + if dominfo['vcpus'] > 1: + dominfo['cpu'] =3D '-' + dominfo['state'] =3D sxp.child_value(info, 'state', '??') + dominfo['cpu_time'] =3D float(sxp.child_value(info, 'cpu_time', '0')) + # get the console + console =3D sxp.child(info, 'console') + if console: + dominfo['port'] =3D sxp.child_value(console, 'console_port') + else: + dominfo['port'] =3D '' + # security identifiers + if ((int(sxp.child_value(info, 'ssidref', '0'))) !=3D 0): + dominfo['ssidref1'] =3D int(sxp.child_value(info, 'ssidref', '0')= ) & 0xffff + dominfo['ssidref2'] =3D (int(sxp.child_value(info, 'ssidref', '0')= ) >> 16) & 0xffff + # get out the vcpu information + dominfo['vcpulist'] =3D [] + vcpu_to_cpu =3D sxp.child_value(info, 'vcpu_to_cpu', '-1').split('|') + cpumap =3D sxp.child_value(info, 'cpumap', []) + mask =3D ((int(sxp.child_value(info, 'vcpus', '0')))**2) - 1 + count =3D 0 + for cpu in vcpu_to_cpu: + vcpuinfo =3D {} + vcpuinfo['name'] =3D sxp.child_value(info, 'name', '??') + vcpuinfo['dom'] =3D int(sxp.child_value(info, 'id', '-1')) + vcpuinfo['vcpu'] =3D int(count) + vcpuinfo['cpu'] =3D int(cpu) + vcpuinfo['cpumap'] =3D int(cpumap[count])&mask + count =3D count + 1 + dominfo['vcpulist'].append(vcpuinfo) + return dominfo =20 -# Create the application object, then add the sub-program classes. -xm =3D Xm() - -class GroupAll(Group): - - name =3D "all" - info =3D "" - -xm.group(GroupAll) +def xm_brief_list(domsinfo): + print 'Name Id Mem(MB) CPU VCPU(s) State Time(s) Con= sole' + for dominfo in domsinfo: + print ("%(name)-16s %(dom)3d %(mem)7d %(cpu)3s %(vcpus)5d %(s= tate)5s %(cpu_time)7.1f %(port)4s" % dominfo) + +def xm_show_vcpus(domsinfo): + print 'Name Id VCPU CPU CPUMAP' + for dominfo in domsinfo: + for vcpuinfo in dominfo['vcpulist']: + print ("%(name)-16s %(dom)3d %(vcpu)4d %(cpu)3d 0x%(cpumap)= x" % + vcpuinfo) + +def xm_vcpu_list(args): + args.insert(0,"-v") + xm_list(args) + +def xm_destroy(args): + arg_check(args,1,"destroy") + + from xen.xm import destroy + # ugly hack because the opt parser apparently wants + # the subcommand name just to throw it away! + args.insert(0,"bogus") + destroy.main(args) + =20 +# TODO: make reboot do the right thing, right now +# reboot and shutdown are exactly the same +def xm_reboot(args): + arg_check(args,1,"reboot") + # ugly hack because the opt parser apparently wants + # the subcommand name just to throw it away! + args.insert(0,"bogus") + from xen.xm import shutdown + shutdown.main(args) + +def xm_shutdown(args): + arg_check(args,1,"shutdown") + + # ugly hack because the opt parser apparently wants + # the subcommand name just to throw it away! + args.insert(0,"bogus") + from xen.xm import shutdown + shutdown.main(args) + +def xm_sysrq(args): + from xen.xm import sysrq + # ugly hack because the opt parser apparently wants + # the subcommand name just to throw it away! + args.insert(0,"bogus") + sysrq.main(args) + +def xm_pause(args): + arg_check(args, 1, "pause") + dom =3D args[0] + + from xen.xend.XendClient import server + server.xend_domain_pause(dom) + +def xm_unpause(args): + arg_check(args, 1, "unpause") + dom =3D args[0] + + from xen.xend.XendClient import server + server.xend_domain_unpause(dom) + +############################################################# + +def cpu_make_map(cpulist): + cpus =3D [] + cpumap =3D 0 + for c in cpulist.split(','): + if c.find('-') !=3D -1: + (x,y) =3D c.split('-') + for i in range(int(x),int(y)+1): + cpus.append(int(i)) + else: + cpus.append(int(c)) + cpus.sort() + for c in cpus: + cpumap =3D cpumap | 1< 1: - d['cpu'] =3D '-' - if ((int(sxp.child_value(info, 'ssidref', '0'))) !=3D 0): - d['ssidref1'] =3D int(sxp.child_value(info, 'ssidref', '0= ')) & 0xffff - d['ssidref2'] =3D (int(sxp.child_value(info, 'ssidref', '0= ')) >> 16) & 0xffff - print ("%(name)-16s %(dom)3d %(mem)7d %(cpu)3s %(vcpus)= 5d %(state)5s %(cpu_time)7.1f %(port)4s s:%(ssidref2)02x/p:%(ssid= ref1)02x" % d) - else: - print ("%(name)-16s %(dom)3d %(mem)7d %(cpu)3s %(vcpus)= 5d %(state)5s %(cpu_time)7.1f %(port)4s" % d) - - def show_vcpus(self, doms): - print 'Name Id VCPU CPU CPUMAP' - for dom in doms: - info =3D server.xend_domain(dom) - vcpu_to_cpu =3D sxp.child_value(info, 'vcpu_to_cpu', '-1').spl= it('|') - cpumap =3D sxp.child_value(info, 'cpumap', []) - mask =3D ((int(sxp.child_value(info, 'vcpus', '0')))**2) - 1 - count =3D 0 - for cpu in vcpu_to_cpu: - d =3D {} - d['name'] =3D sxp.child_value(info, 'name', '??') - d['dom'] =3D int(sxp.child_value(info, 'id', '-1')) - d['vcpu'] =3D int(count) - d['cpu'] =3D int(cpu) - d['cpumap'] =3D int(cpumap[count])&mask - count =3D count + 1 - print ("%(name)-16s %(dom)3d %(vcpu)4d %(cpu)3d 0x%(cpu= map)x" % d) - - def long_list(self, doms): - for dom in doms: - info =3D server.xend_domain(dom) - PrettyPrint.prettyprint(info) - -xm.prog(ProgList) - -class ProgDestroy(Prog): - group =3D 'domain' - name =3D "destroy" - info =3D """Terminate a domain immediately.""" - - def help(self, args): - destroy.main([args[0], '-h']) - - def main(self, args): - destroy.main(args) - -xm.prog(ProgDestroy) - -class ProgShutdown(Prog): - group =3D 'domain' - name =3D "shutdown" - info =3D """Shutdown a domain.""" - - def help(self, args): - shutdown.main([args[0], '-h']) - =20 - def main(self, args): - shutdown.main(args) - -xm.prog(ProgShutdown) - -class ProgSysrq(Prog): - group =3D 'domain' - name =3D "sysrq" - info =3D """Send a sysrq to a domain.""" - - def help(self, args): - sysrq.main([args[0], '-h']) - =20 - def main(self, args): - sysrq.main(args) - -xm.prog(ProgSysrq) - -class ProgPause(Prog): - group =3D 'domain' - name =3D "pause" - info =3D """Pause execution of a domain.""" - - def help(self, args): - print args[0], 'DOM' - print '\nPause execution of domain DOM.' - - def main(self, args): - if len(args) < 2: self.err("%s: Missing domain" % args[0]) - dom =3D args[1] - server.xend_domain_pause(dom) - -xm.prog(ProgPause) - -class ProgUnpause(Prog): - group =3D 'domain' - name =3D "unpause" - info =3D """Unpause a paused domain.""" - - def help(self, args): - print args[0], 'DOM' - print '\nUnpause execution of domain DOM.' - - def main(self, args): - if len(args) < 2: self.err("%s: Missing domain" % args[0]) - dom =3D args[1] - server.xend_domain_unpause(dom) - -xm.prog(ProgUnpause) - -class ProgPincpu(Prog): - group =3D 'domain' - name =3D "pincpu" - info =3D """Set which cpus a VCPU can use. """ - - def help(self, args): - print args[0],'DOM VCPU CPUS' - print '\nSet which cpus VCPU in domain DOM can use.' - - # convert list of cpus to bitmap integer value - def make_map(self, cpulist): - cpus =3D [] - cpumap =3D 0 - for c in cpulist.split(','): - if c.find('-') !=3D -1: - (x,y) =3D c.split('-') - for i in range(int(x),int(y)+1): - cpus.append(int(i)) - else: - cpus.append(int(c)) - cpus.sort() - for c in cpus: - cpumap =3D cpumap | 1< 5: + err("%s: Invalid argument(s)" % args[0]) + usage("block-create") + + dom =3D args[0] + vbd =3D ['vbd', + ['uname', args[1]], + ['dev', args[2]], + ['mode', args[3]]] + if n =3D=3D 5: + vbd.append(['backend', args[4]]) + + from xen.xend.XendClient import server + server.xend_domain_device_create(dom, vbd) + +def xm_block_refresh(args): + arg_check(args,2,"block-refresh") + + dom =3D args[0] + dev =3D args[1] + + from xen.xend.XendClient import server + server.xend_domain_device_refresh(dom, 'vbd', dev) + +def xm_block_destroy(args): + arg_check(args,2,"block-destroy") + + dom =3D args[0] + dev =3D args[1] + + from xen.xend.XendClient import server + server.xend_domain_device_destroy(dom, 'vbd', dev) + +commands =3D { + # console commands + "console": xm_console, + "console-list": xm_console_list, + # domain commands + "domid": xm_domid, + "domname": xm_domname, + "create": xm_create, + "destroy": xm_destroy, + "restore": xm_restore, + "save": xm_save, + "shutdown": xm_shutdown, + "reboot": xm_reboot, + "list": xm_list, + # memory commands + "mem-max": xm_mem_max, + "mem-set": xm_mem_set, + # cpu commands + "cpus-set": xm_cpus_set, +# "cpus-list": xm_cpus_list, + "vcpu-enable": xm_vcpu_enable, + "vcpu-disable": xm_vcpu_disable, + "vcpu-list": xm_vcpu_list, + # migration + "migrate": xm_migrate, + # special + "sysrq": xm_sysrq, + "pause": xm_pause, + "unpause": xm_unpause, + # host commands + "dmesg": xm_dmesg, + "info": xm_info, + "log": xm_log, + # scheduler + "bvt": xm_bvt, + "bvt_ctxallow": xm_bvt_ctxallow, + "sedf": xm_sedf, + # block + "block-create": xm_block_create, + "block-destroy": xm_block_destroy, + "block-list": xm_block_list, + "block-refresh": xm_block_refresh, + # network + "network-limit": xm_network_limit, + "network-list": xm_network_list + } + +aliases =3D { + "balloon": "mem-set", + "vif-list": "network-list", + "vif-limit": "network-limit", + "vbd-create": "block-create", + "vbd-destroy": "block-destroy", + "vbd-list": "block-list", + "vbd-refresh": "block-refresh", + "consoles": "console-list", + } + +help =3D { + "--long": longhelp + } + +def xm_lookup_cmd(cmd): + if commands.has_key(cmd): + return commands[cmd] + elif aliases.has_key(cmd): + deprecated(cmd,aliases[cmd]) + return commands[aliases[cmd]] + else: + err('Sub Command %s not found!' % cmd) + usage() =20 -xm.prog(ProgVifList) +def deprecated(old,new): + err('Option %s is deprecated, and will be removed in future!!!' % old) + err('Option %s is the new replacement, see "xm help %s" for more info'= % (new, new)) + +def usage(cmd=3DNone): + if cmd =3D=3D "full": + print fullhelp + elif help.has_key(cmd): + print help[cmd] + else: + print shorthelp + sys.exit(1) =20 -class ProgVbdList(Prog): - group =3D 'vbd' - name =3D 'vbd-list' - info =3D """List virtual block devices for a domain.""" - - def help(self, args): - print args[0], "DOM" - print "\nList virtual block devices for domain DOM" - - def main(self, args): - if len(args) !=3D 2: self.err("%s: Invalid argument(s)" % args[0]) - dom =3D args[1] - for x in server.xend_domain_devices(dom, 'vbd'): - sxp.show(x) +def main(argv=3Dsys.argv): + if len(argv) < 2: + usage() + =20 + if re.compile('-*help').match(argv[1]): + if len(argv) > 2 and help.has_key(argv[2]): + usage(argv[2]) + else: + usage() + sys.exit(0) + + cmd =3D xm_lookup_cmd(argv[1]) + + # strip off prog name and subcmd + args =3D argv[2:] + if cmd: + try: + from xen.xend.XendClient import XendError + rc =3D cmd(args) + if rc: + usage() + except socket.error, ex: + print >>sys.stderr, ex + err("Error connecting to xend, is xend running?") + sys.exit(1) + except IOError: + err("Most commands need root access. Please try again as root= ") + sys.exit(1) + except XendError, ex: + if len(args) > 0: + handle_xend_error(argv[1], args[0], ex) + else: + print "Unexpected error:", sys.exc_info()[0] + print + print "Please report to xen-devel@lists.xensource.com" + raise + except SystemExit: + sys.exit(1) + except: + print "Unexpected error:", sys.exc_info()[0] print + print "Please report to xen-devel@lists.xensource.com" + raise + =20 + else: + usage() =20 -xm.prog(ProgVbdList) - -class ProgVbdCreate(Prog): - group =3D 'vbd' - name =3D 'vbd-create' - info =3D """Create a new virtual block device for a domain""" - - def help(self, args): - print args[0], "DOM UNAME DEV MODE [BACKEND]" - print """ -Create a virtual block device for a domain. - - UNAME - device to export, e.g. phy:hda2 - DEV - device name in the domain, e.g. sda1 - MODE - access mode: r for read, w for read-write - BACKEND - backend driver domain -""" - - def main(self, args): - n =3D len(args) - if n < 5 or n > 6: self.err("%s: Invalid argument(s)" % args[0]) - dom =3D args[1] - vbd =3D ['vbd', - ['uname', args[2]], - ['dev', args[3]], - ['mode', args[4]]] - if n =3D=3D 6: - vbd.append(['backend', args[5]]) - server.xend_domain_device_create(dom, vbd) - -xm.prog(ProgVbdCreate) - -class ProgVbdRefresh(Prog): - group =3D 'vbd' - name =3D 'vbd-refresh' - info =3D """Refresh a virtual block device for a domain""" - - def help(self, args): - print args[0], "DOM DEV" - print """ -Refresh a virtual block device for a domain. - - DEV - idx field in the device information -""" +if __name__ =3D=3D "__main__": + main() =20 - def main(self, args): - if len(args) !=3D 3: self.err("%s: Invalid argument(s)" % args[0]) - dom =3D args[1] - dev =3D args[2] - server.xend_domain_device_refresh(dom, 'vbd', dev) - -xm.prog(ProgVbdRefresh) - - -class ProgVbdDestroy(Prog): - group =3D 'vbd' - name =3D 'vbd-destroy' - info =3D """Destroy a domain's virtual block device""" - - def help(self, args): - print args[0], "DOM DEV" - print """ -Destroy vbd DEV attached to domain DOM. Detaches the device -from the domain, but does not destroy the device contents. -The device indentifier DEV is the idx field in the device -information. This is visible in 'xm vbd-list'.""" - - def main(self, args): - if len(args) !=3D 3: self.err("%s: Invalid argument(s)" % args[0]) - dom =3D args[1] - dev =3D args[2] - server.xend_domain_device_destroy(dom, 'vbd', dev) =20 -xm.prog(ProgVbdDestroy) =20 -def main(args): - xm.main(args) -Sean --=20 __________________________________________________________________ Sean Dague Mid-Hudson Valley sean at dague dot net Linux Users Group http://dague.net http://mhvlug.org There is no silver bullet. Plus, werewolves make better neighbors than zombies, and they tend to keep the vampire population down. __________________________________________________________________ --LZvS9be/3tNcYl/X Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFC7nZoSamXem9TdyYRAtWTAJ44TnZUTAD2DSCfEIji3wg50gSp7wCfVI9J oN4537vFwAO2Jja4alFIQWI= =ntwT -----END PGP SIGNATURE----- --LZvS9be/3tNcYl/X-- --===============0054681239== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0054681239==--