support SM-CLP to talk with Dell's RAC over ssh
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 3 Jan 2010 19:32:14 +0000 (19:32 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 3 Jan 2010 19:32:14 +0000 (19:32 +0000)
bin/smclp.pl [new file with mode: 0755]

diff --git a/bin/smclp.pl b/bin/smclp.pl
new file mode 100755 (executable)
index 0000000..c4c3d19
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Dell's DRAC SM-CLP
+
+use Data::Dump qw/dump/;
+
+use Net::OpenSSH;
+use Expect;
+
+my $debug = 0;
+my $timeout = 5;
+
+my ( $uri, $command, $path ) = @ARGV;
+die "usage: $0 login:passwd\@host show /system1\n" unless $uri && $command;
+
+my $ssh = Net::OpenSSH->new( $uri );
+my ( $pty, $pid ) = $ssh->open2pty;
+my $expect = Expect->init($pty);
+$expect->raw_pty(1);
+$expect->log_user(1) if $debug;
+
+$expect->expect( $timeout, '$' );
+$expect->send( "smclp\n" );
+
+$expect->expect( $timeout, '>' );
+
+my $data;
+
+sub smclp {
+       my ( $command, $path ) = @_;
+
+       warn "smclp $command $path\n" if $debug;
+
+       $expect->send( "$command $path\n" );
+
+       $expect->expect( $timeout, '>' );
+
+       my $got = $expect->before;
+
+       my $section;
+
+       foreach ( split(/\r\n/, $got ) ) {
+               if ( m{(/.*):} ) {
+                       $path = $1;
+               } elsif ( m{^\s{2}(\w+):} ) {
+                       $section = $1;
+               } elsif ( m{^\s{4}(.+)} ) {
+                       if ( $section eq 'Properties' ) {
+                               my ( $k, $v ) = split(/\s+=\s+/,$1,2);
+                               $data->{$path}->{$section}->{$k} = $v;
+                       } else {
+                               push @{ $data->{$path}->{$section} }, $1;
+                       }
+               } else {
+                       print "# IGNORE [$_]\n" if $debug;
+               }
+       }
+
+       warn "# data = ",dump $data;
+}
+
+smclp $command => $path;
+