]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh-domain: Add --live, --config, --current logic to cmdAttachInterface
authorPeter Krempa <pkrempa@redhat.com>
Tue, 28 May 2013 09:07:33 +0000 (11:07 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Jun 2013 12:23:02 +0000 (14:23 +0200)
Use the approach established in commit
69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too.

tools/virsh-domain.c
tools/virsh.pod

index cc6640c052fabab90a84b05431ad4b3fcea40e2c..46f07edc72910582c5e26ea54083b30816f6bd09 100644 (file)
@@ -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;
 }
index a7e3a8f09a28e0ce0879fad9c955f26534b8ab1b..047c241fd35df13186ea3eb338b84eac8336347b 100644 (file)
@@ -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<attach-interface> I<domain> I<type> I<source>
+[[[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<type> can be either I<network> to indicate a physical network device or
-I<bridge> to indicate a bridge to a device.
-I<source> indicates the source device.
-I<target> allows to indicate the target device in the guest. Names starting
-with 'vnet' are considered as auto-generated an hence blanked out.
-I<mac> allows to specify the MAC address of the network interface.
-I<script> allows to specify a path to a script handling a bridge instead of
-the default one.
-I<model> 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>.
-I<inbound> and I<outbound> control the bandwidth of the interface. I<peak>
-and I<burst> are optional, so "average,peak", "average,,burst" and
+Attach a new network interface to the domain.  I<type> can be either I<network>
+to indicate a physical network device or I<bridge> to indicate a bridge to a
+device.  I<source> indicates the source device.  I<target> allows to indicate
+the target device in the guest. Names starting with 'vnet' are considered as
+auto-generated an hence blanked out.  I<mac> allows to specify the MAC address
+of the network interface.  I<script> allows to specify a path to a script
+handling a bridge instead of the default one.  I<model> allows to specify the
+model type.  I<inbound> and I<outbound> control the bandwidth of the interface.
+I<peak> and I<burst> are optional, so "average,peak", "average,,burst" and
 "average" are also legal.
 
+If I<--live> is specified, affect a running domain.
+If I<--config> is specified, affect the next startup of a persistent domain.
+If I<--current> is specified, affect the current domain state.
+Both I<--live> and I<--config> flags may be given, but I<--current> is
+exclusive. When no flag is specified legacy API is used whose behavior depends
+on the hypervisor driver.
+
+For compatibility purposes, I<--persistent> behaves like I<--config> for
+an offline domain, and like I<--live> I<--config> for a running domain.
+
 B<Note>: the optional target value is the name of a device to be created
 as the back-end on the node. If not provided a device named "vnetN" or "vifN"
 will be created automatically.