import os
import string
+import _fireinfo
+
import cpu
import device
import hypervisor
id = read_from_file(os.path.join(SYS_CLASS_DMI, file)) or ""
ids.append(id)
+ # Use serial number from root disk (if available)
+ root_disk_serial = self.root_disk_serial
+ if root_disk_serial:
+ ids.append(root_disk_serial)
+
# As last resort, we use the UUID from pakfire.
if not ids:
id = read_from_file("/opt/pakfire/db/uuid") or ""
return
with open(path, "r") as f:
return int(f.readline())*512/1024
+
+ @property
+ def root_disk_serial(self):
+ return _fireinfo.get_harddisk_serial("/dev/%s" % self.root_disk).rstrip()
def scan(self):
toscan = (("/sys/bus/pci/devices", device.PCIDevice),
#include <Python.h>
+#include <fcntl.h>
+#include <linux/hdreg.h>
#include <stdbool.h>
+#include <sys/ioctl.h>
/*
Big parts of this were taken from
}
}
+static void
+read_harddisk_serial(char *device, char *serial) {
+ static struct hd_driveid hd;
+ int fd;
+
+ if ((fd = open(device, O_RDONLY | O_NONBLOCK)) < 0) {
+ return;
+ }
+
+ if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) {
+ strncpy(serial, (const char *)hd.serial_no, sizeof(serial));
+ }
+}
+
static bool
is_virtualized() {
unsigned int eax, ebx, ecx, edx;
return Py_False;
}
+static PyObject *
+do_get_harddisk_serial(PyObject *o, PyObject *args) {
+ /*
+ Python wrapper around read_harddisk_serial.
+ */
+
+ char serial[21];
+ memset(serial, 0, sizeof(serial));
+
+ char *device;
+ if (!PyArg_ParseTuple(args, "s", &device))
+ return NULL;
+
+ read_harddisk_serial(device, serial);
+
+ if (serial[0])
+ return PyString_FromString(serial);
+
+ return Py_None;
+}
+
static PyMethodDef fireinfoModuleMethods[] = {
{ "get_hypervisor", (PyCFunction) do_get_hypervisor, METH_NOARGS, NULL },
{ "is_virtualized", (PyCFunction) do_is_virtualized, METH_NOARGS, NULL },
+ { "get_harddisk_serial", (PyCFunction) do_get_harddisk_serial, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};