Changeset 707


Ignore:
Timestamp:
02/27/15 18:17:24 (10 years ago)
Author:
Kris Deugau
Message:

/trunk

Add rDNS update call for splitBlock(). Requires dnsadmin:trunk/@r680
for new RPC sub splitTemplate. See #7.
IPDB::splitBlock() required a change in argument handling to make sure
all the necessary bits got through where needed for the RPC call.

Location:
trunk/cgi-bin
Files:
2 edited

Legend:

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

    r705 r707  
    14621462sub splitBlock {
    14631463  my $dbh = shift;
    1464   my $id = shift;
    1465   my $basetype = shift;
    1466   my $newmask = shift;
     1464  my %args = @_;
     1465#  my $id = shift;
     1466#  my $basetype = shift;
     1467#  my $newmask = shift;
    14671468
    14681469##fixme:  set errstr on errors so caller can suitably clue-by-four the user
    1469   return if $basetype ne 'b';  # only netblocks allowed!
    1470 
    1471   my $binfo = getBlockData($dbh, $id);
     1470  return if $args{basetype} ne 'b';  # only netblocks allowed!
     1471
     1472  my $binfo = getBlockData($dbh, $args{id});
    14721473  return if !$binfo;
    14731474
    1474   return if $newmask !~ /^\d+$/;
     1475  return if $args{newmask} !~ /^\d+$/;
    14751476
    14761477  my @ret;
     
    14811482  # failure modes:
    14821483  # difference between $oldmask and $newmask is negative or 0
    1483   if ($newmask - $oldmask <= 0) {
    1484     $errstr = "Can't split a /$oldmask allocation into /$newmask pieces";
     1484  if ($args{newmask} - $oldmask <= 0) {
     1485    $errstr = "Can't split a /$oldmask allocation into /$args{newmask} pieces";
    14851486    return;
    14861487  }
     
    14901491  # $oldmask > n, for arbitrary n?  At least check limits of data type.
    14911492  if ($block->{isv6}) {
    1492     if ($newmask - $oldmask > 128) {
    1493       $errstr = "Impossible IPv6 mask length /$newmask requested";
     1493    if ($args{newmask} - $oldmask > 128) {
     1494      $errstr = "Impossible IPv6 mask length /$args{newmask} requested";
    14941495      return;
    14951496    }
    14961497  } else {
    1497     if ($newmask - $oldmask > 32) {
    1498       $errstr = "Impossible IPv4 mask length /$newmask requested";
     1498    if ($args{newmask} - $oldmask > 32) {
     1499      $errstr = "Impossible IPv4 mask length /$args{newmask} requested";
    14991500      return;
    15001501    }
    15011502  }
    15021503
    1503   my @newblocks = $block->split($newmask);
     1504  my @newblocks = $block->split($args{newmask});
    15041505
    15051506  local $dbh->{AutoCommit} = 0;
     
    15171518    }
    15181519    # note the first block in the split for return
    1519     push @ret, {nid => $id, nblock => "$newblocks[0]"};
     1520    push @ret, {nid => $args{id}, nblock => "$newblocks[0]"};
    15201521
    15211522    # prepare
     
    15271528
    15281529    # set up update of existing block
    1529     $dbh->do("UPDATE allocations SET cidr = ? WHERE id = ?", undef, ("$newblocks[0]", $id) );
     1530    $dbh->do("UPDATE allocations SET cidr = ? WHERE id = ?", undef, ("$newblocks[0]", $args{id}) );
    15301531
    15311532    # axe the net, gw, and bcast IPs as necessary when splitting a "normal" pool
    15321533    if ($binfo->{type} =~ /.d/) {
    15331534      $newblocks[0]--;
    1534       $nbsth->execute($id, $newblocks[0]->addr);
     1535      $nbsth->execute($args{id}, $newblocks[0]->addr);
    15351536    }
    15361537
     
    15471548      if ($binfo->{type} =~ /.d/) {
    15481549        # net
    1549         $nbsth->execute($id, $newblocks[$i]->addr);
     1550        $nbsth->execute($args{id}, $newblocks[$i]->addr);
    15501551        $newblocks[$i]++;
    15511552        # gw
    1552         $nbsth->execute($id, $newblocks[$i]->addr);
     1553        $nbsth->execute($args{id}, $newblocks[$i]->addr);
    15531554        $newblocks[$i]--;
    15541555        $newblocks[$i]--;
    15551556        # bcast
    1556         $nbsth->execute($id, $newblocks[$i]->addr);
     1557        $nbsth->execute($args{id}, $newblocks[$i]->addr);
    15571558        $newblocks[$i]++;
    15581559      }
    15591560      # ... and update the existing IPs with the new parent_id
    1560       $poolchildsth->execute($nid, $newblocks[$i], $id);
     1561      $poolchildsth->execute($nid, $newblocks[$i], $args{id});
    15611562    }
    15621563
     
    15681569    return;
    15691570  }
     1571##fixme:  RPC return code?
     1572# particularly useful in this case as there may be arbitrary combinations of pass, warn, fail
     1573# results from each of the update and add(s), which could get the user to prod dnsadmin to see what exploded
     1574  my $foo = _rpc('splitTemplate', cidr => $binfo->{block}, newmask => $args{newmask}, rpcuser => $args{user});
    15701575
    15711576  return \@ret;
  • trunk/cgi-bin/main.cgi

    r706 r707  
    11721172    $page->param(issplit => 1);
    11731173    my $block = new NetAddr::IP $blockinfo->{block};
    1174     my $newblocks = splitBlock($ip_dbh, $webvar{block}, 'b', $webvar{split});
     1174    my $newblocks = splitBlock($ip_dbh, id => $webvar{block}, basetype => 'b', newmask => $webvar{split},
     1175        user => $authuser);
    11751176    if ($newblocks) {
    11761177      $page->param(newblocks => $newblocks);
Note: See TracChangeset for help on using the changeset viewer.