From 5c2c4653a1d7021b41f296d07f983110739297da Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 16 Jun 2022 17:59:53 +0200 Subject: [PATCH] extract system uuid of old snapshots --- examples/extract_uuid.py | 36 ++++++++++++++++++++++++++++++++++++ examples/extract_uuids.sh | 1 + 2 files changed, 37 insertions(+) create mode 100644 examples/extract_uuid.py create mode 100644 examples/extract_uuids.sh diff --git a/examples/extract_uuid.py b/examples/extract_uuid.py new file mode 100644 index 00000000..a283f845 --- /dev/null +++ b/examples/extract_uuid.py @@ -0,0 +1,36 @@ +import json +import sys + + +def get_old_smbios_version(snapshot): + capabilities = snapshot.get('debug', {}).get('lshw', {}).get('capabilities', {}) + for x in capabilities.values(): + if "SMBIOS version" in x: + e = x.split("SMBIOS version ")[1].split(".") + if int(e[0]) < 3 and int(e[1]) < 6: + return True + return False + + +def get_uuid(snapshot): + + return ( + snapshot.get('debug', {}).get('lshw', {}).get('configuration', {}).get('uuid') + ) + + +def main(): + _file = sys.argv[1] + with open(_file) as file_snapshot: + snapshot = json.loads(file_snapshot.read()) + + if get_old_smbios_version(snapshot): + return + + system_uuid = get_uuid(snapshot) + if system_uuid: + print("{};{}".format(system_uuid, snapshot['uuid'])) + + +if __name__ == '__main__': + main() diff --git a/examples/extract_uuids.sh b/examples/extract_uuids.sh new file mode 100644 index 00000000..5068aa8b --- /dev/null +++ b/examples/extract_uuids.sh @@ -0,0 +1 @@ +for i in `ls ../snapshots/*/*.json`; do python examples/extract_uuid.py $i; done > system_uuids.csv