Fix script argument parsing.

The vm_vdi_cleaner.py script's argument parsing was broken and unloved.

Change-Id: I1662534d65fd0e8472e092ed9f10d6cc059f1cab
This commit is contained in:
Brian Elliott 2013-02-14 19:09:33 +00:00
parent 07e0c2421a
commit cf51411531

View File

@ -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`.")