Compare commits

...

2 Commits

View File

@ -192,6 +192,28 @@ def run_hook_network(config, targets, args):
break break
def run_hook_copy(config, targets, args):
"""
Copy a file from the local machine to the target(s)
"""
for node in targets:
node_name = node.name
node_address = node.host_ipaddr
source = args.get("source", [])
destination = args.get("destination", [])
mode = args.get("mode", [])
logger.info(f"Copying file {source} to node {node_name}:{destination}")
with run_paramiko(config, node_address) as c:
for sfile, dfile, dmode in zip(source, destination, mode):
tc = c.open_sftp()
tc.put(sfile, dfile)
tc.chmod(dfile, dmode)
tc.close()
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
@ -203,6 +225,7 @@ def run_hook_script(config, targets, args):
script = args.get("script", None) script = args.get("script", None)
source = args.get("source", None) source = args.get("source", None)
path = args.get("path", None) path = args.get("path", None)
arguments = args.get("arguments", [])
logger.info(f"Running script on node {node_name}") logger.info(f"Running script on node {node_name}")
@ -233,7 +256,12 @@ def run_hook_script(config, targets, args):
elif source == "remote": elif source == "remote":
remote_path = path remote_path = path
stdin, stdout, stderr = c.exec_command(remote_path) if len(arguments) > 0:
remote_command = f"{remote_path} {' '.join(arguments)}"
else:
remote_command = remote_path
stdin, stdout, stderr = c.exec_command(remote_command)
logger.debug(stdout.readlines()) logger.debug(stdout.readlines())
logger.debug(stderr.readlines()) logger.debug(stderr.readlines())
@ -269,6 +297,7 @@ hook_functions = {
"osd": run_hook_osd, "osd": run_hook_osd,
"pool": run_hook_pool, "pool": run_hook_pool,
"network": run_hook_network, "network": run_hook_network,
"copy": run_hook_copy,
"script": run_hook_script, "script": run_hook_script,
"webhook": run_hook_webhook, "webhook": run_hook_webhook,
} }
@ -313,4 +342,10 @@ def run_hooks(config, cspec, cluster, nodes):
sleep(5) sleep(5)
# Restart nodes to complete setup # Restart nodes to complete setup
hook_functions['script'](config, cluster_nodes, {'script': '#!/usr/bin/env bash\necho bootstrapped | sudo tee /etc/pvc-install.hooks\nsudo reboot'}) hook_functions["script"](
config,
cluster_nodes,
{
"script": "#!/usr/bin/env bash\necho bootstrapped | sudo tee /etc/pvc-install.hooks\nsudo reboot"
},
)