From 717ffbbd14a8669b32bb4056ba52f01b7f0c25b1 Mon Sep 17 00:00:00 2001 From: George Kraft Date: Tue, 5 Nov 2013 13:55:40 -0600 Subject: CXMAN-236: Add client-side info to tspackage Operating system/distro, tool versions, and python packages --- cxmanage_api/cli/commands/tspackage.py | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/cxmanage_api/cli/commands/tspackage.py b/cxmanage_api/cli/commands/tspackage.py index 10b812d..c10054a 100644 --- a/cxmanage_api/cli/commands/tspackage.py +++ b/cxmanage_api/cli/commands/tspackage.py @@ -41,10 +41,13 @@ import os -import time +import pkg_resources import shutil +import subprocess +import sys import tarfile import tempfile +import time from cxmanage_api.cli import get_tftp, get_nodes, run_command, COMPONENTS @@ -83,6 +86,8 @@ def tspackage_command(args): quiet = args.quiet + write_client_info() + if not quiet: print("Getting version information...") write_version_info(args, nodes) @@ -130,6 +135,36 @@ def tspackage_command(args): shutil.rmtree(temp_dir) +def write_client_info(): + """ Write client-side info """ + with open("client.txt", "w") as fout: + def write_command(command): + """ Safely write output from a single command to the file """ + try: + fout.write(subprocess.check_output( + command, stderr=subprocess.STDOUT, shell=True + )) + except subprocess.CalledProcessError: + pass + + fout.write("[ Operating System ]\n") + fout.write("Operating system: %s\n" % sys.platform) + write_command("lsb_release -a") + write_command("uname -a") + + fout.write("\n[ Tool versions ]\n") + fout.write("Python %s\n" % sys.version.replace("\n", "")) + cxmanage_version = pkg_resources.require("cxmanage")[0].version + fout.write("cxmanage version %s\n" % cxmanage_version) + pyipmi_version = pkg_resources.require("pyipmi")[0].version + fout.write("pyipmi version %s\n" % pyipmi_version) + ipmitool_path = os.environ.get('IPMITOOL_PATH', 'ipmitool') + write_command("%s -V" % ipmitool_path) + + fout.write("\n[ Python packages ]\n") + write_command("pip freeze") + + def write_version_info(args, nodes): """Write the version info (like cxmanage info) for each node to their respective files. -- cgit v1.2.1