[PATCH 0/3] create a VM from an iscsi pool template

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> This patch just support create vm on iscsi lun. Now we have support iSCSI or SCSI pool. Here we want to create volumes for VM in those pools. The best way to do it is on template level - and not on vm level For if we create a template just assign a iSCSI or SCSI pool, the user still need to choose a volume for his VM. Also as we discussion, we do not mix disks from 2 different types of storage pools, for instance: we do not create a template with 2 disks, where one comes from a ISCSI pool and other is a .img in a DIR pool. ShaoHe Feng (3): add a method to get iscsi storage pool auth information. generate a iscsi volume disk for a guest create a VM from an iscsi pool template. src/kimchi/model/templates.py | 11 +++++++++++ src/kimchi/model/vms.py | 4 +++- src/kimchi/vmtemplate.py | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) -- 1.8.5.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> when need the auth information when we create iscsi volume disk for guest. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/templates.py | 11 +++++++++++ src/kimchi/vmtemplate.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py index cf9e088..1a183fb 100644 --- a/src/kimchi/model/templates.py +++ b/src/kimchi/model/templates.py @@ -29,6 +29,7 @@ from kimchi.kvmusertests import UserTests from kimchi.utils import pool_name_from_uri from kimchi.utils import probe_file_permission_as_user from kimchi.vmtemplate import VMTemplate +from lxml import objectify class TemplatesModel(object): @@ -211,6 +212,16 @@ class LibvirtVMTemplate(VMTemplate): xml = pool.XMLDesc(0) return xmlutils.xpath_get_text(xml, "/pool/@type")[0] + def _get_storage_auth(self): + pool = self._storage_validate() + xml = pool.XMLDesc(0) + root = objectify.fromstring(xml) + auth = root.source.find("auth") + if auth is None: + return auth + au = auth.attrib + return au.update(auth.secret.attrib) + def fork_vm_storage(self, vm_uuid): # Provision storage: # TODO: Rebase on the storage API once upstream diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index 003e524..bf43153 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -345,6 +345,9 @@ class VMTemplate(object): def _get_storage_type(self): return '' + def _get_storage_auth(self): + return None + def _get_all_networks_name(self): return [] -- 1.8.5.3

From: ShaoHe Feng <shaohef@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@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

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Now this patch do not touch the scsi code, so it does not support to create a VM from an scsi pool template at present. It just supports iscsi luns for template, and create a VM by this template. Will refactor the related code, and support the scsi lun at template level. 1. how to test this patch: create a iscsi pool named "my-iscsi" with UI 2.get the volumes name of this pool: $ sudo virsh vol-list my-iscsi Name Path ----------------------------------------- unit:0:0:0 /dev/disk/by-id/wwn-0x60014056aefaef96d4e4033953d9627d 3. create a template with this pool like this: $ curl -u shhfeng:123456 -H "Content-Type: application/json" \
-H "Accept: application/json" \ http://localhost:8000/templates/ -X POST -d ' { "cpus": 1, "cdrom":"/home/shhfeng/iso/f17.iso", "name":"F17-ISCSI", "storagepool":"/storagepools/my-iscsi", "disks":[ { "index":0, "volume":"unit:0:0:0" } ] }'
4. create a VM with this template and start it. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 4 +++- src/kimchi/vmtemplate.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 79b335c..f962cbb 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -184,7 +184,9 @@ class VMsModel(object): # If storagepool is SCSI, volumes will be LUNs and must be passed by # the user from UI or manually. vol_list = [] - if t._get_storage_type() in READONLY_POOL_TYPE: + if t._get_storage_type() == "iscsi": + vol_list = [] + elif t._get_storage_type() in READONLY_POOL_TYPE: if not params.get('volumes'): raise MissingParameter('KCHVM0017E') else: diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index 5e84c55..d13f714 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -305,7 +305,9 @@ class VMTemplate(object): # Current implementation just allows to create disk in one single # storage pool, so we cannot mix the types (scsi volumes vs img file) - if self._get_storage_type() in READONLY_POOL_TYPE: + if self._get_storage_type() == "iscsi": + params['disks'] = self._get_iscsi_disks_xml() + elif self._get_storage_type() in READONLY_POOL_TYPE: params['disks'] = self._get_scsi_disks_xml(kwargs.get('volumes')) else: params['disks'] = self._get_disks_xml(vm_uuid) -- 1.8.5.3

On 03/20/2014 07:35 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Now this patch do not touch the scsi code, so it does not support to create a VM from an scsi pool template at present.
It just supports iscsi luns for template, and create a VM by this template.
Will refactor the related code, and support the scsi lun at template level.
1. how to test this patch: create a iscsi pool named "my-iscsi" with UI
2.get the volumes name of this pool: $ sudo virsh vol-list my-iscsi Name Path ----------------------------------------- unit:0:0:0 /dev/disk/by-id/wwn-0x60014056aefaef96d4e4033953d9627d
-H "Accept: application/json" \ http://localhost:8000/templates/ -X POST -d ' { "cpus": 1, "cdrom":"/home/shhfeng/iso/f17.iso", "name":"F17-ISCSI", "storagepool":"/storagepools/my-iscsi", "disks":[ { "index":0, "volume":"unit:0:0:0" } ] }'
3. create a template with this pool like this: $ curl -u shhfeng:123456 -H "Content-Type: application/json" \ 4. create a VM with this template and start it.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/vms.py | 4 +++- src/kimchi/vmtemplate.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py index 79b335c..f962cbb 100644 --- a/src/kimchi/model/vms.py +++ b/src/kimchi/model/vms.py @@ -184,7 +184,9 @@ class VMsModel(object): # If storagepool is SCSI, volumes will be LUNs and must be passed by # the user from UI or manually. vol_list = [] - if t._get_storage_type() in READONLY_POOL_TYPE: + if t._get_storage_type() == "iscsi": + vol_list = [] + elif t._get_storage_type() in READONLY_POOL_TYPE: if not params.get('volumes'): raise MissingParameter('KCHVM0017E') else: diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py index 5e84c55..d13f714 100644 --- a/src/kimchi/vmtemplate.py +++ b/src/kimchi/vmtemplate.py @@ -305,7 +305,9 @@ class VMTemplate(object):
# Current implementation just allows to create disk in one single # storage pool, so we cannot mix the types (scsi volumes vs img file) - if self._get_storage_type() in READONLY_POOL_TYPE: + if self._get_storage_type() == "iscsi": + params['disks'] = self._get_iscsi_disks_xml() + elif self._get_storage_type() in READONLY_POOL_TYPE: params['disks'] = self._get_scsi_disks_xml(kwargs.get('volumes'))
The function self._get_scsi_disks_xml() is specific for scsi, so I suggest to properly update the "if" statement. elif self._get_storage_type() == 'scsi': params['disks'] = self._get_scsi_disks_xml(kwargs.get('volumes')) Also instead of calling self._get_storage_type() twice in the "if" statements, store the value: storage_type = self._get_storage_type() if storage_type == 'iscsi': .... elif storage_type == 'scsi': ....
else: params['disks'] = self._get_disks_xml(vm_uuid)
participants (2)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com