[libvirt] [PATCH 2/2] virsh: add option for selecting domdisplay type

Martin Kletzander mkletzan at redhat.com
Thu Jul 24 13:46:49 UTC 2014


Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=997802

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 tools/virsh-domain.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 4652b7e..6fcfd9c 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9375,7 +9375,8 @@ static const vshCmdInfo info_domdisplay[] = {
      .data = N_("domain display connection URI")
     },
     {.name = "desc",
-     .data = N_("Output the IP address and port number for the graphical display.")
+     .data = N_("Output the IP address and port number "
+                "for the graphical display.")
     },
     {.name = NULL}
 };
@@ -9390,6 +9391,11 @@ static const vshCmdOptDef opts_domdisplay[] = {
      .type = VSH_OT_BOOL,
      .help = N_("includes the password into the connection URI if available")
     },
+    {.name = "type",
+     .type = VSH_OT_DATA,
+     .help = N_("select particular graphics display "
+                "(e.g. \"vnc\", \"spice\", \"rdp\")")
+    },
     {.name = NULL}
 };

@@ -9408,6 +9414,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     char *passwd = NULL;
     char *output = NULL;
     const char *scheme[] = { "vnc", "spice", "rdp", NULL };
+    const char *type = NULL;
     int iter = 0;
     int tmp;
     int flags = 0;
@@ -9426,6 +9433,9 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool(cmd, "include-password"))
         flags |= VIR_DOMAIN_XML_SECURE;

+    if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
+        goto cleanup;
+
     if (!(doc = virDomainGetXMLDesc(dom, flags)))
         goto cleanup;

@@ -9434,6 +9444,10 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)

     /* Attempt to grab our display info */
     for (iter = 0; scheme[iter] != NULL; iter++) {
+        /* Particular scheme requested */
+        if (type && STRNEQ(type, scheme[iter]))
+            continue;
+
         /* Create our XPATH lookup for the current display's port */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0)
             goto cleanup;
@@ -9543,8 +9557,12 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         break;
     }

-    if (!ret)
-        vshError(ctl, _("No graphical display found"));
+    if (!ret) {
+        if (type)
+            vshError(ctl, _("No graphical display with type '%s' found"), type);
+        else
+            vshError(ctl, _("No graphical display found"));
+    }

  cleanup:
     VIR_FREE(doc);
-- 
2.0.2




More information about the libvir-list mailing list