-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhardware_cli.py
More file actions
executable file
·37 lines (30 loc) · 1000 Bytes
/
hardware_cli.py
File metadata and controls
executable file
·37 lines (30 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import json
import sys
from boagent.hardware.lshw import Lshw
from click import command, option, ClickException
@command()
@option("--output-file", help="File to output the hardwate data to")
def main(output_file):
try:
lshw = Lshw()
lshw_cpus = lshw.cpus
lshw_ram = lshw.memories
lshw_disks = lshw.disks
except KeyError:
error_message = "Hardware_cli was not executed with privileges, try `sudo ./hardware_cli.py`."
exception = ClickException(error_message)
exception.show()
else:
hardware_data = {}
hardware_data["disks"] = lshw_disks
hardware_data["cpus"] = lshw_cpus
hardware_data["rams"] = lshw_ram
if output_file is not None:
with open(output_file, "w") as fd:
json.dump(hardware_data, fd, indent=4)
else:
json.dump(hardware_data, sys.stdout, indent=4)
return 0
if __name__ == "__main__":
main()