Hello Gal Hammer,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/12723

to review the following change.

Change subject: BZ#737104 Disallow cross-vendor virtualization.
......................................................................

BZ#737104 Disallow cross-vendor virtualization.

Find vendor for all cpu models, including those based on another
cpu module.

danken: I'm suggesting to cherry-pick this change onto the ovirt-3.1
branch, or otherwise vdsm would misbehave with current libvirt versions.
http://lists.ovirt.org/pipermail/users/2013-March/012857.html

Change-Id: Id52f757971e28058257d819036e58e0f1925c44d
Signed-off-by: Gal Hammer <[email protected]>
Reviewed-on: http://gerrit.ovirt.org/5035
Reviewed-by: Dan Kenigsberg <[email protected]>
---
M vdsm/caps.py
1 file changed, 27 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/23/12723/1

diff --git a/vdsm/caps.py b/vdsm/caps.py
index 5c9fa78..fcd7f8a 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -103,20 +103,35 @@
 
     return [ m.firstChild.toxml() for m in 
guestTag.getElementsByTagName('machine') ]
 
+def _getAllCpuModels():
+    cpu_map = minidom.parseString(
+        file('/usr/share/libvirt/cpu_map.xml').read())
+
+    allModels = dict()
+    for m in cpu_map.getElementsByTagName('arch')[0].childNodes:
+        if m.nodeName != 'model':
+            continue
+        element = m.getElementsByTagName('vendor')
+        if element:
+            vendor = element[0].getAttribute('name')
+        else:
+            # If current model doesn't have a vendor, check if it has a model
+            # that it is based on. The models in the cpu_map.xml file are
+            # sorted in a way that the base model is always defined before.
+            element = m.getElementsByTagName('model')
+            if element:
+                vendor = allModels.get(element[0].getAttribute('name'), None)
+            else:
+                vendor = None
+        allModels[m.getAttribute('name')] = vendor
+
+    return allModels
+
 @utils.memoized
 def _getCompatibleCpuModels():
     c = libvirtconnection.get()
-    cpu_map = minidom.parseString(
-                    file('/usr/share/libvirt/cpu_map.xml').read())
-    def vendor(modelElem):
-        vs = modelElem.getElementsByTagName('vendor')
-        if vs:
-            return vs[0].getAttribute('name')
-        else:
-            return None
-    allModels = [ (m.getAttribute('name'), vendor(m)) for m
-          in cpu_map.getElementsByTagName('arch')[0].childNodes
-          if m.nodeName == 'model' ]
+    allModels = _getAllCpuModels()
+
     def compatible(model, vendor):
         if not vendor:
             return False
@@ -133,7 +148,7 @@
             raise
 
     return [ 'model_' + model for (model, vendor)
-             in allModels if compatible(model, vendor) ]
+        in allModels.iteritems() if compatible(model, vendor) ]
 
 def _parseKeyVal(lines, delim='='):
     d = {}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id52f757971e28058257d819036e58e0f1925c44d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.1
Gerrit-Owner: Dan Kenigsberg <[email protected]>
Gerrit-Reviewer: Gal Hammer <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to