Skip to content

Commit

Permalink
Added agent command and help to bootstrap
Browse files Browse the repository at this point in the history
Ticket: CFE-4467
Signed-off-by: Victor Moene <[email protected]>
  • Loading branch information
victormlg committed Dec 19, 2024
1 parent a5c1588 commit 067c48d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,21 @@ def deploy(hubs, masterfiles):
os.system("rm -rf %s" % tarball)
os.system("tar -czf %s -C %s masterfiles" % (tarball, above))
return deploy_tarball(hubs, tarball)

def agent(hosts, bootstrap=None) :

command = "cf-agent"
if bootstrap :
command += " --bootstrap {}".format(bootstrap)

for host in hosts:
data = get_info(host)

if not data["agent_version"] :
user_error("CFEngine not installed on {}".format(host))

output = run_command(host, command, sudo=True)
if output :
print(output)

return 0
10 changes: 10 additions & 0 deletions cf_remote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ def _get_arg_parser():
type=str,
nargs="?",
)
sp = subp.add_parser("agent", help="Run cf-agent")
sp.add_argument(
"--hosts", "-H", help="Which hosts to run cf-agent from", type=str, required=True
)
sp.add_argument("--bootstrap", "-B", help="Which hub to bootstrap to", type=str)

return ap

Expand All @@ -281,6 +286,9 @@ def run_command_with_args(command, args):
else:
trust_keys = None

if not args.bootstrap :
log.warning("You did not specify --bootstrap in the install command, so CFEngine has been installed, but not started.\nTo fix this, run:\ncf-remote agent --hosts HOSTS --bootstrap BOOTSTRAP")

return commands.install(
args.hub,
args.clients,
Expand Down Expand Up @@ -367,6 +375,8 @@ def run_command_with_args(command, args):
return commands.destroy(group_name)
elif command == "deploy":
return commands.deploy(args.hub, args.masterfiles)
elif command == "agent":
return commands.agent(args.hosts, args.bootstrap)
else:
user_error("Unknown command: '{}'".format(command))

Expand Down

0 comments on commit 067c48d

Please sign in to comment.