Changeset 733 for trunk/cgi-bin


Ignore:
Timestamp:
05/25/15 18:25:20 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Cleanup while rechecking merge-to-container in UI:

  • Move descriptive strings for merge scopes into a hash in IPDB.pm, so we don't have to update them everywhere every time they might change... now that most of the changes are done, of course.
  • Refiddle listForMerge's freeblock branch to show only direct children, or all free blocks depending on another optional argument.
  • Render previous point pointless due to dropping freeblocks from the return list of merged blocks anyway, because Confusion.
  • Force scope as well as type when merging a master block. Merging any other type in a way that happens to intersect a master remains undefined.
  • Make sure to capture the blocks merged/deleted for return.
  • Fix up some variable names for consistency.
  • Fix stupid typo missed in r732.

See #8.

Location:
trunk/cgi-bin
Files:
2 edited

Legend:

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

    r732 r733  
    2525@EXPORT_OK    = qw(
    2626        %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
    27         %IPDBacl %aclmsg %rpcacl $maxfcgi
     27        %IPDBacl %merge_display %aclmsg %rpcacl $maxfcgi
    2828        $errstr
    2929        &initIPDBGlobals &connectDB &finish &checkDBSanity
     
    4141%EXPORT_TAGS    = ( ALL => [qw(
    4242                %disp_alloctypes %list_alloctypes %def_custids @citylist @poplist
    43                 %IPDBacl %aclmsg %rpcacl $maxfcgi
     43                %IPDBacl %merge_display %aclmsg %rpcacl $maxfcgi
    4444                $errstr
    4545                &initIPDBGlobals &connectDB &finish &checkDBSanity
     
    6767# Mapping hash for pooltype -> poolip-as-netblock conversions
    6868my %poolmap = (sd => 'en', cd => 'cn', dp => 'cn', mp => 'cn', wp => 'cn', ld => 'in', ad => 'in', bd => 'in');
     69
     70# Friendly display strings for merge scopes
     71our %merge_display = (
     72        keepall   => "Keep mergeable allocations as suballocations of new block",
     73        mergepeer => "Keep suballocations of mergeable allocations",
     74        clearpeer => "Keep only suballocations of the selected block",
     75        clearall  => "Clear all suballocations"
     76        );
    6977
    7078# mapping table for functional-area => error message
     
    916924  my $btype = shift || 'a';
    917925  $btype = 'a' if $btype !~/^[af]$/;
     926  my $incsub = shift;
     927  $incsub = 1 if !defined($incsub);
    918928
    919929  my $sql;
     
    929939  } else {
    930940##fixme:  Not sure about the casting hackery in "SELECT ?::integer AS id", but it works as intended
    931     my $ret = $dbh->selectall_arrayref(q(
    932         SELECT cidr,id FROM freeblocks
    933         WHERE parent_id IN (SELECT ?::integer AS id UNION
    934                 SELECT id FROM allocations WHERE parent_id = ? AND cidr <<= ?
    935         ) AND cidr <<= ?
    936         ORDER BY cidr
    937         ),
    938         { Slice => {} }, $parent, $parent, $newblock, $newblock) or print $dbh->errstr;
     941    my @dbargs = ($parent, "$newblock");
     942    push @dbargs, $parent, $newblock if $incsub;
     943    my $ret = $dbh->selectall_arrayref(q{
     944        SELECT cidr,id FROM freeblocks
     945        WHERE parent_id IN (
     946      }.($incsub ? "SELECT id FROM allocations WHERE parent_id = ? AND cidr <<= ? UNION " : '').q{
     947                SELECT ?::integer AS id
     948            ) AND cidr <<= ?
     949        ORDER BY cidr
     950      },
     951        { Slice => {} }, @dbargs);
    939952    return $ret;
    940953  }
     954  return;
    941955} # end listForMerge()
    942956
     
    20032017# Takes a "base" block ID and a hash with a mask length and a scope argument to decide
    20042018# how much existing allocation data to delete.
     2019# Returns a list starting with the new merged block, then the merged allocations with comment
    20052020## Merge scope:
    20062021# Merge to container
     
    20642079  $args{newtype} = $binfo->{type} if !$args{newtype};
    20652080  # if the "primary" block being changed is a master, it must remain one.
    2066   $args{newtype} = 'mm' if $binfo->{type} eq 'mm';
     2081  # Also force the scope, since otherwise things get ugly.
     2082  if ($binfo->{type} eq 'mm') {
     2083    $args{newtype} = 'mm';
     2084    # don't want to make a peer master a sub of the existing one;  too many special cases go explodey,
     2085    # but want to retain all other allocations
     2086    $args{scope} = 'mergepeer';
     2087  }
    20672088  my ($newcontainerclass) = ($args{newtype} =~ /^(.).$/);
    20682089
     
    21232144      ## Container
    21242145
    2125       # In case of merging a master block
     2146      # In case of merging a master block.  Somewhat redundant with calls to $fbreparentsth,
     2147      # but not *quite* entirely.
    21262148      my $mfbsth = $dbh->prepare("UPDATE freeblocks SET master_id = ? WHERE master_id = ?");
    21272149
     
    21312153        # and now retrieve the new parent ID
    21322154        ($prime) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
     2155        # snag the new parent info for the return list
     2156        push @retlist, { block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime };
    21332157        # Reparent the free blocks in the new block
    21342158        $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass, $binfo->{vrf},
    21352159            $binfo->{parent_id}, $newblock);
    21362160        # keep existing allocations (including the original primary), just push them down a level
    2137         while (my ($pcidr,$peer_id,$ptype,$m_id) = $peersth->fetchrow_array) {
     2161        while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) {
    21382162          $reparentsth->execute($prime, $binfo->{master_id}, $peer_id);
    21392163          # Fix up master_id on free blocks if we're merging a master block
    2140           $mfbsth->execute($binfo->{master_id}, $m_id) if $ptype eq 'mm';
     2164          $mfbsth->execute($binfo->{master_id}, $m_id) if $peertype eq 'mm';
     2165          # capture block for return
     2166          push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} };
    21412167        }
    21422168
    21432169      } elsif ($args{scope} =~ /^clear/) {
    21442170        # clearpeer and clearall share a starting point
     2171        # snag the new parent info for the return list
     2172        push @retlist, { block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime };
    21452173        # update the primary allocation info
    21462174        $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     
    21532181              $binfo->{master_id});
    21542182        }
    2155         # delete the peers
    2156         while (my ($pcidr,$peer_id) = $peersth->fetchrow_array) {
     2183        # delete the peers.
     2184        while (my ($peercidr, $peer_id, $peertype, $m_id) = $peersth->fetchrow_array) {
    21572185          next if $peer_id == $prime;
    21582186          # push existing allocations down a level before deleting,
     
    21632191          # aren't special cases fun?
    21642192          $dbh->do("INSERT INTO freeblocks (cidr,routed,parent_id,master_id) values (?,?,?,?)",
    2165                 undef, ($pcidr, 'm', $prime, $prime) ) if $binfo->{type} eq 'mm';
     2193              undef, ($peercidr, 'm', $prime, $prime) ) if $binfo->{type} eq 'mm';
     2194          # capture block for return
     2195          push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} };
    21662196        }
    21672197        if ($args{scope} eq 'clearall') {
     
    21822212      } elsif ($args{scope} eq 'mergepeer') { # should this just be an else?
    21832213        # Default case.  Merge "peer" blocks, but keep all suballocations
     2214        # snag the new parent info for the return list
     2215        push @retlist, {block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime};
    21842216        my $substh = $dbh->prepare("UPDATE allocations SET parent_id = ? WHERE parent_id = ?");
    21852217        my $delsth = $dbh->prepare("DELETE FROM allocations WHERE id = ?");
     
    22022234              $binfo->{master_id}) if $peertype =~ /.[enr]/;
    22032235          # Convert pool IPs into allocations or aggregated free blocks
    2204           _poolToAllocations($dbh, $peerfull, $pinfo, newparent => $prime) if $peertype =~ /.[dp];
     2236          _poolToAllocations($dbh, $peerfull, $pinfo, newparent => $prime) if $peertype =~ /.[dp]/;
    22052237          # Fix up master_id on free blocks if we're merging a master block
    22062238          $mfbsth->execute($binfo->{master_id}, $m_id) if $peertype eq 'mm';
     2239          # capture block for return
     2240          push @retlist, { block => $peercidr, mtype => $disp_alloctypes{$peertype} };
    22072241        } # merge peers
    22082242        # update the primary allocation info.  Do this last so we don't stomp extra data-retrieval in the loop above
  • trunk/cgi-bin/main.cgi

    r727 r733  
    12211221  $page->param(typelist => getTypeList($ip_dbh, 'n', $binfo->{type}));  # down the rabbit hole we go...
    12221222
     1223  # Strings for scope;  do this way so we don't have to edit them many places
     1224  $page->param(vis_keepall => $merge_display{keepall});
     1225  $page->param(vis_mergepeer => $merge_display{mergepeer});
     1226  $page->param(vis_clearpeer => $merge_display{clearpeer});
     1227  $page->param(vis_clearall => $merge_display{clearall});
     1228
    12231229  # Tree navigation
    12241230  my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
     
    12651271  $page->param(mergefree => $fb_list);
    12661272
    1267 ##fixme:  push this up the stack somewhere so the labels can be fed to the relevant templates when/as needed
    1268   # scope
    1269   my %merge_friendly = (
    1270         keepall   => "Keep mergeable allocations as suballocations of new block",
    1271         mergepeer => "Keep suballocations of mergeable allocations",
    1272         clearpeer => "Keep only suballocations of $binfo->{block}",
    1273         clearall  => "Clear all suballocations"
    1274     );
    1275   $page->param(vis_scope => $merge_friendly{$webvar{scope}});
     1273  $page->param(vis_scope => $merge_display{$webvar{scope}});
    12761274  $page->param(scope => $webvar{scope});
    12771275} # confMerge()
Note: See TracChangeset for help on using the changeset viewer.