]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Code for unique id.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Dec 2010 17:17:57 +0000 (18:17 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Dec 2010 17:17:57 +0000 (18:17 +0100)
If we cannot determine a ID, we send "0000...0".

fireinfo/system.py

index aadc3fe5d61b1c58f8e9b7978039296a29e61fab..ef63cc1fbf74538e30cf38ab7f60dfb495b2b999 100644 (file)
@@ -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):