devices: add DeviceInfo.devclass attribute
Have DeviceInfo also carry information about its class, to avoid the need to iterate all the devices to get that information.
This commit is contained in:
parent
f7e9c99a5c
commit
bf240cc928
@ -76,10 +76,12 @@ class DeviceAssignment(object): # pylint: disable=too-few-public-methods
|
|||||||
class DeviceInfo(object):
|
class DeviceInfo(object):
|
||||||
''' Holds all information about a device '''
|
''' Holds all information about a device '''
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
def __init__(self, backend_domain, ident, description=None,
|
def __init__(self, backend_domain, devclass, ident, description=None,
|
||||||
options=None, **kwargs):
|
options=None, **kwargs):
|
||||||
#: domain providing this device
|
#: domain providing this device
|
||||||
self.backend_domain = backend_domain
|
self.backend_domain = backend_domain
|
||||||
|
#: device class
|
||||||
|
self.devclass = devclass
|
||||||
#: device identifier (unique for given domain and device type)
|
#: device identifier (unique for given domain and device type)
|
||||||
self.ident = ident
|
self.ident = ident
|
||||||
#: human readable description/name of the device
|
#: human readable description/name of the device
|
||||||
@ -107,12 +109,12 @@ class UnknownDevice(DeviceInfo):
|
|||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
'''Unknown device - for example exposed by domain not running currently'''
|
'''Unknown device - for example exposed by domain not running currently'''
|
||||||
|
|
||||||
def __init__(self, backend_domain, ident, description=None,
|
def __init__(self, backend_domain, devclass, ident, description=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
if description is None:
|
if description is None:
|
||||||
description = "Unknown device"
|
description = "Unknown device"
|
||||||
super(UnknownDevice, self).__init__(backend_domain, ident, description,
|
super(UnknownDevice, self).__init__(backend_domain, devclass, ident,
|
||||||
**kwargs)
|
description, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class DeviceCollection(object):
|
class DeviceCollection(object):
|
||||||
@ -229,7 +231,8 @@ class DeviceCollection(object):
|
|||||||
info, _, description = info.partition('description=')
|
info, _, description = info.partition('description=')
|
||||||
info_dict = dict(info_single.split('=', 1)
|
info_dict = dict(info_single.split('=', 1)
|
||||||
for info_single in info.split(' ') if info_single)
|
for info_single in info.split(' ') if info_single)
|
||||||
yield DeviceInfo(self._vm, ident, description=description,
|
yield DeviceInfo(self._vm, self._class, ident,
|
||||||
|
description=description,
|
||||||
options=None, **info_dict)
|
options=None, **info_dict)
|
||||||
|
|
||||||
def update_persistent(self, device, persistent):
|
def update_persistent(self, device, persistent):
|
||||||
@ -271,7 +274,7 @@ class DeviceCollection(object):
|
|||||||
return dev
|
return dev
|
||||||
# if still nothing, return UnknownDevice instance for the reason
|
# if still nothing, return UnknownDevice instance for the reason
|
||||||
# explained in docstring, but don't cache it
|
# explained in docstring, but don't cache it
|
||||||
return UnknownDevice(self._vm, item)
|
return UnknownDevice(self._vm, self._class, item)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase):
|
|||||||
('test-vm', 'admin.vm.device.test.Set.persistent', 'test-vm2+dev1',
|
('test-vm', 'admin.vm.device.test.Set.persistent', 'test-vm2+dev1',
|
||||||
b'True')] = b'0\0'
|
b'True')] = b'0\0'
|
||||||
dev = qubesadmin.devices.DeviceInfo(
|
dev = qubesadmin.devices.DeviceInfo(
|
||||||
self.app.domains['test-vm2'], 'dev1')
|
self.app.domains['test-vm2'], 'test', 'dev1')
|
||||||
self.vm.devices['test'].update_persistent(dev, True)
|
self.vm.devices['test'].update_persistent(dev, True)
|
||||||
self.assertAllCalled()
|
self.assertAllCalled()
|
||||||
|
|
||||||
@ -307,6 +307,6 @@ class TC_00_DeviceCollection(qubesadmin.tests.QubesTestCase):
|
|||||||
('test-vm', 'admin.vm.device.test.Set.persistent', 'test-vm2+dev1',
|
('test-vm', 'admin.vm.device.test.Set.persistent', 'test-vm2+dev1',
|
||||||
b'False')] = b'0\0'
|
b'False')] = b'0\0'
|
||||||
dev = qubesadmin.devices.DeviceInfo(
|
dev = qubesadmin.devices.DeviceInfo(
|
||||||
self.app.domains['test-vm2'], 'dev1')
|
self.app.domains['test-vm2'], 'test', 'dev1')
|
||||||
self.vm.devices['test'].update_persistent(dev, False)
|
self.vm.devices['test'].update_persistent(dev, False)
|
||||||
self.assertAllCalled()
|
self.assertAllCalled()
|
||||||
|
Loading…
Reference in New Issue
Block a user