From 5d9481d4f315c5e6296e374904d2f22768b995ec Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Tue, 1 Sep 2026 08:10:36 +0000 Subject: version: T9269: omit hardware details on containers A container has no hardware of its own - vendor, model, serial and UUID are read from /sys/class/dmi/id and thus describe the host system. Listing them below "System type: container" reads as a property of the node. Leave the hardware_* keys unset when running as a container and omit the entire block in both "show version" and the airbag bug report. The latter moves the fields into an optional HARDWARE section, as str.format() has no conditionals. --- python/vyos/airbag.py | 14 +++++++++++--- python/vyos/version.py | 21 ++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'python') diff --git a/python/vyos/airbag.py b/python/vyos/airbag.py index 69b44dc9d..4e7bdfd06 100644 --- a/python/vyos/airbag.py +++ b/python/vyos/airbag.py @@ -78,8 +78,13 @@ def bug_report(dtype, value, trace): note = 'noteworthy:\n' note += '\n'.join(list(_noteworthy)) + hardware = '' + if 'hardware_vendor' in information: + hardware = HARDWARE.format(**information) + information.update({ 'date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + 'hardware': hardware, 'trace': trace, 'instructions': INSTRUCTIONS, 'note': note, @@ -141,14 +146,17 @@ Build commit ID: {build_git} Architecture: {system_arch} Boot via: {boot_via} System type: {system_type} +{hardware} +{trace} +{note} +""" +# Optional section of FAULT - a container has no hardware of its own +HARDWARE = """ Hardware vendor: {hardware_vendor} Hardware model: {hardware_model} Hardware S/N: {hardware_serial} Hardware UUID: {hardware_uuid} - -{trace} -{note} """ INTRO = """\ diff --git a/python/vyos/version.py b/python/vyos/version.py index dcaec8817..50359ddf6 100644 --- a/python/vyos/version.py +++ b/python/vyos/version.py @@ -104,15 +104,18 @@ def get_full_version_data(fname=version_file): boot_via = "installed image" version_data['boot_via'] = boot_via - # Get hardware details from DMI - dmi = '/sys/class/dmi/id' - version_data['hardware_vendor'] = read_file(dmi + '/sys_vendor', 'Unknown') - version_data['hardware_model'] = read_file(dmi +'/product_name','Unknown') - - # These two assume script is run as root, normal users can't access those files - subsystem = '/sys/class/dmi/id/subsystem/id' - version_data['hardware_serial'] = read_file(subsystem + '/product_serial','Unknown') - version_data['hardware_uuid'] = read_file(subsystem + '/product_uuid', 'Unknown') + # Get hardware details from DMI - a container has no hardware of its own and + # would report the DMI data of the host system, thus the keys are left unset + # and consumers are expected to omit them + if not is_running_as_container(): + dmi = '/sys/class/dmi/id' + version_data['hardware_vendor'] = read_file(dmi + '/sys_vendor', 'Unknown') + version_data['hardware_model'] = read_file(dmi +'/product_name','Unknown') + + # These two assume script is run as root, normal users can't access those files + subsystem = '/sys/class/dmi/id/subsystem/id' + version_data['hardware_serial'] = read_file(subsystem + '/product_serial','Unknown') + version_data['hardware_uuid'] = read_file(subsystem + '/product_uuid', 'Unknown') return version_data -- cgit v1.2.3