[Kimchi-devel] [PATCH V2] Sort device paths shown when creating a logical storage pool

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Fri Mar 28 02:12:30 UTC 2014


This patch sorts the host partitions list returned by backend by
partition path. Then UI is going to show paths sorted, improving
the user experience.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/kimchi/control/host.py | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
index cfc24bd..d4387f4 100644
--- a/src/kimchi/control/host.py
+++ b/src/kimchi/control/host.py
@@ -20,7 +20,7 @@
 import cherrypy
 
 from kimchi.control.base import Collection, Resource
-from kimchi.control.utils import UrlSubNode, validate_method
+from kimchi.control.utils import UrlSubNode, validate_method, model_fn
 from kimchi.exception import OperationFailed
 from kimchi.template import render
 
@@ -64,6 +64,24 @@ class Partitions(Collection):
         super(Partitions, self).__init__(model)
         self.resource = Partition
 
+    # Defining get_resources in order to return list of partitions in UI
+    # sorted by their path
+    def _get_resources(self, flag_filter):
+        try:
+            get_list = getattr(self.model, model_fn(self, 'get_list'))
+            idents = get_list(*self.model_args, **flag_filter)
+            res_list = []
+            for ident in idents:
+                # internal text, get_list changes ident to unicode for sorted
+                args = self.resource_args + [ident]
+                res = self.resource(self.model, *args)
+                res.lookup()
+                res_list.append(res)
+            # Sort by partition path
+            res_list.sort(key=lambda x: x.info['path'])
+            return res_list
+        except AttributeError:
+            return []
 
 class Partition(Resource):
     def __init__(self, model, id):
-- 
1.8.5.3




More information about the Kimchi-devel mailing list