Signed-off-by: Lin Ma <lma(a)suse.de>
---
tools/virsh-completer-domain.c | 52 ++++++++++++++++++++++++++++++++++
tools/virsh-completer-domain.h | 4 +++
tools/virsh-domain.c | 8 +++++-
3 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 122a9d5f66..ae8baa52e3 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -80,6 +80,58 @@ virshDomainNameCompleter(vshControl *ctl,
}
+char **
+virshDomainUUIDCompleter(vshControl *ctl,
+ const vshCmd *cmd G_GNUC_UNUSED,
+ unsigned int flags)
+{
+ virshControlPtr priv = ctl->privData;
+ virDomainPtr *domains = NULL;
+ int ndomains = 0;
+ size_t i = 0;
+ char **ret = NULL;
+ VIR_AUTOSTRINGLIST tmp = NULL;
+
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+ VIR_CONNECT_LIST_DOMAINS_OTHER |
+ VIR_CONNECT_LIST_DOMAINS_PAUSED |
+ VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+ VIR_CONNECT_LIST_DOMAINS_RUNNING |
+ VIR_CONNECT_LIST_DOMAINS_SHUTOFF |
+ VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE |
+ VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT |
+ VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT,
+ NULL);
+
+ if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+ return NULL;
+
+ if ((ndomains = virConnectListAllDomains(priv->conn, &domains, flags)) <
0)
+ return NULL;
+
+ if (VIR_ALLOC_N(tmp, ndomains + 1) < 0)
+ goto cleanup;
+
+ for (i = 0; i < ndomains; i++) {
+ char uuid[VIR_UUID_STRING_BUFLEN];
+ if (virDomainGetUUIDString(domains[i], uuid) < 0) {
+ vshError(ctl, "%s", _("Failed to get domain's
UUID"));
+ goto cleanup;
+ }
+ tmp[i] = g_strdup(uuid);
+ }
+
+ ret = g_steal_pointer(&tmp);
+
+ cleanup:
+ for (i = 0; i < ndomains; i++)
+ virshDomainFree(domains[i]);
+ VIR_FREE(domains);
+ return ret;
+}
+
+
char **
virshDomainInterfaceCompleter(vshControl *ctl,
const vshCmd *cmd,
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index e3375c3c65..9a8b962cb7 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -70,3 +70,7 @@ char ** virshDomainPerfEnableCompleter(vshControl *ctl,
char ** virshDomainPerfDisableCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+
+char ** virshDomainUUIDCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1ba536466a..c07c8c3527 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10370,7 +10370,13 @@ static const vshCmdInfo info_domname[] = {
};
static const vshCmdOptDef opts_domname[] = {
- VIRSH_COMMON_OPT_DOMAIN(N_("domain id or uuid"), 0),
+ {.name = "domain",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .completer = virshDomainUUIDCompleter,
+ .completer_flags = 0,
+ .help = N_("domain id or uuid")
+ },
{.name = NULL}
};
--
2.26.0