<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 2014&#24180;09&#26376;02&#26085; 00:17, Aline Manera
      wrote:<br>
    </div>
    <blockquote cite="mid:54049C1B.8090607@linux.vnet.ibm.com"
      type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      <br>
      <div class="moz-cite-prefix">On 09/01/2014 08:50 AM, <a
          moz-do-not-send="true" 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 moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:lvroyce@linux.vnet.ibm.com">&lt;lvroyce@linux.vnet.ibm.com&gt;</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 moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:lvroyce@linux.vnet.ibm.com">&lt;lvroyce@linux.vnet.ibm.com&gt;</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 moz-do-not-send="true" class="moz-txt-link-rfc2396E" href="mailto:%29,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%28object%29:self.objstore=kargs[%27objstore%27]defcreate%28self,pool_name,params%29:+vol_source=[%27file%27,%27url%27,%27capacity%27]++ifsum%281forpinvol_sourceifpinparams%29%21=1:+raiseInvalidParameter%28">"),

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>
    </blockquote>
    ACK<br>
    <blockquote cite="mid:54049C1B.8090607@linux.vnet.ibm.com"
      type="cite"> <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>
    </blockquote>
    ACK<br>
    <blockquote cite="mid:54049C1B.8090607@linux.vnet.ibm.com"
      type="cite">
      <pre wrap="">
</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 = """
         &lt;volume&gt;
           &lt;name&gt;%(name)s&lt;/name&gt;
</pre>
      </blockquote>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Kimchi-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Kimchi-devel@ovirt.org">Kimchi-devel@ovirt.org</a>
<a class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/kimchi-devel">http://lists.ovirt.org/mailman/listinfo/kimchi-devel</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>