Parsing the node_list variable from pyslurm.reservation().get()

38 views
Skip to first unread message

Christopher Coser US

unread,
Jul 23, 2019, 12:50:01 PM7/23/19
to pyslurm
The output format of the reservation query seems to use the collapsed format for the 'node_list' field. That is, something like

'node_list': 'foo-bar-[686-687]',

...which is somewhat less than useful when it comes to operating on nodes or comparing them. The 'users' field meanwhile, returns a lovely list structure through which I can easily iterate.

For the moment, I'm just going to write a regex to parse the node_list, but it would be incredibly useful if somehow pyslurm could provide an iterable node list for reservations. Perhaps something like pyslurm.node.parse_gres could be done for this? Do you know if you can get the separated list out of the API or will there have to be post-processing to extract it?

Giovanni

unread,
Jul 23, 2019, 1:36:40 PM7/23/19
to pyslurm
You can use the `hostlist` class to convert it to an iterable list. e.g.

>>> import pyslurm
>>> nodes = 'foo-bar-[686-687]'
>>> hl = pyslurm.hostlist()
>>> hl.create(nodes)
>>> hl.get_list()
['foo-bar-686', 'foo-bar-687']
>>> hl.destroy()

Perhaps PySlurm should offer this automatically and provide two attributes, node_list_str and node_list, so you wouldn't have to do this manually.

Giovanni

Christopher Coser US

unread,
Jul 23, 2019, 2:02:34 PM7/23/19
to pyslurm
Wow, so that's what hostlist is for...very useful!

On the subject of inclusion in pyslurm, that would be quite useful. The string itself is only good for display. To operate on it, it would seem reasonable to have the iterable list.

Thanks again.
Reply all
Reply to author
Forward
0 new messages