[PATCH 01/13] virsh: Add --print-xml option for 'detach-interface'

Ján Tomko jtomko at redhat.com
Fri Dec 2 14:27:16 UTC 2022


On a Friday in 2022, Peter Krempa wrote:
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> docs/manpages/virsh.rst |  5 ++++-
> tools/virsh-domain.c    | 21 ++++++++++++++++++---
> 2 files changed, 22 insertions(+), 4 deletions(-)
>
>diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
>index 1e8a43bc55..09fc1f67ad 100644
>--- a/docs/manpages/virsh.rst
>+++ b/docs/manpages/virsh.rst
>@@ -5090,7 +5090,7 @@ detach-interface
> ::
>
>    detach-interface domain type [--mac mac]
>-      [[[--live] [--config] | [--current]] | [--persistent]]
>+      [[[--live] [--config] | [--current]] | [--persistent]] [--print-xml]
>
> Detach a network interface from a domain.
> *type* can be either *network* to indicate a physical network device or
>@@ -5112,6 +5112,9 @@ an offline domain, and like *--live* *--config* for a running domain.
> Note that older versions of virsh used *--config* as an alias for
> *--persistent*.
>
>+If *--print-xml* is specified, then the XML used to detach the interface
>+is printed instead.
>+
> Please see documentation for ``detach-device`` for known quirks.
>
>
>diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>index 2d22547cc6..9574a6eab6 100644
>--- a/tools/virsh-domain.c
>+++ b/tools/virsh-domain.c
>@@ -12454,6 +12454,10 @@ static const vshCmdOptDef opts_detach_interface[] = {
>     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
>     VIRSH_COMMON_OPT_DOMAIN_LIVE,
>     VIRSH_COMMON_OPT_DOMAIN_CURRENT,
>+    {.name = "print-xml",
>+     .type = VSH_OT_BOOL,
>+     .help = N_("print XML document rather than detach the interface")
>+    },
>     {.name = NULL}
> };
>
>@@ -12464,7 +12468,8 @@ virshDomainDetachInterface(char *doc,
>                            vshControl *ctl,
>                            bool current,
>                            const char *type,
>-                           const char *mac)
>+                           const char *mac,
>+                           bool printxml)
> {
>     g_autoptr(xmlDoc) xml = NULL;
>     g_autoptr(xmlXPathObject) obj = NULL;
>@@ -12533,6 +12538,11 @@ virshDomainDetachInterface(char *doc,
>         return false;
>     }
>
>+    if (printxml) {
>+        vshPrint(ctl, "%s", detach_xml);
>+        return true;
>+    }
>+
>     if (flags != 0 || current)
>         return virDomainDetachDeviceFlags(dom, detach_xml, flags) == 0;
>     return virDomainDetachDevice(dom, detach_xml) == 0;
>@@ -12552,6 +12562,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
>     bool config = vshCommandOptBool(cmd, "config");
>     bool live = vshCommandOptBool(cmd, "live");
>     bool persistent = vshCommandOptBool(cmd, "persistent");
>+    bool printxml = vshCommandOptBool(cmd, "print-xml");
>
>     VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
>
>@@ -12574,7 +12585,8 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
>             goto cleanup;
>         if (!(ret = virshDomainDetachInterface(doc_config,
>                                                flags | VIR_DOMAIN_AFFECT_CONFIG,
>-                                               dom, ctl, current, type, mac)))
>+                                               dom, ctl, current, type, mac,
>+                                               printxml)))
>             goto cleanup;
>     }
>
>@@ -12590,9 +12602,12 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
>             goto cleanup;
>
>         ret = virshDomainDetachInterface(doc_live, flags,
>-                                         dom, ctl, current, type, mac);
>+                                         dom, ctl, current, type, mac, printxml);
>     }
>
>+    if (printxml)
>+        return true;

virshDomainDetachInterface can still fail.

s/true/ret/

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20221202/fff34060/attachment.sig>


More information about the libvir-list mailing list