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(a)linux.vnet.ibm.com>
Signed-off-by: Royce Lv <lvroyce(a)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