Description
nodeset is a Rust library and command-line tool (ns) that deals with
nodesets. It is heavily inspired by
clustershell and aims at supporting
the same nodeset representation in Rust. It also provides a C API for use in
other languages.
A nodeset is a set of names which are generally indexed over one or more integer
dimensions such as node1 or r1sw2-port0. Large nodesets can be represented
in a compact way using a bracket notation such as node[1-1000]. When brackets
are used in multiple dimensions, it implies a cartesian product. For example:
r[1-2]sw[1-2]-port[1-2] represents 8 ports:
r1sw1-port1,r1sw1-port2,r1sw2-port1,...,r2sw2-port2.
ns allows to fold or expand nodesets, as well as to perform algebraic
operations on them (union, intersection, difference, ...)
Command line examples
- Listing nodes:
- Folding nodes:
- Counting nodes:
- Algebraic operations using operators:
Configuration files and groups
ns understands and uses clustershell's configuration files in which node
groups can be defined. Please refer to clustershell's documentation for a full
description of the configuration files syntax.
Library usage example
To compute and display the intersection of two nodesets
use NodeSet;
let ns1: NodeSet = "node[01-15]".parse.unwrap;
let ns2: NodeSet = "node[10-30/2]".parse.unwrap;
let inter = ns1.intersection;
assert_eq!;
C bindings
Along with the CLI binary (ns), running cargo build --all from the crate
root generates the libnodeset.so C dynamic library. The C API is described in
the nodeset.h header.
The following example shows how to iterate over a nodeset. More complete examples are available in the examples directory.
int
Why use this crate
This project is not as mature as clustershell and has fewer features. However,
compared to clustershell's nodeset tool written in Python, ns starts much
faster as it doesn't rely on an interpreter. It can save a lot of time when
performing multiple operations on nodesets in a shell script. It is also faster
at parsing and performing operations on large nodesets. Last but not least, the
library crate can be used to handle nodesets natively in Rust or C while sharing
group definitions with clustershell.