fix: only parse HP/Aruba banner lines in parse_model_from_version
Guard against show version outputs that start with "Image stamp:" or
other non-banner lines — return ("", "") when the first line doesn't
begin with HP/HPE/Aruba.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
da5920a9bc
commit
ff37f3c59f
@@ -195,11 +195,18 @@ def parse_model_from_version(output: str) -> tuple[str, str]:
|
|||||||
``HP J9565A 2520G-8-PoE Switch`` → ("2520G-8-PoE", "J9565A")
|
``HP J9565A 2520G-8-PoE Switch`` → ("2520G-8-PoE", "J9565A")
|
||||||
``HP J9298A Switch 2520G-8-PoE`` → ("2520G-8-PoE", "J9298A")
|
``HP J9298A Switch 2520G-8-PoE`` → ("2520G-8-PoE", "J9298A")
|
||||||
``Aruba 2530-8-PoE+ Switch`` → ("2530-8-PoE+", "")
|
``Aruba 2530-8-PoE+ Switch`` → ("2530-8-PoE+", "")
|
||||||
|
|
||||||
|
Returns ("", "") when the first line is not an HP/Aruba device banner
|
||||||
|
(e.g. when show version starts with "Image stamp:" on newer Aruba).
|
||||||
"""
|
"""
|
||||||
first = output.strip().splitlines()[0] if output.strip() else ""
|
first = output.strip().splitlines()[0] if output.strip() else ""
|
||||||
if not first:
|
if not first:
|
||||||
return "", ""
|
return "", ""
|
||||||
|
|
||||||
|
# Only process lines that start with an HP/Aruba product banner
|
||||||
|
if not re.match(r"\s*(?:HP|HPE|Aruba)\b", first, re.I):
|
||||||
|
return "", ""
|
||||||
|
|
||||||
# Extract J-code part number
|
# Extract J-code part number
|
||||||
_PN_RE_V = re.compile(r"\b(J\d{4}[A-Z]{1,2})\b")
|
_PN_RE_V = re.compile(r"\b(J\d{4}[A-Z]{1,2})\b")
|
||||||
pn_match = _PN_RE_V.search(first)
|
pn_match = _PN_RE_V.search(first)
|
||||||
|
|||||||
Reference in New Issue
Block a user