44
44
from qubesadmin .devices import DEVICE_DENY_LIST
45
45
46
46
47
- def prepare_table (dev_list ):
47
+ def prepare_table (dev_list , with_sbdf = False ):
48
48
"""Converts a list of :py:class:`qubes.devices.DeviceInfo` objects to a
49
49
list of tuples for the :py:func:`qubes.tools.print_table`.
50
50
@@ -53,21 +53,35 @@ def prepare_table(dev_list):
53
53
54
54
:param iterable dev_list: List of :py:class:`qubes.devices.DeviceInfo`
55
55
objects.
56
+ :param bool with_sbdf: when True, include SBDF identifier of PCI device
56
57
:returns: list of tuples
57
58
"""
58
59
output = []
59
60
header = []
60
61
if sys .stdout .isatty ():
61
- header += [("BACKEND:DEVID" , "DESCRIPTION" , "USED BY" )] # NOQA
62
+ if with_sbdf :
63
+ header += [("BACKEND:DEVID" , "SBDF" , "DESCRIPTION" , "USED BY" )]
64
+ else :
65
+ header += [("BACKEND:DEVID" , "DESCRIPTION" , "USED BY" )]
62
66
63
67
for line in dev_list :
64
- output += [
65
- (
66
- line .ident ,
67
- line .description ,
68
- str (line .assignments ),
69
- )
70
- ]
68
+ if with_sbdf :
69
+ output += [
70
+ (
71
+ line .ident ,
72
+ line .sbdf ,
73
+ line .description ,
74
+ str (line .assignments ),
75
+ )
76
+ ]
77
+ else :
78
+ output += [
79
+ (
80
+ line .ident ,
81
+ line .description ,
82
+ str (line .assignments ),
83
+ )
84
+ ]
71
85
72
86
return header + sorted (output )
73
87
@@ -81,6 +95,7 @@ def __init__(self, device: DeviceInfo, assignment=False):
81
95
self .description = device .description
82
96
self .assignment = assignment
83
97
self .frontends = []
98
+ self .sbdf = getattr (device , "data" , {}).get ("sbdf" )
84
99
85
100
@property
86
101
def assignments (self ):
@@ -96,6 +111,8 @@ def list_devices(args):
96
111
"""
97
112
Called by the parser to execute the qubes-devices list subcommand."""
98
113
domains = args .domains if hasattr (args , "domains" ) else None
114
+ if args .devclass != "pci" :
115
+ args .with_sbdf = False
99
116
lines = _load_lines (args .app , domains , args .devclass , actual_devices = True )
100
117
lines = list (lines .values ())
101
118
# short command without (list/ls) should print just existing devices
@@ -107,7 +124,9 @@ def list_devices(args):
107
124
args .app , [], args .devclass , actual_devices = False
108
125
)
109
126
lines += list (extra_lines .values ())
110
- qubesadmin .tools .print_table (prepare_table (lines ))
127
+ qubesadmin .tools .print_table (
128
+ prepare_table (lines , with_sbdf = getattr (args , "with_sbdf" ))
129
+ )
111
130
112
131
113
132
def _load_lines (app , domains , devclass , actual_devices : bool ):
@@ -469,6 +488,13 @@ def init_list_parser(sub_parsers):
469
488
"indicated by '*' before qube name." ,
470
489
)
471
490
491
+ list_parser .add_argument (
492
+ "--with-sbdf" ,
493
+ "--resolve-paths" ,
494
+ action = "store_true" ,
495
+ help = "Include resolved PCI path (SBDF) identifier of the PCI "
496
+ "devices; ignored for non-PCI devices" ,
497
+ )
472
498
vm_name_group = qubesadmin .tools .VmNameGroup (
473
499
list_parser ,
474
500
required = False ,
0 commit comments