fix: extract J-code part numbers in REST API get_facts() path
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2be268a65e
commit
d2915f5829
@@ -226,9 +226,24 @@ class ProcurveApiClient:
|
|||||||
for port in blade.get("data_ports", []):
|
for port in blade.get("data_ports", []):
|
||||||
iface_list.append(port.get("port_name", ""))
|
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 {
|
return {
|
||||||
"vendor": "HPE Aruba",
|
"vendor": "HPE Aruba",
|
||||||
"model": system.get("product_model", ""),
|
"model": model,
|
||||||
|
"part_number": part_number,
|
||||||
"hostname": hostname,
|
"hostname": hostname,
|
||||||
"fqdn": fqdn,
|
"fqdn": fqdn,
|
||||||
"os_version": system.get("firmware_version", ""),
|
"os_version": system.get("firmware_version", ""),
|
||||||
|
|||||||
Reference in New Issue
Block a user