Changeset 3778 in /cluster/svnroot


Ignore:
Timestamp:
Aug 6, 2012 11:56:06 PM (8 years ago)
Author:
skylar
Message:

parsing out lease information (#729)

Location:
bccd-ng/branches/skylar/bccd-3.1.1/trees
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/skylar/bccd-3.1.1/trees/bin/bccd-nic-setup

    r3683 r3778  
    4141       
    4242        foreach my $nic ($Bccd->get_eth_nics()) {
     43                # Response is a hash ref of ipaddr and subnet mask
    4344                $response = $Bccd->run_nic_dhcp($nic,'/etc/dhcp/dhclient.conf-bccd');
    4445               
    4546                if(defined($response)) {
    46                         $nic_conf->{$nic}->{'ipaddr'} = $response;
     47                        $nic_conf->{$nic} = $response;
    4748                        $nic_conf->{$nic}->{'dhcp_source'} = 'BCCD';
    4849                }
     
    5051                        $response = $Bccd->run_nic_dhcp($nic,'/etc/dhcp/dhclient.conf-any');
    5152                        if(defined($response)) {
    52                                 $nic_conf->{$nic}->{'ipaddr'} = $response;
     53                                $nic_conf->{$nic} = $response;
    5354                                $nic_conf->{$nic}->{'dhcp_source'} = 'OTHER';
    5455                        }
  • bccd-ng/branches/skylar/bccd-3.1.1/trees/usr/local/lib/site_perl/Bccd.pm

    r3528 r3778  
    24682468sub run_nic_dhcp {
    24692469    my($self,$nic,$cfg) = @_;
    2470     my($cmd,$out,$rc,$sub);
     2470    my($cmd,$ip_info,$out,$rc,$sub,$DHLEASE,$lease_file);
    24712471    $sub = 'run_nic_dhcp';
    24722472   
     
    24742474    ($out,$rc) = $self->exec_system($cmd);
    24752475   
    2476     foreach my $lease_file ( </var/lib/dhcp/dhclient*leases*> ) {
     2476    foreach $lease_file ( </var/lib/dhcp/dhclient*leases*> ) {
    24772477        if(!$self->run_test('unlink','',"Removing $lease_file.",$lease_file)) {
    24782478            $self->log_and_die("ERROR",$sub,"Couldn't remove $lease_file.");
     
    24822482    $cmd = "dhclient -cf $cfg -1 $nic -v";
    24832483    ($out,$rc) = $self->run_test('system','',"Running $cmd.",$cmd);
    2484    
    2485     if($out =~ m/^bound to ((?:\d{1,3}\.){3}\d{1,3})/m) {
    2486         return $1;
    2487     }
     2484
     2485        # Lease file comes under a variety of names
     2486        # Return undef if none can be found
     2487        if( -f "/var/lib/dhcp/dhclient.$nic.leases") {
     2488                $lease_file = "/var/lib/dhcp/dhclient.$nic.leases";
     2489        }
     2490        elsif( -f "/var/lib/dhcp/dhclient.leases" ) {
     2491                $lease_file = "/var/lib/dhcp/dhclient.leases";
     2492        }
     2493        else {
     2494                return undef;
     2495        }
     2496
     2497        if(!defined(open($DHLEASE, '<', $lease_file))) {
     2498                $self->log_and_die("ERROR",$sub,"Couldn't parse lease file: $!\n");
     2499        }
     2500   
     2501        while(my $line = <$DHLEASE>) {
     2502                chomp $line;
     2503                if($line =~ m{^\s+fixed-address\s+((?:\d{1,3}\.){3}\d{1,3});$}) {
     2504                        $ip_info->{'ipaddr'} = $1;
     2505                }
     2506                elsif($line =~ m{^\s+option subnet-mask\s+((?:\d{1,3}\.){3}\d{1,3});$}) {
     2507                        $ip_info->{'netmask'} = $1;
     2508                }
     2509        }
     2510
     2511        if(!defined(close($DHLEASE))) {
     2512                $self->log_and_cont("ERROR",$sub,"Couldn't close lease file: $!\n");
     2513        }
     2514
     2515        if(defined($ip_info->{'ipaddr'})
     2516                && defined($ip_info->{'netmask'})
     2517        ) {
     2518                return $ip_info;
     2519        }
     2520
    24882521    return undef;
    24892522}
Note: See TracChangeset for help on using the changeset viewer.