blib/lib/XAS/Lib/SSH/Client/Subsystem.pm

filter: Statementstmt 34.7% 8 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 100% 3 / 3 totaltotal 41.9% 13 / 31 CC 1 SCAR 4.7
CC
1
Cov
35%
setup
2.0
run
2.0
call
2.0
CRAP 1.6
« blib/lib/XAS/Lib/Batch/Server.pm ↑ Summary blib/lib/XAS/Lib/Modules/Log/Console.pm »
1 package XAS::Lib::SSH::Client::Subsystem;
2  
3 1 our $VERSION = '0.01';
4  
5 1 ▶use Params::Validate qw(CODEREF SCALAR);;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 use XAS::Class
7 1 debug => 0,
8 version => $VERSION,
9 base => 'XAS::Lib::SSH::Client',
10 utils => 'trim',
11 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #use Data::Hexdumper;
14  
15 # ----------------------------------------------------------------------
16 # Public Methods
17 # ----------------------------------------------------------------------
18  
19 sub setup {
20 0 ▶ my $self = shift;
Subroutine setup: not called CC=1 SCAR=6.9
Pod documented
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 ▶ my $self = shift;
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
32 0 my ($subsystem) = $self->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->put($self->eol);
42 0 $self->get();
43  
44 }
45  
46 sub call {
47 0 ▶ my $self = shift;
Subroutine call: not called CC=1 SCAR=6.9
Pod documented
48 0 my ($command, $parser) = $self->validate_params(\@_, [
49 { type => SCALAR },
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 0 $output = $self->get();
59  
60 0 return $parser->(trim($output));
61  
62 }
63  
64 # ----------------------------------------------------------------------
65 # Private Methods
66 # ----------------------------------------------------------------------
67  
68 1 1;
69  
70 __END__
71  
72 =head1 NAME
73  
74 XAS::Lib::SSH::Client::Subsystem - A class to interact with the SSH Subsystem facility
75  
76 =head1 SYNOPSIS
77  
78 use XAS::Lib::SSH::Client::Subsystem;
79  
80 my $client = XAS::Lib::SSH::Client::Subsystem->new(
81 -host => 'auburn-xen-01',
82 -username => 'root',
83 -password => 'secret',
84 );
85  
86 $client->connect();
87 $client->run('echo');
88  
89 my $output = $client->call('this is a test', sub {
90 my $output = shift;
91 ...
92 });
93  
94 $client->disconnect();
95  
96 =head1 DESCRIPTION
97  
98 The module uses a SSH subsystem to make RPC calls. Which means it
99 sends formated packets to the remote host and parses the resulting output.
100 This module inherits from L<XAS::Lib::SSH::Client|XAS::Lib::SSH::Client>.
101  
102 =head1 METHODS
103  
104 =head2 setup
105  
106 This method will set up the environment.
107  
108 =head2 run($subsystem)
109  
110 This method will invoke a subsystem on the remote host. Wither the remote
111 host supports subsystems is dependent on the SSH Server that is running.
112  
113 =over 4
114  
115 =item B<$subsystem>
116  
117 The subsystem to invoke.
118  
119 =back
120  
121 =head2 call($buffer, $parser)
122  
123 This method sends a buffer to the remote host and parses the output.
124  
125 The assumption with this method is that some sort of parsable data stream will
126 be returned. After the data has been parsed the results are returned to the
127 caller.
128  
129 =over 4
130  
131 =item B<$buffer>
132  
133 The buffer to send.
134  
135 =item B<$parser>
136  
137 A coderef to the parser that will parse the returned data. The parser
138 will accept one parameter which is a reference to that data.
139  
140 =back
141  
142 =head1 SEE ALSO
143  
144 =over 4
145  
146 =item L<XAS|XAS>
147  
148 =back
149  
150 =head1 AUTHOR
151  
152 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
153  
154 =head1 COPYRIGHT AND LICENSE
155  
156 Copyright (C) 2014 Kevin L. Esteb
157  
158 This is free software; you can redistribute it and/or modify it under
159 the terms of the Artistic License 2.0. For details, see the full text
160 of the license at http://www.perlfoundation.org/artistic_license_2_0.
161  
162 =cut
« blib/lib/XAS/Lib/Batch/Server.pm ↑ Summary blib/lib/XAS/Lib/Modules/Log/Console.pm »