mezhekov / parallel-ssh

Automatically exported from code.google.com/p/parallel-ssh
Other
0 stars 0 forks source link

Ability to select a subset of hosts from hostlist #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please consider the attached path, which adds support for selecting a group of 
hosts based on descriptor-columns in the host-list. The host list file parser 
is expanded to support delimiter-separated values where the last column is the 
hostname. A new flag (-s) is introduced which allows the selection of hosts, 
each column can be matched by a regular expression. When all columns match the 
host is selected for the pssh operation.

Example; consider the following hostlist file:
yellow fruit userA@banana
green fruit userB@watermelon
red fruit userC@cherry
green veg userD@cucumber 
yellow veg userE@squash
red veg userF@beet

pssh -h hostlist -s ".* veg" ls: will run ls on all "vegetable" hosts
pssh -h hostlist -s "red .*": will select all red vegetable/fruit hosts.

The change is largely backwards compatible. When no -s flag is passed it is 
assumed that the traditional hostlist format is used. It should be noted that 
when -s is used the "hostname [user]" will not longer be a proper 
specification, and  "[username@]hostname" should be used instead.

The number of "descriptor" columns in the host files is arbitrary, however the 
-s flag must have the corresponding number of space separated regular 
expressions.

The primary use case for this feature is for environments that have many 
different types of hosts and its is often necessary to perform an operation on 
a particular host-class. Previously one would have had to maintain separate 
hostlist file for each host-type and it was rather cumbersome.

Comments/suggestions welcome.

Original issue reported on code.google.com by ilya@sukhanov.net on 1 Mar 2011 at 1:16

Attachments:

GoogleCodeExporter commented 9 years ago
It's an interesting idea.  Could you give a little more detail about why it's 
been cumbersome to maintain separate hostlist files?  It should be possible to 
write a pre-processor that reads a file in the "descriptor" format and outputs 
a set of "classic-style" host files.  Also, what happens when lines in the file 
don't all share the same number of columns?  The "descriptor" format for host 
files seems interesting but a little complicated.

Original comment by amcna...@gmail.com on 1 Mar 2011 at 2:00

GoogleCodeExporter commented 9 years ago
Cumbersomeness is proportional to the number of host classes one has to deal 
with. Certainly pre-processing is an option, but it adds one extra step. 
Furthermore one has to be careful when cleaning up so as to ensure that a 
command is not run on the wrong host (using a stale, derived hostlist). Albeit 
rather uncommon to run pssh against many different permutations of hostclasses 
it complicates the management overhead even more. Carrying one file around is a 
lot easier than dozens.

With current implementation, the behavior around incorrect number of columns is 
similar to behavior of pssh when it encounters more than 2 fields on a line in 
unpatched version. It prints a message that there was an error parsing a line 
and skips it. It is perhaps wise to adjust this behavior for both the patched 
and the unpatched version.

The feature is difficult to describe in words but it is rather intuitive. 
Perhaps my description is unclear. I would be more than happy to clarify it.

Original comment by ilya@sukhanov.net on 1 Mar 2011 at 2:30

GoogleCodeExporter commented 9 years ago

Original comment by amcna...@gmail.com on 1 Mar 2011 at 3:48

GoogleCodeExporter commented 9 years ago
I think this feature is redundant and is easy to workaround.  All you need is 
grep and process subsitution:

pssh -h <(grep -P ".* veg" hostlist)
pssh -h <(grep -P "red .*" hostlist)

Original comment by pablo.ba...@gmail.com on 2 Sep 2011 at 11:01

GoogleCodeExporter commented 9 years ago
That's a cool trick. I think we should add something about that to the examples 
section of the man page.

Original comment by amcna...@gmail.com on 5 Sep 2011 at 2:27

GoogleCodeExporter commented 9 years ago
hi, on Debian i have to use parallel-ssh rather than pssh directly is that 
normal?

Original comment by xl04...@gmail.com on 9 Feb 2014 at 9:05

GoogleCodeExporter commented 9 years ago
ok got it ... i debian does not use the last version ... i pip install 
--upgrade pssh and now it works as :: pssh -Aih bob sudo apt-get update && sudo 
apt-get upgrade but does not let me select the machine I want.

Original comment by xl04...@gmail.com on 9 Feb 2014 at 9:19