coraid

Coraid CEC Script

It’s been a couple months now that I’ve been at Coraid and I figure I might as well start automating and scripting where needed.  I wrote a quick script to wrap our CEC tool with Perl’s Expect module.  Works really well and it will help anyone who’s trying to automate a lot of tasks on a Coraid SRX platform.

#!/usr/bin/perl

use lib qw{ /opt/coraid/lib/perl5/site_perl };

use Expect;
use strict;
use warnings;

if(! @ARGV) {
  print "usage: $0 <test> <aoe-interface> <cmd>  \n";
  exit 1;
}

$ENV{TERM} = 'vt100';
my $cec = "/usr/sbin/cec";
my $shelf = shift(@ARGV);
my $aoeif = shift(@ARGV);
my @cmd = @ARGV;
my $file = ".cec";

&run($shelf,$aoeif);


#########################################
sub run {
        my $shelf = $_[0];
        my $aoeif = $_[1];
        my $exp = Expect->spawn("$cec -s $shelf $aoeif") or return "Cannot spawn cec: $!\n";
        $exp->log_stdout(0);
        $exp->log_file($file, "w");
        return 0 unless $exp->expect(30, '-re','Escape is Ctrl-.*');

        $exp->send("\r");
        return 0 unless $exp->expect(10, '-re','SRX shelf(.*)');
        $exp->send("@cmd\r");
        return 0 unless $exp->expect(5, '-re','SRX shelf(.*)');

        &read;

}

sub cleanse {
        foreach my $o(@_) {
                if($o !~ /(^\s*$|done|escape|Shelf|^@cmd|connect|shelves)/i ) {
                        print $o;
                }
        }
}

sub read {
        open(F, $file);
        my @out = <F>;
        close(F);
        &cleanse(@out);
}
youtube

SAN Storage at 1/5th the cost of Fibrechannel or ISCSI.