Skip to content

Commit aeabebd

Browse files
committed
refactor: modified is_controller
1 parent fcdc0d0 commit aeabebd

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

pyslurm/pyslurm.pyx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,25 @@ def get_controllers():
275275
return control_machs
276276

277277

278-
#def is_controller(Host=None):
279-
# u"""Return slurm controller status for host.
280-
#
281-
# :param string Host: Name of host to check
282-
#
283-
# :returns: None, primary or backup
284-
# :rtype: `string`
285-
# """
286-
# primary, backup = get_controllers()
287-
# if not Host:
288-
# Host = gethostname()
289-
#
290-
# if primary == Host:
291-
# return u'primary'
292-
# if backup == Host:
293-
# return u'backup'
278+
def is_controller(Host=None):
279+
u"""Return slurm controller status for host.
280+
281+
:param string Host: Name of host to check
282+
283+
:returns: None, primary or backup
284+
:rtype: `string`
285+
"""
286+
control_machs = get_controllers()
287+
if not Host:
288+
Host = gethostname()
289+
290+
index = control_machs.index(Host)
291+
if index == -1:
292+
return None
293+
if index == 0:
294+
return u'primary'
295+
if index > 0:
296+
return u'backup'
294297

295298

296299
def slurm_api_version():

0 commit comments

Comments
 (0)