Use the approach established in commit
69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too.
---
tools/virsh-domain.c | 59 +++-
tools/virsh.pod | 34 +-
2 files changed, 60 insertions(+), 33 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 4de5dd5..96f6765 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -724,14 +724,6 @@ static const vshCmdOptDef opts_attach_interface[] = {
.type = VSH_OT_DATA,
.help = N_(model type)
},
-{.name = persistent,
- .type = VSH_OT_ALIAS,
- .help = config
-},
-{.name = config,
- .type = VSH_OT_BOOL,
- .help = N_(affect next boot)
-},
{.name = inbound,
.type = VSH_OT_DATA,
.help = N_(control domain's incoming traffics)
@@ -740,6 +732,22 @@ static const vshCmdOptDef opts_attach_interface[] = {
.type = VSH_OT_DATA,
.help = N_(control domain's outgoing traffics)
},
+{.name = persistent,
+ .type = VSH_OT_BOOL,
+ .help = N_(make live change persistent)
+},
+{.name = config,
+ .type = VSH_OT_BOOL,
+ .help = N_(affect next boot)
+},
+{.name = live,
+ .type = VSH_OT_BOOL,
+ .help = N_(affect running domain)
+},
+{.name = current,
+ .type = VSH_OT_BOOL,
+ .help = N_(affect current domain)
+},
{.name = NULL}
};
@@ -789,12 +797,30 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
int typ;
int ret;
bool functionReturn = false;
-unsigned int flags;
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *xml;
+unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+bool current = vshCommandOptBool(cmd, current);
+bool config = vshCommandOptBool(cmd, config);
+bool live = vshCommandOptBool(cmd, live);
+bool persistent = vshCommandOptBool(cmd, persistent);
+
+VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
+
+VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
+VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+
+if (config || persistent)
+flags |= VIR_DOMAIN_AFFECT_CONFIG;
+if (live)
+flags |= VIR_DOMAIN_AFFECT_LIVE;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
-goto cleanup;
+return false;
+
+if (persistent
+virDomainIsActive(dom) == 1)
+flags |= VIR_DOMAIN_AFFECT_LIVE;
if (vshCommandOptStringReq(ctl, cmd, type, type) 0 ||
vshCommandOptStringReq(ctl, cmd, source, source) 0 ||
@@ -887,14 +913,10 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
xml = virBufferContentAndReset(buf);
-if (vshCommandOptBool(cmd, config)) {
-flags = VIR_DOMAIN_AFFECT_CONFIG;
-if (virDomainIsActive(dom) == 1)
-flags |= VIR_DOMAIN_AFFECT_LIVE;
+if (flags)
ret = virDomainAttachDeviceFlags(dom, xml, flags);
-} else {
+else
ret = virDomainAttachDevice(dom, xml);
-}
VIR_FREE(xml);
@@ -905,9 +927,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
functionReturn = true;
}
- cleanup:
-if (dom)
-virDomainFree(dom);
+cleanup:
+virDomainFree(dom);
virBufferFreeAndReset(buf);
return functionReturn;
}
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 9ae96d1..0fd546d 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1885,25 +1885,31 @@ For compatibility purposes, I--persistent behaves
like I--config for
an offline domain, and like I--live I--config for a running domain.
=item Battach-interface Idomain Itype Isource
+[[[I--live] [I--config] | [I--current]] | [I--persistent]]
[I--target target] [I--mac mac] [I--script script] [I--model model]
[I--config] [I--inbound average,peak,burst] [I--outbound
average,peak,burst]
-Attach a new network interface to the domain.
-Itype can be either Inetwork to indicate a physical network device or
-Ibridge to indicate a bridge to a device.
-Isource indicates the source device.
-Itarget allows to indicate the target device in the guest. Names starting
-with 'vnet' are considered as auto-generated an hence blanked out.
-Imac allows to specify the MAC address of the network interface.
-Iscript allows to specify a path to a script handling a bridge instead of
-the default one.
-Imodel allows to specify the model type.
-I--config indicates the changes will affect the next boot of the domain,
-for compatibility purposes, I--persistent is alias of I--config.
-Iinbound and Ioutbound control the bandwidth of the interface. Ipeak
-and Iburst are optional, so average,peak, average,,burst and
+Attach a new network interface to the domain. Itype can be either Inetwork
+to indicate a physical network device or Ibridge to indicate a bridge to a
+device. Isource indicates the source device. Itarget allows to indicate
+the target device in the guest. Names starting with 'vnet' are considered as
+auto-generated an hence blanked out. Imac