def llstate(nodes=None, filter=None): """LoadLeveler State of netwerk node""" machines = [] query = ll.ll_query(ll.MACHINES) if not ll.PyCObjValid(query): log.error('Error during pyloadl.ll_query') return machines if nodes is not None: rc = ll.ll_set_request(query, ll.QUERY_HOST, nodes, ll.ALL_DATA) else: rc = ll.ll_set_request(query, ll.QUERY_ALL, '', ll.ALL_DATA) if rc != 0: log.error('Error during pyloadl.ll_set_request: %s', rc) ll.ll_deallocate(query) return machines machine, count, err = ll.ll_get_objs(query, ll.LL_CM, '') if err != 0: log.error('Error during pyloadl.ll_get_objs: %s', err) elif count > 0: while ll.PyCObjValid(machine): data = functools.partial(ll.ll_get_data, machine) startd = data(ll.LL_MachineStartdState) if filter is None or startd in filter: machines.append({ 'name': data(ll.LL_MachineName), 'startd': startd, 'schedd': data(ll.LL_MachineScheddState), 'loadavg': data(ll.LL_MachineLoadAverage), 'conf_classes': element_count( data(ll.LL_MachineConfiguredClassList)), 'avail_classes': element_count( data(ll.LL_MachineAvailableClassList)), 'drain_classes': element_count( data(ll.LL_MachineDrainClassList)), 'run': data(ll.LL_MachineStartdRunningJobs) }) machine = ll.ll_next_obj(query) ll.ll_free_objs(machine) ll.ll_deallocate(query) return machines
def llq(state_filter=None, user_filter=None): """LoadLeveler Job queue""" jobs = [] query = ll.ll_query(ll.JOBS) if not ll.PyCObjValid(query): log.error('Error during pyloadl.ll_query') return jobs rc = ll.ll_set_request(query, ll.QUERY_ALL, '', ll.ALL_DATA) if rc != 0: log.error('Error during pyloadl.ll_set_request: %s', rc) ll.ll_deallocate(query) return jobs job, count, err = ll.ll_get_objs(query, ll.LL_CM, '') if err != 0: log.error('Error during pyloadl.ll_get_objs: %s', err) elif count > 0: while ll.PyCObjValid(job): name = ll.ll_get_data(job, ll.LL_JobName) cred = ll.ll_get_data(job, ll.LL_JobCredential) if ll.PyCObjValid(cred): user = ll.ll_get_data(cred, ll.LL_CredentialUserName) group = ll.ll_get_data(cred, ll.LL_CredentialGroupName) if user_filter is not None and user not in user_filter: job = ll.ll_next_obj(query) continue else: log.error('Error during pyloadl.ll_get_data for credentials') step = ll.ll_get_data(job, ll.LL_JobGetFirstStep) steps = [] while ll.PyCObjValid(step): data = functools.partial(ll.ll_get_data, step) state = data(ll.LL_StepState) if state_filter is None or state in state_filter: s = { 'id': data(ll.LL_StepID), 'state': state, 'pri': data(ll.LL_StepPriority), 'class': data(ll.LL_StepJobClass), 'parallel': data(ll.LL_StepParallelMode) == ll.PARALLEL_TYPE, 'total_tasks': data(ll.LL_StepTotalTasksRequested), 'tasks_per_node': data(ll.LL_StepTasksPerNodeRequested), 'blocking': data(ll.LL_StepBlocking), 'node_count': data(ll.LL_StepTotalNodesRequested), 'shared': data(ll.LL_StepNodeUsage) == ll.SHARED, 'task_geometry': data(ll.LL_StepTaskGeometry), } # post process node_count and task_geometry if s['node_count']: nodes = ast.literal_eval(s['node_count']) if isinstance(nodes, int): s['node_count'] = [nodes] * 2 elif len(nodes) == 1: s['node_count'] = nodes * 2 else: log.error('Error during parsing of nodes_count') else: s['node_count'] = (1, 1) if s['task_geometry']: s['task_geometry'] = ast.literal_eval( s['task_geometry'].translate( None, '{} ').replace(')', '),') ) # add to steps list steps.append(s) step = ll.ll_get_data(job, ll.LL_JobGetNextStep) if steps: jobs.append({'name': name, 'user': user, 'group': group, 'steps': steps}) job = ll.ll_next_obj(query) ll.ll_free_objs(job) ll.ll_deallocate(query) return jobs
state_list = ['Idle', 'Pending', 'Starting', 'Running', 'Complete_Pending', 'Reject_Pending', 'Remove_Pending', 'Vacate_Pending', 'Completed', 'Rejected', 'Removed', 'Vacated', 'Canceled', 'NotRun', 'Terminated', 'Unexpanded', 'Submission_Err', 'Hold', 'Deferred', 'NotQueued', 'Preempted', 'Preempt_Pending', 'Resume_Pending'] step_list = [] query_element = pyloadl.ll_query(pyloadl.JOBS) rc = pyloadl.ll_set_request(query_element,pyloadl.QUERY_ALL,"",pyloadl.ALL_DATA) if rc != 0 : print "rc (%s)" % rc raise Failure job, job_count, rc = pyloadl.ll_get_objs(query_element,pyloadl.LL_CM,"") if rc != 0 : print "rc (%s)" % rc raise Failure while pyloadl.PyCObjValid(job) : credential_element = pyloadl.ll_get_data(job,pyloadl.LL_JobCredential) username_string = pyloadl.ll_get_data(credential_element,pyloadl.LL_CredentialUserName) #print username_string group_string = pyloadl.ll_get_data(credential_element,pyloadl.LL_CredentialGroupName) #print group_string submittime = pyloadl.ll_get_data(job,pyloadl.LL_JobSubmitTime) step_element = pyloadl.ll_get_data(job,pyloadl.LL_JobGetFirstStep) while pyloadl.PyCObjValid(step_element) : new_step = {} new_step['username'] = username_string
list_string = "" first_item = 1 for item in item_list: if first_item != 1: list_string = list_string + "+" list_string = list_string + "%s" % (item,) first_item = 0 return list_string query_element = pyloadl.ll_query(pyloadl.MACHINES) rc = pyloadl.ll_set_request(query_element, pyloadl.QUERY_ALL, "", pyloadl.ALL_DATA) if rc != 0: print "rc (%s)" % rc raise Failure machine_ptr, machine_count, rc = pyloadl.ll_get_objs(query_element, pyloadl.LL_CM, "") if rc != 0: print "rc (%s)" % rc raise Failure while pyloadl.PyCObjValid(machine_ptr): sys.stdout.write("#cat_delim#") sys.stdout.write("Machine:%s#cat_delim#" % pyloadl.ll_get_data(machine_ptr, pyloadl.LL_MachineName)) sys.stdout.write("Arch:%s#cat_delim#" % pyloadl.ll_get_data(machine_ptr, pyloadl.LL_MachineArchitecture)) sys.stdout.write("OpSys:%s#cat_delim#" % (pyloadl.ll_get_data(machine_ptr, pyloadl.LL_MachineOperatingSystem),)) sys.stdout.write("Disk:%s#cat_delim#" % pyloadl.ll_get_data(machine_ptr, pyloadl.LL_MachineDisk)) # PoolListSize = pyloadl.ll_get_data(machine_ptr,pyloadl.LL_MachinePoolList) item_list = pyloadl.ll_get_data(machine_ptr, pyloadl.LL_MachinePoolList) # pool_string = "" # first_pool = 1 # for poolnumber in pool_list :