NACK with nits.
2014/2/17 20:50, shaohef(a)linux.vnet.ibm.com:
From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
do not allow to delete a network when the network is used by more than
one guest.
do not allow to deactivate a network when the network is used by more
than one guest with running state.
add a filter for _get_vms_attach_to_a_network
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/networks.py | 9 +++++++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index fd61d4e..ee864f6 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -163,6 +163,8 @@ messages = {
"KCHNET0014E": _("Network interface must be a string"),
"KCHNET0015E": _("Network VLAN ID must be an integer between 1 and
4094"),
"KCHNET0016E": _("Specify name and type to create a Network"),
+ "KCHNET0017E": _("Unable to delete network %(name)s. There are still
some VMs join this network."),
join this network ---> linked to this
network
+ "KCHNET0018E": _("Unable to deactivate network
%(name)s. There are some VMs join this network."),
"KCHDR0001E": _("Debug report %(name)s does not exist"),
"KCHDR0002E": _("Debug report tool not found in system"),
diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index 05105df..96ed43c 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -188,12 +188,13 @@ class NetworkModel(object):
'autostart': network.autostart() == 1,
'state': network.isActive() and "active" or
"inactive"}
- def _get_vms_attach_to_a_network(self, network):
+ def _get_vms_attach_to_a_network(self, network, state=None):
vms = []
conn = self.conn.get()
for dom in conn.listAllDomains(0):
networks = self._vm_get_networks(dom)
- if network in networks:
+ if network in networks and (state == None or
+ state == dom.state()[0]):
vms.append(dom.name())
return vms
@@ -208,12 +209,16 @@ class NetworkModel(object):
def deactivate(self, name):
network = self._get_network(name)
+ if self._get_vms_attach_to_a_network(name, 1):
What does "1"
mean? I think it is not very intuitive. Can we have a
meaningful macro for it?
+ raise InvalidOperation("KCHNET0018E",
{'name': name})
network.destroy()
def delete(self, name):
network = self._get_network(name)
if network.isActive():
raise InvalidOperation("KCHNET0005E", {'name': name})
+ if self._get_vms_attach_to_a_network(name):
+ raise InvalidOperation("KCHNET0017E", {'name': name})
self._remove_vlan_tagged_bridge(network)
network.undefine()