[Kimchi-devel] [PATCHv9 5/8] storage server: Update model and mockmodel

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Mon Jan 20 09:32:49 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Query all storage pool to retrieve storage server we used.
If no query param is given, all supported type will be listed.
With param given, only specified type of server is listed.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/mockmodel.py | 30 ++++++++++++++++++++++++++++++
 src/kimchi/model.py     | 30 ++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 4ef3fa6..87e7220 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -408,6 +408,36 @@ class MockModel(object):
                     iso_volumes.append(res)
         return iso_volumes
 
+    def storageservers_get_list(self, _target_type=None):
+        # FIXME: When added new storage server support, this needs to be updated
+        target_type = kimchi.model.STORAGE_SOURCES.keys() \
+            if not _target_type else [_target_type]
+        pools = self.storagepools_get_list()
+        server_list = []
+        for pool in pools:
+            try:
+                pool_info = self.storagepool_lookup(pool)
+                if (pool_info['type'] in target_type and
+                        pool_info['source']['addr'] not in server_list):
+                    server_list.append(pool_info['source']['addr'])
+            except NotFoundError:
+                pass
+
+        return server_list
+
+    def storageserver_lookup(self, server):
+        pools = self.storagepools_get_list()
+        for pool in pools:
+            try:
+                pool_info = self.storagepool_lookup(pool)
+                if pool_info['source'] and pool_info['source']['addr'] == server:
+                    return dict(addr=server)
+            except NotFoundError:
+            # Avoid inconsistent pool result because of lease between list and lookup
+                pass
+
+        raise NotFoundError("storage server %s not used by kimchi" % server)
+
     def dummy_interfaces(self):
         interfaces = {}
         ifaces = {"eth1": "nic", "bond0": "bonding",
diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index 2c6d3a1..6b009c3 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -1300,6 +1300,36 @@ class Model(object):
             else:
                 raise
 
+    def storageservers_get_list(self, _target_type=None):
+        target_type = STORAGE_SOURCES.keys() if not _target_type else [_target_type]
+        pools = self.storagepools_get_list()
+        server_list = []
+        for pool in pools:
+            try:
+                pool_info = self.storagepool_lookup(pool)
+                if (pool_info['type'] in target_type and
+                        pool_info['source']['addr'] not in server_list):
+                    # Avoid to add same server for multiple times
+                    # if it hosts more than one storage type
+                    server_list.append(pool_info['source']['addr'])
+            except NotFoundError:
+                pass
+
+        return server_list
+
+    def storageserver_lookup(self, server):
+        pools = self.storagepools_get_list()
+        for pool in pools:
+            try:
+                pool_info = self.storagepool_lookup(pool)
+                if pool_info['source'] and pool_info['source']['addr'] == server:
+                    return dict(addr=server)
+            except NotFoundError:
+            # Avoid inconsistent pool result because of lease between list and lookup
+                pass
+
+        raise NotFoundError('server %s does not used by kimchi' % server)
+
     def _get_screenshot(self, vm_uuid):
         with self.objstore as session:
             try:
-- 
1.8.1.2




More information about the Kimchi-devel mailing list