-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbmc_settings.py
More file actions
65 lines (51 loc) · 2.14 KB
/
bmc_settings.py
File metadata and controls
65 lines (51 loc) · 2.14 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
import logging
import os
from understack_workflows.bmc import Bmc
logger = logging.getLogger(__name__)
REQUIRED_VALUES = {
"SNMP.1.AgentEnable": "Enabled",
"SNMP.1.SNMPProtocol": "All",
"SNMP.1.AgentCommunity": "public",
"SNMP.1.AlertPort": 161,
"SwitchConnectionView.1.Enable": "Enabled",
"NTPConfigGroup.1.NTPEnable": "Disabled",
"Time.1.Timezone": "UTC",
"IPv4.1.DNS1": os.getenv("DNS_SERVER_IPV4_ADDR_1"),
"IPv4.1.DNS2": os.getenv("DNS_SERVER_IPV4_ADDR_2"),
}
# When we GET Enum-type keys we can expect a string like "Enabled".
# To change that key requires us to POST the numeric string like "1".
VALUES_TO_POST = REQUIRED_VALUES | {
"SNMP.1.AgentEnable": "1",
"SNMP.1.SNMPProtocol": "0",
}
class BiosSettingException(Exception):
"""Exception when a required key are not present."""
def update_dell_drac_settings(bmc: Bmc) -> dict:
"""Check and update DRAC settings to standard as required.
Returns the changes that were made
"""
attribute_path = bmc.manager_path + "/Attributes"
current_values = bmc.redfish_request(attribute_path)["Attributes"]
required_changes = {}
for key, required_value in REQUIRED_VALUES.items():
if not required_value:
logger.warning(
"We have no required value configured for BMC attribute '%s'", key
)
elif key not in current_values:
logger.warning("%s has no BMC attribute '%s'", bmc, key)
elif current_values[key] == required_value:
logger.info("%s: '%s' already set to '%s'", bmc, key, required_value)
else:
required_changes[key] = VALUES_TO_POST[key]
if required_changes:
logger.info("%s Updating DRAC settings:", bmc)
for k in required_changes:
logger.info(" %s: %s->%s", k, current_values[k], REQUIRED_VALUES[k])
payload = {"Attributes": required_changes}
bmc.redfish_request(attribute_path, payload=payload, method="PATCH")
logger.info("%s DRAC settings have been updated", bmc)
else:
logger.info("%s all required DRAC settings present and correct", bmc)
return required_changes