[Kimchi-devel] [PATCH 2/2] Fix non persistent network handling (frontend)

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Thu Mar 20 23:54:09 UTC 2014


If some network is not persistent and the user tries to stop it, it
is going to be removed by libvirt and causes an error in Kimchi.
This patch warns the user with a message in the ui about the situation,
avoinding mistakes.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.network.js | 55 ++++++++++++++++++++++++++++++---------------
 ui/pages/i18n.html.tmpl     |  1 +
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js
index 7c4bc77..8b523c7 100644
--- a/ui/js/src/kimchi.network.js
+++ b/ui/js/src/kimchi.network.js
@@ -40,6 +40,7 @@ kimchi.initNetworkListView = function() {
             }
             network.interface = data[i].interface ? data[i].interface : null;
             network.addrSpace = data[i].subnet ? data[i].subnet : null;
+            network.persistent = data[i].persistent;
             kimchi.addNetworkItem(network);
         }
     });
@@ -77,6 +78,27 @@ kimchi.getNetworkItemHtml = function(network) {
     return networkItem;
 };
 
+kimchi.stopNetwork = function(network,menu) {
+    $(".network-state", $("#" + network.name)).switchClass("up", "nw-loading");
+    $("[nwAct='stop']", menu).addClass("ui-state-disabled");
+    kimchi.toggleNetwork(network.name, false, function() {
+        $("[nwAct='start']", menu).removeClass("hide-action-item");
+        $("[nwAct='stop']", menu).addClass("hide-action-item");
+        $("[nwAct='stop']", menu).removeClass("ui-state-disabled");
+        if (!network.in_use) {
+            $("[nwAct='delete']", menu).removeClass("ui-state-disabled");
+            $(":first-child", $("[nwAct='delete']", menu)).removeAttr("disabled");
+        }
+        $(".network-state", $("#" + network.name)).switchClass("nw-loading", "down");
+    }, function(err) {
+        $(".network-state", $("#" + network.name)).switchClass("nw-loading", "up");
+        if (!network.in_use) {
+            $("[nwAct='stop']", menu).removeClass("ui-state-disabled");
+        }
+        kimchi.message.error(err.responseJSON.reason);
+    });
+}
+
 kimchi.addNetworkActions = function(network) {
     $(".menu-container", "#" + network.name).menu({
         position : {
@@ -110,24 +132,21 @@ kimchi.addNetworkActions = function(network) {
                     kimchi.message.error(err.responseJSON.reason);
                 });
             } else if ($(evt.currentTarget).attr("nwAct") === "stop") {
-                $(".network-state", $("#" + network.name)).switchClass("up", "nw-loading");
-                $("[nwAct='stop']", menu).addClass("ui-state-disabled");
-                kimchi.toggleNetwork(network.name, false, function() {
-                    $("[nwAct='start']", menu).removeClass("hide-action-item");
-                    $("[nwAct='stop']", menu).addClass("hide-action-item");
-                    $("[nwAct='stop']", menu).removeClass("ui-state-disabled");
-                    if (!network.in_use) {
-                        $("[nwAct='delete']", menu).removeClass("ui-state-disabled");
-                        $(":first-child", $("[nwAct='delete']", menu)).removeAttr("disabled");
-                    }
-                    $(".network-state", $("#" + network.name)).switchClass("nw-loading", "down");
-                }, function(err) {
-                    $(".network-state", $("#" + network.name)).switchClass("nw-loading", "up");
-                    if (!network.in_use) {
-                        $("[nwAct='stop']", menu).removeClass("ui-state-disabled");
-                    }
-                    kimchi.message.error(err.responseJSON.reason);
-                });
+                if (!network.persistent) {
+                    var settings = {
+                        title : i18n['KCHAPI6001M'],
+                        content : i18n['KCHNET6004M'],
+                        confirm : i18n['KCHAPI6002M'],
+                        cancel : i18n['KCHAPI6003M']
+                    };
+                    kimchi.confirm(settings, function() {
+                        kimchi.stopNetwork(network, menu);
+                        $(evt.currentTarget).parents(".item").remove();
+                    }, null);
+                }
+                else {
+                    kimchi.stopNetwork(network, menu);
+                }
             } else if ($(evt.currentTarget).attr("nwAct") === "delete") {
                 kimchi.confirm({
                     title : i18n['KCHAPI6006M'],
diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl
index 2f47e50..66d2e2a 100644
--- a/ui/pages/i18n.html.tmpl
+++ b/ui/pages/i18n.html.tmpl
@@ -119,6 +119,7 @@ var i18n = {
     'KCHNET6001M': "$_("unavailable")",
     'KCHNET6002M': "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")",
     'KCHNET6003M': "$_("Create a network")",
+    'KCHNET6004M': "$_("This network is not persistent. Instead of stop, this action will permanently delete it. Would you like to continue?")",
 
     'KCHPOOL6001M': "$_("This will permanently delete the storage pool. Would you like to continue?")",
     'KCHPOOL6002M': "$_("This storage pool is empty.")",
-- 
1.8.5.3




More information about the Kimchi-devel mailing list