18
18
# along with this program; if not, write to the Free Software
19
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
20
# USA.
21
- import itertools
21
+ import importlib
22
22
import asyncio
23
23
import subprocess
24
- import sys
25
-
26
- import gbulb
27
24
28
25
import qubes
29
26
30
27
from typing import Type
31
28
32
- from qubes .ext .attachment_confirm import confirm_device_attachment
33
- from qrexec import server
29
+ from qubes import device_protocol
34
30
35
31
36
32
def device_list_change (
@@ -70,6 +66,8 @@ def device_list_change(
70
66
continue
71
67
for assignment in front_vm .devices [devclass ].get_assigned_devices ():
72
68
if (assignment .backend_domain == vm
69
+ and assignment .device_identity
70
+ == assignment .device .self_identity
73
71
and assignment .ident in added
74
72
and assignment .ident not in attached
75
73
):
@@ -79,27 +77,22 @@ def device_list_change(
79
77
80
78
for ident , frontends in to_attach .items ():
81
79
if len (frontends ) > 1 :
82
- guivm = 'dom0' # TODO
83
-
84
- assignment = tuple (frontends .values ())[0 ]
85
-
86
- proc = subprocess .Popen (
87
- ["/home/user/devel/test.py" , guivm ,
88
- assignment .backend_domain .name , assignment .ident ,
89
- * [f .name for f in frontends .keys ()]],
90
- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
91
- (target_name , _ ) = proc .communicate ()
92
- target_name = target_name .decode ()
80
+ device = tuple (frontends .values ())[0 ].device
81
+ target_name = confirm_device_attachment (device , frontends )
93
82
for front in frontends :
94
83
if front .name == target_name :
95
84
target = front
85
+ assignment = frontends [front ]
86
+ # already asked
87
+ if assignment .mode .value == "ask-to-attach" :
88
+ assignment .mode = device_protocol .AssignmentMode .AUTO
96
89
break
97
90
else :
98
- print ("Something really goes bad :/" , file = sys .stderr )
99
91
return
100
92
else :
101
93
target = tuple (frontends .keys ())[0 ]
102
- assignment = frontends [target ]
94
+ assignment = frontends [target ]
95
+
103
96
asyncio .ensure_future (ext .attach_and_notify (target , assignment ))
104
97
105
98
@@ -137,3 +130,17 @@ def compare_device_cache(vm, devices_cache, current_devices):
137
130
if cached_front is not None :
138
131
detached [dev_id ] = cached_front
139
132
return added , attached , detached , removed
133
+
134
+
135
+ def confirm_device_attachment (device , frontends ) -> str :
136
+ guivm = 'dom0' # TODO
137
+ # TODO: guivm rpc?
138
+
139
+ proc = subprocess .Popen (
140
+ ["attach-confirm" , guivm ,
141
+ device .backend_domain .name , device .ident ,
142
+ device .description ,
143
+ * [f .name for f in frontends .keys ()]],
144
+ stdout = subprocess .PIPE , stderr = subprocess .PIPE )
145
+ (target_name , _ ) = proc .communicate ()
146
+ return target_name .decode ()
0 commit comments