def ls(clusters, args, _): """Lists contents of the corresponding Mesos sandbox path by job or instance uuid.""" guard_no_cluster(clusters) entity_refs, clusters_of_interest = parse_entity_refs(clusters, args.get('uuid')) path = args.get('path') long_format = args.get('long_format') as_json = args.get('json') literal = args.get('literal') if len(entity_refs) > 1: # argparse should prevent this, but we'll be defensive anyway raise Exception(f'You can only provide a single uuid.') if path and not literal and any(c in path for c in '*?[]{}'): message = 'It looks like you are trying to glob, but ls does not support globbing. ' \ f'You can use the {terminal.bold("ssh")} command instead:\n' \ '\n' \ f' cs ssh {entity_refs[0]}\n' \ '\n' \ f'Or, if you want the literal path {terminal.bold(path)}, add {terminal.bold("--literal")}:\n' \ '\n' \ f' cs ls {terminal.bold("--literal")} {entity_refs[0]} {path}' print(message) return 1 command_fn = partial(ls_for_instance, path=path, long_format=long_format, as_json=as_json) query_unique_and_run(clusters_of_interest, entity_refs[0], command_fn)
def ssh(clusters, args, _): """Attempts to ssh (using os.execlp) to the Mesos agent corresponding to the given job or instance uuid.""" guard_no_cluster(clusters) entity_refs, clusters_of_interest = parse_entity_refs(clusters, args.get('uuid')) if len(entity_refs) > 1: # argparse should prevent this, but we'll be defensive anyway raise Exception(f'You can only provide a single uuid.') query_unique_and_run(clusters_of_interest, entity_refs[0], ssh_to_instance)
def cat(clusters, args, _): """Outputs the contents of the corresponding Mesos sandbox path by job or instance uuid.""" guard_no_cluster(clusters) entity_refs, clusters_of_interest = parse_entity_refs(clusters, args.get('target-entity')) paths = args.get('path') # argparse should prevent these, but we'll be defensive anyway assert len(entity_refs) == 1, 'Only a single UUID or URL is supported.' assert len(paths) == 1, 'Only a single path is supported.' command_fn = partial(cat_for_instance, path=paths[0]) query_unique_and_run(clusters_of_interest, entity_refs[0], command_fn)
def tail(clusters, args, _): """Tails the contents of the corresponding Mesos sandbox path by job or instance uuid.""" guard_no_cluster(clusters) entity_refs, clusters_of_interest = parse_entity_refs(clusters, args.get('uuid')) paths = args.get('path') lines = args.get('lines') follow = args.get('follow') sleep_interval = args.get('sleep-interval') if len(entity_refs) > 1: # argparse should prevent this, but we'll be defensive anyway raise Exception(f'You can only provide a single uuid.') if len(paths) > 1: # argparse should prevent this, but we'll be defensive anyway raise Exception(f'You can only provide a single path.') command_fn = partial(tail_for_instance, path=paths[0], num_lines_to_print=lines, follow=follow, follow_sleep_seconds=sleep_interval) query_unique_and_run(clusters_of_interest, entity_refs[0], command_fn)