Changeset 524 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
10/22/12 17:10:07 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL for showmaster to IPDB.pm. See #34.
Tweak template to use odd for row colors

File:
1 edited

Legend:

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

    r523 r524  
    2727        &initIPDBGlobals &connectDB &finish &checkDBSanity
    2828        &addMaster
    29         &listSummary &listMaster &listRBlock
     29        &listSummary &listMaster &listRBlock &listFree
    3030        &allocateBlock &deleteBlock &getBlockData
    3131        &getNodeList
     
    3939                &initIPDBGlobals &connectDB &finish &checkDBSanity
    4040                &addMaster
    41                 &listSummary &listMaster &listRBlock
     41                &listSummary &listMaster &listRBlock &listFree
    4242                &allocateBlock &deleteBlock &getBlockData
    4343                &getNodeList
     
    345345
    346346
    347 # &listMaster &listRBlock
     347## IPDB::listMaster()
     348# Get list of routed blocks in the requested master
     349# Returns an arrayref to a list of hashrefs containing the routed block, POP/city the block is routed to,
     350# allocated count, free count, and largest free block masklength
     351sub listMaster {
     352  my $dbh = shift;
     353  my $master = shift;
     354
     355  my $rlist = $dbh->selectall_arrayref("SELECT cidr AS block,city FROM routed WHERE cidr <<= ? ORDER BY cidr",
     356        { Slice => {} }, ($master) );
     357
     358  foreach (@{$rlist}) {
     359    my ($acnt) = $dbh->selectrow_array("SELECT count(*) FROM allocations WHERE cidr <<= ?", undef, ($$_{block}));
     360    $$_{nsubs} = $acnt;
     361    my ($fcnt) = $dbh->selectrow_array("SELECT count(*) FROM freeblocks WHERE cidr <<= ?".
     362        " AND (routed='y' OR routed='n')", undef, ($$_{block}));
     363    $$_{nfree} = $fcnt;
     364    my ($bigfree) = $dbh->selectrow_array("SELECT maskbits FROM freeblocks WHERE cidr <<= ?".
     365        " AND (routed='y' OR routed='n') ORDER BY maskbits LIMIT 1", undef, ($$_{block}));
     366##fixme:  should find a way to do this without having to HTMLize the <>
     367    $bigfree = "/$bigfree" if $bigfree;
     368    $bigfree = '&lt;NONE&gt;' if !$bigfree;
     369    $$_{lfree} = $bigfree;
     370  }
     371  return $rlist;
     372} # end listMaster()
     373
     374
     375# &listRBlock
     376
     377
     378## IPDB::listFree()
     379# Gets a list of free blocks in the requested parent/master in both CIDR and range notation
     380# Takes a parent/master and an optional flag to look at routed or unrouted blocks, depending
     381# on whether the master is a direct master or a routed block
     382# Returns an arrayref to a list of hashrefs containing the CIDR and range-notation blocks
     383sub listFree {
     384  my $dbh = shift;
     385  my $master = shift;
     386  my $routed = shift || 'y';
     387
     388  # do it this way so we can waste a little less time iterating
     389  my $sth = $dbh->prepare("SELECT cidr FROM freeblocks WHERE cidr <<= ? AND routed = ? ORDER BY cidr");
     390  $sth->execute($master, $routed);
     391  my @flist;
     392  while (my ($cidr) = $sth->fetchrow_array()) {
     393    $cidr = new NetAddr::IP $cidr;
     394    my %row = (fblock => "$cidr", frange => $cidr->range);
     395    push @flist, \%row;
     396  }
     397  return \@flist;
     398}
    348399
    349400
Note: See TracChangeset for help on using the changeset viewer.