Add check if node is registered

Avoids reprovisioning existing nodes until they are manually removed
from the database.
This commit is contained in:
Joshua Boniface 2022-10-26 17:51:00 +00:00
parent b4796ef4c9
commit 1c3c59b6f0
1 changed files with 30 additions and 16 deletions

View File

@ -50,7 +50,23 @@ def dnsmasq_checkin(config, data):
)
cspec = git.load_cspec_yaml(config)
is_in_bootstrap_map = True if data["macaddr"] in cspec["bootstrap"] else False
if is_in_bootstrap_map:
try:
if is_in_bootstrap_map
cspec_cluster = cspec["bootstrap"][data["macaddr"]]["node"]["cluster"]
is_registered = True if data["macaddr"] in [x.bmc_macaddr for x in db.get_nodes_in_cluster(config, cspec_cluster)] else False
else:
raise Exception()
except Exception:
is_registered = False
if not is_in_bootstrap_map:
logger.warn(f"Device '{data['macaddr']}' not in bootstrap map; ignoring.")
return
if is_registered:
logger.info(f"Device '{data['macaddr']}' has already been bootstrapped; ignoring.")
return
notifications.send_webhook(config, "info", f"New host checkin from MAC {data['macaddr']} as host {cspec['bootstrap'][data['macaddr']]['node']['fqdn']} in cluster {cspec['bootstrap'][data['macaddr']]['node']['cluster']}")
if (
cspec["bootstrap"][data["macaddr"]]["bmc"].get("redfish", None)
@ -66,8 +82,6 @@ def dnsmasq_checkin(config, data):
logger.info(f"Is device '{data['macaddr']}' Redfish capable? {is_redfish}")
if is_redfish:
redfish.redfish_init(config, cspec, data)
else:
logger.warn(f"Device '{data['macaddr']}' not in bootstrap map; ignoring.")
return
@ -142,7 +156,7 @@ def host_checkin(config, data):
target_state = "completed"
for node in all_nodes:
host.set_boot_state(config, cspec, node, target_state)
host.set_boot_state(config, cspec, data, target_state)
# Hosts will now power down ready for real activation in production
sleep(60)