qubes/devices: allow non-persistent attach

QubesOS/qubes-issues#2257
This commit is contained in:
Marek Marczykowski-Górecki 2016-08-18 14:05:07 +02:00
parent 70d3f58024
commit e5d6c4e078
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -113,7 +113,7 @@ class DeviceCollection(object):
self.devclass = qubes.utils.get_entry_point_one( self.devclass = qubes.utils.get_entry_point_one(
'qubes.devices', self._class) 'qubes.devices', self._class)
def attach(self, device): def attach(self, device, persistent=True):
'''Attach (add) device to domain. '''Attach (add) device to domain.
:param DeviceInfo device: device object :param DeviceInfo device: device object
@ -124,11 +124,12 @@ class DeviceCollection(object):
'device {!r} of class {} already attached to {!r}'.format( 'device {!r} of class {} already attached to {!r}'.format(
device, self._class, self._vm)) device, self._class, self._vm))
self._vm.fire_event_pre('device-pre-attach:' + self._class, device) self._vm.fire_event_pre('device-pre-attach:' + self._class, device)
if persistent:
self._set.add(device) self._set.add(device)
self._vm.fire_event('device-attach:' + self._class, device) self._vm.fire_event('device-attach:' + self._class, device)
def detach(self, device): def detach(self, device, persistent=True):
'''Detach (remove) device from domain. '''Detach (remove) device from domain.
:param DeviceInfo device: device object :param DeviceInfo device: device object
@ -139,6 +140,7 @@ class DeviceCollection(object):
'device {!r} of class {} not attached to {!r}'.format( 'device {!r} of class {} not attached to {!r}'.format(
device, self._class, self._vm)) device, self._class, self._vm))
self._vm.fire_event_pre('device-pre-detach:' + self._class, device) self._vm.fire_event_pre('device-pre-detach:' + self._class, device)
if persistent:
self._set.remove(device) self._set.remove(device)
self._vm.fire_event('device-detach:' + self._class, device) self._vm.fire_event('device-detach:' + self._class, device)