nodeset

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: GPL-3.0, LGPL-3.0 Imports: 7 Imported by: ? 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 nodeset parses, folds and expands ClusterShell style node sets.

A node set expression names a set of hosts. Numeric parts of a host name may be written as a bracketed range, and several expressions may be combined with set operators:

exe[0001-0010]            a padded range
exe[1-10/2]               a range with a step
rack[1-2]node[01-04]      two independent numeric dimensions
@compute                  a group, resolved by a Resolver
exe[1-10],sub[1-2]        union
exe[1-10]!exe5            difference
exe[1-10]&@idle           intersection
exe[1-10]^@drained        symmetric difference

Operators have no precedence; an expression is evaluated strictly from left to right. Whitespace acts as a union operator, so the arguments of a command line may be joined with a space and parsed in one call. The operators !, & and ^ need an operand on each side: "exe[1-10]&" is an error, not exe[1-10].

Node names

Every maximal run of digits in a name is a numeric dimension, whether or not it was written in brackets. "exe0001" and "exe[0001]" parse identically, and "10.0.1.7" has four dimensions. A dimension holding a single value is rendered without brackets, so folding is stable: parsing the output of String and folding it again yields the same string. A name may not begin with "-".

Zero padding is not part of a node's identity: "exe1" and "exe01" are the same host, so Parse("exe1,exe01") has Len 1 and Contains("exe01") is true for a set holding exe1. Each host keeps the spelling it was first given, and a set never shows a host under a name it was not given: "exe[01-02],exe3" prints as exe[01-02,3], and Canonical("exe1") on a set holding exe0001 answers "exe0001". In a range the padding of the first bound applies to the whole range, and a last bound padded to another width, such as exe[1-010], is an error.

A set does not report that it was given one host under two spellings; the second is simply the same member again. A program for which such a pair is an error, such as two machines in an inventory, checks its names itself: before it adds a name, Canonical on the set built so far answers the spelling already held for that host, if there is one.

These rules, and each place where this package differs from ClusterShell, are set out in the node set language reference in the doc directory of the repository this package comes from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lister added in v0.4.0

type Lister interface {
	// List returns the group names a source offers. An empty source means
	// the default one.
	List(source string) ([]string, error)
	// DefaultSource names the source used when a reference names none.
	DefaultSource() string
}

Lister is implemented by a Resolver that can also say which groups it offers, for a program that lists them or completes a group name. Parsing never needs it.

type MapResolver

type MapResolver struct {
	// Groups maps a source name to its groups.
	Groups map[string]map[string]string
	// Default names the source used when a reference names none.
	Default string
}

MapResolver resolves groups from an in-memory table, such as groups a program reads from its configuration, or those of a test.

func NewMapResolver

func NewMapResolver(source string, groups map[string]string) *MapResolver

NewMapResolver builds a resolver for a single unnamed source.

func (*MapResolver) All

func (m *MapResolver) All(source string) (string, error)

All implements Resolver by unioning every group of the source.

func (*MapResolver) DefaultSource

func (m *MapResolver) DefaultSource() string

DefaultSource implements Lister.

func (*MapResolver) List

func (m *MapResolver) List(source string) ([]string, error)

List implements Lister. An empty source means the default one.

func (*MapResolver) Resolve

func (m *MapResolver) Resolve(source, group string) (string, error)

Resolve implements Resolver. An empty source means the default one.

type NodeSet

type NodeSet struct {
	// contains filtered or unexported fields
}

NodeSet is an unordered set of host names that renders in folded form. The zero value is not usable; call New or Parse.

Padding is not part of a host's identity: exe1 and exe01 are one host. Each host keeps the spelling it was first given, and when sets are combined the spelling already held wins, so a set never shows a host under a name it was not given.

func MustParse

func MustParse(expr string, opts ...Option) *NodeSet

MustParse is Parse for expressions fixed at compile time; it panics on a parse error.

func New

func New(opts ...Option) *NodeSet

New returns an empty set.

func Parse

func Parse(expr string, opts ...Option) (*NodeSet, error)

Parse evaluates a node set expression without resolving groups. An expression containing a group reference is rejected.

func ParseWith

func ParseWith(expr string, res Resolver, opts ...Option) (*NodeSet, error)

ParseWith evaluates a node set expression, resolving group references through res. A nil resolver rejects every group reference.

func (*NodeSet) Add

func (ns *NodeSet) Add(expr string) error

Add parses names and adds the hosts they name to the set.

func (*NodeSet) Canonical

func (ns *NodeSet) Canonical(name string) (string, bool)

Canonical returns the name this set holds for a host, which is always a name the set was given.

It differs from the name asked about when the two were written with different padding: a set holding exe0001 answers "exe0001" when asked about "exe1", because padding is not part of a host's identity and both name one host. A set holding exe0001 and exe11 answers "exe11" for exe11.

func (*NodeSet) Clone

func (ns *NodeSet) Clone() *NodeSet

Clone returns an independent copy.

func (*NodeSet) Contains

func (ns *NodeSet) Contains(name string) bool

Contains reports whether name is a member. Padding is ignored, so "exe01" and "exe1" name the same host.

func (*NodeSet) Difference

func (ns *NodeSet) Difference(other *NodeSet) *NodeSet

Difference returns the hosts of ns that are not in other.

func (*NodeSet) Expand

func (ns *NodeSet) Expand() []string

Expand returns the host names in ascending order: by pattern first, then by each numeric dimension from left to right.

func (*NodeSet) Hostlist

func (ns *NodeSet) Hostlist() string

Hostlist renders the set in the syntax Slurm and FreeIPMI accept: one bracketed range per name at most, and no steps.

Each pattern is folded along the one dimension that gives the fewest names, so rack[1-2]node[001-100] becomes rack1node[001-100],rack2node[001-100] rather than two hundred names, and the argument stays short. Both parsers read several bracketed dimensions in one name as well, but this form is the one every version of them reads.

func (*NodeSet) Intersection

func (ns *NodeSet) Intersection(other *NodeSet) *NodeSet

Intersection returns the hosts in both sets.

func (*NodeSet) IsEmpty

func (ns *NodeSet) IsEmpty() bool

IsEmpty reports whether the set names no host.

func (*NodeSet) Len

func (ns *NodeSet) Len() int

Len reports the number of hosts in the set.

func (*NodeSet) Split

func (ns *NodeSet) Split(n int) []*NodeSet

Split partitions the set into at most n chunks of near equal size, in expansion order. It returns nil for n below one.

func (*NodeSet) String

func (ns *NodeSet) String() string

String renders the set in folded form, which Parse reads back as the same set, every host spelled as before. An empty set renders as the empty string.

func (*NodeSet) SymmetricDifference

func (ns *NodeSet) SymmetricDifference(other *NodeSet) *NodeSet

SymmetricDifference returns the hosts in exactly one of the two sets.

func (*NodeSet) Union

func (ns *NodeSet) Union(other *NodeSet) *NodeSet

Union returns the hosts in either set.

type Option

type Option func(*NodeSet)

Option configures parsing and rendering.

func WithAutostep

func WithAutostep(n int) Option

WithAutostep folds arithmetic progressions of at least n elements into "first-last/step" form. ClusterShell disables this by default, and so does this package; n below 2 keeps it disabled.

type Resolver

type Resolver interface {
	// Resolve returns the expression a group names. An unknown group is an
	// error; an empty group returns an empty expression.
	Resolve(source, group string) (string, error)
	// All returns the expression naming every host a source knows. It
	// answers the reference @source:*, or @* for an empty source.
	All(source string) (string, error)
}

Resolver turns a group reference into a node set expression.

A reference is written @group, or @source:group when several group sources are configured. The expression a resolver returns is parsed in turn, so a group may refer to other groups.

The source is passed on as written, and is empty for a bare @group: which source that means, the default one or a search of several, is the resolver's to decide.

Jump to

Keyboard shortcuts

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