mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 14:07:55 +00:00
parallel: Auto add hostgroup if given on arg.
This commit is contained in:
parent
414667b8b4
commit
b843ec7398
32
src/parallel
32
src/parallel
|
@ -1021,7 +1021,7 @@ sub options_hash {
|
||||||
"replace|i:s" => \$opt::i,
|
"replace|i:s" => \$opt::i,
|
||||||
"E=s" => \$opt::eof,
|
"E=s" => \$opt::eof,
|
||||||
"eof|e:s" => \$opt::eof,
|
"eof|e:s" => \$opt::eof,
|
||||||
"max-args|n=i" => \$opt::max_args,
|
"max-args|maxargs|n=i" => \$opt::max_args,
|
||||||
"max-replace-args|N=i" => \$opt::max_replace_args,
|
"max-replace-args|N=i" => \$opt::max_replace_args,
|
||||||
"colsep|col-sep|C=s" => \$opt::colsep,
|
"colsep|col-sep|C=s" => \$opt::colsep,
|
||||||
"help|h" => \$opt::help,
|
"help|h" => \$opt::help,
|
||||||
|
@ -4918,6 +4918,8 @@ sub new {
|
||||||
# Look for SSHLogin hostgroups
|
# Look for SSHLogin hostgroups
|
||||||
%hostgroups = map { $_ => 1 } split(/\+/, $1);
|
%hostgroups = map { $_ => 1 } split(/\+/, $1);
|
||||||
}
|
}
|
||||||
|
# An SSHLogin is always in the hostgroup of its "numcpu/host"
|
||||||
|
$hostgroups{$sshlogin_string} = 1;
|
||||||
if ($sshlogin_string =~ s:^(\d+)/::) {
|
if ($sshlogin_string =~ s:^(\d+)/::) {
|
||||||
# Override default autodetected ncpus unless missing
|
# Override default autodetected ncpus unless missing
|
||||||
$ncpus = $1;
|
$ncpus = $1;
|
||||||
|
@ -10302,8 +10304,8 @@ sub get {
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
my $ret = $self->{'arg_sub_queue'}->get();
|
my $ret = $self->{'arg_sub_queue'}->get();
|
||||||
if($ret and
|
if($ret) {
|
||||||
grep { index($_->orig(),"\0") > 0 } @$ret) {
|
if(grep { index($_->orig(),"\0") > 0 } @$ret) {
|
||||||
# Allow for \0 in position 0 because GNU Parallel uses "\0"
|
# Allow for \0 in position 0 because GNU Parallel uses "\0"
|
||||||
# to mean no-string
|
# to mean no-string
|
||||||
::warning("a NUL character occurred in the input.",
|
::warning("a NUL character occurred in the input.",
|
||||||
|
@ -10314,14 +10316,12 @@ sub get {
|
||||||
and $Global::max_number_of_args == 0) {
|
and $Global::max_number_of_args == 0) {
|
||||||
::debug("run", "Read 1 but return 0 args\n");
|
::debug("run", "Read 1 but return 0 args\n");
|
||||||
# \0 => nothing (not the empty string)
|
# \0 => nothing (not the empty string)
|
||||||
$ret = [Arg->new("\0")];
|
map { $_->set_orig("\0"); } @$ret;
|
||||||
} else {
|
}
|
||||||
# Flush cached computed replacements in Arg-objects
|
# Flush cached computed replacements in Arg-objects
|
||||||
# To fix: parallel --bar echo {%} ::: a b c ::: d e f
|
# To fix: parallel --bar echo {%} ::: a b c ::: d e f
|
||||||
if($ret) {
|
|
||||||
map { $_->flush_cache() } @$ret;
|
map { $_->flush_cache() } @$ret;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10703,10 +10703,19 @@ sub new {
|
||||||
# We found hostgroups on the arg
|
# We found hostgroups on the arg
|
||||||
@hostgroups = split(/\+/, $1);
|
@hostgroups = split(/\+/, $1);
|
||||||
if(not grep { defined $Global::hostgroups{$_} } @hostgroups) {
|
if(not grep { defined $Global::hostgroups{$_} } @hostgroups) {
|
||||||
::warning("No such hostgroup (@hostgroups).");
|
# This hostgroup is not defined using -S
|
||||||
@hostgroups = (keys %Global::hostgroups);
|
# Add it
|
||||||
|
::warning("Adding hostgroups: @hostgroups");
|
||||||
|
# Add sshlogin
|
||||||
|
for(grep { not defined $Global::hostgroups{$_} } @hostgroups) {
|
||||||
|
my $sshlogin = SSHLogin->new($_);
|
||||||
|
my $sshlogin_string = $sshlogin->string();
|
||||||
|
$Global::host{$sshlogin_string} = $sshlogin;
|
||||||
|
$Global::hostgroups{$sshlogin_string} = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
# No hostgroup on the arg => any hostgroup
|
||||||
@hostgroups = (keys %Global::hostgroups);
|
@hostgroups = (keys %Global::hostgroups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10806,6 +10815,11 @@ sub orig {
|
||||||
return $self->{'orig'};
|
return $self->{'orig'};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub set_orig {
|
||||||
|
my $self = shift;
|
||||||
|
$self->{'orig'} = shift;
|
||||||
|
}
|
||||||
|
|
||||||
sub trim_of {
|
sub trim_of {
|
||||||
# Removes white space as specifed by --trim:
|
# Removes white space as specifed by --trim:
|
||||||
# n = nothing
|
# n = nothing
|
||||||
|
|
|
@ -91,6 +91,11 @@ par_quoting_for_onall() {
|
||||||
echo foo: /bin/ls | parallel --colsep ' ' -S lo --onall ls {2}
|
echo foo: /bin/ls | parallel --colsep ' ' -S lo --onall ls {2}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
par_hostgroup_only_on_args() {
|
||||||
|
echo '### Auto add hostgroup if given on on argument'
|
||||||
|
parallel --hostgroup ::: whoami@sh@lo
|
||||||
|
}
|
||||||
|
|
||||||
export -f $(compgen -A function | grep par_)
|
export -f $(compgen -A function | grep par_)
|
||||||
# Tested with -j1..8
|
# Tested with -j1..8
|
||||||
# -j6 was fastest
|
# -j6 was fastest
|
||||||
|
|
|
@ -39,6 +39,9 @@ echo '### bug #49404: "Max jobs to run" does not equal the number of jobs specif
|
||||||
should give 10 running jobs
|
should give 10 running jobs
|
||||||
stdout parallel -S 16/lo --progress true ::: {1..10} | grep /.10
|
stdout parallel -S 16/lo --progress true ::: {1..10} | grep /.10
|
||||||
1:lo / 16 / 10
|
1:lo / 16 / 10
|
||||||
|
par_hostgroup_only_on_args ### Auto add hostgroup if given on on argument
|
||||||
|
par_hostgroup_only_on_args parallel: Warning: Adding hostgroups: sh@lo
|
||||||
|
par_hostgroup_only_on_args sh
|
||||||
par_quoting_for_onall ### bug #35427: quoting of {2} broken for --onall
|
par_quoting_for_onall ### bug #35427: quoting of {2} broken for --onall
|
||||||
par_quoting_for_onall /bin/ls
|
par_quoting_for_onall /bin/ls
|
||||||
par_return_with_fixedstring ### Test --return with fixed string (Gave undef warnings)
|
par_return_with_fixedstring ### Test --return with fixed string (Gave undef warnings)
|
||||||
|
|
Loading…
Reference in a new issue