Changeset 737


Ignore:
Timestamp:
05/28/15 13:30:15 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Fill in merge-to-pool. See #8.

File:
1 edited

Legend:

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

    r736 r737  
    22092209    my $reparentsth = $dbh->prepare("UPDATE allocations SET parent_id = ?, master_id = ? WHERE id = ?");
    22102210    my $insfbsth = $dbh->prepare("INSERT INTO freeblocks (cidr,city,routed,vrf,parent_id,master_id) VALUES (?,?,?,?,?,?)");
     2211    my $delsth = $dbh->prepare("DELETE FROM allocations WHERE id = ?");
    22112212
    22122213    my $fbreparentsth = $dbh->prepare(q{
     
    23252326    } elsif ($args{newtype} =~ /.[dp]/) {
    23262327      ## Pool
     2328      # Snag the new parent info for the return list
     2329      push @retlist, { block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime };
     2330
     2331      if ($args{scope} eq 'keepall') {
     2332        # Convert all mergeable allocations and subs to chunks of pool IP assignments
     2333        push @retlist, @{ _toPool($dbh, $prime, $newblock, $args{newtype}) };
     2334
     2335      } elsif ($args{scope} =~ /^clear/) {
     2336        # Clear it all out for a fresh (mostly?) empty IP pool
     2337        while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) {
     2338          next if $peer_id == $prime;
     2339          # Push existing allocations down a level before deleting,
     2340          # so that when they're deleted the parent info is correct
     2341          $reparentsth->execute($prime, $binfo->{master_id}, $peer_id);
     2342          _deleteCascade($dbh, $peer_id, 0);
     2343          # Capture block for return
     2344          push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} };
     2345        }
     2346        if ($args{scope} eq 'clearall') {
     2347          # Delete any subs of $prime as well
     2348          my $substh = $dbh->prepare("SELECT cidr,id FROM allocations WHERE parent_id = ?");
     2349          $substh->execute($prime);
     2350          while (my ($scidr, $s_id) = $substh->fetchrow_array) {
     2351            _deleteCascade($dbh, $s_id);
     2352          }
     2353        } else {
     2354          # Convert (subs of) self if not a leaf.
     2355          _toPool($dbh, $prime, $newblock, $args{newtype}) unless $binfo->{type} =~ /.[enr]/;
     2356        } # scope ne 'clearall'
     2357
     2358      } elsif ($args{scope} eq 'mergepeer') {
     2359        # Try to match behaviour from (target type == container) by deleting immediate peer leaf allocations
     2360        while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) {
     2361          next if $peer_id == $prime;  # don't delete the block we're turning into the pool allocation
     2362          # Capture block for return
     2363          push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} };
     2364          next unless $peertype =~ /.[enr]/;
     2365          # Don't need _deleteCascade(), since we'll just be deleting the freshly
     2366          # added free block a little later anyway
     2367          $delsth->execute($peer_id);
     2368        }
     2369        # Convert self if not a leaf, to match behaviour with a container type as target
     2370        _toPool($dbh, $prime, $newblock, $args{newtype}) unless $binfo->{type} =~ /.[enr]/;
     2371      }
     2372      # Update the primary allocation info.
     2373      $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     2374      # Delete any lingering free blocks
     2375      $dbh->do("DELETE FROM freeblocks WHERE parent_id = ? AND cidr <<= ?", undef, $binfo->{parent_id}, $newblock);
     2376      # Fix up the rest of the pool IPs
     2377      my ($code,$msg) = initPool($dbh, $newblock, $args{newtype}, $binfo->{city},
     2378              ($args{newtype} =~ /.p/ ? 'all' : 'normal'), $prime);
    23272379
    23282380    } elsif ($args{newtype} =~ /.[enr]/) {
Note: See TracChangeset for help on using the changeset viewer.