--- /dev/null
+#!/usr/bin/python
+
+import _fireinfo
+
+class Hypervisor(object):
+ def __init__(self):
+ self.__info = _fireinfo.get_hypervisor()
+
+ @property
+ def vendor(self):
+ """
+ Returns the name of the hypervisor vendor.
+ """
+ if not self.virtual:
+ return None
+
+ # If the script already returned a hypervisor, we return the name.
+ if self.__info["hypervisor"]:
+ return self.__info["hypervisor"]
+
+ # XXX fill in some code to detect hypervisors, that do
+ # not say their name.
+
+ return "unknown"
+
+ @property
+ def type(self):
+ """
+ Returns if the host is running in full virt mode or
+ if it is running in a paravirtualized environment.
+ """
+ if not self.virtual:
+ return None
+
+ return self.__info["virtype"]
+
+ @property
+ def virtual(self):
+ """
+ Returns true if the host is running in a virtual environment.
+ Otherwise: false.
+ """
+ return _fireinfo.is_virtualized()
+
+
+if __name__ == "__main__":
+ h = Hypervisor()
+
+ print "Vendor:", h.vendor
+ print "Type:", h.type
+ print "Virtual:", h.virtual
import os
import string
-import _fireinfo
import cpu
import device
+import hypervisor
class System(object):
self.devices = []
self.scan()
self.cpu = cpu.CPU()
-
+ self.hypervisor = hypervisor.Hypervisor()
+
def profile(self):
p = {
"public_id" : self.public_id,
"family" : self.cpu.family,
"count" : self.cpu.count
}
-
+
+ # Only append hypervisor information if we are virtualized.
+ if self.virtual:
+ p["hypervisor"] = {
+ "type" : self.hypervisor.type,
+ "vendor" : self.hypervisor.vendor,
+ }
+
return json.dumps(p)
"""
Say if the host is running in a virtual environment.
"""
- return _fireinfo.is_virtualized()
+ return self.hypervisor.virtual
int ncpus; /* number of CPUs */
};
+struct hypervisor_desc {
+ int hyper; /* hypervisor vendor ID */
+ int virtype; /* VIRT_PARA|FULL|NONE ? */
+};
+
static size_t sysrootlen;
static char pathbuf[PATH_MAX];
static int maxcpus; /* size in bits of kernel cpu mask */
: "1" (op), "c"(0));
}
-static void
-read_hypervisor_cpuid(struct lscpu_desc *desc)
+static int
+read_hypervisor_cpuid(struct hypervisor_desc *desc)
{
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
char hyper_vendor_id[13];
#endif
static void
-read_hypervisor(struct lscpu_desc *desc)
+read_hypervisor(struct hypervisor_desc *desc)
{
read_hypervisor_cpuid(desc);
return d;
}
+static PyObject *
+do_get_hypervisor() {
+ /*
+ Get hypervisor from the cpuid command.
+ */
+ struct hypervisor_desc _desc, *desc = &_desc;
+ memset(desc, 0, sizeof(*desc));
+
+ read_hypervisor(desc);
+
+ PyObject *d = PyDict_New();
+ PyObject *o;
+
+ /* Hypervisor */
+ if (desc->hyper == HYPER_NONE) {
+ o = Py_None;
+ } else {
+ o = PyString_FromString((const char *)hv_vendors[desc->hyper]);
+ }
+ PyDict_SetItemString(d, "hypervisor", o);
+
+ /* Virtualization type */
+ if (desc->virtype == VIRT_NONE) {
+ o = Py_None;
+ } else {
+ o = PyString_FromString((const char *)virt_types[desc->virtype]);
+ }
+ PyDict_SetItemString(d, "virtype", o);
+
+ return d;
+}
+
static PyObject *
do_is_virtualized() {
/*
static PyMethodDef fireinfoModuleMethods[] = {
{ "cpuinfo", (PyCFunction) do_cpuinfo, METH_NOARGS, NULL },
+ { "get_hypervisor", (PyCFunction) do_get_hypervisor, METH_NOARGS, NULL },
{ "is_virtualized", (PyCFunction) do_is_virtualized, METH_NOARGS, NULL },
{ NULL, NULL, 0, NULL }
};