[Kimchi-devel] [PATCH V2] Implement integrity verification: don't disable network used by guest
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Mon Feb 17 14:46:59 UTC 2014
From: ShaoHe Feng <shaohef at 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 at linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/networks.py | 13 +++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index fd61d4e..03b232d 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 linked to this network."),
+ "KCHNET0018E": _("Unable to deactivate network %(name)s. There are some VMs running linked to 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..9a88fe9 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -188,12 +188,17 @@ 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, filter="all"):
+ DOM_STATE_MAP = {'nostate': 0, 'running': 1, 'blocked': 2,
+ 'paused':3, 'shutdown': 4, 'shutoff': 5,
+ 'crashed': 6}
+ state = DOM_STATE_MAP.get(filter)
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 +213,16 @@ class NetworkModel(object):
def deactivate(self, name):
network = self._get_network(name)
+ if self._get_vms_attach_to_a_network(name, "running"):
+ 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()
--
1.8.4.2
More information about the Kimchi-devel
mailing list