-import argparse
+import docopt
import sys
import teuthology.lock
+doc = """
+usage: teuthology-updatekeys -h
+ teuthology-updatekeys [-v] [-t <targets> | -a | <machine> ...]
-def main():
- status = teuthology.lock.updatekeys(parse_args())
- sys.exit(status)
-
+Update any hostkeys that have changed. You can list specific machines to run
+on, or use -a to check all of them automatically.
-def parse_args():
- parser = argparse.ArgumentParser(description="""
-Update any hostkeys that have changed. You can list specific machines
-to run on, or use -a to check all of them automatically.
-""")
- parser.add_argument(
- '-v', '--verbose',
- action='store_true',
- default=False,
- help='be more verbose',
- )
- group = parser.add_mutually_exclusive_group()
- group.add_argument(
- '-t', '--targets',
- default=None,
- help='input yaml containing targets to check',
- )
- group.add_argument(
- '-a', '--all',
- action='store_true',
- default=False,
- help='update hostkeys of all machines in the db',
- )
- group.add_argument(
- 'machines',
- metavar='MACHINES',
- default=[],
- nargs='*',
- help='hosts to check for updated keys',
- )
+positional arguments:
+ MACHINES hosts to check for updated keys
- args = parser.parse_args()
+optional arguments:
+ -h, --help Show this help message and exit
+ -v, --verbose Be more verbose
+ -t <targets>, --targets <targets>
+ Input yaml containing targets to check
+ -a, --all Update hostkeys of all machines in the db
+"""
- if not (args.all or args.targets or args.machines):
- parser.print_usage()
- print "{name}: error: You must specify machines to update".format(
- name='teuthology-updatekeys')
- sys.exit(2)
- return args
+def main():
+ args = docopt.docopt(doc)
+ status = teuthology.lock.updatekeys(args)
+ sys.exit(status)
log.info('Using default values for supported os_type/os_version')
return default_table
-
+
def vps_version_or_type_valid(machine_type, os_type, os_version):
"""
Check os-type and os-version parameters when locking a vps.
Os-type will always be set (defaults to ubuntu).
-
+
In the case where downburst does not handle list-json (an older version
of downburst, for instance), a message is printed and this checking
is skipped (so that this code should behave as it did before this
if version in supported_versions:
return True
for parts in supported_versions:
- part = parts.split('(')
+ part = parts.split('(')
if len(part) == 2:
if version == part[0]:
return True
p.wait()
keys_dict = dict()
+ for line in p.stderr.readlines():
+ if not line.startswith('#'):
+ log.error(line)
for line in p.stdout.readlines():
host, key = line.strip().split(' ', 1)
keys_dict[host] = key
return keys_dict
-def updatekeys(ctx):
- loglevel = logging.INFO
- if ctx.verbose:
- loglevel = logging.DEBUG
-
+def updatekeys(args):
+ loglevel = logging.DEBUG if args['--verbose'] else logging.INFO
logging.basicConfig(
level=loglevel,
)
-
- misc.read_config(ctx)
-
- machines = [misc.canonicalize_hostname(m, user=None) for m in ctx.machines]
-
- if ctx.targets:
- try:
- with file(ctx.targets) as f:
- g = yaml.safe_load_all(f)
- for new in g:
- if 'targets' in new:
- for t in new['targets'].iterkeys():
- machines.append(t)
- except IOError as e:
- raise argparse.ArgumentTypeError(str(e))
-
- return do_update_keys(machines)
-
-
-def do_update_keys(machines):
+ all_ = args['--all']
+ if all_:
+ machines = []
+ elif args['<machine>']:
+ machines = [misc.canonicalize_hostname(m, user=None)
+ for m in args['<machine>']]
+ elif args['--targets']:
+ targets = args['--targets']
+ with file(targets) as f:
+ docs = yaml.safe_load_all(f)
+ for doc in docs:
+ machines = [n for n in doc.get('targets', dict()).iterkeys()]
+
+ return do_update_keys(machines, all_)
+
+
+def do_update_keys(machines, all_=False):
reference = list_locks(keyed_by_name=True)
- if not machines:
+ if all_:
machines = reference.keys()
keys_dict = ssh_keyscan(machines)
return push_new_keys(keys_dict, reference)