[libvirt] [PATCH] virsh-domain: update attach-interface to support bridge type

ZhiPeng Lu lu.zhipeng at zte.com.cn
Tue Apr 25 09:13:59 UTC 2017


Adding this feature will allow users to attach a network to linux bridge
or openvswitch. The interface can be attached using --brtype=linux or
--brtype=openvswitch. If --brtype is not set, the network is attached
to linux bridge.

Signed-off-by: ZhiPeng Lu <lu.zhipeng at zte.com.cn>
---
 tools/virsh-domain.c | 23 +++++++++++++++++++++--
 tools/virsh.pod      |  3 +++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index db8accf..2690689 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -766,6 +766,10 @@ static const vshCmdOptDef opts_attach_interface[] = {
      .type = VSH_OT_BOOL,
      .help = N_("libvirt will automatically detach/attach the device from/to host")
     },
+    {.name = "brtype",
+     .type = VSH_OT_STRING,
+     .help = N_("Bridge type: linux / openvswitch")
+    },
     {.name = NULL}
 };
 
@@ -819,7 +823,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     virDomainPtr dom = NULL;
     const char *mac = NULL, *target = NULL, *script = NULL,
                *type = NULL, *source = NULL, *model = NULL,
-               *inboundStr = NULL, *outboundStr = NULL;
+               *inboundStr = NULL, *outboundStr = NULL,
+               *brtype = NULL;
     virNetDevBandwidthRate inbound, outbound;
     virDomainNetType typ;
     int ret;
@@ -850,7 +855,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
         vshCommandOptStringReq(ctl, cmd, "script", &script) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "model", &model) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "inbound", &inboundStr) < 0 ||
-        vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0)
+        vshCommandOptStringReq(ctl, cmd, "outbound", &outboundStr) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "brtype", &brtype) < 0)
         goto cleanup;
 
     /* check interface type */
@@ -946,6 +952,19 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
     if (model != NULL)
         virBufferAsprintf(&buf, "<model type='%s'/>\n", model);
 
+    if ((brtype != NULL)) {
+        if (STRNEQ(brtype , "linux") && STRNEQ(brtype , "openvswitch")) {
+            vshError(ctl, _("bridge type is incorrect, should be linux "
+            "or openvswitch"));
+            goto cleanup;
+        }
+        if (typ != VIR_DOMAIN_NET_TYPE_BRIDGE) {
+            vshError(ctl, _("No support for %s with bridge type"), type);
+            goto cleanup;
+        }
+        if (STREQ(brtype , "openvswitch"))
+            virBufferAsprintf(&buf, "  <virtualport type='openvswitch'/>\n");
+    }
     if (inboundStr || outboundStr) {
         virBufferAddLit(&buf, "<bandwidth>\n");
         virBufferAdjustIndent(&buf, 2);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e16f62f..3cd0490 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2935,6 +2935,9 @@ B<--managed> is usable only for I<hostdev> type and tells libvirt
 that the interface should be managed, which means detached and reattached
 from/to the host by libvirt.
 
+B<--brtype> is usable only for I<bridge> type and tells libvirt
+that the interface attached to bridge type (linux bridge or openvswitch).
+
 If B<--print-xml> is specified, then the XML of the interface that would be
 attached is printed instead.
 
-- 
1.8.3.1





More information about the libvir-list mailing list