From d2915f582980c5a58800e6457f21a3a7e79de419 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Mon, 22 Jun 2026 23:10:07 +0200 Subject: [PATCH] fix: extract J-code part numbers in REST API get_facts() path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit api_client.get_facts() now applies the same J-code extraction as the CLI path: product_model "HP2530-8G Switch(J9777A)" → model="HP2530-8G Switch", part_number="J9777A". Co-Authored-By: Claude Sonnet 4.6 --- napalm_procurve/api_client.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/napalm_procurve/api_client.py b/napalm_procurve/api_client.py index 63211f6..be7a921 100644 --- a/napalm_procurve/api_client.py +++ b/napalm_procurve/api_client.py @@ -226,9 +226,24 @@ class ProcurveApiClient: for port in blade.get("data_ports", []): iface_list.append(port.get("port_name", "")) + model_raw = system.get("product_model", "") + # Extract J-code part numbers (e.g. J9777A) from the model string + import re as _re + _PN_RE = _re.compile(r"\b(J\d{4}[A-Z]{1,2})\b") + pn_match = _PN_RE.search(model_raw) + part_number = pn_match.group(1) if pn_match else "" + if pn_match: + clean = _PN_RE.sub("", model_raw) + clean = _re.sub(r"\(\s*\)", "", clean) + clean = _re.sub(r"\s{2,}", " ", clean).strip(" -()") + model = clean if clean else model_raw + else: + model = model_raw + return { "vendor": "HPE Aruba", - "model": system.get("product_model", ""), + "model": model, + "part_number": part_number, "hostname": hostname, "fqdn": fqdn, "os_version": system.get("firmware_version", ""),