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.remove("blue[36-40]").

Instance Methods [hide private]
 
__init__(self, nodes=None, autostep=None, resolver=None)
Initialize a NodeSet.
source code
 
__getstate__(self)
Called when pickling: remove references to group resolver.
source code
 
__setstate__(self, dict)
Called when unpickling: restore parser using non group resolver.
source code
 
_find_groups(self, node, namespace, allgroups)
Find groups of node by namespace.
source code
 
regroup(self, groupsource=None, autostep=None, overlap=False, noprefix=False)
Regroup nodeset using 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
 
__getslice__(self, i, j)
Return the slice from index i to index j-1.
source code
 
split(self, nbr)
Split the nodeset into nbr sub-nodeset.
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) returns nodeset s after removing 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__, __getitem__, __gt__, __iand__, __ior__, __isub__, __iter__, __ixor__, __le__, __len__, __lt__, __or__, __str__, __sub__, __xor__, add, clear, difference, intersection, remove, symmetric_difference, union

Inherited from NodeSetBase (private): _add, _binary_sanity_check, _iter, _iterbase

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

Class Methods [hide private]
 
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
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 

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

Overrides: object.__init__

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

__getslice__(self, i, j)
(Slicling operator)

source code 

Return the slice from index i to index j-1. For convenience only, not optimized as of version 1.0.

split(self, nbr)

source code 

Split the nodeset into nbr sub-nodeset. Each sub-nodeset will have the same number of element more or less 1. Current nodeset remains unmodified.

>>> NodeSet("foo[1-5]").split(3) 
NodeSet("foo[1-2]")
NodeSet("foo[3-4]")
NodeSet("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) returns nodeset s after removing elements found in t. If strict is True, raise KeyError if an element cannot be removed.

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