[Kimchi-devel] [WIP][PATCH 1/4] Storage volume upload: Dispatch volume create to right handler
lvroyce0210 at gmail.com
lvroyce0210 at gmail.com
Thu Aug 21 14:42:58 UTC 2014
From: Royce Lv <lvroyce at 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 at 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"),
"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>
--
1.8.3.2
More information about the Kimchi-devel
mailing list