def show(clusters, args, _): """Prints info for the jobs / instances / groups with the given UUIDs.""" guard_no_cluster(clusters) as_json = args.get('json') entity_refs, _ = parse_entity_refs(clusters, args.get('uuid')) query_result, clusters_of_interest = query_with_stdin_support( clusters, entity_refs) if as_json: print(json.dumps(query_result)) else: for cluster_name, entities in query_result['clusters'].items(): if 'jobs' in entities: show_data(cluster_name, entities['jobs'], tabulate_job) if 'instances' in entities: show_data(cluster_name, entities['instances'], tabulate_instance) if 'groups' in entities: show_data(cluster_name, entities['groups'], tabulate_group) if query_result['count'] > 0: return 0 else: if not as_json: print_no_data(clusters_of_interest) return 1
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 kill(clusters, args, _): """Attempts to kill the jobs / instances / groups with the given UUIDs.""" guard_no_cluster(clusters) entity_refs, _ = parse_entity_refs(clusters, args.get('uuid')) query_result, clusters_of_interest = query_with_stdin_support( clusters, entity_refs) if query_result['count'] == 0: print_no_data(clusters_of_interest) return 1 # If the user provides UUIDs that map to more than one entity, # we will raise an Exception that contains the details guard_against_duplicates(query_result) return kill_entities(query_result, clusters_of_interest)
def wait(clusters, args, _): """Waits for jobs / instances / groups with the given UUIDs to complete.""" guard_no_cluster(clusters) timeout = args.get('timeout') interval = args.get('interval') entity_refs, _ = parse_entity_refs(clusters, args.get('uuid')) timeout_text = ( 'up to %s' % seconds_to_timedelta(timeout)) if timeout else 'indefinitely' print_info('Will wait %s.' % timeout_text) query_result, clusters_of_interest = query_with_stdin_support( clusters, entity_refs, all_jobs_completed, all_instances_completed, all_groups_completed, timeout, interval) if query_result['count'] > 0: return 0 else: print_no_data(clusters_of_interest) return 1
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)