line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::SSH::Client::Subsystem; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XAS::Class |
6
|
1
|
|
|
|
|
5
|
debug => 0, |
7
|
|
|
|
|
|
|
version => $VERSION, |
8
|
|
|
|
|
|
|
base => 'XAS::Lib::SSH::Client', |
9
|
|
|
|
|
|
|
utils => ':validation trim', |
10
|
|
|
|
|
|
|
constants => 'CODEREF', |
11
|
1
|
|
|
1
|
|
782
|
; |
|
1
|
|
|
|
|
1
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#use Data::Hexdumper; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
# Public Methods |
17
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub setup { |
20
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $output; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Merge stderr and stdout. |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->chan->ext_data('merge'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub run { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my ($subsystem) = validate_params(\@_, [1] ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Invoke the subsystem. |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->chan->pty('vt100'); # set up a default pty |
37
|
0
|
|
|
|
|
|
$self->chan->subsystem($subsystem); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# flush the buffers |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->puts(""); |
42
|
0
|
|
|
|
|
|
$self->gets(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub call { |
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my ($command, $parser) = validate_params(\@_, [ |
49
|
|
|
|
|
|
|
1, |
50
|
|
|
|
|
|
|
{ type => CODEREF }, |
51
|
|
|
|
|
|
|
]); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my @output; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# execute a command, retrieve the output and dispatch to a parser. |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->puts($command); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
do { |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $line = $self->gets; |
62
|
0
|
|
|
|
|
|
push(@output, $line); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} while ($self->pending); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $parser->(\@output); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
71
|
|
|
|
|
|
|
# Private Methods |
72
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
XAS::Lib::SSH::Client::Subsystem - A class to interact with the SSH Subsystem facility |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SYNOPSIS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use XAS::Lib::SSH::Client::Subsystem; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $client = XAS::Lib::SSH::Client::Subsystem->new( |
87
|
|
|
|
|
|
|
-host => 'auburn-xen-01', |
88
|
|
|
|
|
|
|
-username => 'root', |
89
|
|
|
|
|
|
|
-password => 'secret', |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$client->connect(); |
93
|
|
|
|
|
|
|
$client->run('echo'); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $output = $client->call('this is a test', sub { |
96
|
|
|
|
|
|
|
my $output = shift; |
97
|
|
|
|
|
|
|
... |
98
|
|
|
|
|
|
|
}); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$client->disconnect(); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The module uses a SSH subsystem to make RPC calls. Which means it |
105
|
|
|
|
|
|
|
sends formated packets to the remote host and parses the resulting output. |
106
|
|
|
|
|
|
|
This module inherits from L<XAS::Lib::SSH::Client|XAS::Lib::SSH::Client>. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 METHODS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 setup |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This method will set up the environment. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 run($subsystem) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This method will invoke a subsystem on the remote host. Wither the remote |
117
|
|
|
|
|
|
|
host supports subsystems is dependent on the SSH Server that is running. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over 4 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item B<$subsystem> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The subsystem to invoke. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 call($buffer, $parser) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This method sends a buffer to the remote host and parses the output. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The assumption with this method is that some sort of parsable data stream will |
132
|
|
|
|
|
|
|
be returned. After the data has been parsed the results are returned to the |
133
|
|
|
|
|
|
|
caller. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item B<$buffer> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The buffer to send. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item B<$parser> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
A coderef to the parser that will parse the returned data. The parser |
144
|
|
|
|
|
|
|
will accept one parameter which is a reference to that data. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SEE ALSO |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item L<XAS::Lib::SSH::Client|XAS::Lib::SSH::Client> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item L<XAS|XAS> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright (c) 2012-2015 Kevin L. Esteb |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
167
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
168
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |