From cf51411531af49299be472e41b1c70aaaf6e5c3e Mon Sep 17 00:00:00 2001 From: Brian Elliott Date: Thu, 14 Feb 2013 19:09:33 +0000 Subject: [PATCH] Fix script argument parsing. The vm_vdi_cleaner.py script's argument parsing was broken and unloved. Change-Id: I1662534d65fd0e8472e092ed9f10d6cc059f1cab --- tools/xenserver/vm_vdi_cleaner.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/xenserver/vm_vdi_cleaner.py b/tools/xenserver/vm_vdi_cleaner.py index 27b89d510e30..c9dc0b53d17c 100755 --- a/tools/xenserver/vm_vdi_cleaner.py +++ b/tools/xenserver/vm_vdi_cleaner.py @@ -40,8 +40,14 @@ cleaner_opts = [ default=172800, help='Number of seconds zombie instances are cleaned up.'), ] + +cli_opt = cfg.StrOpt('command', + default=None, + help='Cleaner command') + CONF = cfg.CONF CONF.register_opts(cleaner_opts) +CONF.register_cli_opt(cli_opt) CONF.import_opt('verbose', 'nova.openstack.common.log') CONF.import_opt("resize_confirm_window", "nova.compute.manager") @@ -279,14 +285,14 @@ def clean_orphaned_instances(xenapi, orphaned_instances): def main(): """Main loop.""" - args = CONF(args=sys.argv, - usage='%prog [options] [' + '|'.join(ALLOWED_COMMANDS) + ']') - if len(args) < 2: + args = CONF(args=sys.argv[1:], usage='%(prog)s [options] --command={' + + '|'.join(ALLOWED_COMMANDS) + '}') + + command = CONF.command + if not command or command not in ALLOWED_COMMANDS: CONF.print_usage() sys.exit(1) - command = args[1] - if CONF.zombie_instance_updated_at_window < CONF.resize_confirm_window: raise Exception("`zombie_instance_updated_at_window` has to be longer" " than `resize_confirm_window`.")