App-Validation-Automation

 view release on metacpan or  search on metacpan

lib/App/Validation/Automation/Unix.pm  view on Meta::CPAN

package App::Validation::Automation::Unix;

use Moose;
use namespace::autoclean;
use English qw( -no_match_vars );

=head1 NAME

App::Validation::Automation::Unix - Base Classs App::Validation::Automation

Stores utilities that perform Unix based validation

=head1 SYNOPSIS

App::Validation::Automation::Unix connects to remote server using SSH.The Public/Private Key pair should be generated and stored else connection establishment will fail.The location of Private key also needs to be specifed in the configuration file.L...

=head1 ATTRIBUTES

unix_msg stores the message generated by Unix Class Methods,
connection stores the ssh connection object.

=cut

has 'unix_msg' => (
    is      => 'rw',
    isa     => 'Str',
    clearer => 'clear_unix_msg',
);

has 'connection' => (
    is  => 'rw',
    isa => 'Net::SSH::Perl',
);   

=head1 METHODS

=head2 connect

Connect and login to remote server. Host to connect to and user is passed as arguments.Returns true on success.

=cut

sub connect {
    my $self     = shift;
    my $hostname = shift;
    my $user     = shift;
    my ($ssh);

    #Prepare Connetion
    $ssh = Net::SSH::Perl->new(
        $hostname,
        protocol       => $self->config->{'COMMON.SSH_PROTO'},
        debug          => $self->config->{'COMMON.DEBUG_SSH'},
        identity_files => $self->config->{'COMMON.ID_RSA'},
    ) || confess "Couldn't ssh to $hostname : $OS_ERROR";
    $ssh->login($user)
        || confess "Couldn't login $user\@$hostname : $OS_ERROR";
   
    #set connection state in connection attribute
    $self->connection($ssh);

    return 1;
}



( run in 0.723 second using v1.01-cache-2.11-cpan-39bf76dae61 )