[Kimchi-devel] [PATCH 5/6] Pass libvirt connection as CapabilitiesModel parameter

Daniel Henrique Barboza danielhb at linux.vnet.ibm.com
Thu Nov 13 15:57:17 UTC 2014


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

On 11/11/2014 06:46 PM, Aline Manera wrote:
> CapabilitiesModel depends on libvirt connection to properly run the
> FeatureTests against the right connection.
>
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/host.py           |  3 ++-
>   src/kimchi/model/storagepools.py   |  2 +-
>   src/kimchi/model/storagetargets.py |  2 +-
>   src/kimchi/model/utils.py          | 15 +++++++--------
>   src/kimchi/model/vmhostdevs.py     |  3 ++-
>   src/kimchi/model/vmifaces.py       |  5 ++++-
>   src/kimchi/model/vms.py            | 23 ++++++++++++++---------
>   src/kimchi/model/vmstorages.py     | 16 +++++++++++-----
>   8 files changed, 42 insertions(+), 27 deletions(-)
>
> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
> index 8cddcdc..3b43b95 100644
> --- a/src/kimchi/model/host.py
> +++ b/src/kimchi/model/host.py
> @@ -282,6 +282,7 @@ class PartitionModel(object):
>   class DevicesModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
> +        self.caps = CapabilitiesModel(**kargs)
>           self.cap_map = \
>               {'net': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET,
>                'pci': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV,
> @@ -343,7 +344,7 @@ class DevicesModel(object):
>       def _get_devices_fc_host(self):
>           conn = self.conn.get()
>           # Libvirt < 1.0.5 does not support fc_host capability
> -        if not CapabilitiesModel().fc_host_support:
> +        if not self.caps.fc_host_support:
>               ret = []
>               scsi_hosts = self._get_devices_with_capability('scsi_host')
>               for host in scsi_hosts:
> diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
> index d44e079..20c9e5a 100644
> --- a/src/kimchi/model/storagepools.py
> +++ b/src/kimchi/model/storagepools.py
> @@ -54,7 +54,7 @@ class StoragePoolsModel(object):
>           self.objstore = kargs['objstore']
>           self.scanner = Scanner(self._clean_scan)
>           self.scanner.delete()
> -        self.caps = CapabilitiesModel()
> +        self.caps = CapabilitiesModel(**kargs)
>           self.device = DeviceModel(**kargs)
>
>       def get_list(self):
> diff --git a/src/kimchi/model/storagetargets.py b/src/kimchi/model/storagetargets.py
> index 30717fd..159f987 100644
> --- a/src/kimchi/model/storagetargets.py
> +++ b/src/kimchi/model/storagetargets.py
> @@ -30,7 +30,7 @@ from kimchi.utils import kimchi_log, patch_find_nfs_target
>   class StorageTargetsModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
> -        self.caps = CapabilitiesModel()
> +        self.caps = CapabilitiesModel(**kargs)
>
>       def get_list(self, storage_server, _target_type=None, _server_port=None):
>           target_list = list()
> diff --git a/src/kimchi/model/utils.py b/src/kimchi/model/utils.py
> index d084f74..dc911a9 100644
> --- a/src/kimchi/model/utils.py
> +++ b/src/kimchi/model/utils.py
> @@ -24,7 +24,6 @@ from lxml import etree, objectify
>   from lxml.builder import E, ElementMaker
>
>   from kimchi.exception import OperationFailed
> -from kimchi.model.config import CapabilitiesModel
>   from kimchi.model.featuretests import FeatureTests
>
>   KIMCHI_META_URL = "https://github.com/kimchi-project/kimchi"
> @@ -41,9 +40,9 @@ def get_vm_name(vm_name, t_name, name_list):
>       raise OperationFailed("KCHUTILS0003E")
>
>
> -def check_remote_disk_path(path):
> +def check_remote_disk_path(path, qemu_stream_dns):
>       hostname = urlparse.urlparse(path).hostname
> -    if hostname is not None and not CapabilitiesModel().qemu_stream_dns:
> +    if hostname is not None and not qemu_stream_dns:
>           ip = socket.gethostbyname(hostname)
>           return path.replace(hostname, ip)
>
> @@ -107,10 +106,10 @@ def libvirt_get_kimchi_metadata_node(dom, mode="current"):
>           FeatureTests.enable_libvirt_error_logging()
>
>
> -def set_metadata_node(dom, node, mode="all"):
> -    if CapabilitiesModel().metadata_support:
> +def set_metadata_node(dom, node, metadata_support, mode="all"):
> +    if metadata_support:
>           kimchi = libvirt_get_kimchi_metadata_node(dom, mode)
> -        kimchi = E.kimchi() if kimchi is None else kimchi
> +        kimchi = E.metadata(E.kimchi()) if kimchi is None else kimchi
>
>           update_node(kimchi, node)
>           kimchi_xml = etree.tostring(kimchi)
> @@ -148,8 +147,8 @@ def _kimchi_get_metadata_node(dom, tag):
>       return None
>
>
> -def get_metadata_node(dom, tag, mode="current"):
> -    if CapabilitiesModel().metadata_support:
> +def get_metadata_node(dom, tag, metadata_support, mode="current"):
> +    if metadata_support:
>           kimchi = libvirt_get_kimchi_metadata_node(dom, mode)
>       else:
>           # FIXME remove this code when all distro libvirt supports metadata
> diff --git a/src/kimchi/model/vmhostdevs.py b/src/kimchi/model/vmhostdevs.py
> index 1098f88..964ec49 100644
> --- a/src/kimchi/model/vmhostdevs.py
> +++ b/src/kimchi/model/vmhostdevs.py
> @@ -36,6 +36,7 @@ from kimchi.utils import kimchi_log, run_command
>   class VMHostDevsModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
> +        self.caps = CapabilitiesModel(**kargs)
>
>       def get_list(self, vmid):
>           dom = VMModel.get_vm(vmid, self.conn)
> @@ -161,7 +162,7 @@ class VMHostDevsModel(object):
>           # Due to libvirt limitation, we don't support live assigne device to
>           # vfio driver.
>           driver = ('vfio' if DOM_STATE_MAP[dom.info()[0]] == "shutoff" and
> -                  CapabilitiesModel().kernel_vfio else 'kvm')
> +                  self.caps.kernel_vfio else 'kvm')
>
>           # Attach all PCI devices in the same IOMMU group
>           dev_model = DeviceModel(conn=self.conn)
> diff --git a/src/kimchi/model/vmifaces.py b/src/kimchi/model/vmifaces.py
> index 87ada6d..1206cde 100644
> --- a/src/kimchi/model/vmifaces.py
> +++ b/src/kimchi/model/vmifaces.py
> @@ -23,6 +23,7 @@ import libvirt
>   from lxml import etree, objectify
>
>   from kimchi.exception import InvalidOperation, InvalidParameter, NotFoundError
> +from kimchi.model.config import CapabilitiesModel
>   from kimchi.model.vms import DOM_STATE_MAP, VMModel
>   from kimchi.xmlutils.interface import get_iface_xml
>
> @@ -30,6 +31,7 @@ from kimchi.xmlutils.interface import get_iface_xml
>   class VMIfacesModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
> +        self.caps = CapabilitiesModel(**kargs)
>
>       def get_list(self, vm):
>           macs = []
> @@ -57,7 +59,8 @@ class VMIfacesModel(object):
>               if params['mac'] not in macs:
>                   break
>
> -        os_distro, os_version = VMModel.vm_get_os_metadata(dom)
> +        os_data = VMModel.vm_get_os_metadata(dom, self.caps.metadata_support)
> +        os_distro, os_version = os_data
>           xml = get_iface_xml(params, conn.getInfo()[0], os_distro, os_version)
>           dom.attachDeviceFlags(xml, libvirt.VIR_DOMAIN_AFFECT_CURRENT)
>
> diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
> index 8c10618..7ea948f 100644
> --- a/src/kimchi/model/vms.py
> +++ b/src/kimchi/model/vms.py
> @@ -79,7 +79,7 @@ class VMsModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
>           self.objstore = kargs['objstore']
> -        self.caps = CapabilitiesModel()
> +        self.caps = CapabilitiesModel(**kargs)
>           self.guests_stats_thread = BackgroundTask(GUESTS_STATS_INTERVAL,
>                                                     self._update_guests_stats)
>           self.guests_stats_thread.start()
> @@ -242,7 +242,8 @@ class VMsModel(object):
>               raise OperationFailed("KCHVM0007E", {'name': name,
>                                                    'err': e.get_error_message()})
>
> -        VMModel.vm_update_os_metadata(VMModel.get_vm(name, self.conn), t.info)
> +        VMModel.vm_update_os_metadata(VMModel.get_vm(name, self.conn), t.info,
> +                                      self.caps.metadata_support)
>
>           return name
>
> @@ -260,6 +261,7 @@ class VMModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
>           self.objstore = kargs['objstore']
> +        self.caps = CapabilitiesModel(**kargs)
>           self.vmscreenshot = VMScreenshotModel(**kargs)
>           self.users = import_class('kimchi.model.host.UsersModel')(**kargs)
>           self.groups = import_class('kimchi.model.host.GroupsModel')(**kargs)
> @@ -562,7 +564,8 @@ class VMModel(object):
>           if users is None and groups is None:
>               return
>
> -        access_xml = (get_metadata_node(dom, "access") or
> +        access_xml = (get_metadata_node(dom, "access",
> +                                        self.caps.metadata_support) or
>                         """<access></access>""")
>           old_users = xpath_get_text(access_xml, "/access/user")
>           old_groups = xpath_get_text(access_xml, "/access/group")
> @@ -570,22 +573,23 @@ class VMModel(object):
>           groups = old_groups if groups is None else groups
>
>           node = self._build_access_elem(users, groups)
> -        set_metadata_node(dom, node)
> +        set_metadata_node(dom, node, self.caps.metadata_support)
>
>       @staticmethod
> -    def vm_get_os_metadata(dom):
> -        os_xml = get_metadata_node(dom, "os") or """<os></os>"""
> +    def vm_get_os_metadata(dom, metadata_support):
> +        os_xml = (get_metadata_node(dom, "os", metadata_support) or
> +                  """<os></os>""")
>           os_elem = ET.fromstring(os_xml)
>           return (os_elem.attrib.get("version"), os_elem.attrib.get("distro"))
>
>       @staticmethod
> -    def vm_update_os_metadata(dom, params):
> +    def vm_update_os_metadata(dom, params, metadata_support):
>           distro = params.get("os_distro")
>           version = params.get("os_version")
>           if distro is None:
>               return
>           os_elem = E.os({"distro": distro, "version": version})
> -        set_metadata_node(dom, os_elem)
> +        set_metadata_node(dom, os_elem, metadata_support)
>
>       def _update_graphics(self, dom, xml, params):
>           root = objectify.fromstring(xml)
> @@ -701,7 +705,8 @@ class VMModel(object):
>           res['io_throughput'] = vm_stats.get('disk_io', 0)
>           res['io_throughput_peak'] = vm_stats.get('max_disk_io', 100)
>
> -        access_xml = (get_metadata_node(dom, "access") or
> +        access_xml = (get_metadata_node(dom, "access",
> +                                        self.caps.metadata_support) or
>                         """<access></access>""")
>           users = xpath_get_text(access_xml, "/access/user")
>           groups = xpath_get_text(access_xml, "/access/group")
> diff --git a/src/kimchi/model/vmstorages.py b/src/kimchi/model/vmstorages.py
> index 790766c..95ca6e6 100644
> --- a/src/kimchi/model/vmstorages.py
> +++ b/src/kimchi/model/vmstorages.py
> @@ -23,6 +23,7 @@ from lxml import etree
>
>   from kimchi.exception import InvalidOperation, InvalidParameter, NotFoundError
>   from kimchi.exception import OperationFailed
> +from kimchi.model.config import CapabilitiesModel
>   from kimchi.model.vms import DOM_STATE_MAP, VMModel
>   from kimchi.model.storagevolumes import StorageVolumeModel
>   from kimchi.model.utils import check_remote_disk_path, get_vm_config_flag
> @@ -33,9 +34,9 @@ from kimchi.xmlutils.disk import get_vm_disk_info, get_vm_disks
>   HOTPLUG_TYPE = ['scsi', 'virtio']
>
>
> -def _get_device_bus(dev_type, dom):
> +def _get_device_bus(dev_type, dom, metadata_support):
>       try:
> -        version, distro = VMModel.vm_get_os_metadata(dom)
> +        version, distro = VMModel.vm_get_os_metadata(dom, metadata_support)
>       except:
>           version, distro = ('unknown', 'unknown')
>       return lookup(distro, version)[dev_type+'_bus']
> @@ -45,6 +46,7 @@ class VMStoragesModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
>           self.objstore = kargs['objstore']
> +        self.caps = CapabilitiesModel(**kargs)
>
>       def _get_available_bus_address(self, bus_type, vm_name):
>           if bus_type not in ['ide']:
> @@ -79,7 +81,8 @@ class VMStoragesModel(object):
>               raise InvalidParameter("KCHVMSTOR0017E")
>
>           dom = VMModel.get_vm(vm_name, self.conn)
> -        params['bus'] = _get_device_bus(params['type'], dom)
> +        params['bus'] = _get_device_bus(params['type'], dom,
> +                                        self.caps.metadata_support)
>           params['format'] = 'raw'
>
>           dev_list = [dev for dev, bus in get_vm_disks(dom).iteritems()
> @@ -125,7 +128,8 @@ class VMStoragesModel(object):
>               params['disk'] = vol_info['type']
>
>           params.update(self._get_available_bus_address(params['bus'], vm_name))
> -        params['path'] = check_remote_disk_path(params['path'])
> +        params['path'] = check_remote_disk_path(params['path'],
> +                                                self.caps.qemu_stream_dns)
>
>           # Add device to VM
>           dev, xml = get_disk_xml(params)
> @@ -145,6 +149,7 @@ class VMStoragesModel(object):
>   class VMStorageModel(object):
>       def __init__(self, **kargs):
>           self.conn = kargs['conn']
> +        self.caps = CapabilitiesModel(**kargs)
>
>       def lookup(self, vm_name, dev_name):
>           # Retrieve disk xml and format return dict
> @@ -180,7 +185,8 @@ class VMStorageModel(object):
>           if dev_info['type'] != 'cdrom':
>               raise InvalidOperation("KCHVMSTOR0006E")
>
> -        params['path'] = check_remote_disk_path(params.get('path', ''))
> +        params['path'] = check_remote_disk_path(params.get('path', ''),
> +                                                self.caps.qemu_stream_dns)
>           dev_info.update(params)
>           dev, xml = get_disk_xml(dev_info)
>




More information about the Kimchi-devel mailing list