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.
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.
Zero padding is part of a node's identity: "exe1" and "exe01" are two different hosts, and each element remembers the width it was written with. In a range the padding of the first bound applies to the whole range.
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.
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 uses for a host.
It differs from the name given when the two were written with different padding: a set holding exe0001 answers "exe0001" when asked about "exe1", because padding is a display property and both name one host.
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. Those parsers understand a single bracketed range per name but not several dimensions, so a multi dimensional set is expanded instead of folded.
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.