From 3d10b6d9d82de6489630c5e845d197f7966d3658 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 1 Dec 2010 18:17:57 +0100 Subject: [PATCH] Code for unique id. If we cannot determine a ID, we send "0000...0". --- fireinfo/system.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/fireinfo/system.py b/fireinfo/system.py index aadc3fe..ef63cc1 100644 --- a/fireinfo/system.py +++ b/fireinfo/system.py @@ -129,8 +129,12 @@ class System(object): This returns a globally (hopefully) ID to identify the host later (by request) in the database. """ - return hashlib.sha1(self._unique_id).hexdigest() - + public_id = self._unique_id + if not public_id: + return "0" * 40 + + return hashlib.sha1(public_id).hexdigest() + @property def private_id(self): """ @@ -143,6 +147,9 @@ class System(object): for i in reversed(self._unique_id): private_id += i + if not private_id: + return "0" * 40 + return hashlib.sha1(private_id).hexdigest() @property @@ -153,7 +160,21 @@ class System(object): None of the data here is ever sent to the server. """ - return "123456789" # XXX just a dummy + id = "" + + # Virtual machines (for example) and some boards have a UUID + # which is globally unique. + for file in ("product_uuid", "product_serial", "chassis_serial"): + id = read_from_file(os.path.join(SYS_CLASS_DMI, file)) + if id: + return id + + # As last resort, we use the UUID from pakfire. + id = read_from_file("/opt/pakfire/db/uuid") + if id: + return id + + return "" @property def language(self): -- 2.39.2