diff --git a/es24n_conf.py b/es24n_conf.py index ec22dd3..7b8c2fe 100644 --- a/es24n_conf.py +++ b/es24n_conf.py @@ -604,26 +604,10 @@ def apply_configuration(cfg: ShelfConfig) -> bool: results = [] all_ok = True for iom_cfg in [cfg.iom1, cfg.iom2]: - if iom_cfg.dhcp: - payload = {"DHCPv4": {"DHCPEnabled": True}} - else: - payload = { - "DHCPv4": {"DHCPEnabled": False}, - "IPv4StaticAddresses": [{ - "Address": iom_cfg.ip, - "Gateway": iom_cfg.gateway, - "SubnetMask": iom_cfg.netmask, - }], - } - - path = f"/redfish/v1/Managers/{iom_cfg.iom}/EthernetInterfaces/1" - success, data = _redfish_request(cfg.password, "PATCH", path, payload) - - if success: - mode = "DHCP" if iom_cfg.dhcp else f"Static {iom_cfg.ip}" - results.append([iom_cfg.iom, _c(C.GRN, "OK"), f"Configured: {mode}"]) - else: - results.append([iom_cfg.iom, _c(C.RED, "FAIL"), str(data)[:60]]) + success, detail = _apply_iom(cfg.password, iom_cfg) + status = _c(C.GRN, "OK") if success else _c(C.RED, "FAIL") + results.append([iom_cfg.iom, status, detail]) + if not success: all_ok = False draw_table(["IOM", "Result", "Detail"], results, [6, 8, 50]) @@ -631,6 +615,60 @@ def apply_configuration(cfg: ShelfConfig) -> bool: return all_ok +def _apply_iom(password: str, iom_cfg: IOMConfig) -> tuple: + """ + Apply network config to a single IOM. + + DHCP: single PATCH enabling DHCPv4. + + Static: two sequential PATCHes to work around a firmware bug in the + current ES24N release that prevents disabling DHCP and setting a static + address in the same request. + Pass 1 -- set the static IP/gateway/netmask (DHCP still on) + Pass 2 -- disable DHCP (address is already committed) + """ + path = f"/redfish/v1/Managers/{iom_cfg.iom}/EthernetInterfaces/1" + + if iom_cfg.dhcp: + # DHCP -- single call, no firmware quirk involved + ok_flag, data = _redfish_request( + password, "PATCH", path, + {"DHCPv4": {"DHCPEnabled": True}}, + ) + if ok_flag: + return True, "Configured: DHCP" + return False, str(data)[:80] + + # Static -- Pass 1: set address while DHCP is still enabled + info(f" {iom_cfg.iom} pass 1/2 -- setting static address {iom_cfg.ip}...") + ok_flag, data = _redfish_request( + password, "PATCH", path, + { + "IPv4StaticAddresses": [{ + "Address": iom_cfg.ip, + "Gateway": iom_cfg.gateway, + "SubnetMask": iom_cfg.netmask, + }] + }, + ) + if not ok_flag: + return False, f"Pass 1 failed: {str(data)[:70]}" + + # Brief pause to allow the IOM to commit the address before the next call + time.sleep(1) + + # Static -- Pass 2: disable DHCP now that the static address is committed + info(f" {iom_cfg.iom} pass 2/2 -- disabling DHCP...") + ok_flag, data = _redfish_request( + password, "PATCH", path, + {"DHCPv4": {"DHCPEnabled": False}}, + ) + if not ok_flag: + return False, f"Pass 2 failed: {str(data)[:70]}" + + return True, f"Configured: Static {iom_cfg.ip}" + + # ── Step 5b: Print applied-settings summary ─────────────────────────────────── def print_summary(cfg: ShelfConfig, changed: bool): rule("Summary")