Changeset 79 for trunk


Ignore:
Timestamp:
11/26/04 12:35:43 (20 years ago)
Author:
Kris Deugau
Message:

/trunk

Redesigned error handling in allocateBlock() to return more useful
error messages than DBI provides

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r78 r79  
    136136  my $alloc_from = new NetAddr::IP $_[2];
    137137  my $sth;
    138   my $msg;      # To contain the error message, if any.
     138
     139  # To contain the error message, if any.
     140  my $msg = "Unknown error allocating $cidr as '$type'";
    139141
    140142  # Enable transactions and error handling
     
    143145
    144146  if ($type =~ /^[cdsmw]i$/) {
     147    $msg = "Unable to assign static IP $cidr to $custid";
    145148    eval {
    146149      # We'll just have to put up with the oddities caused by SQL (un)sort order
     
    162165        " where ip='$cidr'");
    163166      $sth->execute;
    164 ##err handle the error
     167      $dbh->commit;
    165168    };
    166169    if ($@) {
    167       $msg = $@;
    168170      eval { $dbh->rollback; };
    169171      return ('FAIL',$msg);
     
    181183
    182184      eval {
     185        $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'";
    183186        if ($type eq 'rr') {
    184187          $sth = $dbh->prepare("update freeblocks set routed='y',city='$city'".
     
    200203          # And initialize the pool, if necessary
    201204          if ($type =~ /^.p$/) {
    202             my ($pooltype) = ($type =~ /^(.)p$/);
    203             # have to insert all pool IPs into poolips table as "unallocated".
    204             $sth = $dbh->prepare("insert into poolips values ('$cidr',".
    205                 " ?, '6750400', '$city', '$pooltype', 'y', '', '', '')");
    206             my @poolip_list = $cidr->hostenum;
    207             if ($type eq 'dp') { # (DSLish block - *all* IPs available
    208               $sth->execute($cidr->addr);
    209               for (my $i=0; $i<=$#poolip_list; $i++) {
    210                 $sth->execute($poolip_list[$i]->addr);
    211               }
    212               $cidr--;
    213               $sth->execute($cidr->addr);
    214             } else { # (real netblock)
    215               for (my $i=1; $i<=$#poolip_list; $i++) {
    216                 $sth->execute($poolip_list[$i]->addr);
    217               }
    218             }
    219           } # end type = pool
     205            $msg = "Could not initialize IPs in new $disp_alloctypes{$type} pool $cidr";
     206            initPool($dbh,$cidr,$type,$city,0);
     207          }
     208
    220209        } # routing vs non-routing netblock
     210
    221211        $dbh->commit;
    222212      }; # end of eval
     
    250240      # Begin SQL transaction block
    251241      eval {
     242        $msg = "Unable to allocate $cidr as '$disp_alloctypes{$type}'";
     243
    252244        # Delete old freeblocks entry
    253245        $sth = $dbh->prepare("delete from freeblocks where cidr='$alloc_from'");
     
    256248        # now we have to do some magic for routing blocks
    257249        if ($type eq 'rr') {
     250
    258251          # Insert the new freeblocks entries
    259252          # Note that non-routed blocks are assigned to <NULL>
     
    262255            $sth->execute("$block", $block->masklen);
    263256          }
     257
    264258          # Insert the entry in the routed table
    265259          $sth = $dbh->prepare("insert into routed values ('$cidr',".
     
    279273            $sth->execute("$block", $block->masklen);
    280274          }
     275
    281276          # Insert the allocations entry
    282277          $sth = $dbh->prepare("insert into allocations values ('$cidr',".
     
    287282          # And initialize the pool, if necessary
    288283          if ($type =~ /^.p$/) {
    289             my ($pooltype) = ($type =~ /^(.)p$/);
    290             # have to insert all pool IPs into poolips table as "unallocated".
    291             $sth = $dbh->prepare("insert into poolips values ('$cidr',".
    292                 " ?, '6750400', '$city', '$pooltype', 'y', '', '', '')");
    293             my @poolip_list = $cidr->hostenum;
    294             if ($type eq 'dp') { # (DSLish block - *all* IPs available
    295               $sth->execute($cidr->addr);
    296               for (my $i=0; $i<=$#poolip_list; $i++) {
    297                 $sth->execute($poolip_list[$i]->addr);
    298               }
    299               $cidr--;
    300               $sth->execute($cidr->addr);
    301             } else { # (real netblock)
    302               for (my $i=1; $i<=$#poolip_list; $i++) {
    303                 $sth->execute($poolip_list[$i]->addr);
    304               }
    305             }
    306           } # end type = pool
     284            $msg = "Could not initialize IPs in new $disp_alloctypes{$type} $cidr";
     285            initPool($dbh,$cidr,$type,$city,0);
     286          }
     287
    307288        } # done with netblock alloctype != rr
     289
    308290        $dbh->commit;
    309291      }; # end eval
    310292      if ($@) {
    311         $msg = $@;
    312293        eval { $dbh->rollback; };
    313294        return ('FAIL',$msg);
Note: See TracChangeset for help on using the changeset viewer.