-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbmc_bios.py
More file actions
65 lines (52 loc) · 2.22 KB
/
bmc_bios.py
File metadata and controls
65 lines (52 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from understack_workflows.bmc import Bmc
from understack_workflows.bmc import RedfishRequestError
from understack_workflows.helpers import setup_logger
logger = setup_logger(__name__)
def required_bios_settings(pxe_interface: str) -> dict:
"""Return adjusted Bios settings map for BMC."""
return {
"PxeDev1EnDis": "Enabled",
"PxeDev1Interface": pxe_interface,
"HttpDev1EnDis": "Enabled",
"HttpDev1Interface": pxe_interface,
# at this time ironic conductor returns http URLs
# when its serving data from its own http server
"HttpDev1TlsMode": "None",
"TimeZone": "UTC",
}
def update_dell_bios_settings(bmc: Bmc, pxe_interface: str) -> dict:
"""Check and update BIOS settings to standard as required.
Any changes take effect on next server reboot.
Returns the changes that were made
"""
current_settings = bmc.redfish_request(bmc.system_path + "/Bios")["Attributes"]
required_settings = required_bios_settings(pxe_interface)
required_changes = {
k: v
for k, v in required_settings.items()
if (k in current_settings and current_settings[k] != v)
}
missing_keys = {k for k in required_settings.keys() if k not in current_settings}
if missing_keys:
logger.info("%s Has no BIOS setting for %s, ignoring.", bmc, missing_keys)
if required_changes:
logger.info("%s Updating BIOS settings: %s", bmc, required_changes)
patch_bios_settings(bmc, required_changes)
logger.info("%s BIOS settings will be updated on next server boot.", bmc)
else:
logger.info("%s No BIOS settings need to be changed.", bmc)
return required_changes
def patch_bios_settings(bmc: Bmc, new_settings: dict):
"""Apply Bios settings to BMC."""
settings_path = f"{bmc.system_path}/Bios/Settings"
payload = {
"@Redfish.SettingsApplyTime": {"ApplyTime": "OnReset"},
"Attributes": new_settings,
}
try:
bmc.redfish_request(settings_path, payload=payload, method="PATCH")
except RedfishRequestError as e:
if "Pending configuration values" in repr(e):
logger.info("%s BIOS settings job already queued, ignoring.", bmc)
return
raise