[Kimchi-devel] [PATCH v2] Add vm names to delete/deactivate network error message

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Tue Jan 13 13:45:13 UTC 2015


This patch changes the error message returned by backend, adding the
name of virtual machines that are prohibiting the network to be removed
or deactivated. In other words, the vms linked to that network.
MSG example:
"Unable to delete network NET1. There are some virtual machines ['VM1',
 'VM2', 'VM3'] and/or templates linked to this network

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py           |  4 ++--
 src/kimchi/model/networks.py | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index e3a051c..33c26f7 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -229,8 +229,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 some virtual machines and/or templates linked to this network."),
-    "KCHNET0018E": _("Unable to deactivate network %(name)s. There are some virtual machines and/or templates linked to this network."),
+    "KCHNET0017E": _("Unable to delete network %(name)s. There are some virtual machines%(vms)s and/or templates linked to this network."),
+    "KCHNET0018E": _("Unable to deactivate network %(name)s. There are some virtual machines%(vms)s and/or templates linked to this network."),
     "KCHNET0019E": _("Bridge device %(name)s can not be the trunk device of a VLAN."),
     "KCHNET0020E": _("Failed to activate interface %(iface)s: %(err)s."),
     "KCHNET0021E": _("Failed to activate interface %(iface)s. Please check the physical link status."),
diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py
index 1e94fd2..072bbd5 100644
--- a/src/kimchi/model/networks.py
+++ b/src/kimchi/model/networks.py
@@ -17,6 +17,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
+import string
 import sys
 import time
 
@@ -313,14 +314,26 @@ class NetworkModel(object):
 
     def deactivate(self, name):
         if self._is_network_in_use(name):
-            raise InvalidOperation("KCHNET0018E", {'name': name})
+            vms = self._get_vms_attach_to_a_network(name)
+            if not vms:
+                vms = ""
+            else:
+                vms.sort()
+                vms = ' ' + string.join(vms, ', ')
+            raise InvalidOperation("KCHNET0018E", {'name': name, 'vms': vms})
 
         network = self.get_network(self.conn.get(), name)
         network.destroy()
 
     def delete(self, name):
         if self._is_network_in_use(name):
-            raise InvalidOperation("KCHNET0017E", {'name': name})
+            vms = self._get_vms_attach_to_a_network(name)
+            if not vms:
+                vms = ""
+            else:
+                vms.sort()
+                vms = ' ' + string.join(vms, ', ')
+            raise InvalidOperation("KCHNET0017E", {'name': name, 'vms': vms})
 
         network = self.get_network(self.conn.get(), name)
         if network.isActive():
-- 
1.9.3




More information about the Kimchi-devel mailing list