[rancid] Re: Huawei routers

andy andy at shady.org
Tue Jul 11 14:40:50 UTC 2006


yes but in a messy way using tftp to offload the config.

$tftphost = "x.x.x.x"; needs defined.

see attached, but im sure the expect coders could be far more impressive and actually do a proper one.


cheers


On Thu, Jun 29, 2006 at 08:40:18AM +0200, georg.naggies at r-it.at wrote:
> Anyone got Rancid to work with Huawei equipment and would care to share?
> 
> Regards,
> 
> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at shrubbery.net
> http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
> 

-- 
andy    andy at shady.org
-----------------------------------------------
Never argue with an idiot. They drag you down 
to their level, then beat you with experience.
----------------------------------------------- 
-------------- next part --------------
#!/usr/bin/perl
##
#  RANCID - Really Awesome New Cisco confIg Differ
#  Makes Huawei Switch TFTP its current-config
#  Prepends other environment, power, fan, version info 
#

# Syntax: hslogin [-l] [-d] [-f filename] host
use Getopt::Std;
getopts('dfl');
$log = $opt_l;
$debug = $opt_d;
$host = $ARGV[0];
$file = $opt_f;
$tftphost = "x.x.x.x";

# This routine is used to print out the router configuration
sub ProcessHistory {
    my($new_hist_tag,$new_command,$command_string, at string)=(@_);
    if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
       && defined %history) {
        print eval "$command \%history";
        undef %history;
    }
    if (($new_hist_tag) && ($new_command) && ($command_string)) {
        if ($history{$command_string}) {
            $history{$command_string} = "$history{$command_string}@string";
        } else {
            $history{$command_string} = "@string";
        }
    } elsif (($new_hist_tag) && ($new_command)) {
        $history{++$#history} = "@string";
    } else {
        print "@string";
    }
    $hist_tag = $new_hist_tag;
    $command = $new_command;
    1;
}


# Create the tftp file, and set it 777
open(TOUCH,">/tftpboot/$host.tftp");
close(TOUCH);
chmod 0777, "/tftpboot/$host.tftp";

# Main
$huawei_commands=sprintf("display fan;display power;display environment;display version;tftp put flash:/vrpcfg.txt //%s/%s.tftp",$tftphost,$host);

open(OUTPUT,">$host.new") || die "Can't open $host.new for writing: $!\n";
select(OUTPUT);
# make OUTPUT unbuffered
if ($debug) { $| = 1; }

if ($file) {
    print STDERR "opening file $file\n" if ($debug);
    print STDOUT "opening file $file\n" if ($log);
    open(INPUT,"< $file") || die "open failed for $file: $!\n";
} else {
    print "# RANCID-CONTENT-TYPE: huawei\n!\n";
    print(STDERR "executing echo hslogin -c\"$huawei_commands\" $host\n") if ($debug);
    print(STDOUT "executing echo hslogin -c\"$huawei_commands\" $host\n") if ($debug);

    if (defined($ENV{NOPIPE})) {
        system "hslogin -c  \"$huawei_commands\" $host </dev/null > $host.raw" || die "hslogin failed for $host: $!\n";
        open(INPUT, "< $host.raw") || die "hslogin failed for $host: $!\n";
    } else {
        open(INPUT,"hslogin -c  \"$huawei_commands\" $host </dev/null |") || die "hslogin failed for $host: $!\n";
    }

}

# Read in the file from /tftpboot and append each line to host.new
if ( -s "/tftpboot/$host.tftp" )
{
        open(INPUT,"</tftpboot/$host.tftp");
        while($line=<INPUT>)
        {
                print $line;
        }
}

close(INPUT);
close(OUTPUT);



More information about the Rancid-discuss mailing list