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") holds one host 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.
These rules, and the others where this package differs from ClusterShell, are listed in doc/nodeset.md in the source repository.
Index ¶
- type MapResolver
- type NodeSet
- func (ns *NodeSet) Add(expr string) error
- func (ns *NodeSet) Canonical(name string) (string, bool)
- func (ns *NodeSet) Clone() *NodeSet
- func (ns *NodeSet) Contains(name string) bool
- func (ns *NodeSet) Difference(other *NodeSet) *NodeSet
- func (ns *NodeSet) Expand() []string
- func (ns *NodeSet) Hostlist() string
- func (ns *NodeSet) Intersection(other *NodeSet) *NodeSet
- func (ns *NodeSet) IsEmpty() bool
- func (ns *NodeSet) Len() int
- func (ns *NodeSet) Split(n int) []*NodeSet
- func (ns *NodeSet) String() string
- func (ns *NodeSet) SymmetricDifference(other *NodeSet) *NodeSet
- func (ns *NodeSet) Union(other *NodeSet) *NodeSet
- type Option
- type Resolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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. It backs the static group definitions in the site configuration and the tests.
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 Resolver.
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 ¶
MustParse is Parse for expressions fixed at compile time; it panics on a parse error.
func Parse ¶
Parse evaluates a node set expression without resolving groups. An expression containing a group reference is rejected.
func ParseWith ¶
ParseWith evaluates a node set expression, resolving group references through res. A nil resolver rejects every group reference.
func (*NodeSet) Canonical ¶
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) Contains ¶
Contains reports whether name is a member. Padding is ignored, so "exe01" and "exe1" name the same host.
func (*NodeSet) Difference ¶
Difference returns the hosts of ns that are not in other.
func (*NodeSet) Expand ¶
Expand returns the host names in ascending order: by pattern first, then by each numeric dimension from left to right.
func (*NodeSet) Hostlist ¶
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 ¶
Intersection returns the hosts in both sets.
func (*NodeSet) Split ¶
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 ¶
String renders the set in folded form, the representation clusterctl prints and accepts. An empty set renders as the empty string.
func (*NodeSet) SymmetricDifference ¶
SymmetricDifference returns the hosts in exactly one of the two sets.
type Option ¶
type Option func(*NodeSet)
Option configures parsing and rendering.
func WithAutostep ¶
WithAutostep folds arithmetic progressions of at least n elements into "first-last/step" form. ClusterShell disables this by default and so does clusterctl; 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)
// List returns the group names a source offers.
List(source string) ([]string, error)
// All returns the expression naming every host a source knows.
All(source string) (string, error)
// DefaultSource names the source used when a reference names none.
DefaultSource() string
}
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.