[Kimchi-devel] [PATCH V2 6/7] (WIP) Storagepool SCSI/FC: Create new VM with given SCSI FC LUN (backend)
Aline Manera
alinefm at linux.vnet.ibm.com
Sat Jan 25 23:50:00 UTC 2014
On 01/23/2014 10:29 PM, Rodrigo Trujillo wrote:
> If a user wants to create a VM using a SCSI Fibre Channel storagepool
> (where LUNs are the storagepool volumes), he can assign one of the LUNs
> as the new VM disk, passing the LUN name. This patch implements the
> backend of this feature.
>
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
> docs/API.md | 1 +
> src/kimchi/model.py | 8 +++++++-
> src/kimchi/vmtemplate.py | 14 +++++++++++---
> 3 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/docs/API.md b/docs/API.md
> index d00cdd5..af32ec8 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -55,6 +55,7 @@ the following general conventions:
> Independent Computing Environments
> * null: Graphics is disabled or type not supported
> * listen: The network which the vnc/spice server listens on.
> + * volume *(optional)*: Fibre channel LUN name to be assigned as disk to VM
>
>
> ### Resource: Virtual Machine
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 4a5f344..5546c4f 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -682,7 +682,8 @@ class Model(object):
> xml = t.to_vm_xml(name, vm_uuid,
> libvirt_stream=libvirt_stream,
> qemu_stream_dns=self.qemu_stream_dns,
> - graphics=graphics)
> + graphics=graphics,
> + volume=params.get('volume'))
> try:
> dom = conn.defineXML(xml.encode('utf-8'))
> except libvirt.libvirtError as e:
> @@ -1567,6 +1568,11 @@ class LibvirtVMTemplate(VMTemplate):
> xml = pool.XMLDesc(0)
> return xmlutils.xpath_get_text(xml, "/pool/@type")[0]
>
> + def _get_volume_path(self, volume):
> + pool = self._storage_validate()
> + volxml = pool.storageVolLookupByName(volume).XMLDesc(0)
> + return xmlutils.xpath_get_text(volxml, "/volume/target/path")[0]
> +
> def _get_available_volumes(self):
> pool = self._storage_validate()
> vol_names = pool.listVolumes()
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index d6f807a..5bdaa67 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -181,7 +181,7 @@ class VMTemplate(object):
> graphics_xml = graphics_xml + spicevmc_xml
> return graphics_xml
>
> - def _get_scsi_disks_xml(self):
> + def _get_scsi_disks_xml(self, volume=None):
> ret = ""
> # Passthrough configuration
> disk_xml = """
> @@ -193,7 +193,12 @@ class VMTemplate(object):
> if is_libvirt_version_lesser('1.0.5'):
> disk_xml = disk_xml.replace('volume','block')
> - luns = self._get_available_volumes()
> + # Get a list of available volumes or use which was passed
> + if volume == None:
> + luns = self._get_available_volumes()
If user doesn't pass any volume you need to raise an error
> + else:
> + luns = [(self._get_volume_path(volume),)]
> +
> for i, disk in enumerate(self.info['disks']):
> index = disk.get('index', i)
> try:
> @@ -261,7 +266,7 @@ class VMTemplate(object):
>
> # SCSI FC disk are different
> if self._get_storage_type() == 'scsi':
> - params['disks'] = self._get_scsi_disks_xml()
> + params['disks'] = self._get_scsi_disks_xml(kwargs.get('volume'))
> else:
> params['disks'] = self._get_disks_xml(vm_uuid)
>
> @@ -330,3 +335,6 @@ class VMTemplate(object):
>
> def _get_available_volumes(self):
> return []
> +
> + def _get_volume_path(self, volume):
> + return ''
More information about the Kimchi-devel
mailing list