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("clustername3")     # contains only clustername3
    nodeset = NodeSet("clustername[5,10-42]")
    nodeset = NodeSet("clustername[0-10/2]")
    nodeset = NodeSet("clustername[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, pattern=None, autostep=None)
Initialize a NodeSet.
source code
 
__iter__(self)
Iterate over concret nodes.
source code
 
__len__(self)
Get the number of nodes in NodeSet.
source code
 
__str__(self)
Get pdsh-like, ranges-based pattern of node list.
source code
 
__contains__(self, other)
Is node contained in NodeSet ?
source code
 
_binary_sanity_check(self, other) 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
 
__eq__(self, other)
NodeSet equality comparison.
source code
 
__le__(self, other)
Report whether another nodeset contains this nodeset.
source code
 
__ge__(self, other)
Report whether this nodeset contains another nodeset.
source code
 
__lt__(x, y)
x<y
source code
 
__gt__(x, y)
x>y
source code
 
__getitem__(self, i)
Return the node at index i.
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
 
_add_rangeset(self, pat, rangeset)
Add a rangeset to a new or existing pattern.
source code
 
union(self, other)
s.union(t) returns a new set with elements from both s and t.
source code
 
__or__(self, other)
Implements the | operator.
source code
 
add(self, other)
Add node to NodeSet.
source code
 
update(self, other)
s.update(t) returns nodeset s with elements added from t.
source code
 
clear(self)
Remove all nodes from this nodeset.
source code
 
__ior__(self, other)
Implements the |= operator.
source code
 
intersection(self, other)
s.intersection(t) returns a new set with elements common to s and t.
source code
 
__and__(self, other)
Implements the & operator.
source code
 
intersection_update(self, other)
s.intersection_update(t) returns nodeset s keeping only elements also found in t.
source code
 
__iand__(self, other)
Implements the &= operator.
source code
 
difference(self, other)
s.difference(t) returns a new NodeSet with elements in s but not in t.
source code
 
__sub__(self, other)
Implement the - operator.
source code
 
difference_update(self, other, strict=False)
s.difference_update(t) returns nodeset s after removing elements found in t.
source code
 
__isub__(self, other)
Implement the -= operator.
source code
 
remove(self, elem)
Remove element elem from the nodeset.
source code
 
symmetric_difference(self, other)
s.symmetric_difference(t) returns the symmetric difference of two nodesets as a new NodeSet.
source code
 
__xor__(self, other)
Implement the ^ operator.
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
 
__ixor__(self, other)
Implement the ^= operator.
source code

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

Class Methods [hide private]
 
fromlist(cls, nodelist, autostep=None)
Class method that returns a new NodeSet with nodes from provided list.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, pattern=None, autostep=None)
(Constructor)

source code 

Initialize a NodeSet. If no pattern is specified, an empty NodeSet is created.

Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

Get pdsh-like, ranges-based pattern of node list.

Overrides: object.__str__

__getitem__(self, i)
(Indexing operator)

source code 

Return the node at index i. For convenience only, not optimized as of version 1.0.

__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")

__or__(self, other)
(Or operator)

source code 

Implements the | operator. So s | t returns a new nodeset with elements from both s and t.

__ior__(self, other)

source code 

Implements the |= operator. So s |= t returns nodeset s with elements added from t. (Python version 2.5+ required)

__and__(self, other)
(And operator)

source code 

Implements the & operator. So s & t returns a new nodeset with elements common to s and t.

__iand__(self, other)

source code 

Implements the &= operator. So s &= t returns nodeset s keeping only elements also found in t. (Python version 2.5+ required)

__sub__(self, other)
(Subtraction operator)

source code 

Implement the - operator. So s - t returns a new nodeset with elements in s but not in t.

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.

__isub__(self, other)

source code 

Implement the -= operator. So s -= t returns nodeset s after removing elements found in t. (Python version 2.5+ required)

remove(self, elem)

source code 

Remove element elem from the nodeset. Raise KeyError if elem is not contained in the nodeset.

symmetric_difference(self, other)

source code 

s.symmetric_difference(t) returns the symmetric difference of two nodesets as a new NodeSet.

(ie. all nodes that are in exactly one of the nodesets.)

__xor__(self, other)
(Exclusive-Or operator)

source code 

Implement the ^ operator. So s ^ t returns a new NodeSet with nodes that are in exactly one of the nodesets.

__ixor__(self, other)

source code 

Implement the ^= operator. So s ^= t returns nodeset s after keeping all nodes that are in exactly one of the nodesets. (Python version 2.5+ required)