4444from qubesadmin .devices import DEVICE_DENY_LIST
4545
4646
47- def prepare_table (dev_list ):
47+ def prepare_table (dev_list , with_sbdf = False ):
4848 """Converts a list of :py:class:`qubes.devices.DeviceInfo` objects to a
4949 list of tuples for the :py:func:`qubes.tools.print_table`.
5050
@@ -53,21 +53,35 @@ def prepare_table(dev_list):
5353
5454 :param iterable dev_list: List of :py:class:`qubes.devices.DeviceInfo`
5555 objects.
56+ :param bool with_sbdf: when True, include SBDF identifier of PCI device
5657 :returns: list of tuples
5758 """
5859 output = []
5960 header = []
6061 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" )]
6266
6367 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+ ]
7185
7286 return header + sorted (output )
7387
@@ -81,6 +95,7 @@ def __init__(self, device: DeviceInfo, assignment=False):
8195 self .description = device .description
8296 self .assignment = assignment
8397 self .frontends = []
98+ self .sbdf = getattr (device , "data" , {}).get ("sbdf" )
8499
85100 @property
86101 def assignments (self ):
@@ -96,6 +111,8 @@ def list_devices(args):
96111 """
97112 Called by the parser to execute the qubes-devices list subcommand."""
98113 domains = args .domains if hasattr (args , "domains" ) else None
114+ if args .devclass != "pci" :
115+ args .with_sbdf = False
99116 lines = _load_lines (args .app , domains , args .devclass , actual_devices = True )
100117 lines = list (lines .values ())
101118 # short command without (list/ls) should print just existing devices
@@ -107,7 +124,9 @@ def list_devices(args):
107124 args .app , [], args .devclass , actual_devices = False
108125 )
109126 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+ )
111130
112131
113132def _load_lines (app , domains , devclass , actual_devices : bool ):
@@ -469,6 +488,13 @@ def init_list_parser(sub_parsers):
469488 "indicated by '*' before qube name." ,
470489 )
471490
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+ )
472498 vm_name_group = qubesadmin .tools .VmNameGroup (
473499 list_parser ,
474500 required = False ,
0 commit comments