Package ClusterShell :: Module NodeSet :: Class NodeSet
[hide private]
[frames] | no frames]

Class NodeSet

source code


Iterable class of nodes with node ranges support.

NodeSet creation examples:

>>> nodeset = NodeSet()               # empty NodeSet
>>> nodeset = NodeSet("cluster3")     # contains only cluster3
>>> nodeset = NodeSet("cluster[5,10-42]")
>>> nodeset = NodeSet("cluster[0-10/2]")
>>> nodeset = NodeSet("cluster[0-10/2],othername[7-9,120-300]")

NodeSet provides methods like update(), intersection_update() or difference_update() methods, which conform to the Python Set API. However, unlike RangeSet or standard Set, NodeSet is somewhat not so strict for convenience, and understands NodeSet instance or NodeSet string as argument. Also, there is no strict definition of one element, for example, it IS allowed to do:

>>> nodeset = NodeSet("blue[1-50]")
>>> nodeset.remove("blue[36-40]")
>>> print nodeset
blue[1-35,41-50]

Additionally, the NodeSet class recognizes the "extended string pattern" which adds support for union (special character ","), difference ("!"), intersection ("&") and symmetric difference ("^") operations. String patterns are read from left to right, by proceeding any character operators accordinately.

Extended string pattern usage examples:

>>> nodeset = NodeSet("node[0-10],node[14-16]") # union
>>> nodeset = NodeSet("node[0-10]!node[8-10]")  # difference
>>> nodeset = NodeSet("node[0-10]&node[5-13]")  # intersection
>>> nodeset = NodeSet("node[0-10]^node[5-13]")  # xor
Instance Methods [hide private]
 
__init__(self, nodes=None, autostep=None, resolver=None, fold_axis=None)
Initialize a NodeSet object.
source code
 
__getstate__(self)
Called when pickling: remove references to group resolver.
source code
 
__setstate__(self, dic)
Called when unpickling: restore parser using non group resolver.
source code
 
copy(self)
Return a shallow copy of a NodeSet.
source code
 
__copy__(self)
Return a shallow copy of a NodeSet.
source code
 
_find_groups(self, node, namespace, allgroups)
Find groups of node by namespace.
source code
 
_groups2(self, groupsource=None, autostep=None)
Find node groups this nodeset belongs to.
source code
 
groups(self, groupsource=None, noprefix=False)
Find node groups this nodeset belongs to.
source code
 
regroup(self, groupsource=None, autostep=None, overlap=False, noprefix=False)
Regroup nodeset using node groups.
source code
 
issubset(self, other)
Report whether another nodeset contains this nodeset.
source code
 
issuperset(self, other)
Report whether this nodeset contains another nodeset.
source code
 
__getitem__(self, index)
Return the node at specified index or a subnodeset when a slice is specified.
source code
 
split(self, nbr)
Split the nodeset into nbr sub-nodesets (at most).
source code
 
update(self, other)
s.update(t) returns nodeset s with elements added from t.
source code
 
intersection_update(self, other)
s.intersection_update(t) returns nodeset s keeping only elements also found in t.
source code
 
difference_update(self, other, strict=False)
s.difference_update(t) removes from s all the elements found in t.
source code
 
symmetric_difference_update(self, other)
s.symmetric_difference_update(t) returns nodeset s keeping all nodes that are in exactly one of the nodesets.
source code

Inherited from NodeSetBase: __and__, __contains__, __eq__, __ge__, __gt__, __iand__, __ior__, __isub__, __iter__, __ixor__, __le__, __len__, __lt__, __or__, __str__, __sub__, __xor__, add, clear, contiguous, difference, get_autostep, intersection, nsiter, remove, set_autostep, striter, symmetric_difference, union, updaten

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
_fromlist1(cls, nodelist, autostep=None, resolver=None)
Class method that returns a new NodeSet with single nodes from provided list (optimized constructor).
source code
 
fromlist(cls, nodelist, autostep=None, resolver=None)
Class method that returns a new NodeSet with nodes from provided list.
source code
 
fromall(cls, groupsource=None, autostep=None, resolver=None)
Class method that returns a new NodeSet with all nodes from optional groupsource.
source code
Class Variables [hide private]
  _VERSION = 2
Instance Variables [hide private]

Inherited from NodeSetBase: fold_axis

Properties [hide private]

Inherited from NodeSetBase: autostep

Inherited from object: __class__

Method Details [hide private]

__init__(self, nodes=None, autostep=None, resolver=None, fold_axis=None)
(Constructor)

source code 

Initialize a NodeSet object.

The `nodes` argument may be a valid nodeset string or a NodeSet object. If no nodes are specified, an empty NodeSet is created.

The optional `autostep` argument is passed to underlying :class:`.RangeSet.RangeSet` objects and aims to enable and make use of the range/step syntax (eg. ``node[1-9/2]``) when converting NodeSet to string (using folding). To enable this feature, autostep must be set there to the min number of indexes that are found at equal distance of each other inside a range before NodeSet starts to use this syntax. For example, `autostep=3` (or less) will pack ``n[2,4,6]`` into ``n[2-6/2]``. Default autostep value is None which means "inherit whenever possible", ie. do not enable it unless set in NodeSet objects passed as `nodes` here or during arithmetic operations. You may however use the special ``AUTOSTEP_DISABLED`` constant to force turning off autostep feature.

The optional `resolver` argument may be used to override the group resolving behavior for this NodeSet object. It can either be set to a :class:`.NodeUtils.GroupResolver` object, to the ``RESOLVER_NOGROUP`` constant to disable any group resolution, or to None (default) to use standard NodeSet group resolver (see :func:`.set_std_group_resolver()` at the module level to change it if needed).

nD nodeset only: the optional `fold_axis` parameter, if specified, set the public instance member `fold_axis` to an iterable over nD 0-indexed axis integers. This parameter may be used to disengage some nD folding. That may be useful as all cluster tools don't support folded-nD nodeset syntax. Pass ``[0]``, for example, to only fold along first axis (that is, to fold first dimension using ``[a-b]`` rangeset syntax whenever possible). Using `fold_axis` ensures that rangeset won't be folded on unspecified axis, but please note however, that using `fold_axis` may lead to suboptimial folding, this is because NodeSet algorithms are optimized for folding along all axis (default behavior).

Overrides: object.__init__

copy(self)

source code 

Return a shallow copy of a NodeSet.

Overrides: NodeSetBase.copy

_groups2(self, groupsource=None, autostep=None)

source code 

Find node groups this nodeset belongs to. [private]

groups(self, groupsource=None, noprefix=False)

source code 
Find node groups this nodeset belongs to.

Return a dictionary of the form:
    group_name => (group_nodeset, contained_nodeset)

Group names are always prefixed with "@". If groupsource is provided,
they are prefixed with "@groupsource:", unless noprefix is True.

regroup(self, groupsource=None, autostep=None, overlap=False, noprefix=False)

source code 

Regroup nodeset using node groups.

Try to find fully matching node groups (within specified groupsource) and return a string that represents this node set (containing these potential node groups). When no matching node groups are found, this method returns the same result as str().

issubset(self, other)

source code 

Report whether another nodeset contains this nodeset.

Overrides: NodeSetBase.issubset

issuperset(self, other)

source code 

Report whether this nodeset contains another nodeset.

Overrides: NodeSetBase.issuperset

__getitem__(self, index)
(Indexing operator)

source code 

Return the node at specified index or a subnodeset when a slice is specified.

Overrides: NodeSetBase.__getitem__

split(self, nbr)

source code 

Split the nodeset into nbr sub-nodesets (at most). Each sub-nodeset will have the same number of elements more or less 1. Current nodeset remains unmodified.

>>> for nodeset in NodeSet("foo[1-5]").split(3):
...     print nodeset
foo[1-2]
foo[3-4]
foo5

update(self, other)

source code 

s.update(t) returns nodeset s with elements added from t.

Overrides: NodeSetBase.update

intersection_update(self, other)

source code 

s.intersection_update(t) returns nodeset s keeping only elements also found in t.

Overrides: NodeSetBase.intersection_update

difference_update(self, other, strict=False)

source code 

s.difference_update(t) removes from s all the elements found in t. If strict is True, raise KeyError if an element in t cannot be removed from s.

Overrides: NodeSetBase.difference_update

symmetric_difference_update(self, other)

source code 

s.symmetric_difference_update(t) returns nodeset s keeping all nodes that are in exactly one of the nodesets.

Overrides: NodeSetBase.symmetric_difference_update