Documentation
¶
Overview ¶
Package hostlist provides functionality to expand compact hostlist specifications into individual host names. This is particularly useful for cluster computing environments where hosts are often specified using range notation.
The package supports expanding hostlist expressions like:
- "n[1-3]" expands to ["n1", "n2", "n3"]
- "n[01-03]" expands to ["n01", "n02", "n03"] (preserves zero-padding)
- "n[1-2],m[3-4]" expands to ["m3", "m4", "n1", "n2"] (sorted and deduplicated)
- "n[1-2]-suffix" expands to ["n1-suffix", "n2-suffix"]
The expansion automatically sorts results alphabetically and removes duplicates.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Expand ¶
Expand converts a compact hostlist specification into a slice of individual host names.
The function accepts hostlist expressions containing:
- Single hosts: "node1"
- Numeric ranges in brackets: "node[1-5]"
- Multiple ranges or indices: "node[1-3,5,7-9]"
- Optional suffixes after ranges: "node[1-3]-ib" for InfiniBand interfaces
- Multiple comma-separated expressions: "n[1-2],m[3-4]"
Syntax rules:
- Ranges must be specified in brackets using the format [start-end]
- Multiple ranges or indices within brackets must be comma-separated
- Only one bracketed range specification is allowed per host expression
- Range start must be less than or equal to range end
- Zero-padding is preserved when start and end have the same width
- Valid DNS characters: a-z, A-Z, 0-9, and hyphen (-)
The function automatically:
- Sorts the resulting host names alphabetically
- Removes duplicate entries
- Trims leading/trailing spaces and commas from the input
Parameters:
- in: The hostlist specification string to expand
Returns:
- result: A sorted slice of unique host names
- err: An error if the input is malformed or contains invalid syntax
Examples:
// Simple range
hosts, _ := Expand("n[1-3]")
// Returns: []string{"n1", "n2", "n3"}
// Zero-padded range
hosts, _ := Expand("node[01-03]")
// Returns: []string{"node01", "node02", "node03"}
// Multiple ranges and indices
hosts, _ := Expand("n[1-2,5,7-8]")
// Returns: []string{"n1", "n2", "n5", "n7", "n8"}
// With suffix
hosts, _ := Expand("n[1-2]-ib")
// Returns: []string{"n1-ib", "n2-ib"}
// Multiple host groups
hosts, _ := Expand("n[1-2],m[3-4]")
// Returns: []string{"m3", "m4", "n1", "n2"}
// Duplicates are removed
hosts, _ := Expand("n1,n1,n2")
// Returns: []string{"n1", "n2"}
Error conditions:
- Invalid characters (e.g., "@", "$")
- Malformed range syntax (e.g., "[1-2-3]")
- Decreasing ranges (e.g., "[5-1]")
- Invalid bracket nesting or missing brackets
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.