1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
package Net::CLI::Interact::Transport::Net_OpenSSH;
{
$Net::CLI::Interact::Transport::Net_OpenSSH::VERSION = '0.01';
}
use Moo;
use Sub::Quote;
use MooX::Types::MooseLike::Base qw(InstanceOf ArrayRef Str);
extends 'Net::CLI::Interact::Transport::Base';
{
package # hide from pause
Net::CLI::Interact::Transport::Net_OpenSSH::Options;
use Moo;
use Sub::Quote;
use MooX::Types::MooseLike::Base qw(InstanceOf Any Str HashRef ArrayRef);
extends 'Net::CLI::Interact::Transport::Options';
has 'master' => (
is => 'rw',
isa => InstanceOf['Net::OpenSSH'],
required => 1,
);
has 'opts' => (
is => 'rw',
isa => HashRef[Any],
default => sub { {} },
);
has 'shell_cmd' => (
is => 'rw',
coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? [$_[0]] : $_[0] }),
isa => ArrayRef[Str],
default => sub { [] },
);
}
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
has 'connect_options' => (
is => 'ro',
isa => InstanceOf['Net::CLI::Interact::Transport::Net_OpenSSH::Options'],
coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? $_[0] :
Net::CLI::Interact::Transport::Net_OpenSSH::Options->new(@_) }),
required => 1,
);
has app_and_runtime_options => (
is => 'lazy',
isa => ArrayRef[Str],
);
sub _build_app_and_runtime_options {
my $self = shift;
my $master = $self->connect_options->master;
[ $master->make_remote_command($self->connect_options->opts,
@{$self->connect_options->shell_cmd}) ]
}
sub app {
shift->app_and_runtime_options->[0]
}
sub runtime_options {
my @cmd = @{ shift->app_and_runtime_options };
shift @cmd;
@cmd;
}
1;
# ABSTRACT: Net_OpenSSH based CLI connection
__END__
=pod
=encoding UTF-8
=head1 NAME
Net::CLI::Interact::Transport::Net_OpenSSH - Net::OpenSSH based CLI connection
=head1 VERSION
Version 0.01
=head1 DESCRIPTION
This module provides a wrapped instance of a L<Net::OpenSSH> SSH
client object for use by L<Net::CLI::Interact>.
This allows one to combine the capability of Net::CLI::Interact to
talk to remote servers for which Net::OpenSSH one-command-per-session
approach is not well suited (i.e. network equipment running custom
administration shells) and still use the capability of Net::OpenSSH to
run several sessions over one single SSH connection, including
accessing SCP and SFTP services.
Note that this transport is not supported on Windows as Net::OpenSSH
is not supported there either.
=head1 INTERFACE
=head2 app_and_runtime_options
Based on the C<connect_options> hash provided to Net::CLI::Interact on
construction, selects and formats the command and arguments required
to run the SSH session over the Net::OpenSSH connection.
Under the hood, this method just wraps Net::OpenSSH
C<make_remote_command> method.
Supported attributes:
=over 4
=item master
Reference to the Net::OpenSSH object wrapping the SSH master connection.
=item opts
Optional hash of extra options to be forwarded to Net::OpenSSH
C<make_remote_command> method.
=item shell_cmd
Remote command to start the shell. Can be a single string or an array reference.
The default is to pass nothing which on conforming SSH implementations
starts the shell configured for the user.
Examples:
# interact with default user shell:
$s->new({
# ...other parameters to new()...
connect_options => { master => $ssh },
});
# interact with csh:
$s->new({
# ...other parameters to new()...
connect_options => {
master => $ssh,
shell_cmd => ['csh', '-i'],
},
});
=item reap
Only used on Unix platforms, this installs a signal handler which attempts to
reap the C<ssh> child process. Pass a true value to enable this feature only
if you notice zombie processes are being left behind after use.
=back
=head1 COMPOSITION
See the following for further interface details:
=over 4
=item *
L<Net::CLI::Interact::Transport::Base>
=back
=head1 AUTHORS
Oliver Gorwits <oliver@cpan.org>
Salvador FandiE<ntilde>o <sfandino@yahoo.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Oliver Gorwits.
This software is copyright (c) 2014 by Salvador FandiƱo.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|