Changeset 720


Ignore:
Timestamp:
05/07/15 15:17:05 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Second page in merge sequence; show main allocations and free blocks
that would be affected by the merge, along with reminders as
appropriate about data that may be lost with the combination of merge
scope and target type selected for the new allocation.
See #8.

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r716 r720  
    2929        &initIPDBGlobals &connectDB &finish &checkDBSanity
    3030        &addMaster &touchMaster
    31         &listSummary &listSubs &listContainers &listAllocations &listFree &listPool
     31        &listSummary &listSubs &listContainers &listAllocations &listForMerge &listFree &listPool
    3232        &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    3333        &ipParent &subParent &blockParent &getBreadCrumbs &getRoutedCity
     
    4545                &initIPDBGlobals &connectDB &finish &checkDBSanity
    4646                &addMaster &touchMaster
    47                 &listSummary &listSubs &listContainers &listAllocations &listFree &listPool
     47                &listSummary &listSubs &listContainers &listAllocations &listForMerge &listFree &listPool
    4848                &getMasterList &getTypeList &getPoolSelect &findAllocateFrom
    4949                &ipParent &subParent &blockParent &getBreadCrumbs &getRoutedCity
     
    810810
    811811
     812## IPDB::listForMerge()
     813# Get a list of blocks targetted in a proposed merge
     814sub listForMerge {
     815  my $dbh = shift;
     816  my $parent = shift;
     817  my $newblock = shift;
     818  my $btype = shift || 'a';
     819  $btype = 'a' if $btype !~/^[af]$/;
     820
     821  my $sql;
     822  if ($btype eq 'a') {
     823    my $ret = $dbh->selectall_arrayref(q(
     824        SELECT a.cidr,a.id,t.dispname FROM allocations a
     825        JOIN alloctypes t ON a.type=t.type
     826        WHERE a.parent_id = ? AND a.cidr <<= ?
     827        ORDER BY a.cidr
     828        ),
     829        { Slice => {} }, $parent, $newblock);
     830    return $ret;
     831  } else {
     832##fixme:  Not sure about the casting hackery in "SELECT ?::integer AS id", but it works as intended
     833    my $ret = $dbh->selectall_arrayref(q(
     834        SELECT cidr,id FROM freeblocks
     835        WHERE parent_id IN (SELECT ?::integer AS id UNION
     836                SELECT id FROM allocations WHERE parent_id = ? AND cidr <<= ?
     837        ) AND cidr <<= ?
     838        ORDER BY cidr
     839        ),
     840        { Slice => {} }, $parent, $parent, $newblock, $newblock) or print $dbh->errstr;
     841    return $ret;
     842  }
     843} # end listForMerge()
     844
     845
    812846## IPDB::listFree()
    813847# Gets a list of free blocks in the requested parent/master and VRF instance in both CIDR and range notation
  • trunk/cgi-bin/main.cgi

    r717 r720  
    180180elsif($webvar{action} eq 'merge') {
    181181  prepMerge();
     182}
     183elsif($webvar{action} eq 'confmerge') {
     184  confMerge();
    182185}
    183186elsif($webvar{action} eq 'delete') {
     
    12251228
    12261229
     1230# Show what will be merged, present warnings about data loss
     1231sub confMerge {
     1232  if (!$webvar{newmask} || $webvar{newmask} !~ /^\d+$/) {
     1233    $page->param(err => 'New netmask required');
     1234    return;
     1235  }
     1236
     1237  $page->param(block => $webvar{block});
     1238  my $binfo = getBlockData($ip_dbh, $webvar{block});
     1239  my $pinfo = getBlockData($ip_dbh, $binfo->{parent_id});
     1240  my $minfo = getBlockData($ip_dbh, $binfo->{master_id});
     1241  my $block = new NetAddr::IP $binfo->{block};
     1242
     1243  # Tree navigation
     1244  my $crumbs = getBreadCrumbs($ip_dbh, $binfo->{parent_id});
     1245  my @rcrumbs = reverse (@$crumbs);
     1246  $utilbar->param(breadcrumb => \@rcrumbs);
     1247
     1248  $page->param(oldblock => $binfo->{block});
     1249  $page->param(oldtype => $disp_alloctypes{$binfo->{type}});
     1250  $page->param(ismaster => $binfo->{type} eq 'mm');
     1251  $page->param(iscontainer => $webvar{alloctype} eq 'rm' || $webvar{alloctype} =~ /.c/);
     1252  $page->param(ispool => $webvar{alloctype} =~ /.[dp]/);
     1253  $page->param(isleaf => $webvar{alloctype} =~ /.[enr]/);
     1254  $page->param(newtype => $webvar{alloctype});
     1255  $page->param(newdisptype => $disp_alloctypes{$webvar{alloctype}});
     1256  my $newblock = new NetAddr::IP $block->addr."/$webvar{newmask}";
     1257  $newblock = $newblock->network;
     1258  $page->param(newmask => $webvar{newmask});
     1259  $page->param(newblock => "$newblock");
     1260
     1261  # get list of allocations and freeblocks to be merged
     1262  my $malloc_list = listForMerge($ip_dbh, $binfo->{parent_id}, $newblock, 'a');
     1263  $page->param(mergealloc => $malloc_list);
     1264  my $fb_list = listForMerge($ip_dbh, $binfo->{parent_id}, $newblock, 'f');
     1265  $page->param(mergefree => $fb_list);
     1266
     1267  # scope
     1268  my %merge_friendly = (
     1269        keepall   => "Keep mergeable allocations as suballocations of new block",
     1270        mergepeer => "Make suballocations of mergeable allocations direct children of new block",
     1271        clearpeer => "Keep only suballocations of $binfo->{block}",
     1272        clearall  => "Clear all suballocations"
     1273    );
     1274  $page->param(scope => $merge_friendly{$webvar{mscope}});
     1275} # confMerge()
     1276
     1277
    12271278# Delete an allocation.
    12281279sub remove {
Note: See TracChangeset for help on using the changeset viewer.