Ignore:
Timestamp:
05/16/13 16:43:45 (11 years ago)
Author:
Kris Deugau
Message:

/branches/stable

Introduce informational VRF tags on allocations to match uncomitted patch
in production.
Also add a minor main.cgi error-log-cleanup hack around deleting routed
blocks and master blocks instead of bending getBlockData() out of shape
only to have to put it back when the database structure changes get merged.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/cgi-bin/IPDB.pm

    r595 r598  
    396396
    397397  # Snag the allocations for this block
    398   my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description".
     398  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf".
    399399        " FROM allocations WHERE cidr <<= ? ORDER BY cidr");
    400400  $sth->execute($routed);
     
    405405
    406406  my @blocklist;
    407   while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
     407  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf) = $sth->fetchrow_array()) {
     408    $desc .= " - vrf:$vrf" if $desc && $vrf;
     409    $desc = "vrf:$vrf" if !$desc && $vrf;
    408410    $custsth->execute($custid);
    409411    my ($ncust) = $custsth->fetchrow_array();
     
    462464  my $pool = shift;
    463465
    464   my $sth = $dbh->prepare("SELECT ip,custid,available,description,type".
     466  my $sth = $dbh->prepare("SELECT ip,custid,available,description,type,vrf".
    465467        " FROM poolips WHERE pool = ? ORDER BY ip");
    466468  $sth->execute($pool);
    467469  my @poolips;
    468   while (my ($ip,$custid,$available,$desc,$type) = $sth->fetchrow_array) {
     470  while (my ($ip,$custid,$available,$desc,$type,$vrf) = $sth->fetchrow_array) {
     471    $desc .= " - vrf:$vrf" if $desc && $vrf;
     472    $desc = "vrf:$vrf" if !$desc && $vrf;
    469473    my %row = (
    470474        ip => $ip,
     
    673677# Returns a success code and optional error message.
    674678sub allocateBlock {
    675   my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$privdata,$nodeid) = @_;
     679  my ($dbh,undef,undef,$custid,$type,$city,$desc,$notes,$circid,$privdata,$nodeid,$vrf) = @_;
    676680  $privdata = '' if !defined($privdata);
     681  $vrf = '' if !defined($vrf);
    677682
    678683  my $cidr = new NetAddr::IP $_[1];
     
    720725                undef, ($alloc_from) );
    721726      }
    722       $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,notes=?,circuitid=?,privdata=? ".
    723         "WHERE ip=?", undef, ($custid, $city, $desc, $notes, $circid, $privdata, $cidr) );
     727      $dbh->do("UPDATE poolips SET custid=?,city=?,available='n',description=?,".
     728        "notes=?,circuitid=?,privdata=?,vrf=? ".
     729        "WHERE ip=?", undef, ($custid, $city, $desc, $notes, $circid, $privdata, $vrf, $cidr) );
    724730
    725731# node hack
     
    771777          }
    772778          $sth = $dbh->prepare("insert into allocations".
    773                 " (cidr,custid,type,city,description,notes,maskbits,circuitid,privdata)".
    774                 " values (?,?,?,?,?,?,?,?,?)");
    775           $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata);
     779                " (cidr,custid,type,city,description,notes,maskbits,circuitid,privdata,vrf)".
     780                " values (?,?,?,?,?,?,?,?,?,?)");
     781          $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata, $vrf);
    776782
    777783          # And initialize the pool, if necessary
     
    884890          # Insert the allocations entry
    885891          $sth = $dbh->prepare("insert into allocations (cidr,custid,type,city,".
    886                 "description,notes,maskbits,circuitid,privdata)".
    887                 " values (?,?,?,?,?,?,?,?,?)");
    888           $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata);
     892                "description,notes,maskbits,circuitid,privdata,vrf)".
     893                " values (?,?,?,?,?,?,?,?,?,?)");
     894          $sth->execute("$cidr", $custid, $type, $city, $desc, $notes, $cidr->masklen, $circid, $privdata, $vrf);
    889895
    890896          # And initialize the pool, if necessary
     
    9971003  my @fieldlist;
    9981004  my @vallist;
    999   foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata') {
     1005  foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata', 'vrf') {
    10001006    if ($args{$_}) {
    10011007      push @fieldlist, $_;
     
    11001106    $msg = "Unable to delete master block $cidr";
    11011107    eval {
    1102       $sth = $dbh->prepare("delete from masterblocks where cidr='$cidr'");
    1103       $sth->execute;
    1104       $sth = $dbh->prepare("delete from freeblocks where cidr <<= '$cidr'");
    1105       $sth->execute;
     1108      $sth = $dbh->prepare("delete from masterblocks where cidr=?");
     1109      $sth->execute($cidr);
     1110      $sth = $dbh->prepare("delete from freeblocks where cidr <<= ?");
     1111      $sth->execute($cidr);
    11061112      $dbh->commit;
    11071113    };
     
    12641270## IPDB::getBlockData()
    12651271# Get CIDR or IP, custid, type, city, circuit ID, description, notes, modification time, private/restricted
    1266 # data, for a CIDR block or pool IP
     1272# data, and VRF tag, for a CIDR block or pool IP
    12671273# Also returns SWIP status flag for CIDR blocks
    12681274# Takes the block/IP to look up
     
    12861292  }
    12871293  my $binfo = $dbh->selectrow_hashref("SELECT $keycol AS block, custid, type, city, circuitid, description,".
    1288         " notes, modifystamp AS lastmod, privdata".($poolip ? '' : ', swip')." FROM $blocktable".
     1294        " notes, modifystamp AS lastmod, privdata, vrf".($poolip ? '' : ', swip')." FROM $blocktable".
    12891295        " WHERE $keycol = ?", undef, ($block) );
    12901296  return $binfo;
Note: See TracChangeset for help on using the changeset viewer.