<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 03/26/2014 03:33 AM, Aline Manera
wrote:<br>
</div>
<blockquote cite="mid:5331D9F3.8060401@linux.vnet.ibm.com"
type="cite">On 03/25/2014 09:49 AM, <a class="moz-txt-link-abbreviated" href="mailto:shaohef@linux.vnet.ibm.com">shaohef@linux.vnet.ibm.com</a>
wrote:
<br>
<blockquote type="cite">From: ShaoHe Feng
<a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com"><shaohef@linux.vnet.ibm.com></a>
<br>
<br>
When the pool of template is iscsi or scsi, the volume parameter
can not
<br>
be NULL.
<br>
And as we discussion, we do not mix disks from 2 different types
of
<br>
storage pools, for instance: we do not create a template with 2
<br>
disks, where one comes from a SCSI pool and other is a .img in
<br>
a DIR pool.
<br>
<br>
Signed-off-by: ShaoHe Feng <a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com"><shaohef@linux.vnet.ibm.com></a>
<br>
---
<br>
src/kimchi/i18n.py | 2 ++
<br>
src/kimchi/model/templates.py | 50
+++++++++++++++++++++++++++++++++----------
<br>
2 files changed, 41 insertions(+), 11 deletions(-)
<br>
<br>
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
<br>
index 1f84034..bcc15b7 100644
<br>
--- a/src/kimchi/i18n.py
<br>
+++ b/src/kimchi/i18n.py
<br>
@@ -107,6 +107,8 @@ messages = {
<br>
"KCHTMPL0015E": _("Invalid storage pool URI %(value)s
specified for template"),
<br>
"KCHTMPL0016E": _("Specify an ISO image as CDROM to create
a template"),
<br>
"KCHTMPL0017E": _("All networks for the template must be
specified in a list."),
<br>
+ "KCHTMPL0018E": _("Must specify a volume to a template,
when storage pool is iscsi or scsi"),
<br>
+ "KCHTMPL0019E": _("The volume: %(volume)s in not in storage
pool %(pool)"),
<br>
<br>
"KCHPOOL0001E": _("Storage pool %(name)s already exists"),
<br>
"KCHPOOL0002E": _("Storage pool %(name)s does not exist"),
<br>
diff --git a/src/kimchi/model/templates.py
b/src/kimchi/model/templates.py
<br>
index d49632e..0e5c2b2 100644
<br>
--- a/src/kimchi/model/templates.py
<br>
+++ b/src/kimchi/model/templates.py
<br>
@@ -55,15 +55,17 @@ class TemplatesModel(object):
<br>
params['name'] = name
<br>
<br>
conn = self.conn.get()
<br>
-
<br>
pool_uri = params.get(u'storagepool', '')
<br>
if pool_uri:
<br>
- pool_name = pool_name_from_uri(pool_uri)
<br>
try:
<br>
-
conn.storagePoolLookupByName(pool_name.encode("utf-8"))
<br>
+ pool_name = pool_name_from_uri(pool_uri)
<br>
+ pool =
conn.storagePoolLookupByName(pool_name.encode("utf-8"))
<br>
except Exception:
<br>
raise InvalidParameter("KCHTMPL0004E",
{'pool': pool_name,
<br>
'template': name})
<br>
+ tmp_volumes = [disk['volume'] for disk in
params.get('disks', [])
<br>
+ if 'volume' in disk]
<br>
+ self.template_volume_validate(tmp_volumes, pool)
<br>
<br>
for net_name in params.get(u'networks', []):
<br>
try:
<br>
@@ -83,6 +85,28 @@ class TemplatesModel(object):
<br>
with self.objstore as session:
<br>
return session.get_list('template')
<br>
<br>
+ def template_volume_validate(self, tmp_volumes, pool):
<br>
+ kwargs = {'conn': self.conn, 'objstore': self.objstore}
<br>
+ pool_type = xmlutils.xpath_get_text(pool.XMLDesc(0),
"/pool/@type")[0]
<br>
+ pool_name = pool.name()
<br>
+
<br>
+ # as we discussion, we do not mix disks from 2
different types of
<br>
+ # storage pools, for instance: we do not create a
template with 2
<br>
+ # disks, where one comes from a SCSI pool and other is
a .img in
<br>
+ # a DIR pool.
<br>
+ if pool_type in ['iscsi', 'scsi']:
<br>
+ if not tmp_volumes:
<br>
+ raise InvalidParameter("KCHTMPL0018E")
<br>
+
<br>
</blockquote>
<br>
<blockquote type="cite">+ storagevolumes =
__import__("kimchi.model.storagevolumes",
<br>
+ fromlist=[''])
<br>
+ pool_volumes = storagevolumes.StorageVolumesModel(
<br>
+ **kwargs).get_list(pool_name)
<br>
</blockquote>
<br>
Why are you importing it that way?
<br>
</blockquote>
I feel strange use normal importing.<br>
$ git diff<br>
diff --git a/src/kimchi/model/templates.py
b/src/kimchi/model/templates.py<br>
index 0e5c2b2..b6d80cf 100644<br>
--- a/src/kimchi/model/templates.py<br>
+++ b/src/kimchi/model/templates.py<br>
@@ -30,6 +30,7 @@ from kimchi.utils import pool_name_from_uri<br>
from kimchi.utils import probe_file_permission_as_user<br>
from kimchi.vmtemplate import VMTemplate<br>
from lxml import objectify<br>
<font color="#3333ff">+from kimchi.model.storagevolumes import
StorageVolumesModel</font><br>
<br>
<br>
<font color="#3333ff">and error:</font><br>
$ sudo PYTHONPATH=src ./src/kimchid --host "0.0.0.0" --port 8000 $@
<br>
Traceback (most recent call last):<br>
File "./src/kimchid", line 26, in <module><br>
import kimchi.server<br>
File "/home/shhfeng/work/workdir/kimchi/src/kimchi/server.py",
line 30, in <module><br>
from kimchi import mockmodel<br>
File "/home/shhfeng/work/workdir/kimchi/src/kimchi/mockmodel.py",
line 49, in <module><br>
from kimchi.model.storagepools import ISO_POOL_NAME,
STORAGE_SOURCES<br>
File
"/home/shhfeng/work/workdir/kimchi/src/kimchi/model/storagepools.py",
line 27, in <module><br>
from kimchi.model.host import DeviceModel<br>
File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/host.py",
line 35, in <module><br>
from kimchi.model.vms import DOM_STATE_MAP<br>
File "/home/shhfeng/work/workdir/kimchi/src/kimchi/model/vms.py",
line 34, in <module><br>
from kimchi.model.templates import TemplateModel<br>
File
"/home/shhfeng/work/workdir/kimchi/src/kimchi/model/templates.py",
line 33, in <module><br>
from kimchi.model.storagevolumes import StorageVolumesModel<br>
File
"/home/shhfeng/work/workdir/kimchi/src/kimchi/model/storagevolumes.py",
line 29, in <module><br>
from kimchi.model.storagepools import StoragePoolModel<br>
ImportError: cannot import name StoragePoolModel<br>
<br>
<br>
In [1]: from kimchi.model.storagevolumes import StorageVolumesModel<br>
---------------------------------------------------------------------------<br>
<font color="#ff0000">ImportError</font>
Traceback (most recent call last)<br>
<ipython-input-1-c7a006156f1e> in <module>()<br>
<font color="#3333ff">----> 1 from kimchi.model.storagevolumes
import StorageVolumesModel</font><br>
<br>
<font color="#009900">/home/shhfeng/work/workdir/kimchi/src/kimchi/model/storagevolumes.py</font>
in <module>()<br>
27 from kimchi.exception import MissingParameter,
NotFoundError, OperationFailed<br>
28 from kimchi.isoinfo import IsoImage<br>
-<font color="#3333ff">--> 29 from kimchi.model.storagepools
import StoragePoolModel</font><br>
30 from kimchi.utils import kimchi_log<br>
31 from kimchi.model.vms import VMsModel<br>
<br>
<font color="#009900">/home/shhfeng/work/workdir/kimchi/src/kimchi/model/storagepools.py</font>
in <module>()<br>
25 from kimchi.exception import NotFoundError, OperationFailed<br>
26 from kimchi.model.config import CapabilitiesModel<br>
<font color="#3333ff">---> 27 from kimchi.model.host import
DeviceModel</font><br>
28 from kimchi.model.libvirtstoragepool import StoragePoolDef<br>
29 from kimchi.utils import add_task, kimchi_log,
pool_name_from_uri, run_command<br>
<br>
<font color="#009900">/home/shhfeng/work/workdir/kimchi/src/kimchi/model/host.py</font>
in <module>()<br>
33 from kimchi.model.config import CapabilitiesModel<br>
34 from kimchi.model.tasks import TaskModel<br>
<font color="#3333ff">---> 35 from kimchi.model.vms import
DOM_STATE_MAP</font><br>
36 from kimchi.repositories import Repositories<br>
37 from kimchi.swupdate import SoftwareUpdate<br>
<font color="#009900"><br>
/home/shhfeng/work/workdir/kimchi/src/kimchi/model/vms.py</font>
in <module>()<br>
32 from kimchi.exception import MissingParameter,
NotFoundError, OperationFailed<br>
33 from kimchi.model.config import CapabilitiesModel<br>
<font color="#3333ff">---> 34 from kimchi.model.templates import
<font color="#cc0000">TemplateModel</font></font><br>
35 from kimchi.model.utils import get_vm_name<br>
36 from kimchi.screenshot import VMScreenshot<br>
<br>
<font color="#009900">/home/shhfeng/work/workdir/kimchi/src/kimchi/model/templates.py</font>
in <module>()<br>
31 from kimchi.vmtemplate import VMTemplate<br>
32 from lxml import objectify<br>
<font color="#3333ff">---> 33 from kimchi.model.storagevolumes
import <font color="#cc0000">StorageVolumesModel</font></font><br>
34 <br>
35 <br>
<br>
<font color="#ff0000">ImportError: cannot import name
StorageVolumesModel</font><br>
<br>
I find this is a loop:<br>
make is simple:<br>
<font color="#3333ff"><font color="#3333ff">storagevolumes</font>, import
xxx <br>
xxx, import </font><font color="#3333ff">templates</font><br>
<font color="#3333ff">templates</font><font color="#3333ff"><font
color="#3333ff">, import</font> </font><font color="#3333ff"><font
color="#3333ff">storagevolumes</font></font><br>
<br>
<br>
But I think python interpret should avoid this loop. <br>
<blockquote cite="mid:5331D9F3.8060401@linux.vnet.ibm.com"
type="cite">
<br>
<blockquote type="cite">+ vols = set(tmp_volumes) -
set(pool_volumes)
<br>
+ if vols:
<br>
+ raise InvalidParameter("KCHTMPL0019E", {'pool':
pool_name,
<br>
+
'volume': vols})
<br>
+
<br>
<br>
class TemplateModel(object):
<br>
def __init__(self, **kargs):
<br>
@@ -128,18 +152,22 @@ class TemplateModel(object):
<br>
new_t.update(params)
<br>
ident = name
<br>
<br>
+ conn = self.conn.get()
<br>
pool_uri = new_t.get(u'storagepool', '')
<br>
- pool_name = pool_name_from_uri(pool_uri)
<br>
- try:
<br>
- conn = self.conn.get()
<br>
-
conn.storagePoolLookupByName(pool_name.encode("utf-8"))
<br>
- except Exception:
<br>
- raise InvalidParameter("KCHTMPL0004E", {'pool':
pool_name,
<br>
- 'template':
name})
<br>
+
<br>
+ if pool_uri:
<br>
+ try:
<br>
+ pool_name = pool_name_from_uri(pool_uri)
<br>
+ pool =
conn.storagePoolLookupByName(pool_name.encode("utf-8"))
<br>
+ except Exception:
<br>
+ raise InvalidParameter("KCHTMPL0004E", {'pool':
pool_name,
<br>
+
'template': name})
<br>
+ tmp_volumes = [disk['volume'] for disk in
new_t.get('disks', [])
<br>
+ if 'volume' in disk]
<br>
+
self.templates.template_volume_validate(tmp_volumes, pool)
<br>
<br>
for net_name in params.get(u'networks', []):
<br>
try:
<br>
- conn = self.conn.get()
<br>
conn.networkLookupByName(net_name)
<br>
except Exception:
<br>
raise InvalidParameter("KCHTMPL0003E",
{'network': net_name,
<br>
</blockquote>
<br>
<br>
<br>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Thanks and best regards!
Sheldon Feng(冯少合)<a class="moz-txt-link-rfc2396E" href="mailto:shaohef@linux.vnet.ibm.com"><shaohef@linux.vnet.ibm.com></a>
IBM Linux Technology Center</pre>
</body>
</html>