support SM-CLP to talk with Dell's RAC over ssh
[pxelator] / bin / smclp.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 # Dell's DRAC SM-CLP
7
8 use Data::Dump qw/dump/;
9
10 use Net::OpenSSH;
11 use Expect;
12
13 my $debug = 0;
14 my $timeout = 5;
15
16 my ( $uri, $command, $path ) = @ARGV;
17 die "usage: $0 login:passwd\@host show /system1\n" unless $uri && $command;
18
19 my $ssh = Net::OpenSSH->new( $uri );
20 my ( $pty, $pid ) = $ssh->open2pty;
21 my $expect = Expect->init($pty);
22 $expect->raw_pty(1);
23 $expect->log_user(1) if $debug;
24
25 $expect->expect( $timeout, '$' );
26 $expect->send( "smclp\n" );
27
28 $expect->expect( $timeout, '>' );
29
30 my $data;
31
32 sub smclp {
33         my ( $command, $path ) = @_;
34
35         warn "smclp $command $path\n" if $debug;
36
37         $expect->send( "$command $path\n" );
38
39         $expect->expect( $timeout, '>' );
40
41         my $got = $expect->before;
42
43         my $section;
44
45         foreach ( split(/\r\n/, $got ) ) {
46                 if ( m{(/.*):} ) {
47                         $path = $1;
48                 } elsif ( m{^\s{2}(\w+):} ) {
49                         $section = $1;
50                 } elsif ( m{^\s{4}(.+)} ) {
51                         if ( $section eq 'Properties' ) {
52                                 my ( $k, $v ) = split(/\s+=\s+/,$1,2);
53                                 $data->{$path}->{$section}->{$k} = $v;
54                         } else {
55                                 push @{ $data->{$path}->{$section} }, $1;
56                         }
57                 } else {
58                         print "# IGNORE [$_]\n" if $debug;
59                 }
60         }
61
62         warn "# data = ",dump $data;
63 }
64
65 smclp $command => $path;
66