[Kimchi-devel] [PATCH 1/4] storagevolume: Split "create" function based on the parameters

Crístian Viana vianac at linux.vnet.ibm.com
Wed Aug 27 03:36:27 UTC 2014


The function "create" in StorageVolume creates a volume with only ....
Soon, Kimchi will support creating storage volumes in different way, so
we need to prepare for that change.

Split the function based on its parameters and call the appropriate
implementation.

Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/model/storagevolumes.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index b60884c..2c3e7a8 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -44,6 +44,21 @@ class StorageVolumesModel(object):
         self.objstore = kargs['objstore']
 
     def create(self, pool_name, params):
+        vol_source = ['file', 'url', 'capacity']
+
+        if len([p for p in params if p in vol_source]) != 1:
+            raise InvalidParameter('KCHVOL0018E', {'param': str(vol_source)})
+
+        for v in vol_source:
+            if v in params:
+                create_func = getattr(self, '_create_volume_with_' + v, None)
+                if not create_func:
+                    # TODO: provide a better and internationalized error msg
+                    raise OperationFailed('<internal error>')
+
+                return create_func(pool_name, params)
+
+    def _create_volume_with_capacity(self, pool_name, params):
         vol_xml = """
         <volume>
           <name>%(name)s</name>
-- 
1.9.3




More information about the Kimchi-devel mailing list