1
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
10
from storm.locals import (
16
from zope.interface import implements
18
from lpresults.database.constants import (
22
from lazr.delegates import delegates
24
from lpresults.database.datetime import UTCDateTime
26
from lpresults.hardware.interfaces.device import IDevice
27
from lpresults.hardware.interfaces.devicestate import IDeviceState
28
from lpresults.hardware.models.device import Device
29
from lpresults.hardware.models.devicedriver import DeviceDriver
30
from lpresults.hardware.models.systemunithelper import SystemUnitHelper
33
class DeviceState(SystemUnitHelper):
35
__storm_table__ = "devicestate"
37
implements(IDeviceState)
38
delegates(IDevice, context="device")
40
id = Int(primary=True, allow_none=False, default=AutoReload)
41
system_unit_id = Int(allow_none=False)
42
device_id = Int(allow_none=False)
45
date_created = UTCDateTime(allow_none=False, default=UTC_NOW)
46
date_deleted = UTCDateTime(allow_none=False, default=INFINITY)
48
device = Reference(device_id, Device.id)
49
subdevice = Reference(subdevice_id, Device.id)
50
driver = Reference(driver_id, DeviceDriver.id)
52
def __init__(self, system_unit, device, subdevice=None, driver=None,
54
super(DeviceState, self).__init__(system_unit)
56
self.subdevice = subdevice
59
if date_created is not None:
60
self.date_created = date_created