def main(args=None): """Main entry-point for running this script. This function parses command-line arguments and passes them on to the remove_node() function. """ usage = "usage: %prog [options] node_name" descr = "Remove a node from the tokenserver database" parser = optparse.OptionParser(usage=usage, description=descr) parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="Control verbosity of log messages") opts, args = parser.parse_args(args) if len(args) != 1: parser.print_usage() return 1 util.configure_script_logging(opts) node_name = args[0] remove_node(node_name) return 0
def main(args=None): """Main entry-point for running this script. This function parses command-line arguments and passes them on to the process_account_events() function. """ usage = "usage: %prog [options] queue_name" parser = optparse.OptionParser(usage=usage) parser.add_option("", "--aws-region", help="aws region in which the queue can be found") parser.add_option("", "--queue-wait-time", type="int", default=20, help="Number of seconds to wait for jobs on the queue") parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="Control verbosity of log messages") opts, args = parser.parse_args(args) if len(args) != 1: parser.print_usage() return 1 util.configure_script_logging(opts) queue_name = args[0] process_account_events(queue_name, opts.aws_region, opts.queue_wait_time) return 0
def main(args=None): """Main entry-point for running this script. This function parses command-line arguments and passes them on to the add_node() function. """ usage = "usage: %prog [options]" descr = "Count total users in the tokenserver database" parser = optparse.OptionParser(usage=usage, description=descr) parser.add_option("-t", "--timestamp", type="int", help="Max creation timestamp; default previous midnight") parser.add_option("-o", "--output", help="Output file; default stderr") parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="Control verbosity of log messages") opts, args = parser.parse_args(args) if len(args) != 0: parser.print_usage() return 1 util.configure_script_logging(opts) if opts.output in (None, "-"): count_users(sys.stdout, opts.timestamp) else: with open(opts.output, "a") as outfile: count_users(outfile, opts.timestamp) return 0
def main(args=None): """Main entry-point for running this script. This function parses command-line arguments and passes them on to the allocate_user() function. """ usage = "usage: %prog [options] email [node_name]" descr = "Allocate a user to a node. You may specify a particular node, "\ "or omit to use the best available node." parser = optparse.OptionParser(usage=usage, description=descr) parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="Control verbosity of log messages") opts, args = parser.parse_args(args) if not 1 <= len(args) <= 2: parser.print_usage() return 1 util.configure_script_logging(opts) email = args[0] if len(args) == 1: node_name = None else: node_name = args[1] allocate_user(email, node_name) return 0
def main(args=None): """Main entry-point for running this script. This function parses command-line arguments and passes them on to the update_node() function. """ usage = "usage: %prog [options] node_name" descr = "Update node details in the tokenserver database" parser = optparse.OptionParser(usage=usage, description=descr) parser.add_option("", "--capacity", type="int", help="How many user slots the node has overall") parser.add_option("", "--available", type="int", help="How many user slots the node has available") parser.add_option("", "--current-load", type="int", help="How many user slots the node has occupied") parser.add_option("", "--downed", action="store_true", help="Mark the node as down in the db") parser.add_option("", "--backoff", action="store_true", help="Mark the node as backed-off in the db") parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="Control verbosity of log messages") opts, args = parser.parse_args(args) if len(args) != 1: parser.print_usage() return 1 util.configure_script_logging(opts) node_name = args[0] kwds = {} if opts.capacity is not None: kwds["capacity"] = opts.capacity if opts.available is not None: kwds["available"] = opts.available if opts.current_load is not None: kwds["current_load"] = opts.current_load if opts.backoff is not None: kwds["backoff"] = opts.backoff if opts.downed is not None: kwds["downed"] = opts.downed update_node(node_name, **kwds) return 0
def main(args=None): """Main entry-point for running this script. This function parses command-line arguments and passes them on to the purge_old_records() function. """ usage = "usage: %prog [options] secret" parser = optparse.OptionParser(usage=usage) parser.add_option("", "--purge-interval", type="int", default=3600, help="Interval to sleep between purging runs") parser.add_option("", "--grace-period", type="int", default=86400, help="Number of seconds grace to allow on replacement") parser.add_option("", "--max-per-loop", type="int", default=10, help="Maximum number of items to fetch in one go") # N.B., if the number of purgeable rows is <<< max_offset then most # selects will return zero rows. Choose this value accordingly. parser.add_option("", "--max-offset", type="int", default=0, help="Use random offset from 0 to max_offset") parser.add_option("", "--request-timeout", type="int", default=60, help="Timeout for service deletion requests") parser.add_option("", "--oneshot", action="store_true", help="Do a single purge run and then exit") parser.add_option("-v", "--verbose", action="count", dest="verbosity", help="Control verbosity of log messages") opts, args = parser.parse_args(args) if len(args) != 2: parser.print_usage() return 1 secret = args[1] util.configure_script_logging(opts) purge_old_records(secret, grace_period=opts.grace_period, max_per_loop=opts.max_per_loop, max_offset=opts.max_offset, request_timeout=opts.request_timeout) if not opts.oneshot: while True: # Randomize sleep interval +/- thirty percent to desynchronize # instances of this script running on multiple webheads. sleep_time = opts.purge_interval sleep_time += random.randint(-0.3 * sleep_time, 0.3 * sleep_time) logger.debug("Sleeping for %d seconds", sleep_time) time.sleep(sleep_time) purge_old_records(grace_period=opts.grace_period, max_per_loop=opts.max_per_loop, max_offset=opts.max_offset, request_timeout=opts.request_timeout) return 0