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
8 changes: 4 additions & 4 deletions pyslurm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

sys.setdlopenflags(sys.getdlopenflags() | os.RTLD_GLOBAL | os.RTLD_DEEPBIND)

# Initialize slurm api
from pyslurm.api import slurm_init, slurm_fini
slurm_init()

from .version import __version__

from pyslurm import db
Expand All @@ -35,3 +31,7 @@

# The old API in deprecated.pyx
from pyslurm.deprecated import *

# Initialize slurm api
from pyslurm.api import slurm_init, slurm_fini
slurm_init()
3 changes: 3 additions & 0 deletions pyslurm/api.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# cython: c_string_type=unicode, c_string_encoding=default
# cython: language_level=3

from pyslurm import settings


def slurm_init(config_path=None):
"""Initialize the Slurm API.
Expand All @@ -36,6 +38,7 @@ def slurm_init(config_path=None):
None, so libslurm will automatically detect its config.
"""
slurm.slurm_init(cstr.from_unicode(config_path))
settings.init()


def slurm_fini():
Expand Down
4 changes: 2 additions & 2 deletions pyslurm/core/job/job.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ from typing import Union
from pyslurm.utils import cstr, ctime
from pyslurm.utils.uint import *
from pyslurm.core.job.util import *
from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
from pyslurm import xcollections
from pyslurm.core.error import (
RPCError,
Expand Down Expand Up @@ -236,7 +236,7 @@ cdef class Job:
self.ptr.job_id = job_id
self.passwd = {}
self.groups = {}
cstr.fmalloc(&self.ptr.cluster, LOCAL_CLUSTER)
cstr.fmalloc(&self.ptr.cluster, settings.LOCAL_CLUSTER)
self.steps = JobSteps()
self.stats = JobStatistics()
self.pids = {}
Expand Down
4 changes: 2 additions & 2 deletions pyslurm/core/job/step.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ from typing import Union
from pyslurm.utils import cstr, ctime
from pyslurm.utils.uint import *
from pyslurm.core.error import RPCError, verify_rpc
from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
from pyslurm import xcollections
from pyslurm.utils.helpers import (
signal_to_num,
Expand Down Expand Up @@ -159,7 +159,7 @@ cdef class JobStep:
self.id = step_id
self.stats = JobStepStatistics()
self.pids = {}
cstr.fmalloc(&self.ptr.cluster, LOCAL_CLUSTER)
cstr.fmalloc(&self.ptr.cluster, settings.LOCAL_CLUSTER)

# Initialize attributes, if any were provided
for k, v in kwargs.items():
Expand Down
6 changes: 3 additions & 3 deletions pyslurm/core/node.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ from pyslurm.utils import ctime
from pyslurm.utils.uint import *
from pyslurm.core.error import RPCError, verify_rpc
from pyslurm.utils.ctime import timestamp_to_date, _raw_time
from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
from pyslurm import xcollections
from pyslurm.utils.helpers import (
uid_to_name,
Expand Down Expand Up @@ -222,7 +222,7 @@ cdef class Node:
def __init__(self, name=None, **kwargs):
self._alloc_impl()
self.name = name
self.cluster = LOCAL_CLUSTER
self.cluster = settings.LOCAL_CLUSTER
for k, v in kwargs.items():
setattr(self, k, v)

Expand Down Expand Up @@ -270,7 +270,7 @@ cdef class Node:
wrap._alloc_info()
wrap.passwd = {}
wrap.groups = {}
wrap.cluster = LOCAL_CLUSTER
wrap.cluster = settings.LOCAL_CLUSTER
memcpy(wrap.info, in_ptr, sizeof(node_info_t))
return wrap

Expand Down
3 changes: 1 addition & 2 deletions pyslurm/core/partition.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ from pyslurm.utils cimport cstr
from pyslurm.utils cimport ctime
from pyslurm.utils.ctime cimport time_t
from pyslurm.utils.uint cimport *
from pyslurm.core cimport slurmctld
from pyslurm.xcollections cimport MultiClusterMap


Expand Down Expand Up @@ -218,7 +217,7 @@ cdef class Partition:
cdef:
partition_info_t *ptr
int power_save_enabled
slurmctld.Config slurm_conf
slurm_conf

cdef readonly cluster

Expand Down
10 changes: 5 additions & 5 deletions pyslurm/core/partition.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ from pyslurm.utils.uint import *
from pyslurm.core.error import RPCError, verify_rpc
from pyslurm.utils.ctime import timestamp_to_date, _raw_time
from pyslurm.constants import UNLIMITED
from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
from pyslurm.core import slurmctld
from pyslurm.core.slurmctld.config import _get_memory
from pyslurm import xcollections
from pyslurm.utils.helpers import (
Expand Down Expand Up @@ -78,7 +79,6 @@ cdef class Partitions(MultiClusterMap):
Partitions partitions = Partitions()
int flags = slurm.SHOW_ALL
Partition partition
slurmctld.Config slurm_conf
int power_save_enabled = 0

verify_rpc(slurm_load_partitions(0, &partitions.info, flags))
Expand Down Expand Up @@ -168,7 +168,7 @@ cdef class Partition:
def __init__(self, name=None, **kwargs):
self._alloc_impl()
self.name = name
self.cluster = LOCAL_CLUSTER
self.cluster = settings.LOCAL_CLUSTER
for k, v in kwargs.items():
setattr(self, k, v)

Expand All @@ -194,7 +194,7 @@ cdef class Partition:
cdef Partition from_ptr(partition_info_t *in_ptr):
cdef Partition wrap = Partition.__new__(Partition)
wrap._alloc_impl()
wrap.cluster = LOCAL_CLUSTER
wrap.cluster = settings.LOCAL_CLUSTER
memcpy(wrap.ptr, in_ptr, sizeof(partition_info_t))
return wrap

Expand Down Expand Up @@ -801,7 +801,7 @@ def _preempt_mode_str_to_int(mode):
return pmode


def _preempt_mode_int_to_str(mode, slurmctld.Config slurm_conf):
def _preempt_mode_int_to_str(mode, slurm_conf):
if mode == slurm.NO_VAL16:
return slurm_conf.preempt_mode if slurm_conf else None
else:
Expand Down
4 changes: 0 additions & 4 deletions pyslurm/core/slurmctld/__init__.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
# cython: c_string_type=unicode, c_string_encoding=default
# cython: language_level=3

from .config cimport Config
8 changes: 4 additions & 4 deletions pyslurm/db/assoc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ from pyslurm.utils.helpers import (
)
from pyslurm.utils.uint import *
from pyslurm.db.connection import _open_conn_or_error
from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
from pyslurm import xcollections


Expand Down Expand Up @@ -65,7 +65,7 @@ cdef class Associations(MultiClusterMap):
# Fetch Assoc Data
assoc_data = SlurmList.wrap(slurmdb_associations_get(
conn.ptr, cond.ptr))

if assoc_data.is_null:
raise RPCError(msg="Failed to get Association data from slurmdbd")

Expand Down Expand Up @@ -135,7 +135,7 @@ cdef class Associations(MultiClusterMap):
else:
# Autodetects the last slurm error
raise RPCError()

if not db_connection:
# Autocommit if no connection was explicitly specified.
conn.commit()
Expand Down Expand Up @@ -185,7 +185,7 @@ cdef class Association:
def __init__(self, **kwargs):
self._alloc_impl()
self.id = 0
self.cluster = LOCAL_CLUSTER
self.cluster = settings.LOCAL_CLUSTER
for k, v in kwargs.items():
setattr(self, k, v)

Expand Down
10 changes: 4 additions & 6 deletions pyslurm/db/job.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@

from typing import Union, Any
from pyslurm.core.error import RPCError, PyslurmError
from pyslurm.core import slurmctld
from typing import Any
from pyslurm.utils.uint import *
from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
from pyslurm import xcollections
from pyslurm.utils.ctime import (
date_to_timestamp,
Expand Down Expand Up @@ -106,7 +104,7 @@ cdef class JobFilter:
if not self.clusters:
# This is a requirement for some other parameters to function
# correctly, like self.nodelist
return [LOCAL_CLUSTER]
return [settings.LOCAL_CLUSTER]
elif self.clusters == "all":
return None
else:
Expand Down Expand Up @@ -450,7 +448,7 @@ cdef class Job:
self._alloc_impl()
self.ptr.jobid = int(job_id)
cstr.fmalloc(&self.ptr.cluster,
LOCAL_CLUSTER if not cluster else cluster)
settings.LOCAL_CLUSTER if not cluster else cluster)
self.qos_data = QualitiesOfService()
self.steps = JobSteps()
self.stats = JobStatistics()
Expand Down Expand Up @@ -511,7 +509,7 @@ cdef class Job:
>>> db_job = pyslurm.db.Job.load(10000, with_script=True)
>>> print(db_job.script)
"""
cluster = LOCAL_CLUSTER if not cluster else cluster
cluster = settings.LOCAL_CLUSTER if not cluster else cluster
jfilter = JobFilter(ids=[int(job_id)], clusters=[cluster],
with_script=with_script, with_env=with_env)
job = Jobs.load(jfilter).get((cluster, int(job_id)))
Expand Down
16 changes: 11 additions & 5 deletions pyslurm/settings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@
# cython: c_string_type=unicode, c_string_encoding=default
# cython: language_level=3

from pyslurm.core import slurmctld
from pyslurm cimport slurm
from pyslurm.utils cimport cstr


LOCAL_CLUSTER = cstr.to_unicode(slurm.slurm_conf.cluster_name)
if not LOCAL_CLUSTER:
slurm_conf = slurmctld.Config.load()
LOCAL_CLUSTER = slurm_conf.cluster_name
LOCAL_CLUSTER = "UNKNOWN"


def init():
from pyslurm.core import slurmctld

global LOCAL_CLUSTER
LOCAL_CLUSTER = cstr.to_unicode(slurm.slurm_conf.cluster_name)
if not LOCAL_CLUSTER:
slurm_conf = slurmctld.Config.load()
LOCAL_CLUSTER = slurm_conf.cluster_name
1 change: 1 addition & 0 deletions pyslurm/xcollections.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ cdef class MultiClusterMap:
_key_type
_val_type
_id_attr
_cluster
19 changes: 10 additions & 9 deletions pyslurm/xcollections.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# cython: language_level=3
"""Custom Collection utilities"""

from pyslurm.settings import LOCAL_CLUSTER
from pyslurm import settings
import json
from typing import Union, Any

Expand Down Expand Up @@ -193,6 +193,7 @@ cdef class MultiClusterMap:
self._key_type = key_type
self._val_type = val_type
self._id_attr = id_attr
self._cluster = settings.LOCAL_CLUSTER
if init_data:
self._init_data(data)

Expand All @@ -201,15 +202,15 @@ cdef class MultiClusterMap:
for item in data:
if isinstance(item, self._key_type):
item = self._val_type(item)
if LOCAL_CLUSTER not in self.data:
self.data[LOCAL_CLUSTER] = {}
if self._cluster not in self.data:
self.data[self._cluster] = {}

self.data[LOCAL_CLUSTER].update({self._item_id(item): item})
self.data[self._cluster].update({self._item_id(item): item})
elif isinstance(data, str):
itemlist = data.split(",")
items = {self._key_type(item):self._val_type(item)
for item in itemlist}
self.data[LOCAL_CLUSTER] = items
self.data[self._cluster] = items
elif isinstance(data, dict):
self.update(data)
elif data is not None:
Expand All @@ -223,8 +224,8 @@ cdef class MultiClusterMap:

def _get_cluster(self):
cluster = None
if not self.data or LOCAL_CLUSTER in self.data:
cluster = LOCAL_CLUSTER
if not self.data or self._cluster in self.data:
cluster = self._cluster
else:
try:
cluster = next(iter(self.keys()))
Expand Down Expand Up @@ -259,7 +260,7 @@ cdef class MultiClusterMap:
try:
cluster = self._get_cluster()
except KeyError:
cluster = LOCAL_CLUSTER
cluster = self._cluster

if not cluster in self.data:
self.data[cluster] = {}
Expand Down Expand Up @@ -394,7 +395,7 @@ cdef class MultiClusterMap:
according to `next(iter(self.keys()))` will be used.

Examples:
Get a Job from the LOCAL_CLUSTER
Get a Job from the local Cluster.

>>> job_id = 1
>>> job = data.get(job_id)
Expand Down
Loading