@@ -315,6 +315,7 @@ def tabulate_recs(recs, header):
315315
316316def tabulate_pci_recs (recs ):
317317 header = [
318+ 'device_bus_id' ,
318319 'vendor_name' ,
319320 'vendor_id' ,
320321 'device_name' ,
@@ -338,39 +339,38 @@ def tabulate_cpu_recs(recs):
338339 ]
339340 return tabulate_recs (recs , header )
340341
341- def print_unit (title , content ):
342- print "%s" % title
343- print ""
344- print content
345- print ""
346-
342+ def create_unit (title , content ):
343+ return "\n %s\n \n %s\n " % (str (title ), str (content ))
347344
348345def validate_args (args ):
349346 if args .machine != 'localhost' :
350347 if not args .username or not args .password :
351348 print "Error: you must specify a username and password to query a remote machine."
352349 sys .exit (1 )
353350
354- def print_system_info (host , options ):
351+ def system_info (host , options ):
352+ info = []
355353
356354 if 'bios' in options :
357- print_unit ( "Bios Info:" , rec_to_table (host .get_info ()))
355+ info . append ( create_unit ( "Bios Info:" , rec_to_table (host .get_info () )))
358356
359357 if 'cpu' in options :
360- print_unit ( "CPU Info:" , tabulate_cpu_recs (host .get_cpu_info ()))
358+ info . append ( create_unit ( "CPU Info:" , tabulate_cpu_recs (host .get_cpu_info () )))
361359
362360 if 'nic' in options :
363361 devices = pci_filter_for_nics (host .get_pci_devices ())
364- print_unit ( "Ethernet Controller Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ]))
362+ info . append ( create_unit ( "Ethernet Controller Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ]) ))
365363
366364 if 'storage' in options :
367365 devices = pci_filter_for_storage (host .get_pci_devices ())
368- print_unit ( "Storage Controller Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ]))
366+ info . append ( create_unit ( "Storage Controller Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ]) ))
369367
370368 if 'gpu' in options :
371369 devices = pci_filter_for_gpu (host .get_pci_devices ())
372370 if devices :
373- print_unit ("GPU Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ]))
371+ info .append (create_unit ("GPU Info:" , tabulate_pci_recs ([dev .get_rec () for dev in devices ])))
372+
373+ return "" .join (info ).strip ()
374374
375375def export_system_info (host , options ):
376376 rec = {}
@@ -393,7 +393,7 @@ def export_system_info(host, options):
393393 devices = pci_filter_for_gpu (host .get_pci_devices ())
394394 rec ["gpus" ] = [dev .get_rec () for dev in devices ]
395395
396- print json .dumps (rec , indent = 4 , separators = (',' , ': ' ))
396+ return json .dumps (rec , indent = 4 , separators = (',' , ': ' ))
397397
398398def main ():
399399 """Entry Point"""
@@ -429,6 +429,6 @@ def main():
429429 options = filter_choices
430430
431431 if args .export :
432- export_system_info (host , options )
432+ print export_system_info (host , options )
433433 else :
434- print_system_info (host , options )
434+ print system_info (host , options )
0 commit comments