]> xenbits.xensource.com Git - libvirt.git/commitdiff
UUID utils, virsh cleanup, ...
authorKarel Zak <kzak@redhat.com>
Mon, 22 May 2006 14:38:33 +0000 (14:38 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 22 May 2006 14:38:33 +0000 (14:38 +0000)
ChangeLog
include/libvirt.h.in
include/libvirt/libvirt.h.in
src/libvirt.c
src/libvirt_sym.version
src/virsh.c
tests/testutils.c
virsh.1

index 8acac5ccb39d78a9488538f36b2896f1c9bf4307..3f4a8b1fe4ecbbfba0372aa69ead6dcf26df87d4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon May 22 15:34:20 CEST 2006 Karel Zak <kzak@redhat.com>
+
+       * src/virsh.c: added UUID: to the dominfo command, vshPrint() refactoring,
+         added support for domain look up by UUID
+       * virsh.1: added information about UUID, fixed list of commands and 
+         domains statuses
+       * src/libvirt.c include/libvirt.h.in src/libvirt_sym.version: added
+         virDomainGetUUIDString() and virDomainLookupByUUIDString()
+
 Wed May 10 15:50:32 CEST 2006 Karel Zak <kzak@redhat.com>
 
        * src/virterror.c include/virterror.h: added VIR_FROM_RPC
index 1846bdda5dba1ea91d5e53246ca6aaa885791043..2668eaafcd55a770c70cf5308b2a9c9f4be7c27f 100644 (file)
@@ -229,6 +229,9 @@ virDomainPtr                virDomainLookupByID     (virConnectPtr conn,
                                                 int id);
 virDomainPtr           virDomainLookupByUUID   (virConnectPtr conn,
                                                 const unsigned char *uuid);
+virDomainPtr           virDomainLookupByUUIDString     (virConnectPtr conn,
+                                                       const char *uuid);
+
 int                    virDomainShutdown       (virDomainPtr domain);
 int                    virDomainReboot         (virDomainPtr domain,
                                                 unsigned int flags);
@@ -262,6 +265,8 @@ const char *                virDomainGetName        (virDomainPtr domain);
 unsigned int           virDomainGetID          (virDomainPtr domain);
 int                    virDomainGetUUID        (virDomainPtr domain,
                                                 unsigned char *uuid);
+int                    virDomainGetUUIDString  (virDomainPtr domain, 
+                                               char *buf);
 char *                 virDomainGetOSType      (virDomainPtr domain);
 unsigned long          virDomainGetMaxMemory   (virDomainPtr domain);
 int                    virDomainSetMaxMemory   (virDomainPtr domain,
index 1846bdda5dba1ea91d5e53246ca6aaa885791043..2668eaafcd55a770c70cf5308b2a9c9f4be7c27f 100644 (file)
@@ -229,6 +229,9 @@ virDomainPtr                virDomainLookupByID     (virConnectPtr conn,
                                                 int id);
 virDomainPtr           virDomainLookupByUUID   (virConnectPtr conn,
                                                 const unsigned char *uuid);
+virDomainPtr           virDomainLookupByUUIDString     (virConnectPtr conn,
+                                                       const char *uuid);
+
 int                    virDomainShutdown       (virDomainPtr domain);
 int                    virDomainReboot         (virDomainPtr domain,
                                                 unsigned int flags);
@@ -262,6 +265,8 @@ const char *                virDomainGetName        (virDomainPtr domain);
 unsigned int           virDomainGetID          (virDomainPtr domain);
 int                    virDomainGetUUID        (virDomainPtr domain,
                                                 unsigned char *uuid);
+int                    virDomainGetUUIDString  (virDomainPtr domain, 
+                                               char *buf);
 char *                 virDomainGetOSType      (virDomainPtr domain);
 unsigned long          virDomainGetMaxMemory   (virDomainPtr domain);
 int                    virDomainSetMaxMemory   (virDomainPtr domain,
index a153fbae4712c7682216466c923f0bce71702477..a77f1a14164273beca41899378fd40706283857c 100644 (file)
@@ -655,7 +655,7 @@ error:
 /**
  * virDomainLookupByUUID:
  * @conn: pointer to the hypervisor connection
- * @uuid: the UUID string for the domain
+ * @uuid: the raw UUID for the domain
  *
  * Try to lookup a domain on the given hypervisor based on its UUID.
  *
@@ -712,6 +712,55 @@ virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
     return (ret);
 }
 
+/**
+ * virDomainLookupByUUIDString:
+ * @conn: pointer to the hypervisor connection
+ * @uuidstr: the string UUID for the domain
+ *
+ * Try to lookup a domain on the given hypervisor based on its UUID.
+ *
+ * Returns a new domain object or NULL in case of failure
+ */
+virDomainPtr
+virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
+{
+    int raw[16], i;
+    unsigned char uuid[16];
+    int ret;
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__);
+        return (NULL);
+    }
+    if (uuidstr == NULL) {
+        virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return (NULL);
+       
+    }
+    /* XXX: sexpr_uuid() also supports 'xxxx-xxxx-xxxx-xxxx' format. 
+     *      We needn't it here. Right? 
+     */
+    ret = sscanf(uuidstr,
+                 "%02x%02x%02x%02x-"
+                 "%02x%02x-"
+                 "%02x%02x-"
+                 "%02x%02x-"
+                 "%02x%02x%02x%02x%02x%02x",
+                 raw + 0, raw + 1, raw + 2, raw + 3,
+                 raw + 4, raw + 5, raw + 6, raw + 7,
+                 raw + 8, raw + 9, raw + 10, raw + 11,
+                 raw + 12, raw + 13, raw + 14, raw + 15);
+    
+    if (ret!=16) {
+       virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+       return (NULL);
+    }
+    for (i = 0; i < 16; i++)
+        uuid[i] = raw[i] & 0xFF;
+    
+    return virDomainLookupByUUID(conn, &uuid[0]);
+}
+
 /**
  * virDomainLookupByName:
  * @conn: pointer to the hypervisor connection
@@ -1110,6 +1159,42 @@ virDomainGetUUID(virDomainPtr domain, unsigned char *uuid)
     return (0);
 }
 
+/**
+ * virDomainGetUUIDString:
+ * @domain: a domain object
+ * @buf: pointer to a 37 bytes array
+ *
+ * Get the UUID for a domain as string. For more information about 
+ * UUID see RFC4122.
+ *
+ * Returns -1 in case of error, 0 in case of success
+ */
+int
+virDomainGetUUIDString(virDomainPtr domain, char *buf)
+{
+    unsigned char uuid[16];
+    
+    if (!VIR_IS_DOMAIN(domain)) {
+        virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        return (-1);
+    }
+    if (buf == NULL) {
+        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return (-1);
+    }
+    
+    if (virDomainGetUUID(domain, &uuid[0]))
+       return (-1);
+
+    snprintf(buf, 37, 
+       "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+                      uuid[0], uuid[1], uuid[2], uuid[3],
+                      uuid[4], uuid[5], uuid[6], uuid[7],
+                      uuid[8], uuid[9], uuid[10], uuid[11],
+                      uuid[12], uuid[13], uuid[14], uuid[15]);
+    return (0);
+}
+
 /**
  * virDomainGetID:
  * @domain: a domain object
index 077e5ee6e8e7f6c04e67b778c07b784b7d23d82b..aa23e5b099d285797b96a5997cb68f959f026e5a 100644 (file)
@@ -13,6 +13,7 @@
        virDomainFree;
        virDomainGetID;
        virDomainGetUUID;
+       virDomainGetUUIDString;
        virDomainGetInfo;
        virDomainGetMaxMemory;
        virDomainGetName;
@@ -21,6 +22,7 @@
        virDomainLookupByID;
        virDomainLookupByName;
        virDomainLookupByUUID;
+       virDomainLookupByUUIDString;
        virDomainRestore;
        virDomainResume;
        virDomainSave;
index c33e11d28476b84ced9d2d0855c09a82b2aac781..60c03a8ebccbc4768dc5dd12929f996b187b2881 100644 (file)
@@ -47,17 +47,6 @@ static char *progname;
         ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
           ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
 
-typedef enum {
-    VSH_MESG,                   /* standard output */
-    VSH_HEADER,                 /* header for standard output */
-    VSH_FOOTER,                 /* timing, last command state, or whatever */
-    VSH_DEBUG1,                 /* debugN where 'N' = level */
-    VSH_DEBUG2,
-    VSH_DEBUG3,
-    VSH_DEBUG4,
-    VSH_DEBUG5
-} vshOutType;
-
 /*
  * The error handler for virtsh
  */
@@ -198,9 +187,9 @@ static int vshCommandOptBool(vshCmd * cmd, const char *name);
 static virDomainPtr vshCommandOptDomain(vshControl * ctl, vshCmd * cmd,
                                         const char *optname, char **name);
 
-
-static void vshPrint(vshControl * ctl, vshOutType out, const char *format,
-                     ...);
+static void vshPrintExtra(vshControl * ctl, const char *format, ...);
+static void vshDebug(vshControl * ctl, int level, const char *format, ...);
+#define vshPrint(_ctl, ...)   fprintf(stdout, __VA_ARGS__)
 
 static const char *vshDomainStateToString(int state);
 static int vshConnectionUsability(vshControl * ctl, virConnectPtr conn,
@@ -244,9 +233,9 @@ cmdHelp(vshControl * ctl, vshCmd * cmd)
     if (!cmdname) {
         vshCmdDef *def;
 
-        vshPrint(ctl, VSH_HEADER, "Commands:\n\n");
+        vshPrint(ctl, "Commands:\n\n");
         for (def = commands; def->name; def++)
-            vshPrint(ctl, VSH_MESG, "    %-15s %s\n", def->name,
+            vshPrint(ctl, "    %-15s %s\n", def->name,
                      vshCmddefGetInfo(def, "help"));
         return TRUE;
     }
@@ -323,8 +312,8 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
 
     virConnectListDomains(ctl->conn, &ids[0], maxid);
 
-    vshPrint(ctl, VSH_HEADER, "%3s %-20s %s\n", "Id", "Name", "State");
-    vshPrint(ctl, VSH_HEADER, "----------------------------------\n");
+    vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
+    vshPrintExtra(ctl, "----------------------------------\n");
 
     for (i = 0; i < maxid; i++) {
         int ret;
@@ -336,7 +325,7 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
             continue;
         ret = virDomainGetInfo(dom, &info);
 
-        vshPrint(ctl, VSH_MESG, "%3d %-20s %s\n",
+        vshPrint(ctl, "%3d %-20s %s\n",
                  virDomainGetID(dom),
                  virDomainGetName(dom),
                  ret <
@@ -376,7 +365,7 @@ cmdDomstate(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainGetInfo(dom, &info) == 0)
-        vshPrint(ctl, VSH_MESG, "%s\n",
+        vshPrint(ctl, "%s\n",
                  vshDomainStateToString(info.state));
     else
         ret = FALSE;
@@ -414,7 +403,7 @@ cmdSuspend(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainSuspend(dom) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain %s suspended\n", name);
+        vshPrint(ctl, "Domain %s suspended\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to suspend domain\n");
         ret = FALSE;
@@ -470,7 +459,7 @@ cmdCreate(vshControl * ctl, vshCmd * cmd)
     buffer[l] = 0;
     dom = virDomainCreateLinux(ctl->conn, &buffer[0], 0);
     if (dom != NULL) {
-        vshPrint(ctl, VSH_MESG, "Domain %s created from %s\n", 
+        vshPrint(ctl, "Domain %s created from %s\n", 
                  virDomainGetName(dom), from);
     } else {
         vshError(ctl, FALSE, "Failed to create domain\n");
@@ -513,7 +502,7 @@ cmdSave(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainSave(dom, to) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain %s saved\n", name);
+        vshPrint(ctl, "Domain %s saved\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to save domain\n");
         ret = FALSE;
@@ -553,7 +542,7 @@ cmdRestore(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainRestore(ctl->conn, from) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain restored from %s\n", from);
+        vshPrint(ctl, "Domain restored from %s\n", from);
     } else {
         vshError(ctl, FALSE, "Failed to restore domain\n");
         ret = FALSE;
@@ -590,7 +579,7 @@ cmdResume(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainResume(dom) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain %s resumed\n", name);
+        vshPrint(ctl, "Domain %s resumed\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to resume domain\n");
         ret = FALSE;
@@ -629,7 +618,7 @@ cmdShutdown(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainShutdown(dom) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain %s is being shutdown\n", name);
+        vshPrint(ctl, "Domain %s is being shutdown\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to shutdown domain\n");
         ret = FALSE;
@@ -668,7 +657,7 @@ cmdReboot(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainReboot(dom, 0) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain %s is being rebooted\n", name);
+        vshPrint(ctl, "Domain %s is being rebooted\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to reboot domain\n");
         ret = FALSE;
@@ -707,7 +696,7 @@ cmdDestroy(vshControl * ctl, vshCmd * cmd)
         return FALSE;
 
     if (virDomainDestroy(dom) == 0) {
-        vshPrint(ctl, VSH_MESG, "Domain %s destroyed\n", name);
+        vshPrint(ctl, "Domain %s destroyed\n", name);
     } else {
         vshError(ctl, FALSE, "Failed to destroy domain\n");
         ret = FALSE;
@@ -738,7 +727,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
     virDomainInfo info;
     virDomainPtr dom;
     int ret = TRUE;
-    char *str;
+    char *str, uuid[37];
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
@@ -746,31 +735,33 @@ cmdDominfo(vshControl * ctl, vshCmd * cmd)
     if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
         return FALSE;
 
-    vshPrint(ctl, VSH_MESG, "%-15s %d\n", "Id:", virDomainGetID(dom));
-    vshPrint(ctl, VSH_MESG, "%-15s %s\n", "Name:", virDomainGetName(dom));
+    vshPrint(ctl, "%-15s %d\n", "Id:", virDomainGetID(dom));
+    vshPrint(ctl, "%-15s %s\n", "Name:", virDomainGetName(dom));
+    if (virDomainGetUUIDString(dom, &uuid[0])==0)
+        vshPrint(ctl, "%-15s %s\n", "UUID:", uuid);
 
     if ((str = virDomainGetOSType(dom))) {
-        vshPrint(ctl, VSH_MESG, "%-15s %s\n", "OS Type:", str);
+        vshPrint(ctl, "%-15s %s\n", "OS Type:", str);
         free(str);
     }
 
     if (virDomainGetInfo(dom, &info) == 0) {
-        vshPrint(ctl, VSH_MESG, "%-15s %s\n", "State:",
+        vshPrint(ctl, "%-15s %s\n", "State:",
                  vshDomainStateToString(info.state));
 
-        vshPrint(ctl, VSH_MESG, "%-15s %d\n", "CPU(s):", info.nrVirtCpu);
+        vshPrint(ctl, "%-15s %d\n", "CPU(s):", info.nrVirtCpu);
 
         if (info.cpuTime != 0) {
             float cpuUsed = info.cpuTime;
 
             cpuUsed /= 1000000000;
 
-            vshPrint(ctl, VSH_MESG, "%-15s %.1fs\n", "CPU time:", cpuUsed);
+            vshPrint(ctl, "%-15s %.1fs\n", "CPU time:", cpuUsed);
         }
 
-        vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Max memory:",
+        vshPrint(ctl, "%-15s %lu kB\n", "Max memory:",
                  info.maxMem);
-        vshPrint(ctl, VSH_MESG, "%-15s %lu kB\n", "Used memory:",
+        vshPrint(ctl, "%-15s %lu kB\n", "Used memory:",
                  info.memory);
 
     } else {
@@ -803,14 +794,14 @@ cmdNodeinfo(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
         vshError(ctl, FALSE, "failed to get node information");
         return FALSE;
     }    
-    vshPrint(ctl, VSH_MESG, "%-20s %s\n", "CPU model:", info.model);
-    vshPrint(ctl, VSH_MESG, "%-20s %d\n", "CPU(s):", info.cpus);
-    vshPrint(ctl, VSH_MESG, "%-20s %d MHz\n", "CPU frequency:", info.mhz);
-    vshPrint(ctl, VSH_MESG, "%-20s %d\n", "CPU socket(s):", info.sockets);
-    vshPrint(ctl, VSH_MESG, "%-20s %d\n", "Core(s) per socket:", info.cores);
-    vshPrint(ctl, VSH_MESG, "%-20s %d\n", "Thread(s) per core:", info.threads);
-    vshPrint(ctl, VSH_MESG, "%-20s %d\n", "NUMA cell(s):", info.nodes);
-    vshPrint(ctl, VSH_MESG, "%-20s %lu kB\n", "Memory size:", info.memory);
+    vshPrint(ctl, "%-20s %s\n", "CPU model:", info.model);
+    vshPrint(ctl, "%-20s %d\n", "CPU(s):", info.cpus);
+    vshPrint(ctl, "%-20s %d MHz\n", "CPU frequency:", info.mhz);
+    vshPrint(ctl, "%-20s %d\n", "CPU socket(s):", info.sockets);
+    vshPrint(ctl, "%-20s %d\n", "Core(s) per socket:", info.cores);
+    vshPrint(ctl, "%-20s %d\n", "Thread(s) per core:", info.threads);
+    vshPrint(ctl, "%-20s %d\n", "NUMA cell(s):", info.nodes);
+    vshPrint(ctl, "%-20s %lu kB\n", "Memory size:", info.memory);
         
     return TRUE;
 }
@@ -883,7 +874,7 @@ cmdDomname(vshControl * ctl, vshCmd * cmd)
 
     dom = virDomainLookupByID(ctl->conn, id);
     if (dom) {
-        vshPrint(ctl, VSH_MESG, "%s\n", virDomainGetName(dom));
+        vshPrint(ctl, "%s\n", virDomainGetName(dom));
         virDomainFree(dom);
     } else {
         vshError(ctl, FALSE, "failed to get domain '%d'", id);
@@ -919,7 +910,7 @@ cmdDomid(vshControl * ctl, vshCmd * cmd)
 
     dom = virDomainLookupByName(ctl->conn, name);
     if (dom) {
-        vshPrint(ctl, VSH_MESG, "%d\n", virDomainGetID(dom));
+        vshPrint(ctl, "%d\n", virDomainGetID(dom));
         virDomainFree(dom);
     } else {
         vshError(ctl, FALSE, "failed to get domain '%s'", name);
@@ -966,7 +957,7 @@ cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
     includeVersion %= 1000000;
     minor = includeVersion / 1000;
     rel = includeVersion % 1000;
-    vshPrint(ctl, VSH_MESG, "Compiled against library: libvir %d.%d.%d\n",
+    vshPrint(ctl, "Compiled against library: libvir %d.%d.%d\n",
              major, minor, rel);
 
     ret = virGetVersion(&libVersion, hvType, &apiVersion);
@@ -978,14 +969,14 @@ cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
     libVersion %= 1000000;
     minor = libVersion / 1000;
     rel = libVersion % 1000;
-    vshPrint(ctl, VSH_MESG, "Using library: libvir %d.%d.%d\n",
+    vshPrint(ctl, "Using library: libvir %d.%d.%d\n",
              major, minor, rel);
 
     major = apiVersion / 1000000;
     apiVersion %= 1000000;
     minor = apiVersion / 1000;
     rel = apiVersion % 1000;
-    vshPrint(ctl, VSH_MESG, "Using API: %s %d.%d.%d\n", hvType,
+    vshPrint(ctl, "Using API: %s %d.%d.%d\n", hvType,
              major, minor, rel);
 
     ret = virConnectGetVersion(ctl->conn, &hvVersion);
@@ -994,7 +985,7 @@ cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
         return FALSE;
     }
     if (hvVersion == 0) {
-        vshPrint(ctl, VSH_MESG,
+        vshPrint(ctl,
                  "cannot extract running %s hypervisor version\n", hvType);
     } else {
         major = hvVersion / 1000000;
@@ -1002,7 +993,7 @@ cmdVersion(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
         minor = hvVersion / 1000;
         rel = hvVersion % 1000;
 
-        vshPrint(ctl, VSH_MESG, "Running hypervisor: %s %d.%d.%d\n",
+        vshPrint(ctl, "Running hypervisor: %s %d.%d.%d\n",
                  hvType, major, minor, rel);
     }
     return TRUE;
@@ -1293,7 +1284,7 @@ vshCommandOptDomain(vshControl * ctl, vshCmd * cmd, const char *optname,
         return NULL;
     }
 
-    vshPrint(ctl, VSH_DEBUG5, "%s: found option <%s>: %s\n",
+    vshDebug(ctl, 5, "%s: found option <%s>: %s\n",
              cmd->def->name, optname, n);
 
     if (name)
@@ -1302,17 +1293,25 @@ vshCommandOptDomain(vshControl * ctl, vshCmd * cmd, const char *optname,
     /* try it by ID */
     id = (int) strtol(n, &end, 10);
     if (id >= 0 && end && *end == '\0') {
-        vshPrint(ctl, VSH_DEBUG5, "%s: <%s> seems like domain ID\n",
+        vshDebug(ctl, 5, "%s: <%s> seems like domain ID\n",
                  cmd->def->name, optname);
         dom = virDomainLookupByID(ctl->conn, id);
     }
 
+    /* try it by UUID */
+    if (dom==NULL && strlen(n)==36) {
+        vshDebug(ctl, 5, "%s: <%s> tring as domain UUID\n",
+                cmd->def->name, optname);
+        dom = virDomainLookupByUUIDString(ctl->conn, (const unsigned char *) n);
+    }
+    
     /* try it by NAME */
     if (!dom) {
-        vshPrint(ctl, VSH_DEBUG5, "%s: <%s> tring as domain NAME\n",
+        vshDebug(ctl, 5, "%s: <%s> tring as domain NAME\n",
                  cmd->def->name, optname);
         dom = virDomainLookupByName(ctl->conn, n);
     }
+
     if (!dom)
         vshError(ctl, FALSE, "failed to get domain '%s'", n);
 
@@ -1342,10 +1341,10 @@ vshCommandRun(vshControl * ctl, vshCmd * cmd)
             return ret;
 
         if (ctl->timing)
-            vshPrint(ctl, VSH_MESG, "\n(Time: %.3f ms)\n\n",
+            vshPrint(ctl, "\n(Time: %.3f ms)\n\n",
                      DIFF_MSEC(&after, &before));
         else
-            vshPrint(ctl, VSH_FOOTER, "\n");
+            vshPrintExtra(ctl, "\n");
         cmd = cmd->next;
     }
     return ret;
@@ -1532,7 +1531,7 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
                     last->next = arg;
                 last = arg;
 
-                vshPrint(ctl, VSH_DEBUG4, "%s: %s(%s): %s\n",
+                vshDebug(ctl, 4, "%s: %s(%s): %s\n",
                          cmd->name,
                          opt->name,
                          tk == VSH_TK_OPTION ? "OPTION" : "DATA",
@@ -1592,6 +1591,8 @@ vshDomainStateToString(int state)
             return "in shutdown";
         case VIR_DOMAIN_SHUTOFF:
             return "shut off";
+        case VIR_DOMAIN_CRASHED:
+            return "crashed";
         default:
             return "no state";  /* = dom0 state */
     }
@@ -1612,46 +1613,25 @@ vshConnectionUsability(vshControl * ctl, virConnectPtr conn, int showerror)
     return TRUE;
 }
 
-static int
-vshWantedDebug(vshOutType type, int mode)
+static void
+vshDebug(vshControl * ctl, int level, const char *format, ...)
 {
-    switch (type) {
-        case VSH_DEBUG5:
-            if (mode < 5)
-                return FALSE;
-            return TRUE;
-        case VSH_DEBUG4:
-            if (mode < 4)
-                return FALSE;
-            return TRUE;
-        case VSH_DEBUG3:
-            if (mode < 3)
-                return FALSE;
-            return TRUE;
-        case VSH_DEBUG2:
-            if (mode < 2)
-                return FALSE;
-            return TRUE;
-        case VSH_DEBUG1:
-            if (mode < 1)
-                return FALSE;
-            return TRUE;
-        default:
-            /* it's right, all others types have to pass */
-            return TRUE;
-    }
-    return FALSE;
+    va_list ap;
+
+    if (level > ctl->debug)
+        return;
+
+    va_start(ap, format);
+    vfprintf(stdout, format, ap);
+    va_end(ap);
 }
 
 static void
-vshPrint(vshControl * ctl, vshOutType type, const char *format, ...)
+vshPrintExtra(vshControl * ctl, const char *format, ...)
 {
     va_list ap;
 
-    if (ctl->quiet == TRUE && (type == VSH_HEADER || type == VSH_FOOTER))
-        return;
-
-    if (!vshWantedDebug(type, ctl->debug))
+    if (ctl->quiet == TRUE)
         return;
 
     va_start(ap, format);
@@ -1659,6 +1639,7 @@ vshPrint(vshControl * ctl, vshOutType type, const char *format, ...)
     va_end(ap);
 }
 
+
 static void
 vshError(vshControl * ctl, int doexit, const char *format, ...)
 {
@@ -2009,7 +1990,7 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
             sz -= strlen(argv[i]);
             strncat(cmdstr, " ", sz--);
         }
-        vshPrint(ctl, VSH_DEBUG2, "command: \"%s\"\n", cmdstr);
+        vshDebug(ctl, 2, "command: \"%s\"\n", cmdstr);
         ret = vshCommandParse(ctl, cmdstr);
 
         free(cmdstr);
@@ -2043,10 +2024,10 @@ main(int argc, char **argv)
     } else {
         /* interactive mode */
         if (!ctl->quiet) {
-            vshPrint(ctl, VSH_MESG,
+            vshPrint(ctl,
                      "Welcome to %s, the virtualization interactive terminal.\n\n",
                      progname);
-            vshPrint(ctl, VSH_MESG,
+            vshPrint(ctl,
                      "Type:  'help' for help with commands\n"
                      "       'quit' to quit\n\n");
         }
index d79b9e5fbcca6bd3031a723905f20da7b2ffb478..ee562d71aa9c7726b5fd1563eb0918b64f38f606 100644 (file)
@@ -34,7 +34,7 @@ virtTestCountAverage(double *items, int nitems)
 }
 
 /* 
- * Runs test anf count average time (if the nloops is grater than 1)
+ * Runs test and count average time (if the nloops is grater than 1)
  * 
  * returns: -1 = error, 0 = success 
  */
diff --git a/virsh.1 b/virsh.1
index 4928a99cccd8afc6f7bea44d4e9641faac229b0e..17e611c55b51723ad9a6721585f404333ce2ec66 100644 (file)
--- a/virsh.1
+++ b/virsh.1
@@ -138,13 +138,13 @@ virsh <subcommand> [args]
 .SH "DESCRIPTION"
 .IX Header "DESCRIPTION"
 The \fBvirsh\fR program is the main interface for managing virsh guest
-domains. The program can be used to create, pause, and shutdown
+domains. The program can be used to create, suspend, resume, save, and shutdown
 domains. It can also be used to list current domains. Libvirt is a C toolkit to interract with the virtualization capabilities of recent versions of Linux (and other OSes). It is free software available under the \s-1GNU\s0 Lesser General Public License. Virtualization of the Linux Operating System means the ability to run multiple instances of Operating Systems concurently on a single hardware system where the basic resources are driven by a Linux instance. The library aim at providing long term stable C \s-1API\s0 initially for the Xen paravirtualization but should be able to integrate other virtualization mechanisms if needed.
 .PP
 The basic structure of every virsh command is almost always:
 .PP
 .Vb 1
-\&  virsh <subcommand> <domain-id> [OPTIONS]
+\&  virsh <subcommand> <domain-id|name|uuid> [OPTIONS]
 .Ve
 .PP
 Where \fIsubcommand\fR is one of the sub commands listed below, \fIdomain-id\fR
@@ -181,18 +181,11 @@ The \fI\-\-readonly\fR option read-only connection
 .IP "\fBcreate\fR \fI\s-1FILE\s0\fR" 4
 .IX Item "create FILE"
 Create a domain from an \s-1XML\s0 <file> an easy way to create one if you have a pre-existing xen guest created via \fBxm\fR create <\s-1XMLFILE\s0>. 
-.Sp
-\&\fBExample\fR
-.Sp
-virsh dumpxml <domain\-name or id> to a file. 
-.IP "\fBdinfo\fR \fIdomain-name or id\fR" 4
-.IX Item "dinfo domain-name or id"
-Returns basic information about the domain.
-.IP "\fBdumpxml\fR \fIdomain-name or id\fR" 4
-.IX Item "dumpxml domain-name or id"
+.IP "\fBdumpxml\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "dumpxml domain-name, id or uuid"
 Ouput the domain informations as an \s-1XML\s0 dump to stdout, this format can be used by the create sub command. 
-.IP "\fBdestroy\fR \fIdomain-name or id\fR" 4
-.IX Item "destroy domain-name or id"
+.IP "\fBdestroy\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "destroy domain-name, id or uuid"
 Immediately terminate the domain domain\-id.  This doesn't give the domain
 \&\s-1OS\s0 any chance to react, and it the equivalent of ripping the power
 cord out on a physical machine.  In most cases you will want to use
@@ -200,14 +193,14 @@ the \fBshutdown\fR command instead.
 .IP "\fBdomid\fR \fIdomain-name\fR" 4
 .IX Item "domid domain-name"
 Converts a domain name to a domain id using xend's internal mapping.
-.IP "\fBdominfo\fR \fIdomain-name or id\fR" 4
-.IX Item "dominfo domain-name or id"
+.IP "\fBdominfo\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "dominfo domain-name, id or uuid"
 Returns basic information about the domain.
 .IP "\fBdomname\fR \fIdomain-id\fR" 4
 .IX Item "domname domain-id"
 convert a domain Id to domain name
-.IP "\fBdomstate\fR \fIdomain-name or id\fR" 4
-.IX Item "domstate domain-name or id"
+.IP "\fBdomstate\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "domstate domain-name, id or uuid"
 Returns state about a running domain.
 .IP "\fBhelp\fR optional \fIsubcommand\fR" 4
 .IX Item "help optional subcommand"
@@ -242,45 +235,43 @@ The State field lists 6 states for a Xen Domain, and which ones the
 current Domain is in.
 =back
 .RE
-.IP "\fBr \- running\fR" 4
-.IX Item "r - running"
+.IP "\fBrunning\fR" 4
+.IX Item "running"
 The domain is currently running on a \s-1CPU\s0
-.IP "\fBb \- blocked\fR" 4
-.IX Item "b - blocked"
+.IP "\fBblocked\fR" 4
+.IX Item "blocked"
 The domain is blocked, and not running or runable.  This can be caused
 because the domain is waiting on \s-1IO\s0 (a traditional wait state) or has
 gone to sleep because there was nothing else for it to do.
-.IP "\fBp \- paused\fR" 4
-.IX Item "p - paused"
+.IP "\fBpaused\fR" 4
+.IX Item "paused"
 The domain has been paused, usually occurring through the administrator
-running \fBxm pause\fR.  When in a paused state the domain will still
+running \fBvirsh suspend\fR.  When in a suspend state the domain will still
 consume allocated resources like memory, but will not be eligible for
 scheduling by the Xen hypervisor.
-.IP "\fBs \- shutdown\fR" 4
-.IX Item "s - shutdown"
-\&\s-1FIXME:\s0 Why would you ever see this state?
-.IP "\fBc \- crashed\fR" 4
-.IX Item "c - crashed"
+.IP "\fBin shutdown\fR" 4
+.IX Item "in shutdown"
+The domain is in process of dying, but hasn't completely shutdown or
+crashed.
+.IP "\fBshut off\fR" 4
+.IX Item "shut off"
+The domain is down.
+.IP "\fBcrashed\fR" 4
+.IX Item "crashed"
 The domain has crashed, which is always a violent ending.  Usually
 this state can only occur if the domain has been configured not to
 restart on crash.  See xmdomain.cfg for more info.
-.IP "\fBd \- dying\fR" 4
-.IX Item "d - dying"
-The domain is in process of dying, but hasn't completely shutdown or
-crashed.
-.Sp
-\&\s-1FIXME:\s0 Is this right?
 .RE
 .RS 4
 .RE
-.IP "\fBnodeinfo\fR \fIdomain-name or id\fR" 4
-.IX Item "nodeinfo domain-name or id"
+.IP "\fBnodeinfo\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "nodeinfo domain-name, id or uuid"
 Returns basic information about the node.
 .IP "\fBquit\fR" 4
 .IX Item "quit"
 quit this interactive terminal
-.IP "\fBreboot\fR \fIdomain-id\fR" 4
-.IX Item "reboot domain-id"
+.IP "\fBreboot\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "reboot domain-name, id or uuid"
 Reboot a domain.  This acts just as if the domain had the \fBreboot\fR
 command run from the console.  The command returns as soon as it has
 executed the reboot action, which may be significantly before the
@@ -292,8 +283,8 @@ created.
 .IP "\fBrestore\fR \fIstate-file\fR" 4
 .IX Item "restore state-file"
 Restores a domain from an \fBvirsh save\fR state file.  See \fIsave\fR for more info.
-.IP "\fBsave\fR \fIdomain-id\fR \fIstate-file\fR" 4
-.IX Item "save domain-id state-file"
+.IP "\fBsave\fR \fIdomain-name, id or uuid\fR \fIstate-file\fR" 4
+.IX Item "save domain-name, id or uuid state-file"
 Saves a running domain to a state file so that it can be restored
 later.  Once saved, the domain will no longer be running on the
 system, thus the memory allocated for the domain will be free for
@@ -302,8 +293,8 @@ other domains to use.  \fBvirsh restore\fR restores from this state file.
 This is roughly equivalent to doing a hibernate on a running computer,
 with all the same limitations.  Open network connections may be
 severed upon restore, as \s-1TCP\s0 timeouts may have expired.
-.IP "\fBshutdown\fR \fIdomain-id\fR" 4
-.IX Item "shutdown domain-id"
+.IP "\fBshutdown\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "shutdown domain-name, id or uuid"
 Gracefully shuts down a domain.  This coordinates with the domain \s-1OS\s0
 to perform graceful shutdown, so there is no guaruntee that it will
 succeed, and may take a variable length of time depending on what
@@ -312,8 +303,12 @@ services must be shutdown in the domain.
 For a xen guest vm the behavior of what happens to a domain when it reboots is set by the
 \&\fIon_shutdown\fR parameter of the xmdomain.cfg file when the domain was
 created.
-.IP "\fBresume\fR \fIdomain-id\fR" 4
-.IX Item "resume domain-id"
+.IP "\fBsuspend\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "suspend domain-name, id or uuid"
+Suspend a domain.  When in a suspened state the domain will still consume allocated resources
+such as memory, but will not be eligible for scheduling by the Xen hypervisor.
+.IP "\fBresume\fR \fIdomain-name, id or uuid\fR" 4
+.IX Item "resume domain-name, id or uuid"
 Moves a domain out of the paused state.  This will allow a previously
 paused domain to now be eligible for scheduling by the the under lying hypervisor.
 .IP "\fBversion\fR" 4
@@ -342,6 +337,7 @@ Running hypervisor: Xen 3.0.0
 .Vb 2
 \&  Andrew Puch <apuch @ redhat.com> 
 \&  Daniel Veillard <veillard @ redhat.com>
+\&  Karel Zak <kzak @ redhat.com>
 .Ve
 .Sp
 .Vb 3