Skip to content

Commit

Permalink
Added setup-feeder option to distributed cleanup script
Browse files Browse the repository at this point in the history
This enables an administrator to setup a single feeder.

/opt/cfengine/federation/bin/distributed_cleanup.py --setup-feeder feederhostname

Ticket: ENT-11844
Changelog: title
(cherry picked from commit d60cc27)
  • Loading branch information
craigcomstock committed Jun 3, 2024
1 parent 60eae14 commit 9241381
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions templates/federated_reporting/distributed_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def interactive_setup_feeder(hub, email, fr_distributed_cleanup_password, force_
)
if response["status"] != 201:
print(
"Problem creating fr_distributed_cleanup role on superhub. {}".format(
"Problem creating fr_distributed_cleanup role on feeder. {}".format(
response
)
)
Expand Down Expand Up @@ -228,6 +228,7 @@ def main():
group.add_argument("--inform", action="store_true")

parser.add_argument("--force-interactive", action="store_true", help="force interactive mode even when no tty, good for automation")
parser.add_argument("--setup-feeder", help="Setup a single feeder by hostname")
args = parser.parse_args()

global logger
Expand All @@ -253,6 +254,12 @@ def main():
sys.exit(1)

fr_distributed_cleanup_password = read_secret(DISTRIBUTED_CLEANUP_SECRET_PATH)
if args.setup_feeder:
email = input("Enter email for fr_distributed_cleanup accounts: ")
print() # newline for easier reading
feeder = { "ui_name": args.setup_feeder }
interactive_setup_feeder(feeder, email, fr_distributed_cleanup_password, force_interactive=args.force_interactive)

api = NovaApi(
api_user="fr_distributed_cleanup", api_password=fr_distributed_cleanup_password
) # defaults to localhost
Expand Down Expand Up @@ -286,7 +293,11 @@ def main():
cert_path=CERT_PATH,
hostname=feeder_hostname,
)
response = feeder_api.status()
try:
response = feeder_api.status()
except Exception as e:
print("Could not connect to {}, error: {}".format(feeder_hostname, e));
sys.exit(1);
if response["status"] == 401 and sys.stdout.isatty():
# auth error when running interactively
# assume it's a new feeder and offer to set it up interactively
Expand Down

0 comments on commit 9241381

Please sign in to comment.