From 33e300229cf30c6efc7411d3b5d45c2050129fc1 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 28 May 2013 11:07:33 +0200 Subject: [PATCH] virsh-domain: Add --live, --config, --current logic to cmdAttachInterface 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 cc6640c052..46f07edc72 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 a7e3a8f09a..047c241fd3 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1892,25 +1892,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 B I I I +[[[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. -I can be either I to indicate a physical network device or -I to indicate a bridge to a device. -I indicates the source device. -I allows to indicate the target device in the guest. Names starting -with 'vnet' are considered as auto-generated an hence blanked out. -I allows to specify the MAC address of the network interface. -I