mirror of
https://github.com/duncs/clusterssh.git
synced 2025-04-22 01:12:24 +00:00
Bring new 'tag' file into use
/etc/tags and $HOME/.clusterssh/tags is now used Refacter some code to make it clearer and update docs for new options
This commit is contained in:
parent
b2ba4daa46
commit
6fccd92d6a
6 changed files with 75 additions and 33 deletions
1
Changes
1
Changes
|
@ -1,6 +1,7 @@
|
|||
????-??-?? Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.02_01
|
||||
- Refactured file loading code
|
||||
- Add in 'tags' file handling
|
||||
- Fix bug whereby cluster files were read in multiple times
|
||||
|
||||
2013-03-05 Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.01_05
|
||||
- New option (-m, --unique-servers) to remove repeated servers when opening terminals (Thanks to Oliver Meissner)
|
||||
|
|
34
bin/cssh
34
bin/cssh
|
@ -212,6 +212,10 @@ Specify an alternate port for connections.
|
|||
IN BETA: Show history within console window. This code is still being
|
||||
worked upon, but may help some users.
|
||||
|
||||
=item --tag-file,-c <file>
|
||||
|
||||
Use supplied file as additional tag file (see also L</"FILES">)
|
||||
|
||||
=item --term-args,-t ""
|
||||
|
||||
Specify arguments to be passed to terminals being used
|
||||
|
@ -339,9 +343,9 @@ S<$ ccon -M master server1 server2>
|
|||
|
||||
=over
|
||||
|
||||
=item F</etc/clusters>
|
||||
=item F</etc/clusters>, F<$HOME/.clusterssh/clusters>
|
||||
|
||||
This file contains a list of tags to server names mappings. When any name
|
||||
These files contain a list of tags to server names mappings. When any name
|
||||
is used on the command line it is checked to see if it is a tag.
|
||||
If it is a tag, then the tag is replaced with the list of servers. The
|
||||
formated is as follows:
|
||||
|
@ -354,16 +358,34 @@ S<< <tag> [user@]<server> [user@]<server> [...] >>
|
|||
live admin1@server1 admin2@server2 server3 server4
|
||||
|
||||
All comments (marked by a #) and blank lines are ignored. Tags may be
|
||||
nested, but be aware of recursive tags which are not checked for.
|
||||
nested, but be aware of using recursive tags as they are not checked for.
|
||||
|
||||
Clusters may also be specified either directly (see C<clusters> configuration
|
||||
options) or indirectly (see C<extra_cluster_file> configuration option)
|
||||
in the users F<$HOME/.clusterssh/config> file.
|
||||
Extra cluster files may also be specified either as an option on the
|
||||
command line (see C<cluster-file>) or in the users F<$HOME/.clusterssh/config>
|
||||
file (see C<extra_cluster_file> configuration option).
|
||||
|
||||
NOTE: the last tag read overwrites any pre-existing tag of that name
|
||||
|
||||
NOTE: there is a special cluster tag called C<default> - any tags or hosts
|
||||
included within this tag will be automatically opened if no other tags
|
||||
are specified on the command line.
|
||||
|
||||
=item F</etc/tags>, F<$HOME/.clusterssh/tags>
|
||||
|
||||
Very similar to F<cluster> files but the definition is reversed. The
|
||||
format is:
|
||||
|
||||
S<< <host> <tag> [...] >>
|
||||
|
||||
This allows one host to be specified as a member of a number of tags. This
|
||||
format can be clearer than using F<clusters> files.
|
||||
|
||||
Extra tag files may be spcieid either an an option (see C<tag-file>) or within
|
||||
the users F<$HOME/.clusterssh/config> file (see C<extra_tag_file>
|
||||
configuration option).
|
||||
|
||||
NOTE: All tags are added together
|
||||
|
||||
=item F</etc/csshrc> & F<$HOME/.clusterssh/config>
|
||||
|
||||
This file contains configuration overrides - the defaults are as marked.
|
||||
|
|
|
@ -98,6 +98,7 @@ my @options_spec = (
|
|||
'man|H',
|
||||
'action|a=s',
|
||||
'cluster-file|c=s',
|
||||
'tag-file|c=s',
|
||||
'config-file|C=s',
|
||||
'evaluate|e=s',
|
||||
'tile|g',
|
||||
|
@ -391,9 +392,12 @@ sub resolve_names(@) {
|
|||
if ( $dirty =~ s/^(.*)@// ) {
|
||||
$username = $1;
|
||||
}
|
||||
|
||||
my @tag_list = $self->cluster->get_tag($dirty);
|
||||
|
||||
if ( $self->config->{use_all_a_records}
|
||||
&& $dirty !~ m/^(\d{1,3}\.?){4}$/
|
||||
&& !defined( $self->cluster->get_tag($dirty) ) )
|
||||
&& ! @tag_list )
|
||||
{
|
||||
my $hostobj = gethostbyname($dirty);
|
||||
if ( defined($hostobj) ) {
|
||||
|
@ -408,9 +412,9 @@ sub resolve_names(@) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ( $self->cluster->get_tag($dirty) ) {
|
||||
if ( @tag_list ) {
|
||||
logmsg( 3, '... it is a cluster' );
|
||||
foreach my $node ( $self->cluster->get_tag($dirty) ) {
|
||||
foreach my $node ( @tag_list) {
|
||||
if ($username) {
|
||||
$node =~ s/^(.*)@//;
|
||||
$node = $username . '@' . $node;
|
||||
|
@ -1871,30 +1875,18 @@ sub run {
|
|||
load_keyboard_map();
|
||||
|
||||
# read in normal cluster files
|
||||
$self->cluster->read_cluster_file('/etc/clusters');
|
||||
if ( $self->config->{extra_cluster_file} || $options{'cluster-file'} ) {
|
||||
foreach my $item ( split( /,/, $self->config->{extra_cluster_file} ),
|
||||
$options{'cluster-file'} )
|
||||
{
|
||||
next unless ($item);
|
||||
$item =~ s/\$HOME/$ENV{HOME}/;
|
||||
foreach my $file ( glob($item) ) {
|
||||
if ( !-r $file ) {
|
||||
warn("Unable to read cluster file '$file': $!\n");
|
||||
next;
|
||||
}
|
||||
$self->config->{extra_cluster_file} .= ','.$options{'cluster-file'} if($options{'cluster-file'});
|
||||
$self->config->{extra_tag_file} .= ','.$options{'tag-file'} if($options{'tag-file'});
|
||||
|
||||
$self->cluster->read_cluster_file($file);
|
||||
$self->cluster->get_cluster_entries( split /,/, $self->config->{extra_cluster_file} || '' );
|
||||
$self->cluster->get_tag_entries( split /,/, $self->config->{extra_tag_file}|| '' );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$self->cluster->get_clusters( $self->config->{extra_cluster_file} );
|
||||
|
||||
if ( $options{'list'} ) {
|
||||
print( 'Available cluster tags:', $/ );
|
||||
print "\t", $_, $/ foreach ( sort( $self->cluster->list_tags ) );
|
||||
|
||||
$self->debug(4, "Full clusters dump: ",$self->_dump_args_hash( $self->cluster->dump_tags ) );
|
||||
exit_prog();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,11 @@ sub _dump_args_hash {
|
|||
$string .= "\t";
|
||||
$string .= $_;
|
||||
$string .= ' => ';
|
||||
$string .= $args{$_};
|
||||
if(ref($args{$_}) eq 'ARRAY') {
|
||||
$string .= "@{ $args{$_} }";
|
||||
} else {
|
||||
$string .= $args{$_};
|
||||
}
|
||||
$string .= ',';
|
||||
$string .= $/;
|
||||
}
|
||||
|
|
|
@ -23,17 +23,28 @@ sub new {
|
|||
return $master_object_ref;
|
||||
}
|
||||
|
||||
sub get_clusters {
|
||||
sub get_cluster_entries {
|
||||
my ( $self, @files ) = @_;
|
||||
|
||||
for my $file ( '/etc/clusters', $ENV{HOME}.'/.clusterssh/clusters',@files ) {
|
||||
$self->debug(3, 'Loading in config from: ', $file);
|
||||
$self->debug(3, 'Loading in clusters from: ', $file);
|
||||
$self->read_cluster_file($file);
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub get_tag_entries {
|
||||
my ( $self, @files ) = @_;
|
||||
|
||||
for my $file ( '/etc/tags', $ENV{HOME}.'/.clusterssh/tags',@files ) {
|
||||
$self->debug(3, 'Loading in tags from: ', $file);
|
||||
$self->read_tag_file($file);
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub read_tag_file {
|
||||
my ( $self, $filename ) = @_;
|
||||
$self->debug( 2, 'Reading tags from file ', $filename );
|
||||
|
@ -97,7 +108,7 @@ sub get_tag {
|
|||
|
||||
if ( $self->{tags}->{$tag} ) {
|
||||
$self->debug( 2, "Retrieving tag $tag: ",
|
||||
join( ' ', $self->{tags}->{$tag} ) );
|
||||
join( ' ', sort @{ $self->{tags}->{$tag} } ) );
|
||||
|
||||
return sort @{ $self->{tags}->{$tag} };
|
||||
}
|
||||
|
@ -146,9 +157,15 @@ Object representing application configuration
|
|||
|
||||
Create a new object. Object should be common across all invocations.
|
||||
|
||||
=item $cluster->get_clusters($filename);
|
||||
=item $cluster->get_cluster_entries($filename);
|
||||
|
||||
Read in /etc/clusters and any other given file name and register the tags found.
|
||||
Read in /etc/clusters, $HOME/.clusterssh/clusters and any other given
|
||||
file name and register the tags found.
|
||||
|
||||
=item $cluster->get_tag_entries($filename);
|
||||
|
||||
Read in /etc/tags, $HOME/.clusterssh/tags and any other given
|
||||
file name and register the tags found.
|
||||
|
||||
=item $cluster->read_cluster_file($filename);
|
||||
|
||||
|
|
6
t/30cluster.tag1
Normal file
6
t/30cluster.tag1
Normal file
|
@ -0,0 +1,6 @@
|
|||
host10 tag10 tag20 tag30
|
||||
host20 tag10 # same host split over two lines
|
||||
host30 tag10
|
||||
host20 tag40 # part two of earlier host
|
||||
host30 tag40 \ # multi line second part tag
|
||||
tag50
|
Loading…
Add table
Reference in a new issue