2
# This file is part of Checkbox.
4
# Copyright 2008 Canonical Ltd.
6
# Checkbox is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# Checkbox is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21
from checkbox.lib.dmi import Dmi
22
from checkbox.lib.safe import safe_md5sum
24
from checkbox.properties import String
25
from checkbox.plugin import Plugin
28
class SystemInfo(Plugin):
30
# System ID to exchange information with the server.
31
system_id = String(required=False)
33
def register(self, manager):
34
super(SystemInfo, self).register(manager)
40
("begin-persist", self.begin_persist),
41
("report-dmi", self.report_dmi)]:
42
self._manager.reactor.call_on(rt, rh)
44
# System report should be generated early.
45
self._manager.reactor.call_on("report", self.report, -10)
47
def begin_persist(self, persist):
48
self.persist = persist.root_at("system_info")
50
def report_dmi(self, resources):
51
for resource in resources:
52
if resource.get("category") == "CHASSIS":
53
self.resource = resource
55
# TODO: report this upon gathering
58
system_id = self.system_id
59
elif self.persist and self.persist.has("system_id"):
60
system_id = self.persist.get("system_id")
65
resource = self.resource
66
if resource is None or "product" not in resource:
69
chassis_type = Dmi.chassis_name_to_type[resource["product"]]
71
fingerprint = safe_md5sum()
76
resource.get("vendor", ""),
77
resource.get("model", "")]:
78
fingerprint.update(field)
80
system_id = fingerprint.hexdigest()
82
self.persist.set("system_id", system_id)
85
logging.info("System ID: %s", message)
86
self._manager.reactor.fire("report-system_id", message)