本文整理汇总了Python中PBSQuery.PBSQuery.getjobs方法的典型用法代码示例。如果您正苦于以下问题:Python PBSQuery.getjobs方法的具体用法?Python PBSQuery.getjobs怎么用?Python PBSQuery.getjobs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PBSQuery.PBSQuery
的用法示例。
在下文中一共展示了PBSQuery.getjobs方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: countppn
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def countppn(queue):
p = PBSQuery()
p.new_data_structure()
jobs = p.getjobs()
nptot = 0
for id in jobs:
try:
if jobs[id].queue[0] == queue and jobs[id].job_state[0] == 'R':
np = jobs[id].Resource_List.nodes
if 'ppn' not in np[0]:
np = 1
else:
npptot = 0
ct = [m.start() for m in re.finditer('ppn', np[0])]
for val in ct:
char = np[0]
vals = val+4
valf = val+6
npp = char[vals:valf]
npp = re.sub('[[email protected]#+:$]', '', npp)
npp = int(npp)
npptot = npp + npptot
np = npptot
nptot = np + nptot
except PBSError, detail:
print detail
pass
示例2: pbs_handler
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def pbs_handler(name):
pbs = PBSQuery()
jobs = pbs.getjobs()
for jobid, jobinfo in jobs.iteritems():
publish(jobid, jobinfo)
publish_queue_state(pbs)
return ""
示例3: main
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def main(args):
"""Main script."""
options = {
'nagios-check-interval-threshold': NAGIOS_CHECK_INTERVAL_THRESHOLD,
'mail-report': ('mail a report to the hpc-admin list with job list for gracing or inactive users',
None, 'store_true', False),
}
opts = ExtendedSimpleOption(options)
try:
vsc_config = VscConfiguration()
LdapQuery(vsc_config)
grace_users = get_user_with_status('grace')
inactive_users = get_user_with_status('inactive')
pbs_query = PBSQuery()
t = time.ctime()
jobs = pbs_query.getjobs() # we just get them all
removed_queued = remove_queued_jobs(jobs, grace_users, inactive_users, opts.options.dry_run)
removed_running = remove_running_jobs(jobs, inactive_users, opts.options.dry_run)
if opts.options.mail_report and not opts.options.dry_run:
if len(removed_queued) > 0 or len(removed_running) > 0:
mail_report(t, removed_queued, removed_running)
except Exception, err:
logger.exception("critical exception caught: %s" % (err))
opts.critical("Script failed in a horrible way")
sys.exit(NAGIOS_EXIT_CRITICAL)
示例4: PBSManager
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
class PBSManager():
def __init__(self):
self.p = PBSQuery()
self.queue = self.p.getqueue(survey)
self.jobs = self.p.getjobs()
self.nodes = self.p.getnodes_with_property(use_ressources)
self.queue_names = self.jobs.keys()
#print self.nodes
#print self.nodes['psr13']['ncpus']
def jobs_running(self):
queue_status = self.queue['state_count'][0]
Transit, Queued, Held, Waiting, Running, Exiting = queue_status.split()
Queued = int(Queued.split(':')[1])
Running = int(Running.split(':')[1])
return Running, Queued
def is_running(self, basefilename):
jobnames = []
for jobs_name in self.queue_names:
job_info = self.jobs[jobs_name]
jobnames.append(job_info["Job_Name"][0])
return (basefilename in jobnames)
def get_stderr_path(self, basefilename):
stderr_path = os.path.join(logs_loc, "%s.err"%(basefilename))
if not os.path.exists(stderr_path):
raise ValueError("Cannot find error log for job (%s): %s" % \
(basefilename, stderr_path))
return stderr_path
def had_errors(self, basefilename):
try:
errorlog = self.get_stderr_path(basefilename)
except ValueError:
errors = False
else:
if os.path.getsize(errorlog) > 0:
errors = True
else:
errors = False
return errors
def get_errors(self, basefilename):
try:
errorlog = self.get_stderr_path(basefilename)
except ValueError, e:
errors = str(e)
else:
示例5: main
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def main():
pq = PBSQuery()
jobsdict = pq.getjobs()
for jobid, job in sorted(jobsdict.iteritems()):
print jobid
for k, v in job.iteritems():
print " ", k, v
print ""
示例6: getModelJobs
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def getModelJobs():
"""
1. get jobs
2. get users
3. map each job to User and Queue
4. save all jobs
"""
resultJobs = []
pQuery = PBSQuery()
try:
jobs = pQuery.getjobs()
for jobName, pbsJob in jobs.items():
customJob = PBSJob(jobId=jobName)
try:
customJob.name = TorqueService._listToStr(pbsJob[pbs.ATTR_name], '|')
except KeyError:
pass
try:
customJob.owner = TorqueService._listToStr(pbsJob[pbs.ATTR_owner], '|')
except KeyError:
pass
try:
customJob.state = TorqueService._listToStr(pbsJob[pbs.ATTR_state], '|')
except KeyError:
pass
try:
customJob.queue_raw = TorqueService._listToStr(pbsJob[pbs.ATTR_queue], '|')
except KeyError:
pass
try:
customJob.start_time = datetime.fromtimestamp(TorqueService._listToInt(pbsJob[pbs.ATTR_start_time]))
except KeyError:
pass
try:
customJob.resource_cput = TorqueService._listToStr(pbsJob[pbs.ATTR_used]['cput'], '|')
except KeyError:
pass
try:
customJob.resource_mem = TorqueService._listToStr(pbsJob[pbs.ATTR_used]['mem'], '|')
except KeyError:
pass
try:
customJob.resource_vmem = TorqueService._listToStr(pbsJob[pbs.ATTR_used]['vmem'], '|')
except KeyError:
pass
try:
customJob.resource_walltime = TorqueService._listToStr(pbsJob[pbs.ATTR_used]['walltime'], '|')
except KeyError:
pass
resultJobs.append(customJob)
except PBSError as pbsErr:
print(pbsErr)
return resultJobs
示例7: print_header
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def print_header():
# try connecting to the PBS server
print "Content-Type: text/html"
try:
pbs = PBSQuery(SERVER)
jobs = pbs.getjobs()
# ldin = ldap.open("192.168.0.90")
except PBSError, error:
print "<h1>Error connecting to PBS server:</h1><tt>",error,"</tt>"
sys.exit(1)
示例8: getJobs
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def getJobs():
resultJobs = []
p = PBSQuery()
try:
jobs = p.getjobs()
for jobId, pbsJob in jobs.items():
customJob = Job(jobId)
try:
customJob.state = TorqueService._listToStr(pbsJob[pbs.ATTR_state], '|')
except KeyError:
pass
try:
customJob.user = TorqueService._listToStr(pbsJob[pbs.ATTR_owner], '|')
except KeyError:
pass
try:
customJob.queue = TorqueService._listToStr(pbsJob[pbs.ATTR_queue], '|')
except KeyError:
pass
try:
customJob.name = TorqueService._listToStr(pbsJob[pbs.ATTR_name], '|')
except KeyError:
pass
try:
customJob.cpu_time = TorqueService._listToStr(pbsJob[pbs.ATTR_l]['walltime'], '|')
except KeyError:
pass
try:
customJob.n_p = TorqueService._splitResourcesList(pbsJob[pbs.ATTR_l]['nodes'])
except KeyError:
pass
try:
customJob.setQueued(TorqueService._listToStr(pbsJob[pbs.ATTR_qtime], '|'))
except KeyError:
pass
try:
customJob.setStarted(TorqueService._listToStr(pbsJob[pbs.ATTR_start_time], '|'))
except KeyError:
pass
try:
customJob.running_time = TorqueService._listToStr(pbsJob[pbs.ATTR_used]['walltime'], '|')
except KeyError:
pass
resultJobs.append(customJob)
except PBSError as pbsErr:
print(pbsErr)
return resultJobs
示例9: main
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def main(args):
"""Main script."""
options = {
'nagios': ('print out nagion information', None, 'store_true', False, 'n'),
'nagios_check_filename': ('filename of where the nagios check data is stored', str, 'store', NAGIOS_CHECK_FILENAME),
'nagios_check_interval_threshold': ('threshold of nagios checks timing out', None, 'store', NAGIOS_CHECK_INTERVAL_THRESHOLD),
'mail-report': ('mail a report to the hpc-admin list with job list for gracing or inactive users',
None, 'store_true', False),
'ha': ('high-availability master IP address', None, 'store', None),
'dry-run': ('do not make any updates whatsoever', None, 'store_true', False),
}
opts = simple_option(options)
nagios_reporter = NagiosReporter(NAGIOS_HEADER, NAGIOS_CHECK_FILENAME, NAGIOS_CHECK_INTERVAL_THRESHOLD)
if opts.options.nagios:
nagios_reporter.report_and_exit()
sys.exit(0) # not reached
if not proceed_on_ha_service(opts.options.ha):
logger.warning("Not running on the target host in the HA setup. Stopping.")
nagios_reporter(NAGIOS_EXIT_WARNING,
NagiosResult("Not running on the HA master."))
sys.exit(NAGIOS_EXIT_WARNING)
try:
vsc_config = VscConfiguration()
LdapQuery(vsc_config)
grace_users = get_user_with_status('grace')
inactive_users = get_user_with_status('inactive')
pbs_query = PBSQuery()
t = time.ctime()
jobs = pbs_query.getjobs() # we just get them all
removed_queued = remove_queued_jobs(jobs, grace_users, inactive_users, opts.options.dry_run)
removed_running = remove_running_jobs(jobs, inactive_users, opts.options.dry_run)
if opts.options.mail_report and not opts.options.dry_run:
if len(removed_queued) > 0 or len(removed_running) > 0:
mail_report(t, removed_queued, removed_running)
except Exception, err:
logger.exception("Something went wrong: {err}".format(err=err))
nagios_reporter.cache(NAGIOS_EXIT_CRITICAL,
NagiosResult("Script failed, check log file ({logfile})".format(logfile=PBS_CHECK_LOG_FILE)))
sys.exit(NAGIOS_EXIT_CRITICAL)
示例10: main
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
def main():
"""Main script."""
options = {
'nagios-check-interval-threshold': NAGIOS_CHECK_INTERVAL_THRESHOLD,
'mail-report': ('mail a report to the hpc-admin list with job list for gracing or inactive users',
None, 'store_true', False),
'access_token': ('OAuth2 token to access the account page REST API', None, 'store', None),
'account_page_url': ('URL of the account page where we can find the REST API', None, 'store', None)
}
opts = ExtendedSimpleOption(options)
try:
now = datetime.datetime.utcnow()
timestamp = now - datetime.timedelta(days=1)
client = AccountpageClient(token=opts.options.access_token, url=opts.options.account_page_url + "/api/")
active_users, inactive_users = client.get_accounts()
grace_users = []
for a in active_users:
try:
if a.expiry_date and datetime.datetime.strptime(a.expiry_date, "%Y-%m-%d") - now < datetime.timedelta(days=7):
grace_users.append(a)
except AttributeError as err:
logger.debug("Account %s does not have expiry date", a.vsc_id)
pbs_query = PBSQuery()
t = time.ctime()
jobs = pbs_query.getjobs() # we just get them all
removed_queued = remove_queued_jobs(jobs, grace_users, inactive_users)
removed_running = remove_running_jobs(jobs, inactive_users)
if opts.options.mail_report and not opts.options.dry_run:
if len(removed_queued) > 0 or len(removed_running) > 0:
mail_report(t, removed_queued, removed_running)
except Exception, err:
logger.exception("critical exception caught: %s" % (err))
opts.critical("Script failed in a horrible way")
sys.exit(NAGIOS_EXIT_CRITICAL)
示例11: nicer
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
class QstatViewer:
"""
Presents a nicer (?) interface to PBSQuery
The two main member objects are:
* jobs -- a dictionary with job ID (as str) as the key,
and the corresponding Job object as the value
* nodes -- a dictionary with node name as the key,
and a set of corresponding job IDs (of jobs
running on node)
"""
def __init__(self, pbs_server=None, debug_p=False):
"""Creates a QstatViewer object. Arguments:
- pbs_server : FQDN of the TORQUE server to query (string)"""
self.debug_p = debug_p
self.nodes = {}
self.jobs = {}
self.queues = {}
self.pbsquery = PBSQuery(pbs_server)
self.servername = self.pbsquery.get_server_name()
self.__make_server()
self.__make_queues()
self.__make_jobs()
self.__make_nodes()
def __make_nodes(self):
"""Make dict with node names as keys, and list of job objects as values"""
# make list of jobids running on the node
#node_jobs = {}
#for jobid,job in self.jobs.iteritems():
# if job.exec_host:
# for node_cpu in job.exec_host:
# node = node_cpu.split('/')[0]
# if node not in node_jobs:
# node_jobs[node] = []
# else:
# node_jobs[node].append(jobid)
rawnodes = self.pbsquery.getnodes()
for n,s in rawnodes.iteritems():
self.nodes[n] = Node(name=n, pbsnodes_dict=dict(s), debug_p=self.debug_p)
def __make_jobs(self):
"""Make dict with job IDs as keys, and job properties as values"""
rawjobs = self.pbsquery.getjobs()
for j,p in rawjobs.iteritems():
self.jobs[j] = Job(id=j, pbsjobs_dict=dict(p), debug_p=self.debug_p)
def __make_queues(self):
"""make dict with queue names as keys, and queue properties as values"""
rawqueues = self.pbsquery.getqueues()
for q,p in rawqueues.iteritems():
self.queues[q] = Queue(name=q, pbsqueue_dict=p)
def __make_server(self):
self.__serverinfo = self.pbsquery.get_serverinfo()[self.servername]
if self.debug_p:
print 'FOOBAR: self.serverinfo =', self.__serverinfo
for k,v in self.__serverinfo.iteritems():
self.__dict__[k] = None
if k == 'state_count':
# Example of state_count: Transit:0 Queued:-6458 Held:6383 Waiting:0 Running:964 Exiting:0
self.__dict__[k] = {}
vals = v[0].strip().split(' ')
for state in vals:
statename = state.split(':')[0]
stateval = int(state.split(':')[1])
self.__dict__[k][statename] = stateval
elif k == 'resources_default':
v['mem'] = Memory(v['mem'][0])
v['pmem'] = Memory(v['pmem'][0])
v['cput'] = pbstimestr_to_timedelta(v['cput'][0])
v['walltime'] = pbstimestr_to_timedelta(v['walltime'][0])
self.__dict__[k] = v
elif k == 'resources_assigned':
if 'mem' in v:
v['mem'] = Memory(v['mem'][0])
if 'vmem' in v:
v['vmem'] = Memory(v['vmem'][0])
if 'ncpus' in v:
v['ncpus'] = int(v['ncpus'][0])
if 'nodect' in v:
v['nodect'] = int(v['nodect'][0])
self.__dict__[k] = v
elif k == 'scheduling' or k == 'query_other_jobs':
if v[0] == 'True':
v[0] = True
elif v[0] == 'False':
v[0] = False
self.__dict__[k] = v[0]
#.........这里部分代码省略.........
示例12:
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
#!/usr/bin/python
from PBSQuery import PBSQuery, PBSError
server = 'grid63.lal.in2p3.fr'
try:
p=PBSQuery(server)
pbs=p.get_serverinfo()
nodes=p.getnodes()
jobs=p.getjobs()
queues=p.getqueues()
except PBSError, e:
print "<h3>Error connecting to PBS server:</h3><tt>",e,"</tt>"
sys.exit(1)
print ""
print "Server info:"
print pbs
print ""
print "Nodes:"
for node in nodes.keys():
print "********** %s *********" % node
print nodes[node]
print ""
print "Jobs:"
for job in jobs.keys():
print "********** Job %s *********" % job
print jobs[job]
示例13: PBSQuery
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
#!/usr/bin/env python
import sys
import os
from PBSQuery import PBSQuery
pq = PBSQuery('torque')
jobs = pq.getjobs()
print '# There are %d jobs\n' % (len(jobs))
for k,v in jobs.iteritems():
v = dict(v)
print k
for l,w in v.iteritems():
print '\t',l,'\t\t',w
print '-----'
示例14: len
# 需要导入模块: from PBSQuery import PBSQuery [as 别名]
# 或者: from PBSQuery.PBSQuery import getjobs [as 别名]
else:
nodereq = self.resource_list['nodes'][0].split('+')
ncpus = len(nodereq)
return ncpus
def __list_unique_hosts(self):
uniq_hosts = set()
if self.exec_host:
for h in self.exec_host:
uniq_hosts.add(h.split('/')[0])
return uniq_hosts
def __str__(self):
return str(self.__dict__)
if __name__ == '__main__':
pq = PBSQuery()
jobs = {}
for k,v in pq.getjobs().iteritems():
#print type(dict(v))
#print dict(v)
jobs[k] = Job(id=k, pbsjobs_dict=dict(v))
for k,v in jobs.iteritems():
print k, ': ', v, '\n'
#print v.id, ': ', v.job_state