Changeset 731 for trunk/cgi-bin


Ignore:
Timestamp:
05/21/15 15:04:54 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Fill in second mergeBlocks() working segment: Merge to container, clear
mergeable allocations or clear all allocations. See #8

File:
1 edited

Legend:

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

    r730 r731  
    21422142
    21432143      } elsif ($args{scope} =~ /^clear/) {
     2144        # clearpeer and clearall share a starting point
     2145        # update the primary allocation info
     2146        $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     2147        # Reparent the free blocks in the new block
     2148        $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass, $binfo->{vrf},
     2149            $binfo->{parent_id}, $newblock);
     2150        # Insert a free block if $prime is a leaf
     2151        if ($binfo->{type} =~ /.[enr]/) {
     2152          $insfbsth->execute($binfo->{block}, $binfo->{city}, $newcontainerclass, $binfo->{vrf}, $prime,
     2153              $binfo->{master_id});
     2154        }
     2155        # delete the peers
     2156        while (my ($pcidr,$peer_id) = $peersth->fetchrow_array) {
     2157          next if $peer_id == $prime;
     2158          # push existing allocations down a level before deleting,
     2159          # so that when they're deleted the parent info is correct
     2160          $reparentsth->execute($prime, $binfo->{master_id}, $peer_id);
     2161          _deleteCascade($dbh, $peer_id);
     2162          # insert the freeblock _deleteCascade() (deliberately) didn't when deleting a master block.
     2163          # aren't special cases fun?
     2164          $dbh->do("INSERT INTO freeblocks (cidr,routed,parent_id,master_id) values (?,?,?,?)",
     2165                undef, ($pcidr, 'm', $prime, $prime) ) if $binfo->{type} eq 'mm';
     2166        }
     2167        if ($args{scope} eq 'clearall') {
     2168          # delete any subs of $prime as well
     2169          my $substh = $dbh->prepare("SELECT cidr,id FROM allocations WHERE parent_id = ?");
     2170          $substh->execute($prime);
     2171          while (my ($scidr, $s_id) = $substh->fetchrow_array) {
     2172            _deleteCascade($dbh, $s_id);
     2173          }
     2174        } else {
     2175          # clearpeer
     2176          if ($basetype =~ /[dp]/) {
     2177            # Convert active IP pool entries to allocations if the original was an IP pool
     2178            _poolToAllocations($dbh, $binfo, $pinfo, newtype => $poolmap{$binfo->{type}});
     2179          }
     2180        } # clearall or clearpeer
     2181
    21442182      } elsif ($args{scope} eq 'mergepeer') { # should this just be an else?
    21452183      } # scope
Note: See TracChangeset for help on using the changeset viewer.