App-EC2Cssh
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/EC2Cssh.pm view on Meta::CPAN
package App::EC2Cssh;
$App::EC2Cssh::VERSION = '0.007';
use Moose;
=head1 NAME
App::EC2Cssh - Package for ec2-cssh CLI application
=head1 SYNOSPSIS
See L<ec2-cssh>
=cut
use autodie qw/:all/;
use Cwd;
use File::Spec;
use IO::Socket::SSL;
use Net::Amazon::EC2;
use Safe;
use Text::Template;
use IO::Pipe;
use AnyEvent;
use Log::Any qw/$log/;
# Config stuff.
has 'config' => ( is => 'ro', isa => 'HashRef', lazy_build => 1);
has 'config_file' => ( is => 'ro' , isa => 'Maybe[Str]');
has 'config_files' => ( is => 'ro' , isa => 'ArrayRef[Str]' , lazy_build => 1);
# Run options stuff
has 'set' => ( is => 'ro' , isa => 'Str', required => 1 );
has 'demux_command' => ( is => 'ro', isa => 'Maybe[Str]', required => 0, predicate => 'has_demux_command' );
# Operational stuff.
has 'ec2' => ( is => 'ro', isa => 'Net::Amazon::EC2', lazy_build => 1);
sub _build_config{
my ($self) = @_;
my $config = {};
foreach my $file (reverse @{$self->config_files()} ){
$log->info("Loading $file..");
my $file_config = do $file;
my $ec2_config = { %{ $config->{ec2_config} || {} } , %{ $file_config->{ec2_config} || {} } };
my $ec2_sets = { %{ $config->{ec2_sets} || {} } , %{ $file_config->{ec2_sets} || {} } };
$config = { %{$config} , %{$file_config} , 'ec2_config' => $ec2_config , ec2_sets => $ec2_sets };
}
$log->info("Available sets: " .( join(', ', sort keys %{$config->{ec2_sets}})));
return $config;
}
sub _build_config_files{
my ($self) = @_;
my @candidates = (
( $self->config_file() ? $self->config_file() : () ),
File::Spec->catfile( getcwd() , '.ec2cssh.conf' ),
File::Spec->catfile( $ENV{HOME} , '.ec2cssh.conf' ),
File::Spec->catfile( '/' , 'etc' , 'ec2ssh.conf' )
);
my @files = ();
foreach my $candidate ( @candidates ){
if( -r $candidate ){
$log->info("Found config file '$candidate'");
push @files , $candidate;
}
}
unless( @files ){
die "Cannot find any config files amongst ".join(', ' , @candidates )."\n";
}
return \@files;
}
sub _build_ec2{
my ($self) = @_;
# Hack so we never verify Amazon's host. Whilst still keeping HTTPS
IO::Socket::SSL::set_defaults( SSL_verify_callback => sub{ return 1; } );
my $ec2 = Net::Amazon::EC2->new({ %{ $self->config()->{ec2_config} || die "No ec2_config in config\n" } , ssl => 1 } );
return $ec2;
}
sub main{
my ($self) = @_;
my @hosts;
my %hostnames = ();
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.584 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )