virsh: Add --print-xml option for 'detach-interface'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-11-30 10:49:26 +01:00
parent 83a8f249c2
commit 601a127573
2 changed files with 22 additions and 4 deletions

View File

@ -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.

View File

@ -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 ret;
cleanup:
if (!ret) {
vshError(ctl, "%s", _("Failed to detach interface"));