Compare commits
6 Commits
871955e5b6
...
1a9bd09788
Author | SHA1 | Date | |
---|---|---|---|
1a9bd09788 | |||
b7859189eb | |||
ddccc91645 | |||
2b180bd5c4 | |||
c0b868896e | |||
f02b128284 |
@@ -69,6 +69,7 @@ def run_hook_osddb(config, targets, args):
|
|||||||
stdin, stdout, stderr = c.exec_command(pvc_cmd_string)
|
stdin, stdout, stderr = c.exec_command(pvc_cmd_string)
|
||||||
logger.debug(stdout.readlines())
|
logger.debug(stdout.readlines())
|
||||||
logger.debug(stderr.readlines())
|
logger.debug(stderr.readlines())
|
||||||
|
return stdout.channel.recv_exit_status()
|
||||||
|
|
||||||
|
|
||||||
def run_hook_osd(config, targets, args):
|
def run_hook_osd(config, targets, args):
|
||||||
@@ -98,6 +99,7 @@ def run_hook_osd(config, targets, args):
|
|||||||
stdin, stdout, stderr = c.exec_command(pvc_cmd_string)
|
stdin, stdout, stderr = c.exec_command(pvc_cmd_string)
|
||||||
logger.debug(stdout.readlines())
|
logger.debug(stdout.readlines())
|
||||||
logger.debug(stderr.readlines())
|
logger.debug(stderr.readlines())
|
||||||
|
return stdout.channel.recv_exit_status()
|
||||||
|
|
||||||
|
|
||||||
def run_hook_pool(config, targets, args):
|
def run_hook_pool(config, targets, args):
|
||||||
@@ -127,7 +129,7 @@ def run_hook_pool(config, targets, args):
|
|||||||
logger.debug(stderr.readlines())
|
logger.debug(stderr.readlines())
|
||||||
|
|
||||||
# This only runs once on whatever the first node is
|
# This only runs once on whatever the first node is
|
||||||
break
|
return stdout.channel.recv_exit_status()
|
||||||
|
|
||||||
|
|
||||||
def run_hook_network(config, targets, args):
|
def run_hook_network(config, targets, args):
|
||||||
@@ -191,7 +193,7 @@ def run_hook_network(config, targets, args):
|
|||||||
logger.debug(stderr.readlines())
|
logger.debug(stderr.readlines())
|
||||||
|
|
||||||
# This only runs once on whatever the first node is
|
# This only runs once on whatever the first node is
|
||||||
break
|
return stdout.channel.recv_exit_status()
|
||||||
|
|
||||||
|
|
||||||
def run_hook_copy(config, targets, args):
|
def run_hook_copy(config, targets, args):
|
||||||
@@ -217,11 +219,14 @@ def run_hook_copy(config, targets, args):
|
|||||||
tc.chmod(dfile, int(dmode, 8))
|
tc.chmod(dfile, int(dmode, 8))
|
||||||
tc.close()
|
tc.close()
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def run_hook_script(config, targets, args):
|
def run_hook_script(config, targets, args):
|
||||||
"""
|
"""
|
||||||
Run a script on the targets
|
Run a script on the targets
|
||||||
"""
|
"""
|
||||||
|
return_status = 0
|
||||||
for node in targets:
|
for node in targets:
|
||||||
node_name = node.name
|
node_name = node.name
|
||||||
node_address = node.host_ipaddr
|
node_address = node.host_ipaddr
|
||||||
@@ -272,6 +277,10 @@ def run_hook_script(config, targets, args):
|
|||||||
stdin, stdout, stderr = c.exec_command(remote_command)
|
stdin, stdout, stderr = c.exec_command(remote_command)
|
||||||
logger.debug(stdout.readlines())
|
logger.debug(stdout.readlines())
|
||||||
logger.debug(stderr.readlines())
|
logger.debug(stderr.readlines())
|
||||||
|
if stdout.channel.recv_exit_status() != 0:
|
||||||
|
return_status = stdout.channel.recv_exit_status()
|
||||||
|
|
||||||
|
return return_status
|
||||||
|
|
||||||
|
|
||||||
def run_hook_webhook(config, targets, args):
|
def run_hook_webhook(config, targets, args):
|
||||||
@@ -345,7 +354,9 @@ def run_hooks(config, cspec, cluster, nodes):
|
|||||||
# Run the hook function
|
# Run the hook function
|
||||||
try:
|
try:
|
||||||
notifications.send_webhook(config, "begin", f"Cluster {cluster.name}: Running hook task '{hook_name}'")
|
notifications.send_webhook(config, "begin", f"Cluster {cluster.name}: Running hook task '{hook_name}'")
|
||||||
hook_functions[hook_type](config, target_nodes, hook_args)
|
retcode = hook_functions[hook_type](config, target_nodes, hook_args)
|
||||||
|
if retcode > 0:
|
||||||
|
raise Exception(f"Hook returned with code {retcode}")
|
||||||
notifications.send_webhook(config, "success", f"Cluster {cluster.name}: Completed hook task '{hook_name}'")
|
notifications.send_webhook(config, "success", f"Cluster {cluster.name}: Completed hook task '{hook_name}'")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Error running hook: {e}")
|
logger.warning(f"Error running hook: {e}")
|
||||||
|
@@ -84,3 +84,16 @@ def set_boot_state(config, cspec, data, state):
|
|||||||
db.update_node_state(config, cspec_cluster, cspec_hostname, state)
|
db.update_node_state(config, cspec_cluster, cspec_hostname, state)
|
||||||
node = db.get_node(config, cspec_cluster, name=cspec_hostname)
|
node = db.get_node(config, cspec_cluster, name=cspec_hostname)
|
||||||
logger.debug(node)
|
logger.debug(node)
|
||||||
|
|
||||||
|
|
||||||
|
def set_completed(config, cspec, cluster):
|
||||||
|
nodes = list()
|
||||||
|
for bmc_macaddr in cspec["bootstrap"]:
|
||||||
|
if cspec["bootstrap"][bmc_macaddr]["node"]["cluster"] == cluster:
|
||||||
|
nodes.append(cspec["bootstrap"][bmc_macaddr])
|
||||||
|
for node in nodes:
|
||||||
|
cspec_cluster = node["node"]["cluster"]
|
||||||
|
cspec_hostname = node["node"]["hostname"]
|
||||||
|
db.update_node_state(config, cspec_cluster, cspec_hostname, "completed")
|
||||||
|
node = db.get_node(config, cspec_cluster, name=cspec_hostname)
|
||||||
|
logger.debug(node)
|
||||||
|
@@ -50,7 +50,23 @@ def dnsmasq_checkin(config, data):
|
|||||||
)
|
)
|
||||||
cspec = git.load_cspec_yaml(config)
|
cspec = git.load_cspec_yaml(config)
|
||||||
is_in_bootstrap_map = True if data["macaddr"] in cspec["bootstrap"] else False
|
is_in_bootstrap_map = True if data["macaddr"] in cspec["bootstrap"] else False
|
||||||
|
try:
|
||||||
if is_in_bootstrap_map:
|
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:
|
||||||
|
is_registered = False
|
||||||
|
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']}")
|
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 (
|
if (
|
||||||
cspec["bootstrap"][data["macaddr"]]["bmc"].get("redfish", None)
|
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}")
|
logger.info(f"Is device '{data['macaddr']}' Redfish capable? {is_redfish}")
|
||||||
if is_redfish:
|
if is_redfish:
|
||||||
redfish.redfish_init(config, cspec, data)
|
redfish.redfish_init(config, cspec, data)
|
||||||
else:
|
|
||||||
logger.warn(f"Device '{data['macaddr']}' not in bootstrap map; ignoring.")
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -140,9 +154,7 @@ def host_checkin(config, data):
|
|||||||
|
|
||||||
hooks.run_hooks(config, cspec, cluster, ready_nodes)
|
hooks.run_hooks(config, cspec, cluster, ready_nodes)
|
||||||
|
|
||||||
target_state = "completed"
|
host.set_completed(config, cspec, cluster)
|
||||||
for node in all_nodes:
|
|
||||||
host.set_boot_state(config, cspec, data, target_state)
|
|
||||||
|
|
||||||
# Hosts will now power down ready for real activation in production
|
# Hosts will now power down ready for real activation in production
|
||||||
sleep(60)
|
sleep(60)
|
||||||
|
Reference in New Issue
Block a user