Skip to content

Commit

Permalink
q-dev: port assignment
Browse files Browse the repository at this point in the history
fix assignment
  • Loading branch information
piotrbartman committed May 26, 2024
1 parent 2e3b1f8 commit de0e882
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc/manpages/qvm-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Assign the device with *DEVICE_ID* from *BACKEND_DOMAIN* to the domain *VMNAME*

Assign device persistently which means it will be required to the qube's startup and then automatically attached.

.. option:: --port

Ignore device presented identity and attach any device connected to the given port number.

aliases: s

unassign
Expand Down
2 changes: 1 addition & 1 deletion qubesadmin/backup/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ def _restore_vms_metadata(self, restore_info):
backend_domain=backend_domain,
ident=ident,
options=options,
required=True)
attach_automatically=True)
try:
if not self.options.verify_only:
new_vm.devices[bus].attach(assignment)
Expand Down
2 changes: 2 additions & 0 deletions qubesadmin/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ def __init__(self, backend_domain, ident, options=None,
required=False, attach_automatically=False):
super().__init__(backend_domain, ident, devclass)
self.__options = options or {}
if required:
assert attach_automatically
self.__required = required
self.__attach_automatically = attach_automatically
self.__frontend_domain = frontend_domain
Expand Down
10 changes: 6 additions & 4 deletions qubesadmin/tests/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,24 @@ def test_021_attach_options(self):
def test_022_attach_required(self):
self.app.expected_calls[
('test-vm', 'admin.vm.device.test.Attach', 'test-vm2+dev1',
b"required='yes' attach_automatically='no' ident='dev1' "
b"required='yes' attach_automatically='yes' ident='dev1' "
b"devclass='test' backend_domain='test-vm2' "
b"frontend_domain='test-vm'")] = b'0\0'
assign = qubesadmin.devices.DeviceAssignment(
self.app.domains['test-vm2'], 'dev1', required=True)
self.app.domains['test-vm2'], 'dev1',
attach_automatically=True, required=True)
self.vm.devices['test'].attach(assign)
self.assertAllCalled()

def test_023_attach_required_options(self):
self.app.expected_calls[
('test-vm', 'admin.vm.device.test.Attach', 'test-vm2+dev1',
b"required='yes' attach_automatically='no' ident='dev1' "
b"required='yes' attach_automatically='yes' ident='dev1' "
b"devclass='test' backend_domain='test-vm2' "
b"frontend_domain='test-vm' _ro='True'")] = b'0\0'
assign = qubesadmin.devices.DeviceAssignment(
self.app.domains['test-vm2'], 'dev1', required=True)
self.app.domains['test-vm2'], 'dev1',
attach_automatically=True, required=True)
assign.options['ro'] = True
self.vm.devices['test'].attach(assign)
self.assertAllCalled()
Expand Down
9 changes: 8 additions & 1 deletion qubesadmin/tools/qvm_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def assign_device(args):
if args.ro:
options['read-only'] = 'yes'
options['identity'] = device.self_identity
if args.port:
options['identity'] = 'any'
assignment.options = options
vm.devices[args.devclass].assign(assignment)
if vm.is_running() and not assignment.attached:
Expand Down Expand Up @@ -378,7 +380,12 @@ def get_parser(device_class=None):
help="Mark device as required so it will "
"be required to the qube's startup and then"
" automatically attached)")

assign_parser.add_argument('--port',
action='store_true',
default=False,
help="Ignore device presented identity and "
"attach any device connected to the given "
"port number")
attach_parser.set_defaults(func=attach_device)
detach_parser.set_defaults(func=detach_device)
assign_parser.set_defaults(func=assign_device)
Expand Down
1 change: 1 addition & 0 deletions qubesadmin/tools/qvm_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def get_drive_assignment(app, drive_str):
backend_domain,
ident,
options=options,
attach_automatically=True,
required=True)

return assignment
Expand Down

0 comments on commit de0e882

Please sign in to comment.