[PATCH V2 0/2] Fix non persistent network handling

V2: Address Ming comments: - Updates API.md - remove useless comments and return V1: 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) docs/API.md | 2 ++ src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 3 ++- ui/js/src/kimchi.network.js | 55 ++++++++++++++++++++++++++++-------------- ui/pages/i18n.html.tmpl | 1 + 5 files changed, 44 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 and expose this information. It also changes API.md. Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- docs/API.md | 2 ++ src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/API.md b/docs/API.md index 672ef14..b8f941a 100644 --- a/docs/API.md +++ b/docs/API.md @@ -504,6 +504,8 @@ A interface represents available interface on host. * interface: The name of a bridge network interface on the host. All traffic on this network will be bridged through the indicated interface. The interface is a bridge or ethernet/bonding device. + * persistent: If 'true', network will persist after a system reboot or be stopped. + All networks created by Kimchi are persistent. * **DELETE**: Remove the Network * **POST**: *See Network Actions* 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..5cd5b7e 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 -- 1.8.5.3

The model test and mockmodel test? On 2014年03月21日 20:24, Rodrigo Trujillo wrote:
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 and expose this information. It also changes API.md.
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> --- docs/API.md | 2 ++ src/kimchi/control/networks.py | 3 ++- src/kimchi/model/networks.py | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/docs/API.md b/docs/API.md index 672ef14..b8f941a 100644 --- a/docs/API.md +++ b/docs/API.md @@ -504,6 +504,8 @@ A interface represents available interface on host. * interface: The name of a bridge network interface on the host. All traffic on this network will be bridged through the indicated interface. The interface is a bridge or ethernet/bonding device. + * persistent: If 'true', network will persist after a system reboot or be stopped. + All networks created by Kimchi are persistent.
* **DELETE**: Remove the Network * **POST**: *See Network Actions* 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..5cd5b7e 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

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
participants (2)
-
Rodrigo Trujillo
-
Royce Lv