[PATCH 0/2] Fix non persistent network handling

Kimchi networks have the same problem storage had. Non persistent networks are not stop, they are removed by libvirt and this causes an error in Kimchi. Rodrigo Trujillo (2): Fix non persistent network handling (backend) Fix non persistent network handling (frontend) src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 9 ++++++- ui/js/src/kimchi.network.js | 55 ++++++++++++++++++++++++++++-------------- ui/pages/i18n.html.tmpl | 1 + 4 files changed, 48 insertions(+), 20 deletions(-) -- 1.8.5.3

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 changes the backend in order to get persistent information. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/kimchi/control/networks.py b/src/kimchi/control/networks.py index 95e8523..b905891 100644 --- a/src/kimchi/control/networks.py +++ b/src/kimchi/control/networks.py @@ -45,4 +45,5 @@ class Network(Resource): 'interface': self.info['interface'], 'subnet': self.info['subnet'], 'dhcp': self.info['dhcp'], - 'state': self.info['state']} + 'state': self.info['state'], + 'persistent': self.info['persistent']} diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index 27abd54..958b75d 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -231,7 +231,8 @@ class NetworkModel(object): 'vms': self._get_vms_attach_to_a_network(name), 'in_use': self._is_network_in_use(name), 'autostart': network.autostart() == 1, - 'state': network.isActive() and "active" or "inactive"} + 'state': network.isActive() and "active" or "inactive", + 'persistent': True if network.isPersistent() else False} def _is_network_in_use(self, name): # The network "default" is used for Kimchi proposal and should not be @@ -280,8 +281,14 @@ class NetworkModel(object): raise InvalidOperation("KCHNET0018E", {'name': name}) network = self.get_network(self.conn.get(), name) + persistent = network.isPersistent() network.destroy() + # If network was not persistent, then it was erased by destroy() and + # must return nothing here, to trigger _redirect() and avoid errors + if not persistent: + return "" + def delete(self, name): if self._is_network_in_use(name): raise InvalidOperation("KCHNET0017E", {'name': name}) -- 1.8.5.3

在 2014-03-20Thu的 20:54 -0300,Rodrigo Trujillo写道:
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 changes the backend in order to get persistent information.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/control/networks.py b/src/kimchi/control/networks.py index 95e8523..b905891 100644 --- a/src/kimchi/control/networks.py +++ b/src/kimchi/control/networks.py @@ -45,4 +45,5 @@ class Network(Resource): 'interface': self.info['interface'], 'subnet': self.info['subnet'], 'dhcp': self.info['dhcp'], - 'state': self.info['state']} + 'state': self.info['state'], + 'persistent': self.info['persistent']} diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index 27abd54..958b75d 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -231,7 +231,8 @@ class NetworkModel(object): 'vms': self._get_vms_attach_to_a_network(name), 'in_use': self._is_network_in_use(name), 'autostart': network.autostart() == 1, - 'state': network.isActive() and "active" or "inactive"} + 'state': network.isActive() and "active" or "inactive", + 'persistent': True if network.isPersistent() else False}
def _is_network_in_use(self, name): # The network "default" is used for Kimchi proposal and should not be @@ -280,8 +281,14 @@ class NetworkModel(object): raise InvalidOperation("KCHNET0018E", {'name': name})
network = self.get_network(self.conn.get(), name) + persistent = network.isPersistent() network.destroy()
+ # If network was not persistent, then it was erased by destroy() and + # must return nothing here, to trigger _redirect() and avoid errors
The comments above are quite confusing. Where is "_redirect()"? What errors are trying to avoid?
+ if not persistent: + return "" + def delete(self, name): if self._is_network_in_use(name): raise InvalidOperation("KCHNET0017E", {'name': name})

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@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

THe API.md should be updated because the GET API of network is changed. 在 2014-03-20Thu 20:54 -0300,Rodrigo Trujillo:
Kimchi networks have the same problem storage had. Non persistent networks are not stop, they are removed by libvirt and this causes an error in Kimchi.
Rodrigo Trujillo (2): Fix non persistent network handling (backend) Fix non persistent network handling (frontend)
src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 9 ++++++- ui/js/src/kimchi.network.js | 55 ++++++++++++++++++++++++++++-------------- ui/pages/i18n.html.tmpl | 1 + 4 files changed, 48 insertions(+), 20 deletions(-)
participants (2)
-
Rodrigo Trujillo
-
Shu Ming