Skip to content
Snippets Groups Projects
Commit 04939f09 authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Format the script

parent 63b0c2bf
No related branches found
No related tags found
1 merge request!152Fix account cli
#!/usr/bin/env python3
import json
import rc_util
import argparse
import signal
import uuid
import pika
import rc_util
from rc_rmq import RCRMQ
import rabbit_config as rcfg
import time
parser = argparse.ArgumentParser(description = "Account management driver script")
parser.add_argument(
"username", help="Username that should be locked/unlocked")
parser = argparse.ArgumentParser(
description="Account management driver script"
)
parser.add_argument("username", help="Username that should be locked/unlocked")
parser.add_argument(
"state", choices=['ok', 'hold', 'certification', 'pre_certification'], help="Choose from states (ok,hold,certification,pre_certification)")
"state",
choices=["ok", "hold", "certification", "pre_certification"],
help="Choose from states (ok,hold,certification,pre_certification)",
)
parser.add_argument(
"-s", "--service", nargs='+', default='all', choices=['ssh', 'newjobs', 'expiration', 'all'], help="List one or more services to be blocked (default: %(default)s)")
"-s",
"--service",
nargs="+",
default="all",
choices=["ssh", "newjobs", "expiration", "all"],
help="List one or more services to be blocked (default: %(default)s)",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="verbose output")
"-v", "--verbose", action="store_true", help="verbose output"
)
parser.add_argument(
"-n", "--dry-run", action="store_true", help="enable dry run mode"
)
......@@ -45,7 +52,7 @@ msg["updated_by"], msg["host"] = rc_util.get_caller_info()
# publish msg with acctmgr.{uname} routing key.
rc_rmq.publish_msg(
{
"routing_key": f'acctmgr.request.{queuename}',
"routing_key": f"acctmgr.request.{queuename}",
"msg": msg,
}
)
......@@ -61,18 +68,23 @@ def callback(ch, method, properties, body):
username = msg["username"]
if msg["success"]:
print(f"Account for {username} has been {msg['action']}ed.\n Updating the user state in DB")
print(
f"Account for {username} has been {msg['action']}ed.\n "
"Updating the user state in DB"
)
else:
print(f"There's some issue in account management agents for {username}")
print(
f"There's some issue in account management agents for {username}"
)
errmsg = msg.get("errmsg", [])
for err in errmsg:
print(err)
ch.basic_ack(delivery_tag=method.delivery_tag)
rc_rmq.stop_consume()
rc_rmq.delete_queue(queuename)
print(f"Request {username} account state set to {state}.")
# Set initial timeout timer
......@@ -83,7 +95,7 @@ print("Waiting for completion...")
rc_rmq.start_consume(
{
"queue": queuename,
"routing_key": f'certified.{queuename}',
"routing_key": f"certified.{queuename}",
"cb": callback,
}
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment