virsh: add option for selecting domdisplay type

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2014-07-24 14:23:12 +02:00
parent e858628e45
commit dd4791c00d

View File

@ -9375,7 +9375,8 @@ static const vshCmdInfo info_domdisplay[] = {
.data = N_("domain display connection URI") .data = N_("domain display connection URI")
}, },
{.name = "desc", {.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} {.name = NULL}
}; };
@ -9390,6 +9391,11 @@ static const vshCmdOptDef opts_domdisplay[] = {
.type = VSH_OT_BOOL, .type = VSH_OT_BOOL,
.help = N_("includes the password into the connection URI if available") .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} {.name = NULL}
}; };
@ -9408,6 +9414,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
char *passwd = NULL; char *passwd = NULL;
char *output = NULL; char *output = NULL;
const char *scheme[] = { "vnc", "spice", "rdp", NULL }; const char *scheme[] = { "vnc", "spice", "rdp", NULL };
const char *type = NULL;
int iter = 0; int iter = 0;
int tmp; int tmp;
int flags = 0; int flags = 0;
@ -9426,6 +9433,9 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "include-password")) if (vshCommandOptBool(cmd, "include-password"))
flags |= VIR_DOMAIN_XML_SECURE; flags |= VIR_DOMAIN_XML_SECURE;
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
goto cleanup;
if (!(doc = virDomainGetXMLDesc(dom, flags))) if (!(doc = virDomainGetXMLDesc(dom, flags)))
goto cleanup; goto cleanup;
@ -9434,6 +9444,10 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
/* Attempt to grab our display info */ /* Attempt to grab our display info */
for (iter = 0; scheme[iter] != NULL; iter++) { 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 */ /* Create our XPATH lookup for the current display's port */
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0) if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "port") < 0)
goto cleanup; goto cleanup;
@ -9543,8 +9557,12 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
break; break;
} }
if (!ret) if (!ret) {
vshError(ctl, _("No graphical display found")); if (type)
vshError(ctl, _("No graphical display with type '%s' found"), type);
else
vshError(ctl, _("No graphical display found"));
}
cleanup: cleanup:
VIR_FREE(doc); VIR_FREE(doc);