[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xl: new global -N option for dry run



# HG changeset patch
# User Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
# Date 1309259955 -3600
# Node ID f707974b04bacae7a6182ea67142af41efe3441d
# Parent  c82d727c17b9ef4452b2dbf08495f6bc4f7e4bca
xl: new global -N option for dry run

This sets a global dryrun_only variable, which individual commands are
expected to honour.  To avoid accidents, we introduce a new can_dryrun
member in the command table, which is initially set to 0 for each
command.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---


diff -r c82d727c17b9 -r f707974b04ba tools/libxl/xl.c
--- a/tools/libxl/xl.c  Tue Jun 28 12:19:15 2011 +0100
+++ b/tools/libxl/xl.c  Tue Jun 28 12:19:15 2011 +0100
@@ -34,6 +34,7 @@
 #include "xl.h"
 
 xentoollog_logger_stdiostream *logger;
+int dryrun_only;
 int autoballoon = 1;
 char *lockfile;
 char *default_vifscript = NULL;
@@ -90,11 +91,14 @@
     void *config_data = 0;
     int config_len = 0;
 
-    while ((opt = getopt(argc, argv, "+v")) >= 0) {
+    while ((opt = getopt(argc, argv, "+vN")) >= 0) {
         switch (opt) {
         case 'v':
             if (minmsglevel > 0) minmsglevel--;
             break;
+        case 'N':
+            dryrun_only = 1;
+            break;
         default:
             fprintf(stderr, "unknown global option\n");
             exit(2);
@@ -138,9 +142,14 @@
     optind = 1;
 
     cspec = cmdtable_lookup(cmd);
-    if (cspec)
+    if (cspec) {
+        if (dryrun_only && !cspec->can_dryrun) {
+            fprintf(stderr, "command does not implement -N (dryrun) option\n");
+            ret = 1;
+            goto xit;
+        }
         ret = cspec->cmd_impl(argc, argv);
-    else if (!strcmp(cmd, "help")) {
+    } else if (!strcmp(cmd, "help")) {
         help(argv[1]);
         ret = 0;
     } else {
@@ -148,8 +157,8 @@
         ret = 1;
     }
 
+ xit:
     libxl_ctx_free(ctx);
     xtl_logger_destroy((xentoollog_logger*)logger);
-
     return ret;
 }
diff -r c82d727c17b9 -r f707974b04ba tools/libxl/xl.h
--- a/tools/libxl/xl.h  Tue Jun 28 12:19:15 2011 +0100
+++ b/tools/libxl/xl.h  Tue Jun 28 12:19:15 2011 +0100
@@ -20,6 +20,7 @@
 struct cmd_spec {
     char *cmd_name;
     int (*cmd_impl)(int argc, char **argv);
+    int can_dryrun;
     char *cmd_desc;
     char *cmd_usage;
     char *cmd_option;
@@ -103,6 +104,7 @@
 
 /* global options */
 extern int autoballoon;
+extern int dryrun_only;
 extern char *lockfile;
 extern char *default_vifscript;
 
diff -r c82d727c17b9 -r f707974b04ba tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue Jun 28 12:19:15 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Tue Jun 28 12:19:15 2011 +0100
@@ -1674,7 +1674,7 @@
     struct cmd_spec *cmd;
 
     if (!command || !strcmp(command, "help")) {
-        printf("Usage xl [-v] <subcommand> [args]\n\n");
+        printf("Usage xl [-vN] <subcommand> [args]\n\n");
         printf("xl full list of subcommands:\n\n");
         for (i = 0; i < cmdtable_len; i++)
             printf(" %-20s%s\n",
@@ -1682,7 +1682,8 @@
     } else {
         cmd = cmdtable_lookup(command);
         if (cmd) {
-            printf("Usage: xl [-v] %s %s\n\n%s.\n\n",
+            printf("Usage: xl [-v%s] %s %s\n\n%s.\n\n",
+                   cmd->can_dryrun ? "N" : "",
                    cmd->cmd_name,
                    cmd->cmd_usage,
                    cmd->cmd_desc);
diff -r c82d727c17b9 -r f707974b04ba tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Tue Jun 28 12:19:15 2011 +0100
+++ b/tools/libxl/xl_cmdtable.c Tue Jun 28 12:19:15 2011 +0100
@@ -19,7 +19,7 @@
 
 struct cmd_spec cmd_table[] = {
     { "create",
-      &main_create,
+      &main_create, 0,
       "Create a domain from config file <filename>",
       "<ConfigFile> [options] [vars]",
       "-h                      Print this help.\n"
@@ -32,7 +32,7 @@
       "-e                      Do not wait in the background for the death of 
the domain."
     },
     { "list",
-      &main_list,
+      &main_list, 0,
       "List information about all/some domains",
       "[options] [Domain]\n",
       "-l, --long              Output all VM details\n"
@@ -40,59 +40,59 @@
       "-Z, --context           Prints out security context"
     },
     { "destroy",
-      &main_destroy,
+      &main_destroy, 0,
       "Terminate a domain immediately",
       "<Domain>",
     },
     { "shutdown",
-      &main_shutdown,
+      &main_shutdown, 0,
       "Issue a shutdown signal to a domain",
       "<Domain>",
     },
     { "reboot",
-      &main_reboot,
+      &main_reboot, 0,
       "Issue a reboot signal to a domain",
       "<Domain>",
     }, 
     { "pci-attach",
-      &main_pciattach,
+      &main_pciattach, 0,
       "Insert a new pass-through pci device",
       "<Domain> <BDF> [Virtual Slot]",
     },
     { "pci-detach",
-      &main_pcidetach,
+      &main_pcidetach, 0,
       "Remove a domain's pass-through pci device",
       "<Domain> <BDF>",
     },
     { "pci-list",
-      &main_pcilist,
+      &main_pcilist, 0,
       "List pass-through pci devices for a domain",
       "<Domain>",
     },
     { "pci-list-assignable-devices",
-      &main_pcilist_assignable,
+      &main_pcilist_assignable, 0,
       "List all the assignable pci devices",
       "",
     },
     { "pause",
-      &main_pause,
+      &main_pause, 0,
       "Pause execution of a domain",
       "<Domain>",
     },
     { "unpause",
-      &main_unpause,
+      &main_unpause, 0,
       "Unpause a paused domain",
       "<Domain>",
     },
     { "console",
-      &main_console,
+      &main_console, 0,
       "Attach to domain's console",
       "[options] <Domain>\n"
       "-t <type>       console type, pv or serial\n"
       "-n <number>     console number"
     },
     { "vncviewer",
-      &main_vncviewer,
+      &main_vncviewer, 0,
       "Attach to domain's VNC server.",
       "[options] <Domain>\n"
       "--autopass               Pass VNC password to viewer via stdin and\n"
@@ -100,14 +100,14 @@
       "--vncviewer-autopass     (consistency alias for --autopass)"
     },
     { "save",
-      &main_save,
+      &main_save, 0,
       "Save a domain state to restore later",
       "[options] <Domain> <CheckpointFile> [<ConfigFile>]",
       "-h  Print this help.\n"
       "-c  Leave domain running after creating the snapshot."
     },
     { "migrate",
-      &main_migrate,
+      &main_migrate, 0,
       "Save a domain state to restore later",
       "[options] <Domain> <host>",
       "-h              Print this help.\n"
@@ -119,12 +119,12 @@
       "                of the domain."
     },
     { "dump-core",
-      &main_dump_core,
+      &main_dump_core, 0,
       "Core dump a domain",
       "<Domain> <filename>"
     },
     { "restore",
-      &main_restore,
+      &main_restore, 0,
       "Restore a domain from a saved state",
       "[options] [<ConfigFile>] <CheckpointFile>",
       "-h  Print this help.\n"
@@ -133,63 +133,63 @@
       "-d  Enable debug messages."
     },
     { "migrate-receive",
-      &main_migrate_receive,
+      &main_migrate_receive, 0,
       "Restore a domain from a saved state",
       "- for internal use only",
     },
     { "cd-insert",
-      &main_cd_insert,
+      &main_cd_insert, 0,
       "Insert a cdrom into a guest's cd drive",
       "<Domain> <VirtualDevice> <type:path>",
     },
     { "cd-eject",
-      &main_cd_eject,
+      &main_cd_eject, 0,
       "Eject a cdrom from a guest's cd drive",
       "<Domain> <VirtualDevice>",
     },
     { "mem-max",
-      &main_memmax,
+      &main_memmax, 0,
       "Set the maximum amount reservation for a domain",
       "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
     },
     { "mem-set",
-      &main_memset,
+      &main_memset, 0,
       "Set the current memory usage for a domain",
       "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
     },
     { "button-press",
-      &main_button_press,
+      &main_button_press, 0,
       "Indicate an ACPI button press to the domain",
       "<Domain> <Button>",
       "<Button> may be 'power' or 'sleep'."
     },
     { "vcpu-list",
-      &main_vcpulist,
+      &main_vcpulist, 0,
       "List the VCPUs for all/some domains",
       "[Domain, ...]",
     },
     { "vcpu-pin",
-      &main_vcpupin,
+      &main_vcpupin, 0,
       "Set which CPUs a VCPU can use",
       "<Domain> <VCPU|all> <CPUs|all>",
     },
     { "vcpu-set",
-      &main_vcpuset,
+      &main_vcpuset, 0,
       "Set the number of active VCPUs allowed for the domain",
       "<Domain> <vCPUs>",
     },
     { "list-vm",
-      &main_list_vm,
+      &main_list_vm, 0,
       "List the VMs,without DOM0",
       "",
     },
     { "info",
-      &main_info,
+      &main_info, 0,
       "Get information about Xen host",
       "-n, --numa         List host NUMA topology information",
     },
     { "sched-credit",
-      &main_sched_credit,
+      &main_sched_credit, 0,
       "Get/set credit scheduler parameters",
       "[-d <Domain> [-w[=WEIGHT]|-c[=CAP]]]",
       "-d DOMAIN, --domain=DOMAIN     Domain to modify\n"
@@ -197,109 +197,109 @@
       "-c CAP, --cap=CAP              Cap (int)"
     },
     { "domid",
-      &main_domid,
+      &main_domid, 0,
       "Convert a domain name to domain id",
       "<DomainName>",
     },
     { "domname",
-      &main_domname,
+      &main_domname, 0,
       "Convert a domain id to domain name",
       "<DomainId>",
     },
     { "rename",
-      &main_rename,
+      &main_rename, 0,
       "Rename a domain",
       "<Domain> <NewDomainName>",
     },
     { "trigger",
-      &main_trigger,
+      &main_trigger, 0,
       "Send a trigger to a domain",
       "<Domain> <nmi|reset|init|power|sleep> [<VCPU>]",
     },
     { "sysrq",
-      &main_sysrq,
+      &main_sysrq, 0,
       "Send a sysrq to a domain",
       "<Domain> <letter>",
     },
     { "debug-keys",
-      &main_debug_keys,
+      &main_debug_keys, 0,
       "Send debug keys to Xen",
       "<Keys>",
     },
     { "dmesg",
-      &main_dmesg,
+      &main_dmesg, 0,
       "Read and/or clear dmesg buffer",
       "[-c]",
       "  -c                        Clear dmesg buffer as well as printing it",
     },
     { "top",
-      &main_top,
+      &main_top, 0,
       "Monitor a host and the domains in real time",
       "",
     },
     { "network-attach",
-      &main_networkattach,
+      &main_networkattach, 0,
       "Create a new virtual network device",
       "<Domain> [type=<type>] [mac=<mac>] [bridge=<bridge>] "
       "[ip=<ip>] [script=<script>] [backend=<BackDomain>] [vifname=<name>] "
       "[rate=<rate>] [model=<model>] [accel=<accel>]",
     },
     { "network-list",
-      &main_networklist,
+      &main_networklist, 0,
       "List virtual network interfaces for a domain",
       "<Domain(s)>",
     },
     { "network-detach",
-      &main_networkdetach,
+      &main_networkdetach, 0,
       "Destroy a domain's virtual network device",
       "<Domain> <DevId|mac>",
     },
     { "block-attach",
-      &main_blockattach,
+      &main_blockattach, 0,
       "Create a new virtual block device",
       "<Domain> <disk-spec-component(s)>...",
     },
     { "block-list",
-      &main_blocklist,
+      &main_blocklist, 0,
       "List virtual block devices for a domain",
       "<Domain(s)>",
     },
     { "block-detach",
-      &main_blockdetach,
+      &main_blockdetach, 0,
       "Destroy a domain's virtual block device",
       "<Domain> <DevId>",
     },
     { "uptime",
-      &main_uptime,
+      &main_uptime, 0,
       "Print uptime for all/some domains",
       "[-s] [Domain]",
     },
     { "tmem-list",
-      &main_tmem_list,
+      &main_tmem_list, 0,
       "List tmem pools",
       "[-l] [<Domain>|-a]",
       "  -l                             List tmem stats",
     },
     { "tmem-freeze",
-      &main_tmem_freeze,
+      &main_tmem_freeze, 0,
       "Freeze tmem pools",
       "[<Domain>|-a]",
       "  -a                             Freeze all tmem",
     },
     { "tmem-destroy",
-      &main_tmem_destroy,
+      &main_tmem_destroy, 0,
       "Destroy tmem pools",
       "[<Domain>|-a]",
       "  -a                             Destroy all tmem",
     },
     { "tmem-thaw",
-      &main_tmem_thaw,
+      &main_tmem_thaw, 0,
       "Thaw tmem pools",
       "[<Domain>|-a]",
       "  -a                             Thaw all tmem",
     },
     { "tmem-set",
-      &main_tmem_set,
+      &main_tmem_set, 0,
       "Change tmem settings",
       "[<Domain>|-a] [-w[=WEIGHT]|-c[=CAP]|-p[=COMPRESS]]",
       "  -a                             Operate on all tmem\n"
@@ -308,7 +308,7 @@
       "  -p COMPRESS                    Compress (int)",
     },
     { "tmem-shared-auth",
-      &main_tmem_shared_auth,
+      &main_tmem_shared_auth, 0,
       "De/authenticate shared tmem pool",
       "[<Domain>|-a] [-u[=UUID] [-A[=AUTH]",
       "  -a                             Authenticate for all tmem pools\n"
@@ -317,12 +317,12 @@
       "  -A AUTH                        0=auth,1=deauth",
     },
     { "tmem-freeable",
-      &main_tmem_freeable,
+      &main_tmem_freeable, 0,
       "Get information about how much freeable memory (MB) is in-use by tmem",
       "",
     },
     { "cpupool-create",
-      &main_cpupoolcreate,
+      &main_cpupoolcreate, 0,
       "Create a CPU pool based an ConfigFile",
       "[options] <ConfigFile> [vars]",
       "-h, --help                   Print this help.\n"
@@ -330,53 +330,53 @@
       "-n, --dryrun                 Dry run - prints the resulting 
configuration."
     },
     { "cpupool-list",
-      &main_cpupoollist,
+      &main_cpupoollist, 0,
       "List CPU pools on host",
       "[-c|--cpus] [<CPU Pool>]",
       "-c, --cpus                     Output list of CPUs used by a pool"
     },
     { "cpupool-destroy",
-      &main_cpupooldestroy,
+      &main_cpupooldestroy, 0,
       "Deactivates a CPU pool",
       "<CPU Pool>",
     },
     { "cpupool-rename",
-      &main_cpupoolrename,
+      &main_cpupoolrename, 0,
       "Renames a CPU pool",
       "<CPU Pool> <new name>",
     },
     { "cpupool-cpu-add",
-      &main_cpupoolcpuadd,
+      &main_cpupoolcpuadd, 0,
       "Adds a CPU to a CPU pool",
       "<CPU Pool> <CPU nr>|node:<node nr>",
     },
     { "cpupool-cpu-remove",
-      &main_cpupoolcpuremove,
+      &main_cpupoolcpuremove, 0,
       "Removes a CPU from a CPU pool",
       "<CPU Pool> <CPU nr>|node:<node nr>",
     },
     { "cpupool-migrate",
-      &main_cpupoolmigrate,
+      &main_cpupoolmigrate, 0,
       "Moves a domain into a CPU pool",
       "<Domain> <CPU Pool>",
     },
     { "cpupool-numa-split",
-      &main_cpupoolnumasplit,
+      &main_cpupoolnumasplit, 0,
       "Splits up the machine into one CPU pool per NUMA node",
       "",
     },
     { "getenforce",
-      &main_getenforce,
+      &main_getenforce, 0,
       "Returns the current enforcing mode of the Flask Xen security module",
       "",
     },
     { "setenforce",
-      &main_setenforce,
+      &main_setenforce, 0,
       "Sets the current enforcing mode of the Flask Xen security module",
       "<1|0|Enforcing|Permissive>",
     },
     { "loadpolicy",
-      &main_loadpolicy,
+      &main_loadpolicy, 0,
       "Loads a new policy int the Flask Xen security module",
       "<policy file>",
     },

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.