From cf44ec557753c2c266c7cb9d1cf0bceb7d613bec Mon Sep 17 00:00:00 2001 From: Julio Faracco Date: Thu, 2 Jan 2020 12:07:06 -0300 Subject: [PATCH] virsh: Add a completer for `domifaddr` --source parameter. The command `domifaddr` can use three different sources to grab IP address of a Virtual Machine: lease, agent and arp. This parameter does not have a completer function to return source options. Signed-off-by: Julio Faracco Reviewed-by: Erik Skultety --- tools/virsh-completer-domain.c | 17 +++++++++++++++++ tools/virsh-completer-domain.h | 5 +++++ tools/virsh-domain-monitor.c | 1 + 3 files changed, 23 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 0311ee50d0..9423d2efb3 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -296,3 +296,20 @@ virshDomainShutdownModeCompleter(vshControl *ctl, return virshCommaStringListComplete(mode, modes); } + + +char ** +virshDomainInterfaceAddrSourceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + const char *sources[] = {"lease", "agent", "arp", NULL}; + const char *source = NULL; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "source", &source) < 0) + return NULL; + + return virshCommaStringListComplete(source, sources); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 083ab327cc..79beec2cfe 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -53,3 +53,8 @@ char ** virshDomainDeviceAliasCompleter(vshControl *ctl, char ** virshDomainShutdownModeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshDomainInterfaceAddrSourceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 30b186ffd1..5639ea56f9 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2346,6 +2346,7 @@ static const vshCmdOptDef opts_domifaddr[] = { {.name = "source", .type = VSH_OT_STRING, .flags = VSH_OFLAG_NONE, + .completer = virshDomainInterfaceAddrSourceCompleter, .help = N_("address source: 'lease', 'agent', or 'arp'")}, {.name = NULL} };