Esempio n. 1
0
def delete_allocation(alloc_delete_input):
    rc, handler = wm.allocation_delete(alloc_delete_input)
    if (rc == 0):
        print("Allocation " + str(alloc_delete_input.allocation_id) +
              " successfully deleted")
    else:
        print("Failed to delete allocation " +
              str(alloc_delete_input.allocation_id))
        csm.api_object_destroy(handler)
        csm.term_lib()
        sys.exit(rc)
Esempio n. 2
0
def create_timed_allocation(alloc_input):
    start_time = datetime.now()
    rc, handler, aid = wm.allocation_create(alloc_input)
    end_time = datetime.now()
    time_to_create = end_time - start_time
    if (rc == 0):
        print("Created allocation: " + str(aid) + " (isolated_cores = " +
              str(alloc_input.isolated_cores) + ")")
        log.write("Allocation: " + str(aid) + " (isolated_cores = " +
                  str(alloc_input.isolated_cores) + ")\n")
        print("Create time: " + str(time_to_create.total_seconds()))
        log.write("Create time: " + str(time_to_create.total_seconds()) + "\n")
        return aid
    else:
        print("Create Failed")
        csm.api_object_destroy(handler)
        csm.term_lib()
        sys.exit(rc)
Esempio n. 3
0
input.set_node_names(nodes)

# set other input data
input.limit=-1
input.offset=-1

# Call the CSM API
rc,handler,output = inv.node_attributes_query(input)

# Access csm api output how ever you want. 

if(rc == csm.csmi_cmd_err_t.CSMI_SUCCESS):
    for i in range (0, output.results_count):
        record = output.get_results(i)
        pprint(record.node_name)
        pprint(record.collection_time)
        pprint(record.update_time)
        print(record.state)
        print("node_state_value: " + str(record.state))
        pprint(record.state)
        pprint("node_state_value: " + str(record.state))
        print(record.state)
        print(record.node_name)
else:
    print("No matching records found.")


csm.api_object_destroy(handler)

csm.term_lib()
Esempio n. 4
0
def query(input_details):
    ''' Queries CSM and Elastic to get a listing of records with a matching key. '''
    # Query CSM for allocation details
    csm.init_lib()
    alloc_input = wm.allocation_query_input_t()
    alloc_input.allocation_id = input_details["allocation_id"]
    alloc_input.primary_job_id = input_details["primary_job_id"]
    alloc_input.secondary_job_id = input_details["secondary_job_id"]

    rc, handler, alloc_output = wm.allocation_query(alloc_input)

    if rc is 0:
        allocation = alloc_output.allocation

        # Build some of the searches.
        end_time = "*"
        if allocation.history is not None:
            end_time = allocation.history.end_time.replace(' ', 'T') + "Z"

        timerange = '''@timestamp:[{0}Z TO {1}]'''.format(
            allocation.begin_time.replace(' ', 'T'), end_time)

        # The hostname query.
        hostnames = 'syslogHostname:('
        host_count = 0
        if input_details["hostnames"] is not None:
            for i in range(0, allocation.num_nodes):
                host = allocation.get_compute_nodes(i)
                if host in input_details["hostnames"]:
                    host_count += 1
                    hostnames += "{0} OR ".format(host)
        else:
            for i in range(0, allocation.num_nodes):
                host_count += 1
                hostnames += "{0} OR ".format(allocation.get_compute_nodes(i))

        hostnames = hostnames[:-4]

        if host_count is 0:
            print("No hosts found matching query.")
            return 1

        # The message portion of the query, splat query needs special TLC.
        message = "message:"
        keys = input_details["key"].split(',')
        if input_details["key"] is not "*":
            for key in keys:
                message += '"{0}",'.format(key)
            message = message[:-1]
        else:
            message += "*"

        aggregation = 'aggs:{ keys: { filter key_count : { value_count: { "field" : " "} }'

        # Open a connection to the elastic cluster.
        es = Elasticsearch(cluster,
                           sniff_on_start=True,
                           sniff_on_connection_fail=True,
                           sniffer_timeout=60)
        query = '{0} AND {1} AND {2})'.format(message, timerange, hostnames)
        #query='message:"{0}" AND {1}'.format(input_details["key"], timerange)
        print(query)
        res = es.search(index="_all", q=query)

        print("Got %d Hits:" % res['hits']['total'])
        #if res['hits']['total'] > 0:
        #    print(res['hits']['hits'][0])

    csm.api_object_destroy(handler)
    csm.term_lib()