From e5d6c4e0780fd5baf6fff13b0ea5032bdbc6c448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 18 Aug 2016 14:05:07 +0200 Subject: [PATCH] qubes/devices: allow non-persistent attach QubesOS/qubes-issues#2257 --- qubes/devices.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qubes/devices.py b/qubes/devices.py index 94ce5e7f..28f63c61 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -113,7 +113,7 @@ class DeviceCollection(object): self.devclass = qubes.utils.get_entry_point_one( 'qubes.devices', self._class) - def attach(self, device): + def attach(self, device, persistent=True): '''Attach (add) device to domain. :param DeviceInfo device: device object @@ -124,11 +124,12 @@ class DeviceCollection(object): 'device {!r} of class {} already attached to {!r}'.format( device, self._class, self._vm)) self._vm.fire_event_pre('device-pre-attach:' + self._class, device) - self._set.add(device) + if persistent: + self._set.add(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. :param DeviceInfo device: device object @@ -139,7 +140,8 @@ class DeviceCollection(object): 'device {!r} of class {} not attached to {!r}'.format( device, self._class, self._vm)) self._vm.fire_event_pre('device-pre-detach:' + self._class, device) - self._set.remove(device) + if persistent: + self._set.remove(device) self._vm.fire_event('device-detach:' + self._class, device) def attached(self, persistent=None):