Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
575 changes: 575 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions examples/blocks_list.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env python

"""
Retrieve list of blocked items
"""
from __future__ import print_function

import pyslurm
from time import gmtime, strftime

def display(block_dict):

def display(block_dict):
"""Format output"""
if block_dict:

date_fields = [ ]
date_fields = []

print('{0:*^80}'.format(''))
print("{0:*^80}".format(""))

for key, value in block_dict.items():

Expand All @@ -22,19 +24,23 @@ def display(block_dict):
ddate = value[part_key]
if ddate == 0:
print("\t{0:<17} : N/A".format(part_key))
elif ('reason_uid' in part_key) and (value['reason'] is None):
elif ("reason_uid" in part_key) and (value["reason"] is None):
print("\t{0:<17} :".format(part_key))
else:
ddate = pyslurm.epoch2date(ddate)
print("\t{0:<17} : {1}".format(part_key, ddate))
elif part_key == 'connection_type':
print("\t{0:<17} : {1}".format(part_key, pyslurm.get_connection_type(value[part_key])))
elif part_key == 'state':
elif part_key == "connection_type":
print(
"\t{0:<17} : {1}".format(
part_key, pyslurm.get_connection_type(value[part_key])
)
)
elif part_key == "state":
print("\t{0:<17} : {1}".format(part_key, value[part_key]))
else:
print("\t{0:<17} : {1}".format(part_key, value[part_key]))

print('{0:*^80}'.format(''))
print("{0:*^80}".format(""))


if __name__ == "__main__":
Expand All @@ -43,15 +49,11 @@ def display(block_dict):
try:
a.load()
block_dict = a.get()
except ValueError as e:
print("Block query failed - {0}".format(e.args[0]))
except ValueError as value_error:
print("Block query failed - {0}".format(value_error.args[0]))
else:
if len(block_dict) > 0:

if block_dict:
display(block_dict)
print()
print("Block IDs - {0}".format(a.ids()))
print()

print("\nBlock IDs - {0}\n".format(a.ids()))
else:
print("No Blocks found !")
48 changes: 33 additions & 15 deletions examples/blocks_list2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python

"""
Retrieve list of blocked items
"""
from __future__ import print_function

import pyslurm
import sys
from time import sleep

class DictDiffer(object):
import pyslurm


class DictDiffer:
"""
http://stackoverflow.com/questions/1165352/fast-comparison-between-two-python-dictionary

Expand All @@ -16,20 +18,37 @@ class DictDiffer(object):
(2) items removed
(3) keys same in both but changed values
(4) keys same in both and unchanged values
"""
"""

def __init__(self, current_dict, past_dict):
"""set class attr"""
self.current_dict, self.past_dict = current_dict, past_dict
self.set_current, self.set_past = set(current_dict.keys()), set(past_dict.keys())
self.set_current, self.set_past = (
set(current_dict.keys()),
set(past_dict.keys()),
)
self.intersect = self.set_current.intersection(self.set_past)

def added(self):
"""Check if added"""
return self.set_current - self.intersect

def removed(self):
"""Check if removed"""
return self.set_past - self.intersect

def changed(self):
return set(o for o in self.intersect if self.past_dict[o] != self.current_dict[o])
"""Check if changed"""
return set(
o for o in self.intersect if self.past_dict[o] != self.current_dict[o]
)

def unchanged(self):
return set(o for o in self.intersect if self.past_dict[o] == self.current_dict[o])
"""Check for no change"""
return set(
o for o in self.intersect if self.past_dict[o] == self.current_dict[o]
)


if __name__ == "__main__":

Expand All @@ -45,14 +64,17 @@ def unchanged(self):

sleep(0.5)

while 1:

while True:
new_dict = a.get()
newUpdate = a.lastUpdate()
if newUpdate > lastUpdate:

lastUpdate = a.lastUpdate()
print("Block data update time changed - {0}".format(pyslurm.epoch2date(lastUpdate)))
print(
"Block data update time changed - {0}".format(
pyslurm.epoch2date(lastUpdate)
)
)

b = DictDiffer(block_dict, new_dict)
if b.changed():
Expand All @@ -64,13 +86,9 @@ def unchanged(self):
if b.removed():
print("\tRemoved block {0}".format(b.removed()))
change = 1

if change == 0:
print("\tBut no data was changed !")
change = 0

block_dict = new_dict

sleep(interval)

sys.exit()
8 changes: 5 additions & 3 deletions examples/cancel_job.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python

"""
Cancel a scheduled job
"""
from __future__ import print_function

import pyslurm

try:
rc = pyslurm.slurm_kill_job(51, 9, 0)
except ValueError as e:
print("Cancel job error - {0}".format(e.args[0]))
except ValueError as value_error:
print("Cancel job error - {0}".format(value_error.args[0]))
else:
print("Success - cancelled job")
10 changes: 6 additions & 4 deletions examples/checkpoint_job.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env python

"""
Retrieve a jobs checkpoint status
"""
from __future__ import print_function

import pyslurm

try:
time = pyslurm.slurm_checkpoint_able(2,0)
except ValueError as e:
print("Checkpointable job failed - {0}".format(e.args[0]))
time = pyslurm.slurm_checkpoint_able(2, 0)
except ValueError as value_error:
print("Checkpointable job failed - {0}".format(value_error.args[0]))
else:
print("Job can be checkpointed at {0}".format(time))
24 changes: 14 additions & 10 deletions examples/controllers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/usr/bin/env python

"""
Retrieve list up Slurm controllers
"""
from __future__ import print_function

import pyslurm
import socket
import sys

def controller_up(controller=1):
import pyslurm


def controller_up(controller=1):
"""Check if controller up via ping"""
try:
pyslurm.slurm_ping(controller)
except valueError as e:
print("Failed - {0}".format(e.args[0]))
except ValueError as value_error:
print("Failed - {0}".format(value_error.args[0]))
else:
print("Success")


if __name__ == "__main__":

print()
Expand All @@ -37,11 +41,11 @@ def controller_up(controller=1):
print("\nPinging SLURM controllers")

if primary:
print("\tPrimary .....", end=' ')
print("\tPrimary .....", end=" ")
controller_up()

if backup:
print("\tBackup .....", end=' ')
print("\tBackup .....", end=" ")
controller_up(2)
except ValueError as e:
print("Error - {0}".format(e.args[0]))
except ValueError as value_error:
print("Error - {0}".format(value_error.args[0]))
16 changes: 9 additions & 7 deletions examples/debug_levels.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#!/usr/bin/env python

"""
How to set Slurm debug level
"""
from __future__ import print_function

import pyslurm

SLURM_DEBUG=1
SCHED_DEBUG=0
SLURM_DEBUG = 1
SCHED_DEBUG = 0

try:
print("Setting Slurmd debug level to {0}".format(SLURM_DEBUG))
rc = pyslurm.slurm_set_debug_level(SLURM_DEBUG)
if rc == 0:
print("\tSuccess...Slurmd debug level updated to {0}".format(SLURM_DEBUG))
except ValueError as e:
print("\tError - {0}".format(e.args[0]))
except ValueError as value_error:
print("\tError - {0}".format(value_error.args[0]))

try:
print("Setting Schedlog debug level to {0}".format(SCHED_DEBUG))
rc = pyslurm.slurm_set_schedlog_level(SCHED_DEBUG)
if rc == 0:
print("\tSuccess...Schedlog log level updated to {0}".format(SCHED_DEBUG))
except ValueError as e:
print("\tError - {0}".format(e.args[0]))
except ValueError as value_error:
print("\tError - {0}".format(value_error.args[0]))
5 changes: 3 additions & 2 deletions examples/hostlist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

"""
Retrieve Slurm hosts
"""
from __future__ import print_function

import pyslurm
Expand All @@ -9,7 +11,6 @@
hosts = "dummy0,dummy1,dummy1,dummy3,dummy4"
print("Creating hostlist ...... with {0}".format(hosts))
if b.create(hosts):

print()
print("\tHost list count is {0}".format(b.count()))
node = "dummy3"
Expand Down
10 changes: 6 additions & 4 deletions examples/job_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python

"""
Class to access/modify Slurm Job Information.
"""
from __future__ import print_function

import pyslurm

try:
a = pyslurm.job()

jobs = a.get()
jobs = a.get()
print(jobs)
except ValueError as e:
print("Job list error - {0}".format(e.args[0]))
except ValueError as value_error:
print("Job list error - {0}".format(value_error.args[0]))
35 changes: 19 additions & 16 deletions examples/jobs_list.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/usr/bin/env python

"""
List Slurm jobs
"""
from __future__ import print_function

import pyslurm
import sys

from time import gmtime, strftime, sleep

def display(job_dict):

"""Format output"""
if job_dict:

time_fields = ['time_limit']
time_fields = ["time_limit"]

date_fields = ['start_time',
'submit_time',
'end_time',
'eligible_time',
'resize_time']
date_fields = [
"start_time",
"submit_time",
"end_time",
"eligible_time",
"resize_time",
]

for key, value in sorted(job_dict.items()):

Expand All @@ -40,23 +42,24 @@ def display(job_dict):

print("-" * 80)


if __name__ == "__main__":

try:
a = pyslurm.job()
jobs = a.get()

if len(jobs) > 0:
if jobs:

display(jobs)

print()
print("Number of Jobs - {0}".format(len(jobs)))
print()

pending = a.find('job_state', 'PENDING')
running = a.find('job_state', 'RUNNING')
held = a.find('job_state', 'RUNNING')
pending = a.find("job_state", "PENDING")
running = a.find("job_state", "RUNNING")
held = a.find("job_state", "RUNNING")

print("Number of pending jobs - {0}".format(len(pending)))
print("Number of running jobs - {0}".format(len(running)))
Expand All @@ -68,5 +71,5 @@ def display(job_dict):
else:

print("No jobs found !")
except ValueError as e:
print("Job query failed - {0}".format(e.args[0]))
except ValueError as value_error:
print("Job query failed - {0}".format(value_error.args[0]))
Loading