11#!/usr/bin/env python
22
33from argparse import ArgumentParser
4- from prettytable import PrettyTable
54import paramiko
65import subprocess
76import os
87import sys
98import tarfile
109import tempfile
1110import shutil
11+ import json
12+
13+ from prettytable import PrettyTable
1214
1315from hwinfo .pci import PCIDevice
1416from hwinfo .pci .lspci import *
@@ -152,7 +154,6 @@ def get_info(self):
152154 data = self .get_dmidecode_data ()
153155 parser = dmidecode .DmidecodeParser (data )
154156 rec = parser .parse ()
155- print rec
156157 #Count sockets
157158 if 'socket_designation' in rec :
158159 rec ['socket_count' ] = len (rec ['socket_designation' ].split (',' ))
@@ -371,6 +372,29 @@ def print_system_info(host, options):
371372 if devices :
372373 print_unit ("GPU Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ]))
373374
375+ def export_system_info (host , options ):
376+ rec = {}
377+
378+ if 'bios' in options :
379+ rec ["bios" ] = host .get_info ()
380+
381+ if 'cpu' in options :
382+ rec ["cpu" ] = host .get_cpu_info ()
383+
384+ if 'nic' in options :
385+ devices = pci_filter_for_nics (host .get_pci_devices ())
386+ rec ["nics" ] = [dev .get_rec () for dev in devices ]
387+
388+ if 'storage' in options :
389+ devices = pci_filter_for_storage (host .get_pci_devices ())
390+ rec ["storage_controllers" ] = [dev .get_rec () for dev in devices ]
391+
392+ if 'gpu' in options :
393+ devices = pci_filter_for_gpu (host .get_pci_devices ())
394+ rec ["gpus" ] = [dev .get_rec () for dev in devices ]
395+
396+ print json .dumps (rec , indent = 4 , separators = (',' , ': ' ))
397+
374398def main ():
375399 """Entry Point"""
376400
@@ -382,6 +406,7 @@ def main():
382406 parser .add_argument ("-u" , "--username" , help = "Username for remote host." )
383407 parser .add_argument ("-p" , "--password" , help = "Password for remote host." )
384408 parser .add_argument ("-l" , "--logs" , help = "Path to the directory with the logfiles." )
409+ parser .add_argument ("-e" , "--export" , action = "store_true" , help = "Export result in JSON format." )
385410
386411 args = parser .parse_args ()
387412 validate_args (args )
@@ -400,4 +425,7 @@ def main():
400425 else :
401426 options = filter_choices
402427
403- print_system_info (host , options )
428+ if args .export :
429+ export_system_info (host , options )
430+ else :
431+ print_system_info (host , options )
0 commit comments