mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virsh: Add mac completion to net-dhcp-leases 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
8a4343a436
commit
aa54cb9d35
@ -174,3 +174,47 @@ virshNetworkUUIDCompleter(vshControl *ctl,
|
||||
g_free(nets);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshNetworkDhcpMacCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControlPtr priv = ctl->privData;
|
||||
virNetworkDHCPLeasePtr *leases = NULL;
|
||||
virNetworkPtr network = NULL;
|
||||
int nleases;
|
||||
size_t i = 0;
|
||||
char **ret = NULL;
|
||||
VIR_AUTOSTRINGLIST tmp = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
|
||||
return NULL;
|
||||
|
||||
if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
|
||||
return NULL;
|
||||
|
||||
if ((nleases = virNetworkGetDHCPLeases(network, NULL, &leases, flags)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
tmp = g_new0(char *, nleases + 1);
|
||||
|
||||
for (i = 0; i < nleases; i++) {
|
||||
virNetworkDHCPLeasePtr lease = leases[i];
|
||||
tmp[i] = g_strdup(lease->mac);
|
||||
}
|
||||
|
||||
ret = g_steal_pointer(&tmp);
|
||||
|
||||
cleanup:
|
||||
if (leases) {
|
||||
for (i = 0; i < nleases; i++)
|
||||
virNetworkDHCPLeaseFree(leases[i]);
|
||||
VIR_FREE(leases);
|
||||
}
|
||||
virNetworkFree(network);
|
||||
return ret;
|
||||
}
|
||||
|
@ -37,3 +37,7 @@ char ** virshNetworkPortUUIDCompleter(vshControl *ctl,
|
||||
char ** virshNetworkUUIDCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshNetworkDhcpMacCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
@ -1376,7 +1376,8 @@ static const vshCmdOptDef opts_network_dhcp_leases[] = {
|
||||
{.name = "mac",
|
||||
.type = VSH_OT_STRING,
|
||||
.flags = VSH_OFLAG_NONE,
|
||||
.help = N_("MAC address")
|
||||
.help = N_("MAC address"),
|
||||
.completer = virshNetworkDhcpMacCompleter,
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user