Changeset 2327 in /cluster/svnroot


Ignore:
Timestamp:
Apr 10, 2010 8:41:42 PM (11 years ago)
Author:
skylar
Message:

doing better to see that we're on a BCCD network (#482)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/skylar-devel/trees/usr/local/lib/site_perl/5.10.0/Bccd.pm

    r2280 r2327  
    2323my $passed = 0;
    2424my $total = 0;
     25Readonly my $DHCFILE => '/etc/dhcp3/dhclient.conf';
    2526Readonly my $ALLOUTFILE    => "allout";
    2627Readonly my $LVMROOT       => "/sbin/";
     
    816817    $self->enter_sub($sub);
    817818    my $rc = 0;
     819        my $temprc;
    818820
    819821    if( $okrc eq "" ) {
     
    822824
    823825    if( "$mode" =~ /^w$/ ) {
    824         open($FILE, '>', $file) or $self->log_and_die("ERROR", $sub, "Opening file $file for replace&write failed with return $?: $!");
     826        $rc += open($FILE, '>', $file) or $self->log_and_die("ERROR", $sub, "Opening file $file for replace&write failed with return $?: $!");
    825827        if($self->is_log($INFO) || $self->is_log($DEBUG)) {
    826828            $self->log_and_cont("INFO",$sub,"Opened file $file for replace&write.");
    827829        }
    828         $rc += $?;
    829830    }
    830831    elsif( "$mode" =~ m/^a$/ ) {
     
    833834            $self->log_and_cont("INFO",$sub,"Opened file $file for appending.");
    834835        }
    835         $rc += $?;
    836836    }
    837837    else {
     
    839839    }
    840840   
    841     $rc += print $FILE "$text\n";
    842     $self->log_and_cont("WARN", $sub, "Writing to filehandle FILE (file $file) failed with return $?, rc $rc.") if( $rc > 2 );
     841    $temprc = print $FILE "$text\n";
     842    $self->log_and_cont("WARN", $sub, "Writing to filehandle FILE (file $file) failed with return $?, rc $rc, errno $!.") if(!$temprc);
     843        $rc += $temprc;
    843844    if($self->is_log($INFO) || $self->is_log($DEBUG)) {
    844845        $self->log_and_cont("INFO",$sub,"Wrote text to filehandle FILE.");
    845846    }
    846847   
    847     $rc += close($FILE) or $self->log_and_die("ERROR", $sub,"Can't close file handle FILE (file $file)!");
     848    $rc += close($FILE) or $self->log_and_die("ERROR", $sub,"Can't close file handle FILE (file $file): $!");
    848849    if($self->is_log($INFO) || $self->is_log($DEBUG)) {
    849850        $self->log_and_cont("INFO",$sub,"Closed filehandle FILE (file $file).");
     
    17021703sub require_bccd_server {
    17031704    my($self) = @_;
    1704     my($sub,$dhc,$replace);
     1705    my($sub,$dhc,$replace,$rc);
    17051706    $sub='require_bccd_server';
    1706     Readonly my $DHCFILE => '/etc/dhcp3/dhclient.conf';
    1707 
    1708     $dhc = $self->snarf_file($DHCFILE);
    1709    
    1710     $dhc =~ s/^#(require bccd-identifier;)$/$1/mg;
    1711    
    1712     return $self->run_test('fwrite','','Wrote out new dhclient.conf.','w',$DHCFILE,$dhc);
     1707
     1708        $rc = 0;
     1709
     1710        $rc += $self->run_test('unlink','','Unlinking dhclient.conf for BCCD.',$DHCFILE);
     1711        $rc += $self->run_test('symlink','','Relinking dhclient.conf for BCCD.',"$DHCFILE-bccd",$DHCFILE);
     1712
     1713        return $rc;
    17131714}
    17141715
    17151716sub unrequire_bccd_server {
    17161717    my($self) = @_;
    1717     my($sub,$dhc,$replace);
     1718    my($sub,$dhc,$replace,$rc);
    17181719    $sub='unrequire_bccd_server';
    1719     Readonly my $DHCFILE => '/etc/dhcp3/dhclient.conf';
    1720    
    1721     $dhc = $self->snarf_file($DHCFILE);
    1722    
    1723     foreach my $string ("request bccd-identifier;", "require bccd-identifier;") {
    1724         if($dhc =~ s/$string\n//g) {
    1725             $replace = 1;
    1726         }
    1727     }
    1728    
    1729     if($replace) {
    1730         return $self->run_test('fwrite','','Wrote out new dhclient.conf.','w',$DHCFILE,$dhc);
    1731     }
    1732    
    1733     return 1;
     1720
     1721        $rc = 0;
     1722
     1723        $rc += $self->run_test('unlink','','Unlinking dhclient.conf for BCCD.',$DHCFILE);
     1724        $rc += $self->run_test('symlink','','Relinking dhclient.conf for BCCD.',"$DHCFILE-any",$DHCFILE);
     1725
     1726        return $rc;
    17341727}
    17351728
     
    17521745            print $INT "iface $nic inet dhcp\n\n";
    17531746            if(defined($nic_conf->{$nic}->{'dhcp_source'}) && $nic_conf->{$nic}->{'dhcp_source'} eq 'BCCD') {
    1754                 if(!$self->require_bccd_server()) {
     1747                if($self->require_bccd_server() > 2) {
    17551748                    $self->log_and_die("ERROR",$sub,"Couldn't set BCCD server in dhclient.");
    17561749                }
    17571750            }
    17581751            else {
    1759                 if(!$self->unrequire_bccd_server()) {
     1752                if($self->unrequire_bccd_server() > 0) {
    17601753                    $self->log_and_die("ERROR",$sub,"Couldn't set BCCD server in dhclient.");
    17611754                }
     
    17791772    close($INT);
    17801773    $self->leave_sub($sub);
     1774}
     1775
     1776sub check_bccd_net{
     1777        my($self,$nic_conf) = @_;
     1778        my $sub = 'check_bccd_net';
     1779
     1780        foreach my $nic (keys(%{$nic_conf})) {
     1781                if($nic_conf->{$nic}->{dhcp_source} eq 'BCCD') {
     1782                        return 1;
     1783                }
     1784        }
     1785
     1786        return undef;
    17811787}
    17821788
     
    21272133            redo FIND_EXT_NIC;
    21282134        }
    2129         if(defined($bccd_nic)) {
     2135        if(defined($bccd_nic) && !$self->check_bccd_net($nic_conf)) {
    21302136            $nic_conf->{"$bccd_nic:1"} = $BCCD_NET;
    21312137        }
    2132        
     2138
    21332139      NIC_CONF:
    21342140        foreach my $nic (sort keys %{$nic_conf}) {
Note: See TracChangeset for help on using the changeset viewer.