hostlist

package
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostlist converts between Slurm host lists and individual host names.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(hosts []string) (string, error)

Compress returns a compact Slurm host list without modifying hosts. It preserves order, duplicates, and padding, like scontrol show hostlist. Consecutive hosts with the same prefix are grouped by their trailing decimal numbers; other names remain literal. For example, node0,node1 becomes node[0-1], while rack0node0,rack1node1 remains unchanged.

Each input must be one nonempty, unbracketed host name without host-list separators or NUL bytes. Numeric suffixes must fit in uint64. The host-count and name-byte limits are the same as Expand. Ranges are split at 65,536 entries so Expand can read the result. Empty input produces an empty string. On error, no partial expression is returned.

Example
package main

import (
	"fmt"

	"github.com/SlinkyProject/slurm-client/pkg/hostlist"
)

func main() {
	expression, _ := hostlist.Compress([]string{"node2", "node1", "node2"})
	fmt.Println(expression)
}
Output:
node[2,1-2]

func Expand

func Expand(expression string) ([]string, error)

Expand returns the hosts in expression, preserving order and duplicates. Hosts are separated by commas, spaces, tabs, or newlines. Bracket groups contain decimal numbers or inclusive ranges, for example node[0-47] or rack[0-1]_node[00-03]. Bare groups such as [0-7] are also supported.

Padding comes from the lower endpoint: node[0-10] starts with node0, whereas node[00-10] starts with node00. With multiple groups, the last group varies fastest, followed by the preceding groups from left to right, as in Slurm.

The reference is Slurm 26.05's scontrol show hostnames (ordinary decimal host lists, not architecture-specific multidimensional box expressions). Unlike Slurm's permissive C number conversion, endpoints must contain only digits and fit in uint64. Malformed brackets, ranges exceeding 65,536 entries, and results exceeding 1,048,576 hosts or a conservative 64 MiB estimate of name bytes are rejected, with no partial result.

Reference: https://github.com/SchedMD/slurm/blob/slurm-26-05-4-1/src/common/hostlist.c

Example
package main

import (
	"fmt"

	"github.com/SlinkyProject/slurm-client/pkg/hostlist"
)

func main() {
	hosts, _ := hostlist.Expand("node[0-2],node[00-02]")
	for _, host := range hosts {
		fmt.Println(host)
	}
}
Output:
node0
node1
node2
node00
node01
node02

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL