diff --git a/cli/main.py b/cli/main.py index 7f73623..6587de8 100644 --- a/cli/main.py +++ b/cli/main.py @@ -113,6 +113,8 @@ def create_args(): help="Query the ECC state of the GPU") argp.add_argument("--query-cc-mode", action='store_true', default=False, help="Query the current Confidential Computing (CC) mode of the GPU.") + argp.add_argument("--output-json-file", + help="Path to write JSON output to for relevant query commands (e.g., --query-cc-mode).") argp.add_argument("--query-cc-settings", action='store_true', default=False, help="Query the Confidential Computing (CC) settings of the GPU." "This prints the lower level setting knobs that will take effect upon GPU reset.") diff --git a/cli/per_gpu.py b/cli/per_gpu.py index c275e4f..8be3a02 100644 --- a/cli/per_gpu.py +++ b/cli/per_gpu.py @@ -21,6 +21,7 @@ # DEALINGS IN THE SOFTWARE. # +import json import os import sys import time @@ -220,7 +221,20 @@ def main_per_gpu(gpu, opts): return False cc_mode = gpu.query_cc_mode() - info(f"{gpu} CC mode is {cc_mode}") + output_data = { + "gpu_bdf": str(gpu.bdf), + "cc_mode": cc_mode + } + print(json.dumps(output_data)) + + if opts.output_json_file: + try: + with open(opts.output_json_file, 'w') as f: + json.dump(output_data, f, indent=4) + info(f"CC mode query result written to {opts.output_json_file}") + except IOError as e: + error(f"Failed to write CC mode query result to {opts.output_json_file}: {e}") + return False if opts.query_bar0_firewall_mode: if not gpu.is_bar0_firewall_supported: