[Kimchi-devel] [PATCH V3 2/3] network improvment: update mockmodel to support vms field for Network Resource

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Mon Jan 6 08:42:50 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

get vms attach to a network

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/mockmodel.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 9488078..e928afc 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -473,8 +473,16 @@ class MockModel(object):
         except KeyError:
             raise NotFoundError("Network '%s'" % name)
 
+    def _get_vms_attach_to_a_network(self, network):
+        vms = []
+        for name, dom in self._mock_vms.iteritems():
+             if network in dom.networks:
+                 vms.append(name)
+        return vms
+
     def network_lookup(self, name):
         network = self._get_network(name)
+        network.info['vms'] = self._get_vms_attach_to_a_network(name)
         return network.info
 
     def network_activate(self, name):
@@ -634,6 +642,7 @@ class MockVM(object):
         self.uuid = uuid
         self.name = name
         self.disk_paths = []
+        self.networks = template_info['networks']
         self.info = {'state': 'shutoff',
                      'stats': "{'cpu_utilization': 20, 'net_throughput' : 35, \
                                 'net_throughput_peak': 100, 'io_throughput': 45, \
-- 
1.8.4.2




More information about the Kimchi-devel mailing list