Debian Codegraph @

doc/sphinx/tools/nodeset.rst

raw
1 .. _nodeset-tool:
2
3 nodeset
4 -------
5
6 .. highlight:: console
7
8 .. note:: The :ref:`cluset-tool` command is introduced in ClusterShell
9 version 1.7.3 as an alternative to the **nodeset** command to avoid
10 conflicts with the **nodeset** command from xCAT. Users are
11 encouraged to transition to using **cluset** for their
12 range/node/group set management tasks.
13
14 The *nodeset* command enables easy manipulation of node sets, as well as
15 node groups, at the command line level. As it is very user-friendly and
16 efficient, the *nodeset* command can quickly improve traditional cluster
17 shell scripts. It is also full-featured as it provides most of the
18 :class:`.NodeSet` and :class:`.RangeSet` class methods (see also
19 :ref:`class-NodeSet`, and :ref:`class-RangeSet`).
20
21 Most of the examples in this section are using simple indexed node sets,
22 however, *nodeset* supports multidimensional node sets, like *dc[1-2]n[1-99]*,
23 introduced in version 1.7 (see :ref:`class-RangeSetND` for more info).
24
25 This section will guide you through the basics and also more advanced features
26 of *nodeset*.
27
28 .. _nodeset-commands:
29
30 Usage basics
31 ^^^^^^^^^^^^
32
33 One exclusive command must be specified to *nodeset*, for example::
34
35 $ nodeset --expand node[13-15,17-19]
36 node13 node14 node15 node17 node18 node19
37
38 $ nodeset --count node[13-15,17-19]
39 6
40
41 $ nodeset --fold node1-ipmi node2-ipmi node3-ipmi
42 node[1-3]-ipmi
43
44
45 .. _nodeset-stdin:
46
47 Commands with inputs
48 """"""""""""""""""""
49
50 Some *nodeset* commands require input (e.g. node names, node sets or node
51 groups), and some only give output. The following table shows commands that
52 require some input:
53
54 +-------------------+--------------------------------------------------------+
55 | Command | Description |
56 +===================+========================================================+
57 | ``-c, --count`` | Count and display the total number of nodes in node |
58 | | sets or/and node groups. |
59 +-------------------+--------------------------------------------------------+
60 | ``-e, --expand`` | Expand node sets or/and node groups as unitary node |
61 | | names separated by current separator string (see |
62 | | ``--separator`` option described in |
63 | | :ref:`nodeset-commands-formatting`). |
64 +-------------------+--------------------------------------------------------+
65 | ``-f, --fold`` | Fold (compact) node sets or/and node groups into one |
66 | | set of nodes (by previously resolving any groups). The |
67 | | resulting node set is guaranteed to be free from node |
68 | | groups (see ``--regroup`` below if you want to resolve |
69 | | node groups in result). Please note that folding may |
70 | | be time consuming for multidimensional node sets. |
71 +-------------------+--------------------------------------------------------+
72 | ``-r, --regroup`` | Fold (compact) node sets or/and node groups into one |
73 | | set of nodes using node groups whenever possible (by |
74 | | previously resolving any groups). |
75 | | See :ref:`nodeset-groups`. |
76 +-------------------+--------------------------------------------------------+
77
78
79 There are three ways to give some input to the *nodeset* command:
80
81 * from command line arguments,
82 * from standard input (enabled when no arguments are found on command line),
83 * from both command line and standard input, by using the dash special
84 argument *"-"* meaning you need to use stdin instead.
85
86 The following example illustrates the three ways to feed *nodeset*::
87
88 $ nodeset -f node1 node6 node7
89 node[1,6-7]
90
91 $ echo node1 node6 node7 | nodeset -f
92 node[1,6-7]
93
94 $ echo node1 node6 node7 | nodeset -f node0 -
95 node[0-1,6-7]
96
97
98 Furthermore, *nodeset*'s standard input reader is able to process multiple
99 lines and multiple node sets or groups per line. The following example shows a
100 simple use case::
101
102 $ mount -t nfs | cut -d':' -f1
103 nfsserv1
104 nfsserv2
105 nfsserv3
106
107 $ mount -t nfs | cut -d':' -f1 | nodeset -f
108 nfsserv[1-3]
109
110
111 Other usage examples of *nodeset* below show how it can be useful to provide
112 node sets from standard input (*sinfo* is a Slurm [#]_ command to view nodes
113 and partitions information and *sacct* is a command to display Slurm
114 accounting data)::
115
116 $ sinfo -p cuda -o '%N' -h
117 node[156-159]
118
119 $ sinfo -p cuda -o '%N' -h | nodeset -e
120 node156 node157 node158 node159
121
122 $ for node in $(sinfo -p cuda -o '%N' -h | nodeset -e); do
123 sacct -a -N $node > /tmp/cudajobs.$node;
124 done
125
126 Previous rules also apply when working with node groups, for example when
127 using ``nodeset -r`` reading from standard input (and a matching group is
128 found)::
129
130 $ nodeset -f @gpu
131 node[156-159]
132
133 $ sinfo -p cuda -o '%N' -h | nodeset -r
134 @gpu
135
136 Most commands described in this section produce output results that may be
137 formatted using ``--output-format`` and ``--separator`` which are described in
138 :ref:`nodeset-commands-formatting`.
139
140 Commands with no input
141 """"""""""""""""""""""
142
143 The following table shows all other commands that are supported by
144 *nodeset*. These commands don't support any input (like node sets), but can
145 still recognize options as specified below.
146
147 +--------------------+-----------------------------------------------------+
148 | Command w/o input | Description |
149 +====================+=====================================================+
150 | ``-l, --list`` | List node groups from selected *group source* as |
151 | | specified with ``-s`` or ``--groupsource``. If |
152 | | not specified, node groups from the default *group |
153 | | source* are listed (see :ref:`groups configuration |
154 | | <groups-config>` for default *group source* |
155 | | configuration). |
156 +--------------------+-----------------------------------------------------+
157 | ``--list-sources`` | List all configured *group sources*, one per line, |
158 | | as configured in *groups.conf* (see |
159 | | :ref:`groups configuration <groups-config>`). |
160 | | The default *group source* is appended with |
161 | | `` (default)``, unless the ``-q``, ``--quiet`` |
162 | | option is specified. This command is mainly here to |
163 | | avoid reading any configuration files, or to check |
164 | | if all work fine when configuring *group sources*. |
165 | | Also available as ``--groupsources``. |
166 +--------------------+-----------------------------------------------------+
167
168 .. _nodeset-commands-formatting:
169
170 Output result formatting
171 """"""""""""""""""""""""
172
173 When using the expand command (``-e, --expand``), a separator string is used
174 when displaying results. The option ``-S``, ``--separator`` allows you to
175 modify it. The specified string is interpreted, so that you can use special
176 characters as separator, like ``\n`` or ``\t``. The default separator is the
177 space character *" "*. This is an example showing such separator string
178 change::
179
180 $ nodeset -e --separator='\n' node[0-3]
181 node0
182 node1
183 node2
184 node3
185
186 The ``-O, --output-format`` option can be used to format output results of
187 most *nodeset* commands. The string passed to this option is used as a base
188 format pattern applied to each node or each result (depending on the command
189 and other options requested). The default format string is *"%s"*. Formatting
190 is performed using the Python builtin string formatting operator, so you must
191 use one format operator of the right type (*%s* is guaranteed to work in all
192 cases). Here is an output formatting example when using the expand command::
193
194 $ nodeset --output-format='%s-ipmi' -e node[1-2]x[1-2]
195 node1x1-ipmi node1x2-ipmi node2x1-ipmi node2x2-ipmi
196
197 Output formatting and separator combined can be useful when using the expand
198 command, as shown here::
199
200 $ nodeset -O '%s-ipmi' -S '\n' -e node[1-2]x[1-2]
201 node1x1-ipmi
202 node1x2-ipmi
203 node2x1-ipmi
204 node2x2-ipmi
205
206 When using the output formatting option along with the folding command, the
207 format is applied to each node but the result is still folded::
208
209 $ nodeset -O '%s-ipmi' -f mgmt1 mgmt2 login[1-4]
210 login[1-4]-ipmi,mgmt[1-2]-ipmi
211
212
213 .. _nodeset-stepping:
214
215 Stepping and auto-stepping
216 ^^^^^^^^^^^^^^^^^^^^^^^^^^
217
218 The *nodeset* command, as does the *clush* command, is able to recognize by
219 default a factorized notation for range sets of the form *a-b/c*, indicating a
220 list of integers starting from *a*, less than or equal to *b* with the
221 increment (step) *c*.
222
223 For example, the *0-6/2* format indicates a range of 0-6 stepped by 2; that
224 is 0,2,4,6::
225
226 $ nodeset -e node[0-6/2]
227 node0 node2 node4 node6
228
229 However, by default, *nodeset* never uses this stepping notation in output
230 results, as other cluster tools seldom if ever support this feature. Thus, to
231 enable such factorized output in *nodeset*, you must specify
232 ``--autostep=AUTOSTEP`` to set an auto step threshold number when folding
233 nodesets (i.e. when using ``-f`` or ``-r``). This threshold number
234 (AUTOSTEP) is the minimum occurrence of equally-spaced integers needed to
235 enable auto-stepping.
236
237 For example::
238
239 $ nodeset -f --autostep=3 node1 node3 node5
240 node[1-5/2]
241
242 $ nodeset -f --autostep=4 node1 node3 node5
243 node[1,3,5]
244
245 It is important to note that resulting node sets with enabled auto-stepping
246 never create overlapping ranges, for example::
247
248 $ nodeset -f --autostep=3 node1 node5 node9 node13
249 node[1-13/4]
250
251 $ nodeset -f --autostep=3 node1 node5 node7 node9 node13
252 node[1,5-9/2,13]
253
254 However, any ranges given as input may still overlap (in this case, *nodeset*
255 will automatically spread them out so that they do not overlap), for example::
256
257 $ nodeset -f --autostep=3 node[1-13/4,7]
258 node[1,5-9/2,13]
259
260
261 A minimum node count threshold **percentage** before autostep is enabled may
262 also be specified as autostep value (or ``auto`` which is currently 100%). In
263 the two following examples, only the first 4 of the 7 indexes may be
264 represented using the step syntax (57% of them)::
265
266 $ nodeset -f --autostep=50% node[1,3,5,7,34,39,99]
267 node[1-7/2,34,39,99]
268
269 $ nodeset -f --autostep=90% node[1,3,5,7,34,39,99]
270 node[1,3,5,7,34,39,99]
271
272
273 .. _nodeset-zeropadding:
274
275 Zero-padding
276 ^^^^^^^^^^^^
277
278 Sometimes, cluster node names are padded with zeros (e.g. *node007*). With
279 *nodeset*, when leading zeros are used, resulting host names or node sets
280 are automatically padded with zeros as well. For example::
281
282 $ nodeset -e node[08-11]
283 node08 node09 node10 node11
284
285 $ nodeset -f node001 node002 node003 node005
286 node[001-003,005]
287
288 Zero-padding and stepping (as seen in :ref:`nodeset-stepping`) together are
289 also supported, for example::
290
291 $ nodeset -e node[000-012/4]
292 node000 node004 node008 node012
293
294 Since v1.9, mixed length padding is allowed, for example::
295
296 $ nodeset -f node2 node01 node001
297 node[2,01,001]
298
299 When mixed length zero-padding is encountered, indexes with smaller padding
300 length are returned first, as you can see in the example above (``2`` comes
301 before ``01``).
302
303 Since v1.9, when using node sets with multiple dimensions, each dimension (or
304 axis) may also use mixed length zero-padding::
305
306 $ nodeset -f foo1bar1 foo1bar00 foo1bar01 foo004bar1 foo004bar00 foo004bar01
307 foo[1,004]bar[1,00-01]
308
309
310 Leading and trailing digits
311 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
312
313 Version 1.7 introduces improved support for bracket leading and trailing
314 digits. Those digits are automatically included within the range set,
315 allowing all node set operations to be fully supported.
316
317 Examples with bracket leading digits::
318
319 $ nodeset -f node-00[00-99]
320 node-[0000-0099]
321
322 $ nodeset -f node-01[01,09,42]
323 node-[0101,0109,0142]
324
325 Examples with bracket trailing digits::
326
327 $ nodeset -f node-[1-2]0-[0-2]5
328 node-[10,20]-[05,15,25]
329
330 Examples with both bracket leading and trailing digits::
331
332 $ nodeset -f node-00[1-6]0
333 node-[0010,0020,0030,0040,0050,0060]
334
335 $ nodeset --autostep=auto -f node-00[1-6]0
336 node-[0010-0060/10]
337
338 Example with leading digit and mixed length zero padding (supported since
339 v1.9)::
340
341 $ nodeset -f node1[00-02,000-032/8]
342 node[100-102,1000,1008,1016,1024,1032]
343
344 Using this syntax can be error-prone especially if used with node sets
345 without 0-padding or with the */step* syntax and also requires additional
346 processing by the parser. In general, we recommend writing the whole rangeset
347 inside the brackets.
348
349 .. warning:: Using the step syntax (seen above) within a bracket-delimited
350 range set is not compatible with **trailing** digits. For instance, this is
351 **not** supported: ``node-00[1-6/2]0``
352
353 .. _nodeset-arithmetic:
354
355 Arithmetic operations
356 ^^^^^^^^^^^^^^^^^^^^^
357
358 As a preamble to this section, keep in mind that all operations can be
359 repeated/mixed within the same *nodeset* command line, they will be
360 processed from left to right.
361
362 Union operation
363 """""""""""""""
364
365 Union is the easiest arithmetic operation supported by *nodeset*: there is
366 no special command line option for that, just provide several node sets and
367 the union operation will be computed, for example::
368
369 $ nodeset -f node[1-3] node[4-7]
370 node[1-7]
371
372 $ nodeset -f node[1-3] node[2-7] node[5-8]
373 node[1-8]
374
375 Other operations
376 """"""""""""""""
377
378 As an extension to the above, other arithmetic operations are available by
379 using the following command-line options (*working set* is the node set
380 currently processed on the command line -- always from left to right):
381
382 +--------------------------------------------+---------------------------------+
383 | *nodeset* command option | Operation |
384 +============================================+=================================+
385 | ``-x NODESET``, ``--exclude=NODESET`` | compute a new set with elements |
386 | | in *working set* but not in |
387 | | ``NODESET`` |
388 +--------------------------------------------+---------------------------------+
389 | ``-i NODESET``, ``--intersection=NODESET`` | compute a new set with elements |
390 | | common to *working set* and |
391 | | ``NODESET`` |
392 +--------------------------------------------+---------------------------------+
393 | ``-X NODESET``, ``--xor=NODESET`` | compute a new set with elements |
394 | | that are in exactly one of the |
395 | | *working set* and ``NODESET`` |
396 +--------------------------------------------+---------------------------------+
397
398
399 If rangeset mode (``-R``) is turned on, all arithmetic operations are
400 supported by replacing ``NODESET`` by any ``RANGESET``. See
401 :ref:`nodeset-rangeset` for more info about *nodeset*'s rangeset mode.
402
403
404 Arithmetic operations usage examples::
405
406 $ nodeset -f node[1-9] -x node6
407 node[1-5,7-9]
408
409 $ nodeset -f node[1-9] -i node[6-11]
410 node[6-9]
411
412 $ nodeset -f node[1-9] -X node[6-11]
413 node[1-5,10-11]
414
415 $ nodeset -f node[1-9] -x node6 -i node[6-12]
416 node[7-9]
417
418 .. _nodeset-extended-patterns:
419
420 *Extended patterns* support
421 """""""""""""""""""""""""""
422
423 *nodeset* does also support arithmetic operations through its "extended
424 patterns" (inherited from :class:`.NodeSet` extended pattern feature, see
425 :ref:`class-NodeSet-extended-patterns`), here is an example of use::
426
427 $ nodeset -f node[1-4],node[5-9]
428 node[1-9]
429
430 $ nodeset -f node[1-9]\!node6
431 node[1-5,7-9]
432
433 $ nodeset -f node[1-9]\&node[6-12]
434 node[6-9]
435
436 $ nodeset -f node[1-9]^node[6-11]
437 node[1-5,10-11]
438
439 .. _nodeset-special:
440
441 Special operations
442 ^^^^^^^^^^^^^^^^^^
443
444 A few special operations are currently available: node set slicing, splitting
445 on a predefined node count, splitting non-contiguous subsets, choosing fold
446 axis (for multidimensional node sets) and picking N nodes randomly. They are
447 all explained below.
448
449 .. _nodeset-slice:
450
451 Slicing
452 """""""
453
454 Slicing is a way to select elements from a node set by their index (or from a
455 range set when using ``-R`` toggle option, see :ref:`nodeset-rangeset`). In
456 this case actually, and because *nodeset*'s underlying :class:`.NodeSet` class
457 sorts elements as observed after folding (for example), the word *set* may
458 sound like a stretch of language (a *set* isn't usually sorted). Indeed,
459 :class:`.NodeSet` further guarantees that its iterator will traverse the set
460 in order, so we should see it as an *ordered set*. The following simple example
461 illustrates this sorting behavior::
462
463 $ nodeset -f b2 b1 b0 b c a0 a
464 a,a0,b,b[0-2],c
465
466 Slicing is performed through the following command-line option:
467
468 +---------------------------------------+-----------------------------------+
469 | *nodeset* command option | Operation |
470 +=======================================+===================================+
471 | ``-I RANGESET``, ``--slice=RANGESET`` | *slicing*: get sliced off result, |
472 | | selecting elements from provided |
473 | | rangeset's indexes |
474 +---------------------------------------+-----------------------------------+
475
476 Some slicing examples are shown below::
477
478 $ nodeset -f -I 0 node[4-8]
479 node4
480
481 $ nodeset -f --slice=0 bnode[0-9] anode[0-9]
482 anode0
483
484 $ nodeset -f --slice=1,4,7,9,15 bnode[0-9] anode[0-9]
485 anode[1,4,7,9],bnode5
486
487 $ nodeset -f --slice=0-18/2 bnode[0-9] anode[0-9]
488 anode[0,2,4,6,8],bnode[0,2,4,6,8]
489
490
491 .. _nodeset-splitting-n:
492
493 Splitting into *n* subsets
494 """"""""""""""""""""""""""
495
496 Splitting a node set into several parts is often useful to get separate groups
497 of nodes, for instance when you want to check MPI comm between nodes, etc.
498 Based on :meth:`.NodeSet.split` method, the *nodeset* command provides the
499 following additional command-line option (since v1.4):
500
501 +--------------------------+--------------------------------------------+
502 | *nodeset* command option | Operation |
503 +==========================+============================================+
504 | ``--split=MAXSPLIT`` | *splitting*: split result into a number of |
505 | | subsets |
506 +--------------------------+--------------------------------------------+
507
508 ``MAXSPLIT`` is an integer specifying the number of separate groups of nodes
509 to compute. Input's node set is divided into smaller groups, whenever possible
510 with the same size (only the last ones may be smaller due to rounding).
511 Obviously, if ``MAXSPLIT`` is higher than or equal to the number N of elements
512 in the set, then the set is split to N single sets.
513
514 Some node set splitting examples::
515
516 $ nodeset -f --split=4 node[0-7]
517 node[0-1]
518 node[2-3]
519 node[4-5]
520 node[6-7]
521
522 $ nodeset -f --split=4 node[0-6]
523 node[0-1]
524 node[2-3]
525 node[4-5]
526 node6
527
528 $ nodeset -f --split=10000 node[0-4]
529 node0
530 node1
531 node2
532 node3
533 node4
534
535 $ nodeset -f --autostep=3 --split=2 node[0-38/2]
536 node[0-18/2]
537 node[20-38/2]
538
539
540 .. _nodeset-splitting-contiguous:
541
542 Splitting off non-contiguous subsets
543 """"""""""""""""""""""""""""""""""""
544
545 It can be useful to split a node set into several contiguous subsets (with
546 same pattern name and contiguous range indexes, e.g. *node[1-100]* or
547 *dc[1-4]node[1-100]*). The ``--contiguous`` option allows you to do that. It
548 is based on :meth:`.NodeSet.contiguous` method, and should be specified with
549 standard commands (fold, expand, count, regroup). The following example shows
550 how to split off non-contiguous subsets of a specified node set, and to
551 display each resulting contiguous node set in a folded manner to separated
552 lines::
553
554 $ nodeset -f --contiguous node[1-100,200-300,500]
555 node[1-100]
556 node[200-300]
557 node500
558
559
560 Similarly, the following example shows how to display each resulting
561 contiguous node set in an expanded manner to separate lines::
562
563 $ nodeset -e --contiguous node[1-9,11-19]
564 node1 node2 node3 node4 node5 node6 node7 node8 node9
565 node11 node12 node13 node14 node15 node16 node17 node18 node19
566
567
568 Choosing fold axis (nD)
569 """""""""""""""""""""""
570
571 The default folding behavior for multidimensional node sets is to fold along
572 all *nD* axes. However, other cluster tools barely support nD nodeset syntax,
573 so it may be useful to fold along one axis (or a few axes) only. The ``--axis``
574 option allows you to specify indexes of dimensions to fold. Using this
575 option, rangesets of unspecified axes won't be folded. Please note
576 however that the obtained result may be suboptimal, this is because
577 :class:`.NodeSet` algorithms are optimized for folding along all axes.
578 ``--axis`` value is a set of integers from 1 to n representing selected nD
579 axes, in the form of a number or a rangeset. A common case is to restrict
580 folding on a single axis, like in the following simple examples::
581
582 $ nodeset --axis=1 -f node1-ib0 node2-ib0 node1-ib1 node2-ib1
583 node[1-2]-ib0,node[1-2]-ib1
584
585 $ nodeset --axis=2 -f node1-ib0 node2-ib0 node1-ib1 node2-ib1
586 node1-ib[0-1],node2-ib[0-1]
587
588 Because a single nodeset may have several different dimensions, axis indices
589 are silently truncated to fall in the allowed range. Negative indices are
590 useful to fold along the last axis whatever number of dimensions used::
591
592 $ nodeset --axis=-1 -f comp-[1-2]-[1-36],login-[1-2]
593 comp-1-[1-36],comp-2-[1-36],login-[1-2]
594
595 See also the :ref:`defaults-config-slurm` of Library Defaults for changing it
596 permanently.
597
598 .. _nodeset-pick:
599
600 Picking N node(s) at random
601 """""""""""""""""""""""""""
602
603 Use ``--pick`` with a maximum number of nodes you wish to pick randomly from
604 the resulting node set (or from the resulting range set with ``-R``)::
605
606 $ nodeset --pick=1 -f node11 node12 node13
607 node12
608 $ nodeset --pick=2 -f node11 node12 node13
609 node[11,13]
610
611
612 .. _nodeset-index:
613
614 Finding the index of a node
615 """""""""""""""""""""""""""
616
617 The ``--index`` command is the reverse of :ref:`slicing <nodeset-slice>`:
618 instead of selecting a node by its position, it outputs the zero-based index
619 of a node within the resulting (ordered) node set. It is the command-line
620 equivalent of the :meth:`.NodeSet.index` method::
621
622 $ nodeset --index node5 node[0-9]
623 5
624
625 If the node is not part of the set, an error is printed and a non-zero exit
626 status is returned, so ``--index`` can also be used to test set membership::
627
628 $ nodeset --index node42 node[0-9]
629 ERROR: 'node42' is not in nodeset
630
631 It also works in range set mode with ``-R``::
632
633 $ nodeset -R --index 18 1,5,18-31
634 2
635
636 The position follows the same ordering as ``-e/--expand``. Two aspects of that
637 ordering are worth knowing, as both can be surprising. First, when a node set
638 spans several distinct patterns (different name templates), the patterns are
639 sorted alphabetically by name, not by the order they were written or by the
640 numbers they contain::
641
642 $ nodeset -e node[1-4],bmc[10-20]
643 bmc10 bmc11 bmc12 bmc13 bmc14 bmc15 bmc16 bmc17 bmc18 bmc19 bmc20 node1 node2 node3 node4
644 $ nodeset --index bmc10 node[1-4],bmc[10-20]
645 0
646 $ nodeset --index node1 node[1-4],bmc[10-20]
647 11
648
649 Second, for multidimensional node sets, the set is traversed as a Cartesian
650 product in which the last dimension varies fastest::
651
652 $ nodeset -e rack[1-2]node[1-3]
653 rack1node1 rack1node2 rack1node3 rack2node1 rack2node2 rack2node3
654 $ nodeset --index rack2node1 rack[1-2]node[1-3]
655 3
656
657 For a one-dimensional node set (for example ``node[01-04]``) the index is just
658 the node's ascending numeric position. A multidimensional node set has no
659 single obvious order, so ClusterShell flattens it using its own convention,
660 which is not guaranteed across versions; do not rely on a given index over
661 time. Within a version it is always deterministic and depends only on the
662 set's contents.
663
664 .. note::
665
666 ``--index`` reflects ClusterShell's own ordering, so for a multidimensional
667 node list it is not guaranteed to match the node rank a resource manager
668 assigns (such as Slurm's ``$SLURM_NODEID``); use the value the resource
669 manager provides instead.
670
671
672 .. _nodeset-groups:
673
674 Node groups
675 ^^^^^^^^^^^
676
677 This section tackles the node groups feature available more particularly
678 through the *nodeset* command-line tool. The ClusterShell library defines a
679 node groups syntax and allows you to bind these group sources to your
680 applications (cf. :ref:`node groups configuration <groups-config>`). Having
681 those group sources, group provisioning is easily done through user-defined
682 external shell commands. Thus, node groups might be very dynamic and their
683 nodes might change very often. However, for performance reasons, external call
684 results are still cached in memory to avoid duplicate external calls during
685 *nodeset* execution. For example, a group source can be bound to a resource
686 manager or a custom cluster database.
687
688 For further details about using node groups in Python, please see
689 :ref:`class-NodeSet-groups`. For advanced usage, you should also be able to
690 define your own group source directly in Python (cf.
691 :ref:`class-NodeSet-groups-override`).
692
693 .. _nodeset-groupsexpr:
694
695 Node group expression rules
696 """""""""""""""""""""""""""
697
698 The general node group expression is ``@source:groupname``. For example,
699 ``@slurm:bigmem`` represents the group *bigmem* of the group source *slurm*.
700 Moreover, a shortened expression is available when using the default group
701 source (defined by configuration); for instance ``@compute`` represents the
702 *compute* group of the default group source.
703
704 Valid group source names and group names can contain alphanumeric characters,
705 hyphens and underscores (no space allowed). Indeed, same rules apply to node
706 names.
707
708 Listing group sources
709 """""""""""""""""""""
710
711 As already mentioned, the following *nodeset* command is available to list
712 configured group sources and also display the default group source (unless
713 ``-q`` is provided). The ``--list-sources`` and ``--groupsources`` options
714 are equivalent::
715
716 $ nodeset --list-sources
717 local (default)
718 genders
719 slurm
720
721 Listing group names
722 """""""""""""""""""
723
724 It is always possible to list the groups from a group source if the source is
725 :ref:`file-based <group-file-based>`.
726 If the source is an :ref:`external group source <group-external-sources>`, the
727 **list** upcall must be configured (see also:
728 :ref:`node groups configuration <groups-config>`).
729
730 To list available groups *from the default source*, use the following command::
731
732 $ nodeset -l
733 @mgnt
734 @mds
735 @oss
736 @login
737 @compute
738
739 To list groups *from a specific group source*, use *-l* in conjunction
740 with *-s* (or *--groupsource*)::
741
742 $ nodeset -l -s slurm
743 @slurm:parallel
744 @slurm:cuda
745
746 Or, to list groups *from all available group sources*, use *-L* (or
747 *--list-all*)::
748
749 $ nodeset -L
750 @mgnt
751 @mds
752 @oss
753 @login
754 @compute
755 @slurm:parallel
756 @slurm:cuda
757
758 You can also use ``nodeset -ll`` or ``nodeset -LL`` to see each group's
759 associated node sets.
760
761 .. _nodeset-rawgroupnames:
762
763 Listing group names in expressions
764 """"""""""""""""""""""""""""""""""
765
766 ClusterShell 1.9 introduces a new operator **@@** optionally followed by a
767 source name (e.g. **@@source**) to access the list of *raw group names* of
768 the source (without the **@** prefix). If no source is specified (as in *just*
769 **@@**), the default group source is used (see :ref:`groups_config_conf`).
770 The **@@** operator may be used in any node set expression to manipulate group
771 names as a node set.
772
773 Example with the default group source::
774
775 $ nodeset -l
776 @mgnt
777 @mds
778 @oss
779 @login
780 @compute
781
782 $ nodeset -e @@
783 compute login mds mgnt oss
784
785 Example with a group source "rack" that defines group names from rack
786 locations in a data center::
787
788 $ nodeset -l -s rack
789 @rack:J1
790 @rack:J2
791 @rack:J3
792
793 $ nodeset -f @@rack
794 J[1-3]
795
796 A set of valid, indexed group sources is also accepted by the **@@** operator
797 (e.g. **@@dc[1-3]**).
798
799
800 .. warning:: An error is generated when using **@@** in an expression if the
801 source is not valid (e.g. invalid name, not configured or upcalls
802 not currently working).
803
804
805 Using node groups in basic commands
806 """""""""""""""""""""""""""""""""""
807
808 The use of node groups with the *nodeset* command is very straightforward.
809 Indeed, any group name, prefixed by **@** as mentioned above, can be used in
810 lieu of a node name, where it will be substituted for all nodes in that group.
811
812 A first, simple example is a group expansion (using default source) with
813 *nodeset*::
814
815 $ nodeset -e @oss
816 node40 node41 node42 node43 node44 node45
817
818 The *nodeset* count command works as expected::
819
820 $ nodeset -c @oss
821 6
822
823 Also *nodeset* folding command can always resolve node groups::
824
825 $ nodeset -f @oss
826 node[40-45]
827
828 There are usually two ways to use a specific group source (need to be properly
829 configured)::
830
831 $ nodeset -f @slurm:parallel
832 node[50-81]
833
834 $ nodeset -f -s slurm @parallel
835 node[50-81]
836
837 .. _nodeset-group-finding:
838
839 Finding node groups
840 """""""""""""""""""
841
842 As an extension to the **list** command, you can search node groups that a
843 specified node set belongs to with ``nodeset -l[ll]`` as follows::
844
845 $ nodeset -l node40
846 @all
847 @oss
848
849 $ nodeset -ll node40
850 @all node[1-159]
851 @oss node[40-45]
852
853 This feature is implemented with the help of the :meth:`.NodeSet.groups`
854 method (see :ref:`class-NodeSet-groups-finding` for further details).
855
856 .. _nodeset-regroup:
857
858 Resolving node groups
859 """""""""""""""""""""
860
861 If needed group configuration conditions are met (cf. :ref:`node groups
862 configuration <groups-config>`), you can try group lookups thanks to the ``-r,
863 --regroup`` command. This feature is implemented with the help of the
864 :meth:`.NodeSet.regroup()` method (see :ref:`class-NodeSet-regroup` for
865 further details). Only exact matching groups are returned (all containing
866 nodes needed), for example::
867
868 $ nodeset -r node[40-45]
869 @oss
870
871 $ nodeset -r node[0,40-45]
872 @mgnt,@oss
873
874
875 When resolving node groups, *nodeset* always returns the largest groups
876 first, instead of several smaller matching groups, for instance::
877
878 $ nodeset -ll
879 @login node[50-51]
880 @compute node[52-81]
881 @intel node[50-81]
882
883 $ nodeset -r node[50-81]
884 @intel
885
886 If no matching group is found, ``nodeset -r`` still returns folded result (as
887 does ``-f``)::
888
889 $ nodeset -r node40 node42
890 node[40,42]
891
892 Indexed node groups
893 """""""""""""""""""
894
895 Node groups are themselves some kind of group sets and can be indexable. To
896 use this feature, node groups external shell commands need to return indexed
897 group names (automatically handled by the library as needed). For example,
898 take a look at these indexed node groups::
899
900 $ nodeset -l
901 @io1
902 @io2
903 @io3
904
905 $ nodeset -f @io[1-3]
906 node[40-45]
907
908
909 Arithmetic operations on node groups
910 """"""""""""""""""""""""""""""""""""
911
912 Arithmetic and special operations (as explained for node sets in
913 :ref:`nodeset-arithmetic` and :ref:`nodeset-special`) are also supported with
914 node groups.
915 Any group name can be used in lieu of a node set, where it will be substituted
916 for all nodes in that group before processing requested operations. Some
917 typical examples are::
918
919 $ nodeset -f @lustre -x @mds
920 node[40-45]
921
922 $ nodeset -r @lustre -x @mds
923 @oss
924
925 $ nodeset -r -a -x @lustre
926 @compute,@login,@mgnt
927
928 More advanced examples, with the use of node group sets, follow::
929
930 $ nodeset -r @io[1-3] -x @io2
931 @io[1,3]
932
933 $ nodeset -f -I0 @io[1-3]
934 node40
935
936 $ nodeset -f --split=3 @oss
937 node[40-41]
938 node[42-43]
939 node[44-45]
940
941 $ nodeset -r --split=3 @oss
942 @io1
943 @io2
944 @io3
945
946
947 *Extended patterns* support with node groups
948 """"""""""""""""""""""""""""""""""""""""""""
949
950 Even for node groups, the *nodeset* command supports arithmetic operations
951 through its *extended pattern* feature (see
952 :ref:`class-NodeSet-extended-patterns`).
953 A first example illustrates node groups intersection, that can be used in
954 practice to get nodes available from two dynamic group sources at a given
955 time::
956
957 $ nodeset -f @db:prod\&@compute
958
959 The following hypothetical example computes a folded node set containing nodes
960 found in node group ``@gpu`` and ``@slurm:bigmem``, but not in both, minus
961 the nodes found in odd ``@chassis`` groups from 1 to 9 (computed from left to
962 right)::
963
964 $ nodeset -f @gpu^@slurm:bigmem\!@chassis[1-9/2]
965
966 Also, version 1.7 introduces a notation extension ``@*`` (or ``@SOURCE:*``)
967 that has been added to quickly represent *all nodes* (please refer to
968 :ref:`clush-all-nodes` for more details).
969
970
971 .. _nodeset-all-nodes:
972
973 Selecting all nodes
974 """""""""""""""""""
975
976 The option ``-a`` (without argument) can be used to select **all** nodes from
977 a group source (see :ref:`node groups configuration <groups-config>` for more
978 details on special **all** external shell command upcall). Example of use for
979 the default group source::
980
981 $ nodeset -a -f
982 example[4-6,32-159]
983
984 Use ``-s/--groupsource`` to select another group source.
985
986 If not properly configured, the ``-a`` option may lead to runtime errors
987 like::
988
989 $ nodeset -s mybrokensource -a -f
990 nodeset: External error: Not enough working methods (all or map + list)
991 to get all nodes
992
993 A similar option is available with :ref:`clush-tool`, see
994 :ref:`selecting all nodes with clush <clush-all-nodes>`.
995
996 Node wildcards
997 """"""""""""""
998
999 ClusterShell 1.8 introduces node wildcards: ``*`` means match zero or more
1000 characters of any type; ``?`` means match exactly one character of any type.
1001
1002 Any wildcard mask found is matched against **all** nodes from the group source
1003 (see :ref:`nodeset-all-nodes`).
1004
1005 This can be especially useful for server farms, or when cluster node names
1006 differ. Say that your :ref:`group configuration <groups-config>` is set to
1007 return the following "all nodes"::
1008
1009 $ nodeset -f -a
1010 bckserv[1-2],dbserv[1-4],wwwserv[1-9]
1011
1012 Then, you can use wildcards to select particular nodes, as shown below::
1013
1014 $ nodeset -f 'www*'
1015 wwwserv[1-9]
1016
1017 $ nodeset -f 'www*[1-4]'
1018 wwwserv[1-4]
1019
1020 $ nodeset -f '*serv1'
1021 bckserv1,dbserv1,wwwserv1
1022
1023 Wildcard masks are resolved prior to
1024 :ref:`extended patterns <nodeset-extended-patterns>`, but each mask is
1025 evaluated as a whole node set operand. In the example below, we select
1026 all nodes matching ``*serv*`` before removing all nodes matching ``www*``::
1027
1028 $ nodeset -f '*serv*!www*'
1029 bckserv[1-2],dbserv[1-4]
1030
1031 .. _nodeset-rangeset:
1032
1033 Range sets
1034 ^^^^^^^^^^
1035
1036 Working with range sets
1037 """""""""""""""""""""""
1038
1039 By default, the *nodeset* command works with node or group sets and its
1040 functionality matches most :class:`.NodeSet` class methods. Similarly, *nodeset*
1041 will match :class:`.RangeSet` methods when you make use of the ``-R`` option
1042 switch. In that case, all operations are restricted to numerical ranges. For
1043 example, to expand the range "``1-10``", you should use::
1044
1045 $ nodeset -e -R 1-10
1046 1 2 3 4 5 6 7 8 9 10
1047
1048 Almost all commands and operations available for node sets are also available
1049 with range sets. The only restrictions are commands and operations related to
1050 node groups. For instance, the following command options are **not** available
1051 with ``nodeset -R``:
1052
1053 * ``-r, --regroup`` as this feature is obviously related to node groups,
1054 * ``-a / --all`` as the **all** external call is also related to node groups.
1055
1056
1057 Using range sets instead of node sets doesn't change the general command
1058 usage, like the need of one command option presence (cf. :ref:`nodeset-commands`),
1059 or the way to give some input (cf. :ref:`nodeset-stdin`), for example::
1060
1061 $ echo 3 2 36 0 4 1 37 | nodeset -fR
1062 0-4,36-37
1063
1064 $ echo 0-8/4 | nodeset -eR -S'\n'
1065 0
1066 4
1067 8
1068
1069 Stepping and auto-stepping are supported (cf. :ref:`nodeset-stepping`) and
1070 also zero-padding (cf. :ref:`nodeset-zeropadding`), which are both
1071 :class:`.RangeSet` class features anyway.
1072
1073 The following examples illustrate these last points::
1074
1075 $ nodeset -fR 03 05 01 07 11 09
1076 01,03,05,07,09,11
1077
1078 $ nodeset -fR --autostep=3 03 05 01 07 11 09
1079 01-11/2
1080
1081 Arithmetic and special operations
1082 """""""""""""""""""""""""""""""""
1083
1084 All arithmetic operations, as seen for node sets (cf.
1085 :ref:`nodeset-arithmetic`), are available for range sets, for example::
1086
1087 $ nodeset -fR 1-14 -x 10-20
1088 1-9
1089
1090 $ nodeset -fR 1-14 -i 10-20
1091 10-14
1092
1093 $ nodeset -fR 1-14 -X 10-20
1094 1-9,15-20
1095
1096 For now, there is no *extended patterns* syntax for range sets as for node
1097 sets (cf. :ref:`nodeset-extended-patterns`). However, as the union operator
1098 ``,`` is available natively by design, such expressions are still allowed::
1099
1100 $ nodeset -fR 4-10,1-2
1101 1-2,4-10
1102
1103
1104 Besides arithmetic operations, special operations may be very convenient for
1105 range sets also. Below is an example with ``-I / --slice`` (cf.
1106 :ref:`nodeset-slice`)::
1107
1108 $ nodeset -fR -I 0 100-131
1109 100
1110
1111 $ nodeset -fR -I 0-15 100-131
1112 100-115
1113
1114 There is another special operation example with ``--split`` (cf.
1115 :ref:`nodeset-splitting-n`)::
1116
1117 $ nodeset -fR --split=2 100-131
1118 100-115
1119 116-131
1120
1121 Finally, an example of the special operation ``--contiguous`` (cf.
1122 :ref:`nodeset-splitting-contiguous`)::
1123
1124 $ nodeset -f -R --contiguous 1-9,11,13-19
1125 1-9
1126 11
1127 13-19
1128
1129 *rangeset* alias
1130 """"""""""""""""
1131
1132 When using *nodeset* with range sets intensively (e.g. for scripting), it may
1133 be convenient to create a local command alias, as shown in the following
1134 example (Bourne shell), making it sort of a super `seq(1)`_ command::
1135
1136 $ alias rangeset='nodeset -R'
1137 $ rangeset -e 0-8/2
1138 0 2 4 6 8
1139
1140
1141 .. [#] Slurm is an open-source resource manager (https://slurm.schedmd.com/overview.html)
1142
1143 .. _seq(1): http://linux.die.net/man/1/seq
1144