On 08/21/2014 11:42 AM, lvroyce0210(a)gmail.com wrote:
From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
As we are starting to support upload and download to create volume,
they need to be distinguished from previous creating through libvirt api.
Adding a dispatcher to support this.
Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 1 +
src/kimchi/model/storagevolumes.py | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 2eae7e8..26b916b 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -185,6 +185,7 @@ messages = {
"KCHVOL0015E": _("Storage volume format not supported"),
"KCHVOL0016E": _("Storage volume requires a volume name"),
"KCHVOL0017E": _("Unable to update database with storage volume
information due error: %(err)s"),
+ "KCHVOL0018E": _("Only one of %(param)s can be specified"),
From the code above, %(param)s will be always "file, url, capacity" so
we can include them to the string and avoid the placeholder
"KCHIFACE0001E": _("Interface %(name)s does not exist"),
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index b60884c..a7823c2 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -44,6 +44,17 @@ class StorageVolumesModel(object):
self.objstore = kargs['objstore']
def create(self, pool_name, params):
+ vol_source = ['file', 'url', 'capacity']
+
+ if sum(1 for p in vol_source if p in params) != 1:
+ raise InvalidParameter("KCHVOL0018E", {'param':
str(vol_source)})
+
+ for p in vol_source:
+ create_func = getattr(self, "_create_volume_with_" + p, None)
+ if create_func and p in params:
+ return create_func(pool_name, params)
+
+ def _create_volume_with_capacity(self, pool_name, params):
vol_xml = """
<volume>
<name>%(name)s</name>