[node-patches] Change in ovirt-node[master]: add cpu details button to status screen

jboggs at redhat.com jboggs at redhat.com
Fri Aug 31 17:15:58 UTC 2012


Joey Boggs has uploaded a new change for review.

Change subject: add cpu details button to status screen
......................................................................

add cpu details button to status screen

rhbz#799708

Change-Id: I8d31a8c25de0e1825f7bfe151c030470dad18703
Signed-off-by: Joey Boggs <jboggs at redhat.com>
---
M scripts/ovirt-config-setup.py
M scripts/ovirtnode/ovirtfunctions.py
2 files changed, 94 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/53/7653/1

diff --git a/scripts/ovirt-config-setup.py b/scripts/ovirt-config-setup.py
index 017e5bf..c9e6e67 100755
--- a/scripts/ovirt-config-setup.py
+++ b/scripts/ovirt-config-setup.py
@@ -820,11 +820,15 @@
         help_text = Textbox(62, 1, "Press F8 For Support Menu")
         main_grid.setField(help_text, 0, 4, anchorLeft=1,
                            padding=(0, 0, 0, 0))
-
+        details_grid = Grid(2, 1)
         self.ssh_hostkey_btn = CompactButton("View Host Key")
-        main_grid.setField(self.ssh_hostkey_btn, 0, 5, anchorLeft=1,
+        details_grid.setField(self.ssh_hostkey_btn, 0, 0, anchorLeft=1,
                            padding=(1, 1, 0, 0))
-
+        self.cpu_details_btn = CompactButton("View CPU Details")
+        details_grid.setField(self.cpu_details_btn, 1, 0, anchorLeft=1,
+                           padding=(1, 1, 0, 0))
+        main_grid.setField(details_grid, 0, 5, anchorLeft=1,
+                           padding=(0, 0, 0, 0))
         return [Label(""), main_grid]
 
     def logging_configuration_page(self, screen):
@@ -1891,6 +1895,13 @@
         self.reset_screen_colors()
         self.gridform.draw()
 
+    def cpu_details_btn_cb(self):
+        self._create_warn_screen()
+        ButtonChoiceWindow(self.screen, "CPU Details", cpu_details(),
+                           buttons=['Ok'], width=40)
+        self.reset_screen_colors()
+        self.gridform.draw()
+
     def quit(self):
         manual_teardown()
         sys.exit(2)
@@ -2055,6 +2066,8 @@
                     self.quit()
                 elif (result is self.ssh_hostkey_btn):
                     self.ssh_hostkey_btn_cb()
+                elif (result is self.cpu_details_btn):
+                    self.cpu_details_btn_cb()
 
                 if self.__current_page == LOCKED_PAGE:
                     self.screen_locked = True
diff --git a/scripts/ovirtnode/ovirtfunctions.py b/scripts/ovirtnode/ovirtfunctions.py
index c04352f..06aa549 100644
--- a/scripts/ovirtnode/ovirtfunctions.py
+++ b/scripts/ovirtnode/ovirtfunctions.py
@@ -19,6 +19,7 @@
 
 import subprocess
 from subprocess import Popen, PIPE, STDOUT
+from xml.dom.minidom import parseString
 import os
 import tempfile
 import string
@@ -1234,25 +1235,92 @@
     size = int(size) * multiplier
     return str(size)
 
+def get_cpu_flags():
+    cpuflags_cmd = "cat /proc/cpuinfo |grep ^flags|tail -n 1"
+    cpuflags_lookup = subprocess_closefds(cpuflags_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+    return cpuflags_lookup.stdout.read().strip()
+
+def kvm_enabled():
+    try:
+        conn = libvirt.openReadOnly(None)
+        libvirt_capabilities = conn.getCapabilities()
+    except:
+        return 0
+    if "kvm" in libvirt_capabilities:
+        return 1
+    else:
+        return 2
+
+def virt_cpu_flags_enabled():
+    cpuflags = get_cpu_flags()
+    if "vmx" in cpuflags or "svm" in cpuflags:
+        return True
+    else:
+        return False
+
 def get_virt_hw_status():
     hwvirt_msg = ""
+    kvm_status = kvm_enabled()
+    if kvm_status == 0:
+        return "(Failed to Establish Libvirt Connection)"
+    elif kvm_status == 1:
+        logger.info("Hardware virtualization detected")
+    elif kvm_status == 2:
+        hwvirt_msg = "Virtualization hardware is unavailable."
+        if virt_cpu_flags_enabled():
+            hwvirt_msg = "(Virtualization hardware detected but disabled)"
+        else:
+            hwvirt_msg = "(Virtualization hardware was not detected)"
+    return hwvirt_msg
+
+
+def cpu_details():
+    status_msg = ""
+    cpu_info_cmd = "cat /proc/cpuinfo"
+    cpu_info = subprocess.Popen(cpu_info_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+    cpu_info = cpu_info.stdout.read().strip()
+    cpu_dict = {}
+    for line in cpu_info.splitlines():
+        try:
+            key, value = line.split(":")
+            cpu_dict[key.replace("\t","")] = value
+        except:
+            pass
+    # get capabilities from libvirt
     try:
         conn = libvirt.openReadOnly(None)
         libvirt_capabilities = conn.getCapabilities()
     except:
         return "(Failed to Establish Libvirt Connection)"
-    if "kvm" in libvirt_capabilities:
-        logger.info("Hardware virtualization detected")
+    dom = parseString(libvirt_capabilities)
+    vendorTag = dom.getElementsByTagName('vendor')[0].toxml()
+    modelTag = dom.getElementsByTagName('model')[0].toxml()
+    topologyTag = dom.getElementsByTagName('topology')[0].toxml()
+    cpu_model = modelTag.replace('<model>','').replace('</model>','')
+    cpu_vendor = vendorTag.replace('<vendor>','').replace('</vendor>','')
+    cpu_topology = topologyTag.replace('<topology>','').replace('</topology>','').split()
+    status_msg += "CPU Name: %s\n" % cpu_dict["model name"].replace("  "," ")
+    status_msg += "CPU Type: %s %s\n" % (cpu_vendor, cpu_model)
+    if kvm_enabled() and virt_cpu_flags_enabled():
+        status_msg += "Virtualization Extensions Enabled: Yes\n"
     else:
-        hwvirt_msg = "Virtualization hardware is unavailable."
-        cpuflags_cmd = "cat /proc/cpuinfo |grep ^flags|tail -n 1"
-        cpuflags_lookup = subprocess_closefds(cpuflags_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
-        cpuflags = cpuflags_lookup.stdout.read().strip()
-        if "vmx" in cpuflags or "svm" in cpuflags:
-            hwvirt_msg = "(Virtualization hardware detected but disabled)"
+        status_msg += "Virtualization Extensions Enabled: \n%s\n" \
+            % get_virt_hw_status()
+    if cpu_vendor == "Intel":
+        if "nx" in cpu_dict["flags"]:
+            status_msg += "NX Flag: Yes\n"
         else:
-            hwvirt_msg = "(Virtualization hardware was not detected)"
-    return hwvirt_msg
+            status_msg += "NX Flag: No\n"
+    if cpu_vendor == "AMD":
+        if "evp" in cpu_dict["flags"]:
+            status_msg += "EVP Flag: Yes\n"
+        else:
+            status_msg += "EVP Flag: No\n"
+    cpu_sockets=cpu_topology[2].split("=")[1].replace('"',"")
+    status_msg += "CPU Sockets: %s\n" % cpu_sockets
+    cpu_cores=cpu_topology[1].split("=")[1].replace('"',"")
+    status_msg += "CPU Cores: %s\n" % cpu_cores
+    return status_msg
 
 def get_ssh_hostkey(variant="rsa"):
     fn_hostkey = "/etc/ssh/ssh_host_%s_key.pub" % variant


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d31a8c25de0e1825f7bfe151c030470dad18703
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>



More information about the node-patches mailing list