[libvirt] [PATCH] virsh: Provide completer for detach-device-alias

Michal Privoznik posted 1 patch 5 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1324c1d6aea15f29e1f85188673649474730bd4f.1530009831.git.mprivozn@redhat.com
Test syntax-check passed
tools/virsh-completer.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh-completer.h |  4 ++++
tools/virsh-domain.c    |  1 +
3 files changed, 53 insertions(+)
[libvirt] [PATCH] virsh: Provide completer for detach-device-alias
Posted by Michal Privoznik 5 years, 10 months ago
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tools/virsh-completer.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh-completer.h |  4 ++++
 tools/virsh-domain.c    |  1 +
 3 files changed, 53 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index d3effe59ea..ae579a5bdb 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -811,3 +811,51 @@ virshCellnoCompleter(vshControl *ctl,
     VIR_FREE(ret);
     goto cleanup;
 }
+
+
+char **
+virshDomainDeviceAliasCompleter(vshControl *ctl,
+                                const vshCmd *cmd,
+                                unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    xmlDocPtr xmldoc = NULL;
+    xmlXPathContextPtr ctxt = NULL;
+    int naliases;
+    xmlNodePtr *aliases = NULL;
+    size_t i;
+    unsigned int domainXMLFlags = 0;
+    char **ret = NULL;
+    char **tmp = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if (vshCommandOptBool(cmd, "config"))
+        domainXMLFlags = VIR_DOMAIN_XML_INACTIVE;
+
+    if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0)
+        goto cleanup;
+
+    naliases = virXPathNodeSet("./devices//alias/@name", ctxt, &aliases);
+    if (naliases < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(tmp, naliases + 1) < 0)
+        goto cleanup;
+
+    for (i = 0; i < naliases; i++) {
+        if (!(tmp[i] = virXMLNodeContentString(aliases[i])))
+            goto cleanup;
+    }
+
+    VIR_STEAL_PTR(ret, tmp);
+ cleanup:
+    VIR_FREE(aliases);
+    xmlFreeDoc(xmldoc);
+    xmlXPathFreeContext(ctxt);
+    virStringListFree(tmp);
+    return ret;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index ee7eec68c5..50dc068d73 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -94,6 +94,10 @@ char ** virshNodedevEventNameCompleter(vshControl *ctl,
                                        const vshCmd *cmd,
                                        unsigned int flags);
 
+char ** virshDomainDeviceAliasCompleter(vshControl *ctl,
+                                        const vshCmd *cmd,
+                                        unsigned int flags);
+
 char ** virshCellnoCompleter(vshControl *ctl,
                              const vshCmd *cmd,
                              unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 6aa79f11b9..e9b88f0013 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11684,6 +11684,7 @@ static const vshCmdOptDef opts_detach_device_alias[] = {
     {.name = "alias",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainDeviceAliasCompleter,
      .help = N_("device alias")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
-- 
2.16.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] virsh: Provide completer for detach-device-alias
Posted by John Ferlan 5 years, 10 months ago

On 06/26/2018 06:43 AM, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tools/virsh-completer.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh-completer.h |  4 ++++
>  tools/virsh-domain.c    |  1 +
>  3 files changed, 53 insertions(+)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

(wait for 4.6)

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list