Changeset 524 for trunk/cgi-bin/IPDB.pm
- Timestamp:
- 10/22/12 17:10:07 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r523 r524 27 27 &initIPDBGlobals &connectDB &finish &checkDBSanity 28 28 &addMaster 29 &listSummary &listMaster &listRBlock 29 &listSummary &listMaster &listRBlock &listFree 30 30 &allocateBlock &deleteBlock &getBlockData 31 31 &getNodeList … … 39 39 &initIPDBGlobals &connectDB &finish &checkDBSanity 40 40 &addMaster 41 &listSummary &listMaster &listRBlock 41 &listSummary &listMaster &listRBlock &listFree 42 42 &allocateBlock &deleteBlock &getBlockData 43 43 &getNodeList … … 345 345 346 346 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 351 sub 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 = '<NONE>' 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 383 sub 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 } 348 399 349 400
Note:
See TracChangeset
for help on using the changeset viewer.