[Kimchi-devel] [PATCHv5 5/8] storage server: Update model and mockmodel
lvroyce at linux.vnet.ibm.com
lvroyce at linux.vnet.ibm.com
Tue Jan 7 09:43:07 UTC 2014
From: Royce Lv <lvroyce at linux.vnet.ibm.com>
Query all storage pool to retrieve storage server we used.
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
src/kimchi/mockmodel.py | 28 ++++++++++++++++++++++++++++
src/kimchi/model.py | 26 ++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
index 9488078..9e9a1b1 100644
--- a/src/kimchi/mockmodel.py
+++ b/src/kimchi/mockmodel.py
@@ -419,6 +419,34 @@ 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:
+ 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(type=pool_info['type'], addr=server)
+ except NotFoundError:
+ # Avoid inconsistent pool result because of lease between list and lookup
+ pass
+ raise NotFoundError
+
def dummy_interfaces(self):
interfaces = {}
ifaces = {"eth1": "nic", "bond0": "bonding",
diff --git a/src/kimchi/model.py b/src/kimchi/model.py
index a21fcf7..cc9d640 100644
--- a/src/kimchi/model.py
+++ b/src/kimchi/model.py
@@ -1237,6 +1237,32 @@ 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:
+ 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(type=pool_info['type'], addr=server)
+ except NotFoundError:
+ # Avoid inconsistent pool result because of lease between list and lookup
+ pass
+ raise NotFoundError
+
def _get_screenshot(self, vm_uuid):
with self.objstore as session:
try:
--
1.8.1.2
More information about the Kimchi-devel
mailing list