Changeset 732 for trunk/cgi-bin


Ignore:
Timestamp:
05/22/15 11:44:39 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Fill in next mergeBlocks() working segment: Merge to container, keep
suballocations, convert mergeable leaf blocks to free blocks. See #8.

File:
1 edited

Legend:

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

    r731 r732  
    21812181
    21822182      } elsif ($args{scope} eq 'mergepeer') { # should this just be an else?
     2183        # Default case.  Merge "peer" blocks, but keep all suballocations
     2184        my $substh = $dbh->prepare("UPDATE allocations SET parent_id = ? WHERE parent_id = ?");
     2185        my $delsth = $dbh->prepare("DELETE FROM allocations WHERE id = ?");
     2186        # Reparent freeblocks in parent
     2187        $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass, $binfo->{vrf},
     2188            $binfo->{parent_id}, $newblock);
     2189        # Loop over "peer" allocations to be merged
     2190        while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) {
     2191          # Snag existing peer data since we may need it
     2192          my $peerfull = getBlockData($dbh, $peer_id);
     2193          # Reparent free blocks from existing containers
     2194          $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass,
     2195              $binfo->{vrf}, $peer_id, $newblock);
     2196          # Reparent any subblocks from existing containers
     2197          $substh->execute($prime, $peer_id);
     2198          # Delete the old container
     2199          $delsth->execute($peer_id) unless $peer_id == $prime;
     2200          # Add new freeblocks for merged leaf blocks
     2201          $insfbsth->execute($peercidr, $binfo->{city}, $newcontainerclass, $binfo->{vrf}, $binfo->{id},
     2202              $binfo->{master_id}) if $peertype =~ /.[enr]/;
     2203          # Convert pool IPs into allocations or aggregated free blocks
     2204          _poolToAllocations($dbh, $peerfull, $pinfo, newparent => $prime) if $peertype =~ /.[dp];
     2205          # Fix up master_id on free blocks if we're merging a master block
     2206          $mfbsth->execute($binfo->{master_id}, $m_id) if $peertype eq 'mm';
     2207        } # merge peers
     2208        # update the primary allocation info.  Do this last so we don't stomp extra data-retrieval in the loop above
     2209        $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     2210
    21832211      } # scope
    21842212
Note: See TracChangeset for help on using the changeset viewer.