Change in vdsm[master]: virt: do not access devices directly outside Vm

fromani at redhat.com fromani at redhat.com
Mon Jun 9 07:55:52 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: virt: do not access devices directly outside Vm
......................................................................

virt: do not access devices directly outside Vm

VmStatsThread used to access directly the _devices and conf
fields of vm.Vm.
This patch does a little cleanup by introducing helper getters
to mediate the access to the devices for the Vm clients,
VmStatsThread being the first.

this patch add little benefit on its own but paves the road
to extract VmStatsThread from vm.py and put it in sampling.py.

Change-Id: I4313da06153fd9f2db90315d16b242352a127d01
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 20 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/28478/1

diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index fabd0db..0e6f291 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -205,7 +205,7 @@
             # Avoid queries from storage during recovery process
             return
 
-        for vmDrive in self._vm._devices[DISK_DEVICES]:
+        for vmDrive in self._vm.getDiskDevices():
             self._vm.updateDriveVolume(vmDrive)
 
     def _sampleCpu(self):
@@ -218,7 +218,7 @@
             return
 
         diskSamples = {}
-        for vmDrive in self._vm._devices[DISK_DEVICES]:
+        for vmDrive in self._vm.getDiskDevices():
             diskSamples[vmDrive.name] = self._vm._dom.blockStats(vmDrive.name)
 
         return diskSamples
@@ -232,14 +232,14 @@
         # 'rd_bytes': 85172430L, 'flush_operations': 0L,
         # 'wr_operations': 0L, 'wr_bytes': 0L}
         diskLatency = {}
-        for vmDrive in self._vm._devices[DISK_DEVICES]:
+        for vmDrive in self._vm.getDiskDevices():
             diskLatency[vmDrive.name] = self._vm._dom.blockStatsFlags(
                 vmDrive.name, flags=libvirt.VIR_TYPED_PARAM_STRING_OKAY)
         return diskLatency
 
     def _sampleNet(self):
         netSamples = {}
-        for nic in self._vm._devices[NIC_DEVICES]:
+        for nic in self._vm.getNicDevices():
             netSamples[nic.name] = self._vm._dom.interfaceStats(nic.name)
         return netSamples
 
@@ -281,9 +281,8 @@
 
         sInfo, eInfo, sampleInterval = self.sampleBalloon.getStats()
 
-        for dev in self._vm.conf['devices']:
-            if dev['type'] == BALLOON_DEVICES and \
-                    dev['specParams']['model'] != 'none':
+        for dev in self._vm.getBalloonDevicesConf():
+            if dev['specParams']['model'] != 'none':
                 balloon_target = dev.get('target', max_mem)
                 break
         else:
@@ -330,7 +329,7 @@
         if sInfo is None:
             return
 
-        for nic in self._vm._devices[NIC_DEVICES]:
+        for nic in self._vm.getNicDevices():
             if nic.name.startswith('hostdev'):
                 continue
 
@@ -345,7 +344,7 @@
     def _getDiskStats(self, stats):
         sInfo, eInfo, sampleInterval = self.sampleDisk.getStats()
 
-        for vmDrive in self._vm._devices[DISK_DEVICES]:
+        for vmDrive in self._vm.getDiskDevices():
             dName = vmDrive.name
             dStats = {}
             try:
@@ -393,7 +392,7 @@
                 'writeLatency': str(writeLatency),
                 'flushLatency': str(flushLatency)}
 
-        for vmDrive in self._vm._devices[DISK_DEVICES]:
+        for vmDrive in self._vm.getDiskDevices():
             dName = vmDrive.name
             dLatency = {'readLatency': '0',
                         'writeLatency': '0',
@@ -5069,6 +5068,17 @@
             if dev.get('type') == GRAPHICS_DEVICES:
                 return dev
 
+    def getDiskDevices(self):
+        return self._devices[DISK_DEVICES]
+
+    def getNicDevices(self):
+        return self._devices[NIC_DEVICES]
+
+    def getBalloonDevicesConf(self):
+        for dev in self.conf['devices']:
+            if dev['type'] == BALLOON_DEVICES:
+                yield dev
+
 
 def _getNetworkIp(network):
     try:


-- 
To view, visit http://gerrit.ovirt.org/28478
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4313da06153fd9f2db90315d16b242352a127d01
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list