virsh domdisplay: introduce '--all' for showing all possible graphical displays

For one VM, it could had more than one graphical display.
Such as we coud add both vnc and spice display to a VM.

This patch introduces '--all' for showing all
possible graphical display of a active VM.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Chen Hanxiao 2016-10-09 18:34:22 +08:00 committed by Michal Privoznik
parent 0f3f8ac97e
commit 599e966efb
2 changed files with 19 additions and 4 deletions

View File

@ -10655,6 +10655,10 @@ static const vshCmdOptDef opts_domdisplay[] = {
.help = N_("select particular graphical display " .help = N_("select particular graphical display "
"(e.g. \"vnc\", \"spice\", \"rdp\")") "(e.g. \"vnc\", \"spice\", \"rdp\")")
}, },
{.name = "all",
.type = VSH_OT_BOOL,
.help = N_("show all possible graphical displays")
},
{.name = NULL} {.name = NULL}
}; };
@ -10678,6 +10682,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
int tmp; int tmp;
int flags = 0; int flags = 0;
bool params = false; bool params = false;
bool all = vshCommandOptBool(cmd, "all");
const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/%s)"; const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/%s)";
virSocketAddr addr; virSocketAddr addr;
@ -10704,10 +10709,11 @@ 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 */ /* Particular scheme requested */
if (type && STRNEQ(type, scheme[iter])) if (!all && type && STRNEQ(type, scheme[iter]))
continue; continue;
/* Create our XPATH lookup for the current display's port */ /* Create our XPATH lookup for the current display's port */
VIR_FREE(xpath);
if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@port") < 0) if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@port") < 0)
goto cleanup; goto cleanup;
@ -10740,6 +10746,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
/* Attempt to get the listening addr if set for the current /* Attempt to get the listening addr if set for the current
* graphics scheme */ * graphics scheme */
VIR_FREE(listen_addr);
listen_addr = virXPathString(xpath, ctxt); listen_addr = virXPathString(xpath, ctxt);
VIR_FREE(xpath); VIR_FREE(xpath);
@ -10795,6 +10802,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
goto cleanup; goto cleanup;
/* Attempt to get the password */ /* Attempt to get the password */
VIR_FREE(passwd);
passwd = virXPathString(xpath, ctxt); passwd = virXPathString(xpath, ctxt);
VIR_FREE(xpath); VIR_FREE(xpath);
@ -10847,12 +10855,17 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
} }
/* Print out our full URI */ /* Print out our full URI */
VIR_FREE(output);
output = virBufferContentAndReset(&buf); output = virBufferContentAndReset(&buf);
vshPrint(ctl, "%s", output); vshPrint(ctl, "%s", output);
/* We got what we came for so return successfully */ /* We got what we came for so return successfully */
ret = true; ret = true;
break; if (!all) {
break;
} else {
vshPrint(ctl, "\n");
}
} }
if (!ret) { if (!ret) {

View File

@ -1223,13 +1223,15 @@ I<size> is a scaled integer (see B<NOTES> above) which defaults to KiB
"B" to get bytes (note that for historical reasons, this differs from "B" to get bytes (note that for historical reasons, this differs from
B<vol-resize> which defaults to bytes without a suffix). B<vol-resize> which defaults to bytes without a suffix).
=item B<domdisplay> I<domain> [I<--include-password>] [[I<--type>] B<type>] =item B<domdisplay> I<domain> [I<--include-password>]
[[I<--type>] B<type>] [I<--all>]
Output a URI which can be used to connect to the graphical display of the Output a URI which can be used to connect to the graphical display of the
domain via VNC, SPICE or RDP. The particular graphical display type can domain via VNC, SPICE or RDP. The particular graphical display type can
be selected using the B<type> parameter (e.g. "vnc", "spice", "rdp"). If be selected using the B<type> parameter (e.g. "vnc", "spice", "rdp"). If
I<--include-password> is specified, the SPICE channel password will be I<--include-password> is specified, the SPICE channel password will be
included in the URI. included in the URI. If I<--all> is specified, then all show all possible
graphical displays, for a VM could have more than one graphical displays.
=item B<domfsinfo> I<domain> =item B<domfsinfo> I<domain>