Skip to content

Commit b03800d

Browse files
marmartapiotrbartman
authored andcommitted
A proposal for new devices API
This is not a working API, this is just a proposal for it. references QubesOS/qubes-issues#4626
1 parent 0572987 commit b03800d

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

qubesadmin/devices.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ class is implemented by an extension.
3131
:py:class:`str`.
3232
"""
3333

34+
# TODO:
35+
# Proposed device events:
36+
# - device-list-changed: device-added
37+
# - device-list-changed: device-remove
38+
# - device-property-changed: property_name
39+
# - device-assignment-changed: created
40+
# - device-assignment-changed: removed
41+
# - device-assignment-changed: attached
42+
# - device-assignment-changed: detached
43+
# - device-assignment-changed: property-set [? this is not great]
44+
3445

3546
class DeviceAssignment(object): # pylint: disable=too-few-public-methods
3647
""" Maps a device to a frontend_domain. """
@@ -73,6 +84,54 @@ def device(self):
7384
"""Get DeviceInfo object corresponding to this DeviceAssignment"""
7485
return self.backend_domain.devices[self.devclass][self.ident]
7586

87+
#### NEW API
88+
@property
89+
def backend_domain(self):
90+
"""
91+
Which domain provides this device
92+
:return: VM
93+
"""
94+
95+
@property
96+
def frontend_domain(self):
97+
"""
98+
Which domain the device is attached to.
99+
:return:
100+
"""
101+
102+
@property
103+
def device_id(self):
104+
"""
105+
Per-backend-qube unique device identifier
106+
:return: str
107+
"""
108+
109+
@property
110+
def required(self):
111+
"""
112+
Is the presence of this device required for the domain to start? If yes,
113+
it will be attached automatically.
114+
TODO: this possibly should not be available for usb device? or always False?
115+
TODO: this is a reworking of the previously existing "persistent" attachment, split in two option
116+
:return: bool
117+
"""
118+
119+
@property
120+
def attach_automatically(self):
121+
"""
122+
Should this device automatically connect to the frontend domain when
123+
available and not connected to other qubes?
124+
TODO: this possibly should not be available for usb device? or always False?
125+
TODO: this is a reworking of the previously existing "persistent" attachment, split in two option
126+
:return: bool
127+
"""
128+
129+
@property
130+
def options(self):
131+
"""
132+
Device options (same as in the old API)5
133+
:return: Dict[str, Any]
134+
"""
76135

77136
class DeviceInfo(object):
78137
""" Holds all information about a device """
@@ -106,6 +165,72 @@ def __eq__(self, other):
106165
def __str__(self):
107166
return '{!s}:{!s}'.format(self.backend_domain, self.ident)
108167

168+
### NEW API
169+
@property
170+
def manufacturer(self):
171+
"""
172+
Device manufacturer
173+
:return: str
174+
"""
175+
176+
@property
177+
def name(self):
178+
"""
179+
Device name
180+
:return: str
181+
"""
182+
183+
@property
184+
def devtype(self):
185+
"""
186+
Type of device, such as "USB Camera", "USB Keyboard", "Microphone" etc.
187+
:return: str
188+
"""
189+
# TODO: perhaps this should be an Enum of possible types?
190+
191+
@property
192+
def devclass(self):
193+
"""
194+
Device class, for compatibility with previous API:
195+
:return: str, one of 'usb', 'pci', 'mic'
196+
"""
197+
198+
@property
199+
def id(self):
200+
"""
201+
Device id (unique per backend qube)
202+
:return: str
203+
"""
204+
205+
@property
206+
def parent_device(self):
207+
"""
208+
If the device is part of another device (e.g. it's a single
209+
partition of a usb stick), the parent device id should be here
210+
:return: Optional[str]
211+
"""
212+
213+
@property
214+
def backend_domain(self):
215+
"""
216+
Which domain provides this device.
217+
:return: VM
218+
"""
219+
220+
@property
221+
def port_id(self):
222+
"""
223+
Which port the device is connected to.
224+
:return: str
225+
"""
226+
227+
@property
228+
def attachments(self):
229+
"""
230+
Device attachments
231+
:return: List[DeviceAssignment]
232+
"""
233+
109234

110235
class UnknownDevice(DeviceInfo):
111236
# pylint: disable=too-few-public-methods

0 commit comments

Comments
 (0)