~launchpad-results/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to lib/lpresults/hardware/interfaces/devicestate.py

  • Committer: Marc Tardif
  • Date: 2011-08-29 09:15:02 UTC
  • Revision ID: marc.tardif@canonical.com-20110829091502-sfl5mwynurpuko1j
Added device states for system units.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
__metaclass__ = type
 
5
 
 
6
__all__ = [
 
7
    "IHasDeviceStates",
 
8
    "IDeviceState",
 
9
    "IDeviceStateSet",
 
10
    "IDeviceStateTarget",
 
11
    "DeviceStateSearchParams",
 
12
    ]
 
13
 
 
14
from zope.interface import Interface
 
15
from zope.schema import Datetime
 
16
 
 
17
from lazr.restful.declarations import (
 
18
    export_as_webservice_entry,
 
19
    exported,
 
20
    export_factory_operation,
 
21
    )
 
22
from lazr.restful.fields import (
 
23
    CollectionField,
 
24
    Reference,
 
25
    )
 
26
from lazr.restful.frameworks.django import IDjangoLocation
 
27
 
 
28
from lpresults.registry.interfaces.search import (
 
29
    ISearchSet,
 
30
    SearchParams,
 
31
    )
 
32
 
 
33
from lpresults.hardware.interfaces.device import IDevice
 
34
from lpresults.hardware.interfaces.devicedriver import IHasDeviceDriver
 
35
 
 
36
 
 
37
class IDeviceState(IDjangoLocation, IDevice, IHasDeviceDriver):
 
38
    """A device state for a particular system unit."""
 
39
 
 
40
    export_as_webservice_entry()
 
41
 
 
42
    date_created = exported(
 
43
        Datetime(
 
44
            title=u"Date created",
 
45
            required=True,
 
46
            readonly=True,
 
47
            description=u"Date on which this device state was created."))
 
48
 
 
49
 
 
50
class IDeviceStateSet(ISearchSet):
 
51
 
 
52
    def add(system_unit, device):
 
53
        """Add a device state and return it."""
 
54
 
 
55
 
 
56
class IHasDeviceStates(Interface):
 
57
    """An entity which has a collection of device states."""
 
58
 
 
59
    states = exported(
 
60
        CollectionField(
 
61
            title=u"List of device states.",
 
62
            value_type=Reference(schema=IDeviceState),
 
63
            readonly=True))
 
64
 
 
65
 
 
66
class IDeviceStateTarget(IHasDeviceStates):
 
67
    """An entity on which a device states can be added.
 
68
 
 
69
    Examples include an ISystemUnit for now.
 
70
    """
 
71
    export_as_webservice_entry()
 
72
 
 
73
    @export_factory_operation(
 
74
        IDeviceState,
 
75
        ["bus_name", "category_name", "product_name", "vendor_name",
 
76
        "product_id", "vendor_id", "subproduct_id", "subvendor_id",
 
77
        "driver_name", "date_created"])
 
78
    def addState(
 
79
        bus_name, category_name=None, product_name=None, vendor_name=None,
 
80
        product_id=None, vendor_id=None, subproduct_id=None,
 
81
        subvendor_id=None, driver_name=None, date_created=None):
 
82
        """Add a new device state on this target."""
 
83
 
 
84
 
 
85
class DeviceStateSearchParams(SearchParams):
 
86
    """Encapsulates search parameters for IDeviceStateSet.search()"""