Add GPU PCI ID fallback names and container passthrough indicators
All checks were successful
Build-Publish / build (linux/amd64) (push) Successful in 7s
Build-Publish / build (linux/arm64) (push) Successful in 15s
Build-Publish / create-manifest (push) Successful in 2s
Build-Publish / publish-template (push) Successful in 9s

This commit is contained in:
j
2026-03-21 08:58:46 +13:00
parent db5cbf99e1
commit bf7f0d44ba
5 changed files with 121 additions and 5 deletions

View File

@@ -738,6 +738,19 @@ def temp_color(temp_c):
return '#22c55e'
# Fallback lookup for GPUs with vague lspci names (outdated pciid database)
_GPU_PCI_FALLBACK = {
# Intel Arc Battlemage
'e20b': 'Intel Arc B580',
'e20c': 'Intel Arc B570',
# Intel Arc Alchemist
'56a0': 'Intel Arc A770',
'56a1': 'Intel Arc A770',
'56a5': 'Intel Arc A580',
'56a6': 'Intel Arc A380',
}
@app.template_filter('clean_gpu')
def clean_gpu(description):
if not description:
@@ -745,6 +758,14 @@ def clean_gpu(description):
s = str(description)
import re
# Extract PCI device ID from lspci -nn output (e.g. [8086:e20b])
pci_id_match = re.search(r'\[([0-9a-f]{4}):([0-9a-f]{4})\]', s, flags=re.IGNORECASE)
pci_device_id = pci_id_match.group(2).lower() if pci_id_match else None
# Remove PCI class and device ID brackets
s = re.sub(r'\s*\[[0-9a-f]{4}:[0-9a-f]{4}\]', '', s, flags=re.IGNORECASE)
s = re.sub(r'\s*\[[0-9a-f]{4}\]', '', s, flags=re.IGNORECASE)
# Strip PCI address prefix (e.g. "01:00.0 ")
s = re.sub(r'^[0-9a-f:.]+\s+', '', s, flags=re.IGNORECASE)
# Strip type prefix
@@ -786,6 +807,14 @@ def clean_gpu(description):
# Remove trailing whitespace
s = s.strip()
# If the name is too vague, try PCI device ID fallback
if pci_device_id:
vague = not s or s.lower() in ('graphics',) or s.lower().startswith('device ')
if vague:
fallback = _GPU_PCI_FALLBACK.get(pci_device_id)
if fallback:
return fallback
# Don't duplicate manufacturer if already in the model name
if manufacturer and s:
s_check = s.lower()
@@ -795,6 +824,44 @@ def clean_gpu(description):
return s or '-'
def _normalize_pci(addr):
"""Normalize PCI address to bus:device for matching (strip domain and function)."""
if not addr:
return ''
addr = str(addr).strip()
# Strip domain prefix (0000:)
if addr.count(':') == 2:
addr = addr.split(':', 1)[1]
# Strip function suffix (.0)
return addr.split('.')[0].lower()
@app.template_filter('gpu_passthrough_map')
def gpu_passthrough_map(details):
"""Build mapping of normalized PCI address -> container name for GPU passthrough."""
if not details:
return {}
mapping = {}
containers = details.get('container', [])
if not containers:
return {}
for c in containers:
pt = c.get('gpu_passthrough', '')
if not pt:
continue
name = c.get('name', c.get('_name', '?'))
for pci_addr in pt.split(','):
normalized = _normalize_pci(pci_addr)
if normalized:
mapping.setdefault(normalized, []).append(name)
return mapping
@app.template_filter('normalize_pci')
def normalize_pci_filter(addr):
return _normalize_pci(addr)
@app.template_filter('usage_color')
def usage_color(percent):
try: