mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
virsh: Add serial/parallel device name completion to console command
Signed-off-by: Lin Ma <lma@suse.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
4583a49ccf
commit
f8b3e98a01
@ -661,3 +661,57 @@ virshDomainVcpulistViaAgentCompleter(vshControl *ctl,
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshDomainConsoleCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControlPtr priv = ctl->privData;
|
||||
g_autoptr(xmlDoc) xmldoc = NULL;
|
||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||
int nserials;
|
||||
int nparallels;
|
||||
g_autofree xmlNodePtr *serials = NULL;
|
||||
g_autofree xmlNodePtr *parallels = NULL;
|
||||
size_t i;
|
||||
size_t offset = 0;
|
||||
VIR_AUTOSTRINGLIST tmp = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
|
||||
return NULL;
|
||||
|
||||
if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0)
|
||||
return NULL;
|
||||
|
||||
nserials = virXPathNodeSet("./devices/serial", ctxt, &serials);
|
||||
if (nserials < 0)
|
||||
return NULL;
|
||||
|
||||
nparallels = virXPathNodeSet("./devices/parallel", ctxt, ¶llels);
|
||||
if (nparallels < 0)
|
||||
return NULL;
|
||||
|
||||
tmp = g_new0(char *, nserials + nparallels + 1);
|
||||
|
||||
for (i = 0; i < nserials + nparallels; i++) {
|
||||
g_autofree char *type = NULL;
|
||||
|
||||
|
||||
if (i < nserials)
|
||||
ctxt->node = serials[i];
|
||||
else
|
||||
ctxt->node = parallels[i - nserials];
|
||||
|
||||
type = virXPathString("string(./@type)", ctxt);
|
||||
if (STRNEQ(type, "pty"))
|
||||
continue;
|
||||
|
||||
tmp[offset++] = virXPathString("string(./alias/@name)", ctxt);
|
||||
}
|
||||
|
||||
return g_steal_pointer(&tmp);
|
||||
}
|
||||
|
@ -94,3 +94,7 @@ char ** virshDomainCpulistCompleter(vshControl *ctl,
|
||||
char ** virshDomainVcpulistViaAgentCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshDomainConsoleCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
@ -2960,6 +2960,7 @@ static const vshCmdOptDef opts_console[] = {
|
||||
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
|
||||
{.name = "devname", /* sc_prohibit_devname */
|
||||
.type = VSH_OT_STRING,
|
||||
.completer = virshDomainConsoleCompleter,
|
||||
.help = N_("character device name")
|
||||
},
|
||||
{.name = "force",
|
||||
|
Loading…
Reference in New Issue
Block a user