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>
Signed-off-by: Crístian Viana <vianac(a)linux.vnet.ibm.com>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/storagevolumes.py | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index c276b38..1fdc217 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -185,6 +185,8 @@ 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"),
+ "KCHVOL0019E": _("Creating volume from %(param)s is not
supported"),
"KCHIFACE0001E": _("Interface %(name)s does not exist"),
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index b60884c..4ec2e82 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -44,6 +44,19 @@ class StorageVolumesModel(object):
self.objstore = kargs['objstore']
def create(self, pool_name, params):
+ vol_source = ['file', 'url', 'capacity']
+
+ index_list = list(i for i in range(len(vol_source)) if vol_source[i] in params)
+ if len(index_list) != 1:
+ raise InvalidParameter("KCHVOL0018E", {'param':
",".join(vol_source)})
+
+ try:
+ create_func = getattr(self, "_create_volume_with_" +
vol_source[index_list[0]])
+ except AttributeError:
+ raise InvalidParameter("KCHVOL0019E", {'param':
vol_source[index_list[0]]})
+ 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