Skip to content

Commit f42d1ce

Browse files
committed
enrol: configure DNS and NTP on our BMCs
1 parent 003085b commit f42d1ce

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

python/understack-workflows/understack_workflows/bmc_settings.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import logging
22

33
from understack_workflows.bmc import Bmc
4+
import os
45

56
logger = logging.getLogger(__name__)
67

7-
# When we read Enum-type keys we can expect a string like "Enabled".
8-
#
9-
# To change that key requires the numeric new_value string like "1".
10-
STANDARD = {
11-
"SNMP.1.AgentEnable": {"expect": "Enabled", "new_value": "1"},
12-
"SNMP.1.SNMPProtocol": {"expect": "All", "new_value": "0"},
13-
"SNMP.1.AgentCommunity": {"expect": "public", "new_value": "public"},
14-
"SNMP.1.AlertPort": {"expect": 161, "new_value": 161},
15-
"SwitchConnectionView.1.Enable": {"expect": "Enabled", "new_value": "Enabled"},
8+
REQUIRED_VALUES = {
9+
"SNMP.1.AgentEnable": "Enabled",
10+
"SNMP.1.SNMPProtocol": "All",
11+
"SNMP.1.AgentCommunity": "public",
12+
"SNMP.1.AlertPort": 161,
13+
"SwitchConnectionView.1.Enable": "Enabled",
14+
"NTPConfigGroup.1.NTPEnable": "Enabled",
15+
"Time.1.Timezone": "Zulu",
16+
"IPv4.1.DNS1": os.getenv("DNS_SERVER_IPV4_ADDR_1"),
17+
"IPv4.1.DNS2": os.getenv("DNS_SERVER_IPV4_ADDR_2"),
18+
"NTPConfigGroup.1.NTP1": os.getenv("NTP_SERVER_IPV4_ADDR_1"),
19+
"NTPConfigGroup.1.NTP2": os.getenv("NTP_SERVER_IPV4_ADDR_2"),
20+
}
21+
22+
# When we GET Enum-type keys we can expect a string like "Enabled".
23+
# To change that key requires us to POST the numeric string like "1".
24+
VALUES_TO_POST = REQUIRED_VALUES | {
25+
"SNMP.1.AgentEnable": "1",
26+
"SNMP.1.SNMPProtocol": "0",
1627
}
1728

1829

@@ -28,20 +39,21 @@ def update_dell_drac_settings(bmc: Bmc) -> dict:
2839
attribute_path = bmc.manager_path + "/Attributes"
2940
current_values = bmc.redfish_request(attribute_path)["Attributes"]
3041

31-
for key, _value in STANDARD.items():
32-
if key not in current_values:
33-
raise BiosSettingException(f"{bmc} has no BMC attribute {key}")
34-
35-
required_changes = {
36-
k: x["new_value"]
37-
for k, x in STANDARD.items()
38-
if current_values[k] != x["expect"]
39-
}
42+
required_changes = {}
43+
for key, required_value in REQUIRED_VALUES.items():
44+
if not required_value:
45+
logger.warning("There is no value set for BMC attribute '%s'", key)
46+
elif key not in current_values:
47+
logger.warning("%s has no BMC attribute '%s'", bmc, key)
48+
elif current_values[key] == required_value:
49+
logger.info("%s has BMC attribute '%s' is already set to '%s'", bmc, key, required_value)
50+
else:
51+
required_changes[key] = VALUES_TO_POST[key]
4052

4153
if required_changes:
4254
logger.info("%s Updating DRAC settings:", bmc)
4355
for k in required_changes.keys():
44-
logger.info(" %s: %s->%s", k, current_values[k], STANDARD[k]["expect"])
56+
logger.info(" %s: %s->%s", k, current_values[k], REQUIRED_VALUES[k])
4557

4658
payload = {"Attributes": required_changes}
4759
bmc.redfish_request(attribute_path, payload=payload, method="PATCH")

0 commit comments

Comments
 (0)