Francesco Romani has uploaded a new change for review.
Change subject: virt: devices: move device creation in a submodule ......................................................................
virt: devices: move device creation in a submodule
In the Vm class, the vm devices are arranged in a tree-like structure. This patch moves the related code into a new hwtree module into the vmdevices subpackages.
Change-Id: If17cce15f653843848eea42b567a0e4454757cd1 Signed-off-by: Francesco Romani fromani@redhat.com --- M debian/vdsm.install M vdsm.spec.in M vdsm/virt/vm.py M vdsm/virt/vmdevices/Makefile.am A vdsm/virt/vmdevices/hwtree.py 5 files changed, 63 insertions(+), 23 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/38077/1
diff --git a/debian/vdsm.install b/debian/vdsm.install index cd71517..38bc299 100644 --- a/debian/vdsm.install +++ b/debian/vdsm.install @@ -162,6 +162,7 @@ ./usr/share/vdsm/virt/vmdevices/core.py ./usr/share/vdsm/virt/vmdevices/graphics.py ./usr/share/vdsm/virt/vmdevices/hwclass.py +./usr/share/vdsm/virt/vmdevices/hwtree.py ./usr/share/vdsm/virt/vmdevices/network.py ./usr/share/vdsm/virt/vmdevices/storage.py ./var/lib/polkit-1/localauthority/10-vendor.d/10-vdsm-libvirt-access.pkla diff --git a/vdsm.spec.in b/vdsm.spec.in index 0740530..824dd31 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1073,6 +1073,7 @@ %{_datadir}/%{vdsm_name}/virt/vmdevices/core.py* %{_datadir}/%{vdsm_name}/virt/vmdevices/graphics.py* %{_datadir}/%{vdsm_name}/virt/vmdevices/hwclass.py* +%{_datadir}/%{vdsm_name}/virt/vmdevices/hwtree.py* %{_datadir}/%{vdsm_name}/virt/vmdevices/network.py* %{_datadir}/%{vdsm_name}/virt/vmdevices/storage.py* %{_datadir}/%{vdsm_name}/tool diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index c9ba79b..19be5f2 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -63,6 +63,7 @@ from . import vmexitreason from . import vmstatus from .vmdevices import hwclass +from .vmdevices import hwtree from .vmtune import update_io_tune_dom, collect_inner_elements from .vmtune import io_tune_values_to_dom, io_tune_dom_to_values from . import vmxml @@ -767,23 +768,6 @@ log = logging.getLogger("vm.Vm") # limit threads number until the libvirt lock will be fixed _ongoingCreations = threading.BoundedSemaphore(4) - DeviceMapping = ((hwclass.DISK, vmdevices.storage.Drive), - (hwclass.NIC, vmdevices.network.Interface), - (hwclass.SOUND, vmdevices.core.Sound), - (hwclass.VIDEO, vmdevices.core.Video), - (hwclass.GRAPHICS, vmdevices.graphics.Graphics), - (hwclass.CONTROLLER, vmdevices.core.Controller), - (hwclass.GENERAL, vmdevices.core.Generic), - (hwclass.BALLOON, vmdevices.core.Balloon), - (hwclass.WATCHDOG, vmdevices.core.Watchdog), - (hwclass.CONSOLE, vmdevices.core.Console), - (hwclass.REDIR, vmdevices.core.Redir), - (hwclass.RNG, vmdevices.core.Rng), - (hwclass.SMARTCARD, vmdevices.core.Smartcard), - (hwclass.TPM, vmdevices.core.Tpm)) - - def _makeDeviceDict(self): - return dict((dev, []) for dev, _ in self.DeviceMapping)
def _makeChannelPath(self, deviceName): return constants.P_LIBVIRT_VMCHANNELS + self.id + '.' + deviceName @@ -852,7 +836,7 @@ self.stopDisksStatsCollection() self._vmCreationEvent = threading.Event() self._pathsPreparedEvent = threading.Event() - self._devices = self._makeDeviceDict() + self._devices = hwtree.empty()
self._connection = libvirtconnection.get(cif) if 'vmName' not in self.conf: @@ -968,7 +952,7 @@ Return the "devices" section of this Vm's conf. If missing, create it according to old API. """ - devices = self._makeDeviceDict() + devices = hwtree.empty()
# For BC we need to save previous behaviour for old type parameters. # The new/old type parameter will be distinguished @@ -2189,10 +2173,7 @@ # rebooting it. Evident on, but not limited to, the HE case. self._fixLegacyConf()
- for devType, devClass in self.DeviceMapping: - for dev in devices[devType]: - self._devices[devType].append(devClass(self.conf, self.log, - **dev)) + self._devices = hwtree.build(devices, self.conf, self.log)
# We should set this event as a last part of drives initialization self._pathsPreparedEvent.set() diff --git a/vdsm/virt/vmdevices/Makefile.am b/vdsm/virt/vmdevices/Makefile.am index 71b0573..3678ccd 100644 --- a/vdsm/virt/vmdevices/Makefile.am +++ b/vdsm/virt/vmdevices/Makefile.am @@ -24,6 +24,7 @@ core.py \ graphics.py \ hwclass.py \ + hwtree.py \ network.py \ storage.py \ $(NULL) diff --git a/vdsm/virt/vmdevices/hwtree.py b/vdsm/virt/vmdevices/hwtree.py new file mode 100644 index 0000000..309db22 --- /dev/null +++ b/vdsm/virt/vmdevices/hwtree.py @@ -0,0 +1,56 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +from . import core +from . import hwclass +from . import graphics +from . import network +from . import storage + + +_DEVICE_MAPPING = ( + (hwclass.DISK, storage.Drive), + (hwclass.NIC, network.Interface), + (hwclass.SOUND, core.Sound), + (hwclass.VIDEO, core.Video), + (hwclass.GRAPHICS, graphics.Graphics), + (hwclass.CONTROLLER, core.Controller), + (hwclass.GENERAL, core.Generic), + (hwclass.BALLOON, core.Balloon), + (hwclass.WATCHDOG, core.Watchdog), + (hwclass.CONSOLE, core.Console), + (hwclass.REDIR, core.Redir), + (hwclass.RNG, core.Rng), + (hwclass.SMARTCARD, core.Smartcard), + (hwclass.TPM, core.Tpm)) + + +def empty(): + return dict((dev, []) for dev, _ in _DEVICE_MAPPING) + + +def build(dev_conf, vm_conf, log): + devices = empty() + + for devType, devClass in _DEVICE_MAPPING: + for dev in dev_conf[devType]: + devices[devType].append(devClass(vm_conf, log, **dev)) + + return devices