From d724ca8fcdf44ef24cf03817c340f4858791a186 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 10 Jan 2022 12:44:23 +0100 Subject: [PATCH] virsh: Introduce net-update --section completer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- tools/virsh-completer-network.c | 20 ++++++++++++++++++++ tools/virsh-completer-network.h | 5 +++++ tools/virsh-network.c | 2 +- tools/virsh-network.h | 1 + 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/virsh-completer-network.c b/tools/virsh-completer-network.c index d0cf80f22c..839d71e961 100644 --- a/tools/virsh-completer-network.c +++ b/tools/virsh-completer-network.c @@ -241,3 +241,23 @@ virshNetworkUpdateCommandCompleter(vshControl *ctl G_GNUC_UNUSED, return ret; } + + +char ** +virshNetworkUpdateSectionCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + char **ret = NULL; + size_t i; + + virCheckFlags(0, NULL); + + ret = g_new0(char *, VIR_NETWORK_SECTION_LAST); + + /* The first item in the enum is not accepted by virsh. */ + for (i = 1; i < VIR_NETWORK_SECTION_LAST; i++) + ret[i - 1] = g_strdup(virshNetworkSectionTypeToString(i)); + + return ret; +} diff --git a/tools/virsh-completer-network.h b/tools/virsh-completer-network.h index 7557dfdb0d..c7ceff0b13 100644 --- a/tools/virsh-completer-network.h +++ b/tools/virsh-completer-network.h @@ -51,3 +51,8 @@ char ** virshNetworkUpdateCommandCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshNetworkUpdateSectionCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 2a0a24c6d3..5f574be78c 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -925,6 +925,7 @@ static const vshCmdOptDef opts_network_update[] = { {.name = "section", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, + .completer = virshNetworkUpdateSectionCompleter, .help = N_("which section of network configuration to update") }, {.name = "xml", @@ -948,7 +949,6 @@ VIR_ENUM_IMPL(virshNetworkUpdateCommand, VIR_NETWORK_UPDATE_COMMAND_LAST, "none", "modify", "delete", "add-last", "add-first"); -VIR_ENUM_DECL(virshNetworkSection); VIR_ENUM_IMPL(virshNetworkSection, VIR_NETWORK_SECTION_LAST, "none", "bridge", "domain", "ip", "ip-dhcp-host", diff --git a/tools/virsh-network.h b/tools/virsh-network.h index 05da736cce..ffd157f054 100644 --- a/tools/virsh-network.h +++ b/tools/virsh-network.h @@ -45,5 +45,6 @@ typedef struct virshNetworkEventCallback virshNetworkEventCallback; extern virshNetworkEventCallback virshNetworkEventCallbacks[]; VIR_ENUM_DECL(virshNetworkUpdateCommand); +VIR_ENUM_DECL(virshNetworkSection); extern const vshCmdDef networkCmds[];