[Kimchi-devel] [PATCH] Update iSCSI volume XML when creating a VM from an iSCSI pool

Daniel H Barboza danielhb at linux.vnet.ibm.com
Fri Aug 29 10:29:23 UTC 2014


Reviewed-by: Daniel Barboza <danielhb at linux.vnet.ibm.com>

On 08/27/2014 11:44 PM, Aline Manera wrote:
> When creating a VM using a iSCSI volume, the volume XML was like below:
>
> <disk type='volume' device='disk'>
>    <driver name='qemu' type='raw'/>
>    <source pool='TEST-ISCSI1' volume='unit:0:0:2' mode='host'/>
>    <target dev='vda' bus='virtio'/>
>    <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
> </disk>
>
> But to attach a new iSCSI volume, the XML is:
>
> <disk type='block' device='disk'>
>    <driver name='qemu' type='raw'/>
>    <source dev='/dev/disk/by-id/wwn-0x60000000000000000e00000000010001'/>
>    <target dev='vdb' bus='virtio'/>
>    <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
> </disk>
>
> We should keep the same XML structure in both cases to avoid problems
> while listing the storage volumes and getting their information.
> To solve that, this patch uses the latter XML also while creating a VM
> from a iSCSI volume.
>
> It eliminates the needs to have the authentication setting in the
> volume, because that the _get_storage_auth() function was replaced by
> _get_volume_path()
>
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> ---
>   src/kimchi/mockmodel.py       |  3 +++
>   src/kimchi/model/templates.py | 15 ++++++---------
>   src/kimchi/model/vms.py       |  6 +-----
>   src/kimchi/vmtemplate.py      | 16 +++++-----------
>   4 files changed, 15 insertions(+), 25 deletions(-)
>
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index fc474de..1bd54cc 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -997,6 +997,9 @@ class MockVMTemplate(VMTemplate):
>           pool = self._storage_validate()
>           return pool.info['path']
>
> +    def _get_volume_path(self, pool, vol):
> +        return self.model.storagevolume_lookup(pool, vol)['path']
> +
>       def fork_vm_storage(self, vm_name):
>           pool = self._storage_validate()
>           volumes = self.to_volume_list(vm_name)
> diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
> index bf04304..9278cdc 100644
> --- a/src/kimchi/model/templates.py
> +++ b/src/kimchi/model/templates.py
> @@ -29,7 +29,6 @@ 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):
> @@ -243,15 +242,13 @@ class LibvirtVMTemplate(VMTemplate):
>           xml = pool.XMLDesc(0)
>           return xmlutils.xpath_get_text(xml, "/pool/@type")[0]
>
> -    def _get_storage_auth(self):
> +    def _get_volume_path(self, pool, vol):
>           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)
> +        try:
> +            return pool.storageVolLookupByName(vol).path()
> +        except:
> +            raise NotFoundError("KCHVOL0002E", {'name': vol,
> +                                                'pool': pool})
>
>       def fork_vm_storage(self, vm_uuid):
>           # Provision storage:
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index 5721b48..4787840 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -203,11 +203,7 @@ 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 ["iscsi", "scsi"]:
> -            # FIXME: iscsi and scsi storage work with base image needs to be
> -            # fixed.
> -            vol_list = []
> -        else:
> +        if t._get_storage_type() not in ["iscsi", "scsi"]:
>               vol_list = t.fork_vm_storage(vm_uuid)
>
>           graphics = params.get('graphics')
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index ddb1f35..c5bb7b3 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -251,25 +251,19 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/>
>
>       def _get_iscsi_disks_xml(self):
>           def build_disk_xml(children=[]):
> -            disk = E.disk(type='volume', device='disk')
> +            disk = E.disk(type='block', 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')
> +            source = E.source(dev=self._get_volume_path(pool_name,
> +                                                        d.get('volume')))
>               # FIXME if more than 26 disks
>               target = E.target(dev=dev_prefix + string.lowercase[i],
>                                 bus=disk_bus)
> @@ -455,8 +449,8 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/>
>       def _get_storage_type(self):
>           return ''
>
> -    def _get_storage_auth(self):
> -        return None
> +    def _get_volume_path(self):
> +        return ''
>
>       def _get_all_networks_name(self):
>           return []




More information about the Kimchi-devel mailing list