cea-hpc/clustershell

NodeSet: change the names of the nodes in the nodeset

lmagdanello opened this issue · 3 comments

Hi,

I'm creating a script that will receive a nodeset as a parameter and execute commands on these nodes, however I need to change the name resolution of these nodes in the nodeset to another one, for example:

I will receive as a parameter: nodes[1-10]
And I need to change it to: bmc[1-10]

I took a look at the NodeSet and RangeSet classes, but I didn't find anything that could help me.

I took a more 'rustic' approach for now:

>>> from ClusterShell.NodeSet import NodeSet

>>> n = "nodes[1-10]"
>>> nodeset = NodeSet(n)
>>> nodeschanged = []
>>> for nodes in nodeset:
...     nodeschanged.append(nodes)
... 
>>>
>>> print(nodeschanged)
['nodes1', 'nodes2', 'nodes3', 'nodes4', 'nodes5', 'nodes6', 'nodes7', 'nodes8', 'nodes9', 'nodes10']

_>>> nodeschanged = [ change.replace("nodes", "bmc") for change in nodeschanged ]_

>>> print(nodeschanged)
['bmc1', 'bmc2', 'bmc3', 'bmc4', 'bmc5', 'bmc6', 'bmc7', 'bmc8', 'bmc9', 'bmc10']

If you know of any easier way to make this name change using Clustershell and can help me in the comments, I would be very grateful! 💯

Hey!

I tried this approach: nodeset = NodeSet (n.replace ('nodes', 'bmc'))

And it's perfect for what I want.

About the context: the question is that I will execute a command in the machine's management console, which by the operating system resolves by another name (in the case bmc), so the idea is to execute the script using the hostname of the machine but transforming it to 'bmc' to execute the command on the management console.

Thank you for your help! : D

Closing the ticket! @fccagou thx a lot!