[Kimchi-devel] [PATCH 2/3] generate a iscsi volume disk for a guest
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Thu Mar 20 10:35:40 UTC 2014
From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
The disk looks like:
"""
<disk type='volume' device='disk'>
<driver name='qemu' type='raw'/>
<source pool='iscsi-pool' volume='unit:0:0:1' mode='host'/>
<auth username='myuser'>
<secret type='chap' usage='libvirtiscsi'/>
</auth>
<target dev='vda' bus='virtio'/>
</disk>
"""
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
src/kimchi/vmtemplate.py | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index bf43153..5e84c55 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -28,6 +28,8 @@ from kimchi.config import READONLY_POOL_TYPE
from kimchi.exception import InvalidParameter, IsoFormatError
from kimchi.isoinfo import IsoImage
from kimchi.utils import check_url_path, pool_name_from_uri
+from lxml import etree
+from lxml.builder import E
QEMU_NAMESPACE = "xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'"
@@ -198,6 +200,34 @@ class VMTemplate(object):
ret = ret + disk_xml % params
return ret
+ def _get_iscsi_disks_xml(self):
+ def build_disk_xml(children=[]):
+ disk = E.disk(type='volume', device='disk')
+ disk.extend(children)
+ return etree.tostring(disk)
+
+ ret = ""
+ children = []
+ auth = self._get_storage_auth()
+ if auth:
+ etree_auth = E.auth(username=auth['username'])
+ etree_auth.append(E.secret(type=auth['type'],
+ usage=auth['libvirtiscsi']))
+ children.append(etree_auth)
+ children.append(E.driver(name='qemu', type='raw'))
+ disk_bus = self.info['disk_bus']
+ dev_prefix = self._bus_to_dev[disk_bus]
+ pool_name = pool_name_from_uri(self.info['storagepool'])
+ for i, d in enumerate(self.info['disks']):
+ source = E.source(pool=pool_name,
+ volume=d.get('volume'), mode='host')
+ # FIXME if more than 26 disks
+ target = E.target(dev=dev_prefix + string.lowercase[i],
+ bus=disk_bus)
+ ret += build_disk_xml(children+[source, target])
+
+ return ret
+
def to_volume_list(self, vm_uuid):
storage_path = self._get_storage_path()
fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2'
--
1.8.5.3
More information about the Kimchi-devel
mailing list