Skip to content

Commit a73708d

Browse files
committed
slurmctld: more docs
1 parent 130478c commit a73708d

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed

pyslurm/core/slurmctld/base.pxd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,21 @@ from pyslurm.utils cimport cstr
4040

4141

4242
cdef class PingResponse:
43-
"""Slurm Controller Ping response information"""
43+
"""Slurm Controller Ping response information
4444
45+
Attributes:
46+
is_primary (bool):
47+
Whether this Slurm Controller is the primary Server.
48+
is_responding (bool):
49+
Whether this Slurm Controller actually responds to the ping.
50+
index (int):
51+
The index in the slurm.conf. For example, 0 means primary.
52+
hostname (str):
53+
Hostname of the Controller
54+
latency (float):
55+
The latency which the Controller responds with. This is in
56+
milliseconds.
57+
"""
4558
cdef public:
4659
is_primary
4760
is_responding

pyslurm/core/slurmctld/base.pyx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
from pyslurm.core.error import verify_rpc, RPCError
2626
from pyslurm.utils.helpers import instance_to_dict
2727
from pyslurm.utils import cstr
28+
from pyslurm.utils.uint import u16_parse
2829
from typing import Union
2930
import time
3031
from enum import IntEnum
3132
from .config import Config
32-
from pyslurm.utils.uint import u16_parse
3333
from .enums import ShutdownMode
3434

3535

@@ -88,6 +88,12 @@ def ping_primary():
8888
8989
Returns:
9090
(pyslurm.slurmctld.PingResponse): a ping response
91+
92+
Examples:
93+
>>> from pyslurm import slurmctld
94+
>>> resp = slurmctld.ping_primary()
95+
>>> print(resp.hostname, resp.latency, resp.is_primary)
96+
slurmctl 1.222 True
9197
"""
9298
return ping(0)
9399

@@ -99,6 +105,12 @@ def ping_backup():
99105
100106
Returns:
101107
(pyslurm.slurmctld.PingResponse): a ping response
108+
109+
Examples:
110+
>>> from pyslurm import slurmctld
111+
>>> resp = slurmctld.ping_backup()
112+
>>> print(resp.hostname, resp.latency, resp.is_primary)
113+
slurmctlbackup 1.373 False
102114
"""
103115
return ping(1)
104116

@@ -140,6 +152,10 @@ def shutdown(mode: Union[ShutdownMode, int]):
140152
141153
Raises:
142154
(pyslurm.RPCError): When shutdowning the daemons was not successful.
155+
156+
Examples:
157+
>>> from pyslurm import slurmctld
158+
>>> slurmctld.shutdown(slurmctld.ShutdownMode.ALL)
143159
"""
144160
verify_rpc(slurm_shutdown(int(mode)))
145161

@@ -149,6 +165,10 @@ def reconfigure():
149165
150166
Raises:
151167
(pyslurm.RPCError): When reconfiguring was not successful.
168+
169+
Examples:
170+
>>> from pyslurm import slurmctld
171+
>>> slurmctld.reconfigure()
152172
"""
153173
verify_rpc(slurm_reconfigure())
154174

@@ -168,6 +188,10 @@ def takeover(index = 1):
168188
169189
Raises:
170190
(pyslurm.RPCError): When reconfiguring was not successful.
191+
192+
Examples:
193+
>>> from pyslurm import slurmctld
194+
>>> slurmctld.takeover(1)
171195
"""
172196
verify_rpc(slurm_takeover(index))
173197

@@ -176,7 +200,7 @@ def add_debug_flags(flags):
176200
"""Add DebugFlags to slurmctld
177201
178202
Args:
179-
flags (list):
203+
flags (list[str]):
180204
For an available list of possible values, please check the
181205
`slurm.conf` documentation under `DebugFlags`.
182206
@@ -185,7 +209,7 @@ def add_debug_flags(flags):
185209
186210
Examples:
187211
>>> from pyslurm import slurmctld
188-
>>> slurmctld.add_debug_flags(["CpuFrequency"])
212+
>>> slurmctld.add_debug_flags(["CpuFrequency", "Backfill"])
189213
"""
190214
if not flags:
191215
return
@@ -201,7 +225,7 @@ def remove_debug_flags(flags):
201225
"""Remove DebugFlags from slurmctld.
202226
203227
Args:
204-
flags (list):
228+
flags (list[str]):
205229
For an available list of possible values, please check the
206230
`slurm.conf` documentation under `DebugFlags`.
207231
@@ -231,6 +255,8 @@ def clear_debug_flags():
231255
Examples:
232256
>>> from pyslurm import slurmctld
233257
>>> slurmctld.clear_debug_flags()
258+
>>> print(slurmctld.get_debug_flags())
259+
[]
234260
"""
235261
current_flags = get_debug_flags()
236262
if not current_flags:
@@ -269,6 +295,9 @@ def set_log_level(level):
269295
Examples:
270296
>>> from pyslurm import slurmctld
271297
>>> slurmctld.set_log_level("quiet")
298+
>>> log_level = slurmctld.get_log_level()
299+
>>> print(log_level)
300+
quiet
272301
"""
273302
data = _log_level_str_to_int(level)
274303
verify_rpc(slurm_set_debug_level(data))
@@ -282,8 +311,8 @@ def get_log_level():
282311
283312
Examples:
284313
>>> from pyslurm import slurmctld
285-
>>> level = slurmctld.get_log_level()
286-
>>> print(level)
314+
>>> log_level = slurmctld.get_log_level()
315+
>>> print(log_level)
287316
quiet
288317
"""
289318
return Config.load().slurmctld_log_level
@@ -298,6 +327,8 @@ def enable_scheduler_logging():
298327
Examples:
299328
>>> from pyslurm import slurmctld
300329
>>> slurmctld.enable_scheduler_logging()
330+
>>> print(slurmctld.is_scheduler_logging_enabled())
331+
True
301332
"""
302333
verify_rpc(slurm_set_schedlog_level(1))
303334

@@ -334,6 +365,8 @@ def set_fair_share_dampening_factor(factor):
334365
Examples:
335366
>>> from pyslurm import slurmctld
336367
>>> slurmctld.set_fair_share_dampening_factor(100)
368+
>>> print(slurmctld.get_fair_share_dampening_factor)
369+
100
337370
"""
338371
max_value = (2 ** 16) - 1
339372
if not factor or factor >= max_value:

pyslurm/core/slurmctld/config.pxd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ cdef class Config:
7979
All attributes in this class are read-only.
8080
8181
Attributes:
82+
cgroup_config (pyslurm.slurmctld.CgroupConfig):
83+
The CGroup Configuration data
84+
accounting_gather_config (pyslurm.slurmctld.AccountingGatherConfig):.
85+
The Accounting Gather Configuration data.
86+
mpi_config (pyslurm.slurmctld.MPIConfig):
87+
The MPI Configuration data.
8288
accounting_storage_enforce (list[str]):
8389
List of enforcements on Job submissions.
8490
@@ -1104,7 +1110,7 @@ cdef class MPIConfig:
11041110
of the job have the same architecture.
11051111
11061112
{mpi.conf#OPT_PMIxDirectSameArch}
1107-
pmix_environment (dict[str, Union[str, int]):
1113+
pmix_environment (dict[str, Union[str, int]]):
11081114
Environment variables to bet set in the Job environment, used by
11091115
PMIx.
11101116

pyslurm/core/slurmctld/config.pyx

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ from typing import Union
4141
cdef class MPIConfig:
4242

4343
def __init__(self):
44-
raise RuntimeError("Cannot instantiate class directly")
44+
raise RuntimeError("Cannot instantiate class directly. "
45+
"Use slurmctld.Config.load() and access the "
46+
"mpi_config attribute there")
4547

4648
def to_dict(self):
4749
"""MPI config formatted as a dictionary.
@@ -82,7 +84,9 @@ cdef class MPIConfig:
8284
cdef class CgroupConfig:
8385

8486
def __init__(self):
85-
raise RuntimeError("Cannot instantiate class directly")
87+
raise RuntimeError("Cannot instantiate class directly. "
88+
"Use slurmctld.Config.load() and access the "
89+
"cgroup_config attribute there")
8690

8791
def to_dict(self):
8892
"""Cgroup config formatted as a dictionary.
@@ -128,7 +132,9 @@ cdef class CgroupConfig:
128132
cdef class AccountingGatherConfig:
129133

130134
def __init__(self):
131-
raise RuntimeError("Cannot instantiate class directly")
135+
raise RuntimeError("Cannot instantiate class directly. "
136+
"Use slurmctld.Config.load() and access the "
137+
"accounting_gather_config attribute there")
132138

133139
def to_dict(self):
134140
"""AccountingGather config formatted as a dictionary.
@@ -152,10 +158,8 @@ cdef class AccountingGatherConfig:
152158
out.energy_ipmi_frequency = int(conf.get("EnergyIPMIFrequency", 30))
153159
out.energy_ipmi_calc_adjustment = _yesno_to_bool(
154160
conf.get("EnergyIPMICalcAdjustment"))
155-
156-
# TODO: maybe dict?
157-
out.energy_ipmi_power_sensors = conf.get("EnergyIPMIPowerSensors")
158-
161+
out.energy_ipmi_power_sensors = cstr.to_dict(
162+
conf.get("EnergyIPMIPowerSensors", ""), delim1=";", delim2="=")
159163
out.energy_ipmi_user_name = conf.get("EnergyIPMIUsername")
160164
out.energy_ipmi_password = conf.get("EnergyIPMIPassword")
161165
out.energy_ipmi_timeout = int(conf.get("EnergyIPMITimeout", 10))
@@ -190,22 +194,6 @@ cdef class Config:
190194
slurm_free_ctl_conf(self.ptr)
191195
self.ptr = NULL
192196

193-
@staticmethod
194-
def load_scontrol():
195-
cdef Config conf = Config.__new__(Config)
196-
verify_rpc(slurm_load_ctl_conf(0, &conf.ptr))
197-
198-
out = _parse_config_key_pairs(slurm_ctl_conf_2_key_pairs(conf.ptr),
199-
owned=True)
200-
out["CgroupSupportConfiguration"] = _parse_config_key_pairs(
201-
conf.ptr.cgroup_conf)
202-
out["AccountingGatherConfiguration"] = _parse_config_key_pairs(
203-
conf.ptr.acct_gather_conf)
204-
out["MPIPluginsConfiguration"] = _parse_config_key_pairs(
205-
conf.ptr.mpi_conf)
206-
207-
return out
208-
209197
@staticmethod
210198
def load():
211199
"""Load the current Slurm configuration (slurm.conf)
@@ -351,7 +339,6 @@ cdef class Config:
351339

352340
@property
353341
def batch_start_timeout(self):
354-
# seconds
355342
return u16_parse(self.ptr.batch_start_timeout)
356343

357344
@property
@@ -394,7 +381,6 @@ cdef class Config:
394381

395382
@property
396383
def complete_wait_time(self):
397-
# seconds
398384
return u16_parse(self.ptr.complete_wait)
399385

400386
@property
@@ -442,7 +428,6 @@ cdef class Config:
442428

443429
@property
444430
def eio_timeout(self):
445-
# seconds
446431
return u16_parse(self.ptr.eio_timeout)
447432

448433
@property
@@ -458,7 +443,6 @@ cdef class Config:
458443

459444
@property
460445
def epilog_msg_time(self):
461-
# ms
462446
return u32_parse(self.ptr.epilog_msg_time)
463447

464448
@property
@@ -525,7 +509,6 @@ cdef class Config:
525509

526510
@property
527511
def inactive_limit(self):
528-
# seconds
529512
return u16_parse(self.ptr.inactive_limit)
530513

531514
@property
@@ -598,7 +581,6 @@ cdef class Config:
598581

599582
@property
600583
def kill_wait_time(self):
601-
# seconds
602584
return u16_parse(self.ptr.kill_wait)
603585

604586
@property
@@ -754,7 +736,6 @@ cdef class Config:
754736

755737
@property
756738
def priority_decay_half_life(self):
757-
# seconds
758739
return u32_parse(self.ptr.priority_decay_hl)
759740

760741
@property
@@ -852,7 +833,6 @@ cdef class Config:
852833

853834
@property
854835
def prolog_epilog_timeout(self):
855-
# seconds
856836
return u16_parse(self.ptr.prolog_epilog_timeout)
857837

858838
@property
@@ -942,7 +922,6 @@ cdef class Config:
942922

943923
@property
944924
def scheduler_time_slice(self):
945-
# seconds
946925
return u16_parse(self.ptr.sched_time_slice)
947926

948927
@property
@@ -1027,7 +1006,6 @@ cdef class Config:
10271006

10281007
@property
10291008
def slurmctld_timeout(self):
1030-
# seconds
10311009
return u16_parse(self.ptr.slurmctld_timeout)
10321010

10331011
@property

0 commit comments

Comments
 (0)