Exemple #1
0
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
Exemple #2
0
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)
Exemple #3
0
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