<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 09/01/2014 08:50 AM,
<a class="moz-txt-link-abbreviated" href="mailto:lvroyce0210@gmail.com">lvroyce0210@gmail.com</a> wrote:<br>
</div>
<blockquote
cite="mid:1409572254-22805-2-git-send-email-lvroyce0210@gmail.comm"
type="cite">
<pre wrap="">From: Royce Lv <a class="moz-txt-link-rfc2396E" href="mailto:lvroyce@linux.vnet.ibm.com"><lvroyce@linux.vnet.ibm.com></a>
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 <a class="moz-txt-link-rfc2396E" href="mailto:lvroyce@linux.vnet.ibm.com"><lvroyce@linux.vnet.ibm.com></a>
---
src/kimchi/i18n.py | 2 ++
src/kimchi/model/storagevolumes.py | 14 ++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 2eae7e8..bbec591 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<a class="moz-txt-link-rfc2396E" href="mailto:),diff--gita/src/kimchi/model/storagevolumes.pyb/src/kimchi/model/storagevolumes.pyindexb60884c..fc63a16100644---a/src/kimchi/model/storagevolumes.py+++b/src/kimchi/model/storagevolumes.py@@-44,6+44,20@@classStorageVolumesModel(object):self.objstore=kargs['objstore']defcreate(self,pool_name,params):+vol_source=['file','url','capacity']++ifsum(1forpinvol_sourceifpinparams)!=1:+raiseInvalidParameter(">"),
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index b60884c..fc63a16 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -44,6 +44,20 @@ 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("</a>KCHVOL0018E", {'param': str(vol_source)})</pre>
</blockquote>
<br>
str(vol_source) will generate a string like "[' file', 'url',
'capacity']"<br>
I suggest to use ", ".join(a) to generate a string like "file, url,
capacity"<br>
<br>
<blockquote
cite="mid:1409572254-22805-2-git-send-email-lvroyce0210@gmail.comm"
type="cite">
<pre wrap="">
+
+ for p in vol_source:
+ if p in params:</pre>
</blockquote>
<br>
As just one option is allowed you don't need a "for" statement<br>
You should be able to do:<br>
<pre wrap="">+ try:
+ create_func = getattr(self, "_create_volume_with_" + <b>vol_source[0]</b>)
+ except AttributeError:
+ raise InvalidParameter("KCHVOL0019E", {'param': <b>vol_source[0]</b>})
+ return create_func(pool_name, params)
</pre>
<br>
<br>
<blockquote
cite="mid:1409572254-22805-2-git-send-email-lvroyce0210@gmail.comm"
type="cite">
<pre wrap="">
+ try:
+ create_func = getattr(self, "_create_volume_with_" + p)
+ except AttributeError:
+ raise InvalidParameter("KCHVOL0019E", {'param': p})
+ return create_func(pool_name, params)
+
+ def _create_volume_with_capacity(self, pool_name, params):
vol_xml = """
<volume>
<name>%(name)s</name>
</pre>
</blockquote>
<br>
</body>
</html>