# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID d1e1d6493d1d30711338201065f88c1674357da7
# Parent d2b957902c6b48fb675ffbde5a46f6d8946c4372
Programmatically generate the xm help strings from the snippets, rather than
splicing the strings together manually.
Replace the word "bogus" with the command in question where it appears, as this
shows up in the Usage statements.
Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
diff -r d2b957902c6b -r d1e1d6493d1d tools/python/xen/xm/main.py
--- a/tools/python/xen/xm/main.py Thu Nov 24 19:53:09 2005
+++ b/tools/python/xen/xm/main.py Thu Nov 24 19:56:38 2005
@@ -24,7 +24,6 @@
import os
import os.path
import sys
-import commands
import re
from getopt import getopt
import socket
@@ -71,7 +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"
-log_help = "log Print the xend log"
+log_help = "log Print the xend log"
sched_bvt_help = """sched-bvt <Parameters> Set Borrowed Virtual Time
scheduler
parameters"""
sched_bvt_ctxallow_help = """sched-bvt-ctxallow <Allow> Set the BVT
scheduler context switch
@@ -96,25 +95,87 @@
vnet_delete_help = "vnet-delete <vnetid> delete a vnet"
+short_command_list = [
+ "console",
+ "create",
+ "destroy",
+ "help",
+ "list",
+ "mem-max",
+ "mem-set",
+ "migrate",
+ "pause",
+ "reboot",
+ "restore",
+ "save",
+ "shutdown",
+ "top",
+ "unpause",
+ ]
+
+domain_commands = [
+ "console",
+ "create",
+ "destroy",
+ "domid",
+ "domname",
+ "list",
+ "mem-max",
+ "mem-set",
+ "migrate",
+ "pause",
+ "reboot",
+ "restore",
+ "save",
+ "shutdown",
+ "sysrq",
+ "top",
+ "unpause",
+ "set-vcpus",
+ "vcpu-pin",
+ ]
+
+host_commands = [
+ "dmesg",
+ "info",
+ "log",
+ "top",
+ ]
+
+scheduler_commands = [
+ "sched-bvt",
+ "sched-bvt-ctxallow",
+ "sched-sedf",
+ ]
+
+device_commands = [
+ "block-attach",
+ "block-detach",
+ "block-list",
+ "network-attach",
+ "network-detach",
+ "network-list",
+ ]
+
+vnet_commands = [
+ "vnet-list",
+ "vnet-create",
+ "vnet-delete",
+ ]
+
+all_commands = (domain_commands + host_commands + scheduler_commands +
+ device_commands + vnet_commands)
+
+
+def commandToHelp(cmd):
+ return eval(cmd.replace("-", "_") + "_help")
+
+
shorthelp = """Usage: xm <subcommand> [args]
Control, list, and manipulate Xen guest instances
-xm common subcommands:""" + help_spacer \
-+ console_help + help_spacer \
-+ create_help + help_spacer \
-+ destroy_help + help_spacer \
-+ help_help + help_spacer \
-+ list_help + help_spacer \
-+ mem_max_help + help_spacer \
-+ mem_set_help + help_spacer \
-+ migrate_help + help_spacer \
-+ pause_help + help_spacer \
-+ reboot_help + help_spacer \
-+ restore_help + help_spacer \
-+ save_help + help_spacer \
-+ shutdown_help + help_spacer \
-+ top_help + help_spacer \
-+ unpause_help + """
+xm common subcommands:
+ """ + help_spacer.join(map(commandToHelp, short_command_list)) + """
<DomName> can be substituted for <DomId> in xm subcommands.
@@ -127,50 +188,20 @@
xm full list of subcommands:
- Domain Commands: """ + help_spacer \
-+ console_help + help_spacer \
-+ create_help + help_spacer \
-+ destroy_help + help_spacer \
-+ domid_help + help_spacer \
-+ domname_help + help_spacer \
-+ list_help + help_spacer \
-+ mem_max_help + help_spacer \
-+ mem_set_help + help_spacer \
-+ migrate_help + help_spacer \
-+ pause_help + help_spacer \
-+ reboot_help + help_spacer \
-+ restore_help + help_spacer \
-+ save_help + help_spacer \
-+ shutdown_help + help_spacer \
-+ sysrq_help + help_spacer \
-+ top_help + help_spacer \
-+ unpause_help + help_spacer \
-+ set_vcpus_help + help_spacer \
-+ vcpu_pin_help + """
-
- Xen Host Commands: """ + help_spacer \
-+ dmesg_help + help_spacer \
-+ info_help + help_spacer \
-+ log_help + help_spacer \
-+ top_help + """
-
- Scheduler Commands: """ + help_spacer \
-+ sched_bvt_help + help_spacer \
-+ sched_bvt_ctxallow_help + help_spacer \
-+ sched_sedf_help + """
-
- Virtual Device Commands:""" + help_spacer \
-+ block_attach_help + help_spacer \
-+ block_detach_help + help_spacer \
-+ block_list_help + help_spacer \
-+ network_attach_help + help_spacer \
-+ network_detach_help + help_spacer \
-+ network_list_help + """
-
- Vnet commands: """ + help_spacer \
-+ vnet_list_help + help_spacer \
-+ vnet_create_help + help_spacer \
-+ vnet_delete_help + """
+ Domain Commands:
+ """ + help_spacer.join(map(commandToHelp, domain_commands)) + """
+
+ Xen Host Commands:
+ """ + help_spacer.join(map(commandToHelp, host_commands)) + """
+
+ Scheduler Commands:
+ """ + help_spacer.join(map(commandToHelp, scheduler_commands)) + """
+
+ Virtual Device Commands:
+ """ + help_spacer.join(map(commandToHelp, device_commands)) + """
+
+ Vnet commands:
+ """ + help_spacer.join(map(commandToHelp, vnet_commands)) + """
<DomName> can be substituted for <DomId> in xm subcommands.
@@ -180,48 +211,14 @@
# array for xm help <command>
help = {
- "--long": longhelp,
- "console": console_help,
-# create is handled specially
- "destroy": destroy_help,
- "domid ": domid_help,
- "domname": domname_help,
- "list": list_help,
- "mem-max": mem_max_help,
- "mem-set": mem_set_help,
- "migrate": migrate_help,
- "pause": pause_help,
- "reboot": reboot_help,
- "restore": restore_help,
- "save": save_help,
- "shutdown": shutdown_help,
- "sysrq": sysrq_help,
- "unpause": unpause_help,
- "set-vcpus": set_vcpus_help,
- "vcpu-list": vcpu_list_help,
- "vcpu-pin": vcpu_pin_help,
-# Xen Host Commands:
- "dmesg": dmesg_help,
- "info": info_help,
- "log": log_help,
- "top": top_help,
-# Scheduler Commands:
- "sched-bvt": sched_bvt_help,
- "sched-bvt-ctxallow": sched_bvt_ctxallow_help,
- "sched-sedf": sched_sedf_help,
-
-# Virtual Device Commands:
- "block-attach": block_attach_help,
- "block-detach": block_detach_help,
- "block-list": block_list_help,
- "network-attach": network_attach_help,
- "network-detach": network_detach_help,
- "network-list": network_list_help,
-# Vnet commands:
- "vnet-list": vnet_list_help,
- "vnet-create": vnet_create_help,
- "vnet-delete": vnet_delete_help
- }
+ "--long": longhelp
+ }
+
+for command in all_commands:
+ # create is handled specially
+ if (command != 'create'):
+ help[command] = commandToHelp(command)
+
####################################################################
#
@@ -484,9 +481,7 @@
def xm_reboot(args):
arg_check(args,1,"reboot")
from xen.xm import shutdown
- # ugly hack because the opt parser apparently wants
- # the subcommand name just to throw it away!
- shutdown.main(["bogus", "-R"] + args)
+ shutdown.main(["shutdown", "-R"] + args)
def xm_pause(args):
arg_check(args, 1, "pause")
@@ -504,7 +499,7 @@
def xm_subcommand(command, args):
cmd = __import__(command, globals(), locals(), 'xen.xm')
- cmd.main(["bogus"] + args)
+ cmd.main([command] + args)
#############################################################
@@ -632,7 +627,7 @@
use="Clear the contents of the Xen message buffer.")
# Work around for gopts
myargs = args
- myargs.insert(0, "bogus")
+ myargs.insert(0, 'dmesg')
gopts.parse(myargs)
if not (1 <= len(myargs) <= 2):
err('Invalid arguments: ' + str(myargs))
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|