Skip to content

Commit e481e22

Browse files
committed
q-dev: implementation of attachment confirmation
1 parent d7302f3 commit e481e22

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

qubes/ext/utils.py

+26-19
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@
1818
# along with this program; if not, write to the Free Software
1919
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2020
# USA.
21-
import itertools
21+
import importlib
2222
import asyncio
2323
import subprocess
24-
import sys
25-
26-
import gbulb
2724

2825
import qubes
2926

3027
from typing import Type
3128

32-
from qubes.ext.attachment_confirm import confirm_device_attachment
33-
from qrexec import server
29+
from qubes import device_protocol
3430

3531

3632
def device_list_change(
@@ -70,6 +66,8 @@ def device_list_change(
7066
continue
7167
for assignment in front_vm.devices[devclass].get_assigned_devices():
7268
if (assignment.backend_domain == vm
69+
and assignment.device_identity
70+
== assignment.device.self_identity
7371
and assignment.ident in added
7472
and assignment.ident not in attached
7573
):
@@ -79,27 +77,22 @@ def device_list_change(
7977

8078
for ident, frontends in to_attach.items():
8179
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)
9382
for front in frontends:
9483
if front.name == target_name:
9584
target = front
85+
assignment = frontends[front]
86+
# already asked
87+
if assignment.mode.value == "ask-to-attach":
88+
assignment.mode = device_protocol.AssignmentMode.AUTO
9689
break
9790
else:
98-
print("Something really goes bad :/", file=sys.stderr)
9991
return
10092
else:
10193
target = tuple(frontends.keys())[0]
102-
assignment = frontends[target]
94+
assignment = frontends[target]
95+
10396
asyncio.ensure_future(ext.attach_and_notify(target, assignment))
10497

10598

@@ -137,3 +130,17 @@ def compare_device_cache(vm, devices_cache, current_devices):
137130
if cached_front is not None:
138131
detached[dev_id] = cached_front
139132
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

Comments
 (0)