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 <jcfaracco@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Julio Faracco 2020-01-02 12:07:06 -03:00 committed by Erik Skultety
parent db5d049911
commit cf44ec5577
3 changed files with 23 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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}
};