[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Added xm rename command. Improve the argument checking and error reporting.
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID 6a2acc1cc505a9553d148517a83ef02921441167 # Parent 7c90df7df37e64704939bbfecc3b0b86a538d267 Added xm rename command. Improve the argument checking and error reporting. diff -r 7c90df7df37e -r 6a2acc1cc505 tools/python/xen/xend/XendClient.py --- a/tools/python/xen/xend/XendClient.py Wed Nov 30 19:48:54 2005 +++ b/tools/python/xen/xend/XendClient.py Wed Nov 30 19:54:28 2005 @@ -231,6 +231,11 @@ def xend_domain_pause(self, id): return self.xendPost(self.domainurl(id), {'op' : 'pause' }) + + def xend_domain_rename(self, id, name): + return self.xendPost(self.domainurl(id), + {'op' : 'rename', + 'name' : name}) def xend_domain_shutdown(self, id, reason): return self.xendPost(self.domainurl(id), diff -r 7c90df7df37e -r 6a2acc1cc505 tools/python/xen/xend/server/SrvDomain.py --- a/tools/python/xen/xend/server/SrvDomain.py Wed Nov 30 19:48:54 2005 +++ b/tools/python/xen/xend/server/SrvDomain.py Wed Nov 30 19:54:28 2005 @@ -54,6 +54,10 @@ def acceptCommand(self, req): req.setResponseCode(http.ACCEPTED) req.setHeader("Location", "%s/.." % req.prePathURL()) + + def op_rename(self, _, req): + self.acceptCommand(req) + return self.dom.setName(req.args['name'][0]) def op_shutdown(self, _, req): self.acceptCommand(req) diff -r 7c90df7df37e -r 6a2acc1cc505 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Wed Nov 30 19:48:54 2005 +++ b/tools/python/xen/xm/main.py Wed Nov 30 19:54:28 2005 @@ -70,6 +70,7 @@ vcpu_pin_help = "vcpu-pin <DomId> <VCPU> <CPUs> Set which cpus a VCPU can use" dmesg_help = "dmesg [--clear] Read or clear Xen's message buffer" info_help = "info Get information about the xen host" +rename_help = "rename <DomId> <New Name> Rename a domain" log_help = "log Print the xend log" sched_bvt_help = """sched-bvt <Parameters> Set Borrowed Virtual Time scheduler parameters""" @@ -125,6 +126,7 @@ "migrate", "pause", "reboot", + "rename", "restore", "save", "shutdown", @@ -226,10 +228,20 @@ # #################################################################### -def arg_check(args,num,name): - if len(args) < num: - err("'xm %s' requires %s argument(s)!\n" % (name, num)) - usage(name) +def arg_check(args, name, lo, hi = -1): + n = len(args) + + if hi == -1: + if n != lo: + err("'xm %s' requires %d argument%s.\n" % (name, lo, + lo > 1 and 's' or '')) + usage(name) + else: + if n < lo or n > hi: + err("'xm %s' requires between %d and %d arguments.\n" % + (name, lo, hi)) + usage(name) + def unit(c): if not c.isalpha(): @@ -259,14 +271,17 @@ def err(msg): print >>sys.stderr, "Error:", msg -def handle_xend_error(cmd, dom, ex): +def handle_xend_error(cmd, args, ex): + non_option = filter(lambda x: x[0] != '-', args) + dom = len(non_option) > 0 and non_option[0] or None + error = str(ex) if error == "Not found" and dom != None: err("Domain '%s' not found when running 'xm %s'" % (dom, cmd)) - sys.exit(1) else: err(error) - sys.exit(1) + + sys.exit(1) ######################################################################### @@ -276,7 +291,7 @@ ######################################################################### def xm_save(args): - arg_check(args,2,"save") + arg_check(args, "save", 2) dom = args[0] # TODO: should check if this exists savefile = os.path.abspath(args[1]) @@ -289,7 +304,7 @@ server.xend_domain_save(dom, savefile) def xm_restore(args): - arg_check(args,1,"restore") + arg_check(args, "restore", 1) savefile = os.path.abspath(args[0]) @@ -479,23 +494,29 @@ def xm_reboot(args): - arg_check(args,1,"reboot") + arg_check(args, "reboot", 1, 4) from xen.xm import shutdown shutdown.main(["shutdown", "-R"] + args) def xm_pause(args): - arg_check(args, 1, "pause") + arg_check(args, "pause", 1) dom = args[0] from xen.xend.XendClient import server server.xend_domain_pause(dom) def xm_unpause(args): - arg_check(args, 1, "unpause") + arg_check(args, "unpause", 1) dom = args[0] from xen.xend.XendClient import server server.xend_domain_unpause(dom) + +def xm_rename(args): + arg_check(args, "rename", 2) + + from xen.xend.XendClient import server + server.xend_domain_rename(args[0], args[1]) def xm_subcommand(command, args): cmd = __import__(command, globals(), locals(), 'xen.xm') @@ -517,7 +538,7 @@ return cpus def xm_vcpu_pin(args): - arg_check(args, 3, "vcpu-pin") + arg_check(args, "vcpu-pin", 3) dom = args[0] vcpu = int(args[1]) @@ -527,7 +548,7 @@ server.xend_domain_pincpu(dom, vcpu, cpumap) def xm_mem_max(args): - arg_check(args, 2, "mem-max") + arg_check(args, "mem-max", 2) dom = args[0] mem = int_unit(args[1], 'm') @@ -536,7 +557,7 @@ server.xend_domain_maxmem_set(dom, mem) def xm_mem_set(args): - arg_check(args, 2, "mem-set") + arg_check(args, "mem-set", 2) dom = args[0] mem_target = int_unit(args[1], 'm') @@ -545,13 +566,13 @@ server.xend_domain_mem_target_set(dom, mem_target) def xm_set_vcpus(args): - arg_check(args, 2, "set-vcpus") + arg_check(args, "set-vcpus", 2) from xen.xend.XendClient import server server.xend_domain_set_vcpus(args[0], int(args[1])) def xm_domid(args): - arg_check(args, 1, "domid") + arg_check(args, "domid", 1) name = args[0] @@ -560,7 +581,7 @@ print sxp.child_value(dom, 'domid') def xm_domname(args): - arg_check(args, 1, "domname") + arg_check(args, "domname", 1) name = args[0] @@ -569,21 +590,21 @@ print sxp.child_value(dom, 'name') def xm_sched_bvt(args): - arg_check(args, 6, "sched-bvt") + arg_check(args, "sched-bvt", 6) dom = args[0] v = map(long, args[1:6]) from xen.xend.XendClient import server server.xend_domain_cpu_bvt_set(dom, *v) def xm_sched_bvt_ctxallow(args): - arg_check(args, 1, "sched-bvt-ctxallow") + arg_check(args, "sched-bvt-ctxallow", 1) slice = int(args[0]) from xen.xend.XendClient import server server.xend_node_cpu_bvt_slice_set(slice) def xm_sched_sedf(args): - arg_check(args, 6, "sched-sedf") + arg_check(args, "sched-sedf", 6) dom = args[0] v = map(int, args[1:6]) @@ -600,9 +621,8 @@ else: print "%-23s:" % x[0], x[1] -# TODO: remove as soon as console server shows up def xm_console(args): - arg_check(args,1,"console") + arg_check(args, "console", 1) dom = args[0] from xen.xend.XendClient import server @@ -639,11 +659,13 @@ server.xend_node_clear_dmesg() def xm_log(args): + arg_check(args, 'xm-log', 0) + from xen.xend.XendClient import server print server.xend_node_log() def xm_network_list(args): - arg_check(args,1,"network-list") + arg_check(args, "network-list", 1) dom = args[0] from xen.xend.XendClient import server for x in server.xend_domain_devices(dom, 'vif'): @@ -651,7 +673,7 @@ print def xm_block_list(args): - arg_check(args,1,"block-list") + arg_check(args, "block-list", 1) dom = args[0] from xen.xend.XendClient import server for x in server.xend_domain_devices(dom, 'vbd'): @@ -659,20 +681,14 @@ print def xm_block_attach(args): - n = len(args) - if n == 0: - usage("block-attach") - - if n < 4 or n > 5: - err("%s: Invalid argument(s)" % args[0]) - usage("block-attach") + arg_check(args, 'block-attach', 4, 5) dom = args[0] vbd = ['vbd', ['uname', args[1]], ['dev', args[2]], ['mode', args[3]]] - if n == 5: + if len(args) == 5: vbd.append(['backend', args[4]]) from xen.xend.XendClient import server @@ -680,10 +696,8 @@ def xm_network_attach(args): - n = len(args) - if n == 0: - usage("network-attach") - + arg_check(args, 'network-attach', 1, 10000) + dom = args[0] vif = ['vif'] @@ -695,7 +709,7 @@ def detach(args, command, deviceClass): - arg_check(args, 2, command) + arg_check(args, command, 2) dom = args[0] dev = args[1] @@ -742,7 +756,7 @@ print vnet, ex def xm_vnet_create(args): - arg_check(args, 1, "vnet-create") + arg_check(args, "vnet-create", 1) conf = args[0] if not os.access(conf, os.R_OK): print "File not found: %s" % conf @@ -752,7 +766,7 @@ server.xend_vnet_create(conf) def xm_vnet_delete(args): - arg_check(args, 1, "vnet-delete") + arg_check(args, "vnet-delete", 1) vnet = args[0] from xen.xend.XendClient import server server.xend_vnet_delete(vnet) @@ -765,6 +779,7 @@ # domain commands "domid": xm_domid, "domname": xm_domname, + "rename": xm_rename, "restore": xm_restore, "save": xm_save, "reboot": xm_reboot, @@ -888,7 +903,7 @@ sys.exit(1) except xen.xend.XendError.XendError, ex: if len(args) > 0: - handle_xend_error(argv[1], args[0], ex) + handle_xend_error(argv[1], args, ex) else: print "Unexpected error:", sys.exc_info()[0] print @@ -896,7 +911,7 @@ raise except xen.xend.XendProtocol.XendError, ex: if len(args) > 0: - handle_xend_error(argv[1], args[0], ex) + handle_xend_error(argv[1], args, ex) else: print "Unexpected error:", sys.exc_info()[0] print _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |