From 3e7c74075b6b0a4641263f09238ce0f6a6600c8c Mon Sep 17 00:00:00 2001 From: Yichen Wang Date: Wed, 25 Feb 2015 16:07:19 -0800 Subject: [PATCH] Adding support to store CPU info Change-Id: I7c305f0b9221ce4f9d559735c498c02110e8dc24 --- requirements-dev.txt | 3 ++- sshutils.py | 23 +++++++++++++++++++++++ vmtp.py | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8da3847..dacaa14 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,7 @@ -r requirements.txt +flake8>=2.3.0 git-review>=1.24 pylint>=1.3 pep8>=1.5.7 -flake8>=2.3.0 sphinx>=1.2.3 +tox>=1.9.0 diff --git a/sshutils.py b/sshutils.py index 5927326..b64cb59 100644 --- a/sshutils.py +++ b/sshutils.py @@ -471,6 +471,28 @@ class SSH(object): release_str = self.get_openstack_release(err_output) return release_str + " (" + ver_str + ")" + def get_cpu_info(self): + ''' + Get the CPU info of the controller. + + Note: Here we are assuming the controller node has the exact + hardware as the compute nodes. + ''' + + cmd = 'cat /proc/cpuinfo | grep -m1 "model name"' + (status, std_output, _) = self.execute(cmd) + if status: + return "Unknown" + model_name = re.search(r":\s(.*)", std_output).group(1) + + cmd = 'cat /proc/cpuinfo | grep "model name" | wc -l' + (status, std_output, _) = self.execute(cmd) + if status: + return "Unknown" + cores = std_output.strip() + + return (cores + " * " + model_name) + ################################################## # Only invoke the module directly for test purposes. Should be @@ -487,6 +509,7 @@ def main(): print ssh.pidof('bash') print ssh.stat('/tmp') print ssh.check_openstack_version() + print ssh.get_cpu_info() if __name__ == "__main__": main() diff --git a/vmtp.py b/vmtp.py index f089927..b5f0be8 100755 --- a/vmtp.py +++ b/vmtp.py @@ -124,6 +124,7 @@ class ResultsCollector(object): if sshcon is not None: self.results['distro'] = sshcon.get_host_os_version() self.results['openstack_version'] = sshcon.check_openstack_version() + self.results['cpu_info'] = sshcon.get_cpu_info() else: print 'ERROR: Cannot connect to the controller node.'