<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <br>
    <div class="moz-cite-prefix">On 02/03/2016 02:41 PM,
      <a class="moz-txt-link-abbreviated" href="mailto:peterpnns@gmail.com">peterpnns@gmail.com</a> wrote:<br>
    </div>
    <blockquote
      cite="mid:1454517713-2315-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">From: peterpennings <a class="moz-txt-link-rfc2396E" href="mailto:peterpnns@gmail.com">&lt;peterpnns@gmail.com&gt;</a>

This commit adds the new UI changes for network bridges and enables OVS bridges that where temporary hidden

Signed-off-by: peterpennings <a class="moz-txt-link-rfc2396E" href="mailto:peterpnns@gmail.com">&lt;peterpnns@gmail.com&gt;</a>
---
 netinfo.py                           |   3 +-
 ui/js/src/kimchi.network.js          |   2 +
 ui/js/src/kimchi.network_add_main.js | 146 ++++++++++++++++++++++-------------
 ui/pages/network-add.html.tmpl       |   3 +-
 4 files changed, 96 insertions(+), 58 deletions(-)

diff --git a/netinfo.py b/netinfo.py
index 2d83466..c00f603 100644
--- a/netinfo.py
+++ b/netinfo.py
@@ -221,8 +221,7 @@ def is_bare_nic(iface):
 #  a slave of bond.
 #  The bridge will not be exposed when all it's port are tap.
 def all_favored_interfaces():
-    return list(set(aggregated_bridges() + bare_nics() + bondings()) -
-                set(ovs_bridges()))
+    return aggregated_bridges() + bare_nics() + bondings()


 def get_interface_type(iface):
diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index 923aeb9..96c3fea 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -17,6 +17,8 @@
  */

 kimchi.NETWORK_TYPE_MACVTAP = "macvtap";
+kimchi.NETWORK_TYPE_BRIDGED = "bridge";
+

 kimchi.initNetwork = function() {
     if(wok.tabMode['network'] === 'admin') {
diff --git a/ui/js/src/kimchi.network_add_main.js b/ui/js/src/kimchi.network_add_main.js
index 76d436f..603a5ee 100644
--- a/ui/js/src/kimchi.network_add_main.js
+++ b/ui/js/src/kimchi.network_add_main.js
@@ -31,20 +31,20 @@ kimchi.startNetworkCreation = function() {
     var network = kimchi.getNetworkDialogValues();
     var data = {
         name : network.name,
-        connection: network.type
+        connection: network.type,
+        interface: network.interface,
+        vlan_id: network.vlan_id
     };
-    if (network.type === kimchi.NETWORK_TYPE_MACVTAP) {
-        data.connection = "macvtap";
-        data.interface = network.interface;
-        if ($("#enableVlan").prop("checked")) {
+
+    if (network.type === kimchi.NETWORK_TYPE_BRIDGED &amp;&amp; $("#enableVlan").prop("checked")) {
             data.vlan_id = network.vlan_id;
             if (!(data.vlan_id &gt;=1 &amp;&amp; data.vlan_id &lt;= 4094)) {
                 wok.message.error.code('KCHNET6001E');
                 errorCallback();
                 return;
             }
-        }
     }
+
     kimchi.createNetwork(data, function(result) {
         network.state = result.state === "active" ? "up" : "down";
         network.interface = result.interface ? result.interface : i18n["KCHNET6001M"];
@@ -59,30 +59,8 @@ kimchi.startNetworkCreation = function() {
 };

 kimchi.openNetworkDialog = function(okCallback) {
-        kimchi.getInterfaces(function(result) {
-        var options = [];
-        $selectDestination = $('#networkDestinationID');
-        var nics = {};
-        var selectDestinationOptionHTML = '';
-        for (var i = 0; i &lt; result.length; i++) {
-            options.push({label:result[i].name,value:result[i].name});
-            nics[result[i].name] = result[i];
-            selectDestinationOptionHTML += '&lt;option value="'+ result[i].name + '"&gt;' + result[i].name + '&lt;/option&gt;';
-        }
-        $selectDestination.append(selectDestinationOptionHTML);
-        $selectDestination.selectpicker();
-        onChange = function() {
-            if (result.length&gt;0 &amp;&amp; $selectDestination.val() !== "") {
-                $("#enableVlan").prop("disabled",false);
-                $("#networkVlanID").val("");
-            } else {
-                $("#enableVlan").prop("disabled",true);
-            }
-        };
-        $("#networkDestinationID").on("change", onChange);
-        kimchi.setDefaultNetworkType(result.length!==0);
-        onChange();
-    });
+    kimchi.loadInterfaces();
+
     $("#networkFormOk").on("click", function() {
         $("#networkFormOk").button("disable");
         $("#networkName").prop("readonly", "readonly<a class="moz-txt-link-rfc2396E" href="mailto:);@@-98,28+76,10@@kimchi.openNetworkDialog=function(okCallback){});};-kimchi.enableBridgeOptions=function(enable){-$(">");
@@ -98,28 +76,10 @@ kimchi.openNetworkDialog = function(okCallback) {
     });
 };

-kimchi.enableBridgeOptions = function(enable) {
-    $("</a>#enableVlan").prop("checked", false);
-    $("#networkVlanID").val("");
-    if (enable) {
-        $('#bridgedContent').slideDown(300);
-        $('#enableVlan').prop("disabled", false);
-        $('#networkVlanID').prop("disabled", true);
-    } else {
-        $('#bridgedContent').slideUp(300);
-        $('#enableVlan').prop("disabled", true);
-        $('#networkVlanID').prop("disabled", true);
-    }
-};
-
-
 kimchi.setDefaultNetworkType = function(isInterfaceAvail) {
-    $("#networkType").val('macvtap', isInterfaceAvail);
-    $("#networkType option:contains('bridged')").prop("disabled", !isInterfaceAvail);
-    $("#networkType").val('nat', !isInterfaceAvail);
     $("#networkType").selectpicker();
     if (!isInterfaceAvail) {</pre>
    </blockquote>
    <br>
    <blockquote
      cite="mid:1454517713-2315-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">
-        kimchi.enableBridgeOptions(false);
+        kimchi.enableBridgeOptions2(false);</pre>
    </blockquote>
    <br>
    Why did you rename the function name to 'enableBridgedOptions<b>2</b>'
    ?<br>
    <br>
    <blockquote
      cite="mid:1454517713-2315-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">
         $("#networkBriDisabledLabel").removeClass('hidden');
     } else {
         if (kimchi.capabilities &amp;&amp; kimchi.capabilities.nm_running) {
@@ -136,7 +96,12 @@ kimchi.getNetworkDialogValues = function() {
     };
     if (network.type === kimchi.NETWORK_TYPE_MACVTAP) {
         network.interface = $("#networkDestinationID").val();
-        network.vlan_id = parseInt($("#networkVlanID").val());
+    }
+    if (network.type === kimchi.NETWORK_TYPE_BRIDGED) {
+        network.interface = $("#networkDestinationID").val();
+        if (network.interface === 'nic' || network.interface === 'bonding') {
+            network.vlan_id = parseInt($("#networkVlanID").val());
+        }
     }</pre>
    </blockquote>
    <br>
    The VLAN information is associated with a macvtap bridge not with a
    Linux brigde.<br>
    <br>
    The current bridged UI (ie, macvtap) needs to keep the same.<br>
    <br>
    We will only add a new option "Linux bridged" which will also list
    the interface combo box but without the VLAN configuration.<br>
    <br>
    <blockquote
      cite="mid:1454517713-2315-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">
     return network;
 };
@@ -147,14 +112,26 @@ kimchi.setupNetworkFormEvent = function() {
         $("#networkName").toggleClass("invalid-field", !$("#networkName").val().match(/^[^\"\/]+$/));
         kimchi.updateNetworkFormButton();
     });
-    $('#networkType').on('change', function() {
-        var selectedType = $(this).val();
+
+    $('#networkType, #networkDestinationID').on('change', function() {
+        var selectedType = $("#networkType").val();
+        var selectedDestination = $("#networkDestinationID").val();
         if(selectedType ==  'isolated' ||  selectedType ==  'nat') {
-            kimchi.enableBridgeOptions(false);
-        } else if (selectedType ==  'macvtap') {
-            kimchi.enableBridgeOptions(true);
+            kimchi.enableBridgeOptions2(false);
+        } else {
+            kimchi.enableBridgeOptions2(true, selectedType, selectedDestination); 
         }
+        
     });
+
+    $('#networkType').on('change', function() {
+        var selectedType = $("#networkType").val();
+        if(selectedType === kimchi.NETWORK_TYPE_MACVTAP) {
+            kimchi.loadInterfaces(new Array("nic", "bonding"));
+        } else {
+            kimchi.loadInterfaces();
+        }
+    });    
 };

 kimchi.updateNetworkFormButton = function() {
@@ -164,3 +141,62 @@ kimchi.updateNetworkFormButton = function() {
         $("#networkFormOk").button("enable");
     }
 };
+
+kimchi.enableBridgeOptions2 = function(enable, networkType, networkDestination) {
+    $("#enableVlan").prop("checked", false);
+    $("#networkVlanID").val("");
+    $('#vlan').hide(); 
+    if (enable) {
+        $('#bridgedContent').slideDown(300);
+        $('#enableVlan').prop("disabled", false);
+        $('#networkVlanID').prop("disabled", true);
+        if (networkType === kimchi.NETWORK_TYPE_BRIDGED &amp;&amp; (networkDestination === 'nic' || networkDestination === 'bonding')) {
+            $('#vlan').show();
+        } 
+    } else {
+        $('#bridgedContent').slideUp(300);
+        $('#enableVlan').prop("disabled", true);
+        $('#networkVlanID').prop("disabled", true);
+    };
+    
+};
+
+kimchi.loadInterfaces = function(interfaceFilterArray) {
+   kimchi.getInterfaces(function(result) {
+
+        var options = [];
+        $selectDestination = $('#networkDestinationID');
+        var nics = {};
+        $('#networkDestinationID').find('option').remove();
+        var selectDestinationOptionHTML = '';
+        for (var i = 0; i &lt; result.length; i++) {
+            if (typeof interfaceFilterArray === 'undefined') {
+                options.push({label:result[i].name,value:result[i].name});
+                nics[result[i].name] = result[i];
+                selectDestinationOptionHTML += '&lt;option value="'+ result[i].name + '"&gt;' + result[i].name + '&lt;/option&gt;';
+            } else {
+                for (var k = 0; k &lt; interfaceFilterArray.length; k++) {
+                    if (result[i].type == interfaceFilterArray[k]) {
+                        options.push({label:result[i].name,value:result[i].name});
+                        nics[result[i].name] = result[i];
+                        selectDestinationOptionHTML += '&lt;option value="'+ result[i].name + '"&gt;' + result[i].name + '&lt;/option&gt;';
+                    }
+                }
+            }
+
+        }
+        $selectDestination.append(selectDestinationOptionHTML);
+        $('#networkDestinationID').selectpicker('refresh'); 
+        onChange = function() {
+            if (result.length&gt;0 &amp;&amp; $selectDestination.val() !== "") {
+                $("#enableVlan").prop("disabled",false);
+                $("#networkVlanID").val("");
+            } else {
+                $("#enableVlan").prop("disabled",true);
+            }
+        };
+        kimchi.setDefaultNetworkType(result.length!==0);  
+        onChange();   
+    });
+};
+
diff --git a/ui/pages/network-add.html.tmpl b/ui/pages/network-add.html.tmpl
index 7158b75..b1f3e21 100644
--- a/ui/pages/network-add.html.tmpl
+++ b/ui/pages/network-add.html.tmpl
@@ -41,6 +41,7 @@
                 &lt;option value="isolated"&gt;$_("Isolated: no external network connection")&lt;/option&gt;
                 &lt;option value="nat"&gt;$_("NAT: outbound physical network connection only")&lt;/option&gt;
                 &lt;option value="macvtap"&gt;$_("Bridged: Virtual machines are connected to physical network directly")&lt;/option&gt;</pre>
    </blockquote>
    <br>
    <blockquote
      cite="mid:1454517713-2315-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">
+                &lt;option value="bridge"&gt;$_("Linux bridges and OVS bridges")&lt;/option&gt;</pre>
    </blockquote>
    <br>
    Please, use: "Linux bridged: Virtual machines are connected through
    a network bridge"<br>
    <br>
    <blockquote
      cite="mid:1454517713-2315-2-git-send-email-peterpnns@gmail.com"
      type="cite">
      <pre wrap="">
             &lt;/select&gt;
         &lt;/div&gt;
         &lt;div id="networkBriDisabledLabel" class="form-group hidden"&gt;
@@ -52,7 +53,7 @@
                 &lt;select id="networkDestinationID"  class="selectpicker col-md-12 col-lg-12"&gt;
                 &lt;/select&gt;
             &lt;/div&gt;
-            &lt;div class="form-group"&gt;
+            &lt;div class="form-group" id="vlan"&gt;
                 &lt;input id="enableVlan" class="wok-checkbox" type="checkbox" value="" /&gt;
                 &lt;label for="enableVlan" id="labelEnableVlan"&gt;$_("Enable VLAN") &lt;/label&gt;
                 &lt;div id="vlan-enabled"&gt;
</pre>
    </blockquote>
    <br>
    Also every time, I change the network type on combo box a new
    warning message about the Network Manager is appended in the dialog.<br>
    It happened to have 4 messages in a time.<br>
  </body>
</html>