resetvlans 953 Bytes
Newer Older
1 2 3 4 5 6 7 8
#!/usr/bin/perl

# This program takes a list of machines and removes all the VLANs
# whose every member is an argument.

$snmpit = "/usr/testbed/bin/snmpit";

if ($#ARGV < 0) {
9 10
  #  die "Syntax: $0 machines\n";
	exit(0);
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
}
open(SNMPIT,"$snmpit -l |") || die "Error running $snmpit -l\n";

%machines = {};

while ($#ARGV >= 0) {
    $machines{pop(@ARGV)} = "";
}

@toremove = ();

while (<SNMPIT>) {
    chop;
    @line = split;
    $id = $line[0];
    if (! ($id =~ /[0-9]+/)) {next;}
    if ($line[1] eq "Control") {next;}
    if ($line[1] eq "System") {next;}
    $remove = 1;
    foreach $member (@line[2..$#line]) {
	@elements = split(":",$member);
	if (! defined($machines{$elements[0]})) {
	    $remove = 0;
	    last;
	}
    }
    if ($remove == 1) {
	push(@toremove,$id);
    }
}

$toremove = join(" ",@toremove);
print "Removing VLANs: $toremove\n";

if ($#toremove > 0) {
    system("$snmpit -u -r $toremove");
}

print "VLANs removed\n";

0;