Changeset 663 for trunk/cgi-bin
- Timestamp:
- 12/30/14 16:09:20 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r662 r663 29 29 &initIPDBGlobals &connectDB &finish &checkDBSanity 30 30 &addMaster &touchMaster 31 &listSummary &listSubs &list Free &listPool31 &listSummary &listSubs &listContainers &listAllocations &listFree &listPool 32 32 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom 33 33 &ipParent &subParent &blockParent &getRoutedCity … … 44 44 &initIPDBGlobals &connectDB &finish &checkDBSanity 45 45 &addMaster &touchMaster 46 &listSummary &listSubs &list Free &listPool46 &listSummary &listSubs &listContainers &listAllocations &listFree &listPool 47 47 &getMasterList &getTypeList &getPoolSelect &findAllocateFrom 48 48 &ipParent &subParent &blockParent &getRoutedCity … … 506 506 507 507 # snag some more details 508 my $substh = $dbh->prepare("SELECT count(*) FROM allocations WHERE cidr <<= ? AND type='rm' AND master_id = ? AND NOT cidr = ? "); 508 my $substh = $dbh->prepare("SELECT count(*) FROM allocations WHERE cidr <<= ? AND ". 509 "AND type ~ '[mc]\$' AND master_id = ? AND NOT cidr = ? "); 509 510 my $alsth = $dbh->prepare("SELECT count(*) FROM allocations WHERE cidr <<= ? ". 510 511 "AND NOT type='rm' AND NOT type='mm' AND master_id = ?"); … … 550 551 551 552 553 ## IPDB::listContainers() 554 # List all container-type allocations in a given parent 555 # Takes a database handle and a hash: 556 # - parent is the ID of the parent block 557 # Returns an arrayref to a list of hashrefs with the CIDR block, location, type, 558 # description, block ID, and counts for the nmber uf suballocations (all types), 559 # free blocks, and the CIDR size of the largest free block 560 sub listContainers { 561 my $dbh = shift; 562 my %args = @_; 563 564 # Just In Case 565 $args{vrf} = '' if !$args{vrf}; 566 567 # Snag the allocations for this block 568 my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id". 569 " FROM allocations WHERE parent_id = ? AND type ~ '[mc]\$' ORDER BY cidr"); 570 $sth->execute($args{parent}); 571 572 my $alsth = $dbh->prepare("SELECT count(*) FROM allocations WHERE cidr <<= ? ". 573 "AND NOT type='rm' AND NOT type='mm' AND master_id = ?"); 574 my $freesth = $dbh->prepare("SELECT count(*) FROM freeblocks WHERE cidr <<= ? AND master_id = ?"); 575 my $lfreesth = $dbh->prepare("SELECT masklen(cidr) AS maskbits FROM freeblocks WHERE cidr <<= ?". 576 " AND master_id = ? ORDER BY masklen(cidr) LIMIT 1"); 577 578 my @blocklist; 579 while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) { 580 $alsth->execute($cidr, $mid); 581 my ($alloc) = $alsth->fetchrow_array(); 582 $freesth->execute($cidr, $mid); 583 my ($free) = $freesth->fetchrow_array(); 584 $lfreesth->execute($cidr, $mid); 585 my ($lfree) = $lfreesth->fetchrow_array(); 586 $lfree = "/$lfree" if $lfree; 587 $lfree = '<NONE>' if !$lfree; 588 my %row = ( 589 block => $cidr, 590 suballocs => $alloc, 591 subfree => $free, 592 lfree => $lfree, 593 city => $city, 594 type => $disp_alloctypes{$type}, 595 desc => $desc, 596 id => $id, 597 ); 598 push (@blocklist, \%row); 599 } 600 return \@blocklist; 601 } # end listContainers() 602 603 604 ## IPDB::listAllocations() 605 # List all end-use allocations in a given parent 606 # Takes a database handle and a hash: 607 # - parent is the ID of the parent block 608 # Returns an arrayref to a list of hashrefs with the CIDR block, location, type, 609 # custID, SWIP flag, description, block ID, and master ID 610 sub listAllocations { 611 my $dbh = shift; 612 my %args = @_; 613 614 # Snag the allocations for this block 615 my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id". 616 " FROM allocations WHERE parent_id = ? AND type !~ '[mc]\$' ORDER BY cidr"); 617 $sth->execute($args{parent}); 618 619 # hack hack hack 620 # set up to flag swip=y records if they don't actually have supporting data in the customers table 621 my $custsth = $dbh->prepare("SELECT count(*) FROM customers WHERE custid = ?"); 622 623 my @blocklist; 624 while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) { 625 $custsth->execute($custid); 626 my ($ncust) = $custsth->fetchrow_array(); 627 my %row = ( 628 block => $cidr, 629 city => $city, 630 type => $disp_alloctypes{$type}, 631 custid => $custid, 632 swip => ($swip eq 'y' ? 'Yes' : 'No'), 633 partswip => ($swip eq 'y' && $ncust == 0 ? 1 : 0), 634 desc => $desc, 635 id => $id, 636 ); 637 # $row{subblock} = ($type =~ /^.r$/); # hmf. wonder why these won't work in the hash declaration... 638 $row{listpool} = ($type =~ /^.[pd]$/); 639 push (@blocklist, \%row); 640 } 641 return \@blocklist; 642 } # end listAllocations() 643 644 552 645 ## IPDB::listFree() 553 646 # Gets a list of free blocks in the requested parent/master and VRF instance in both CIDR and range notation … … 670 763 $ptype .= '_'; 671 764 672 my $plist = $dbh->selectall_arrayref( 673 "SELECT count(*) AS poolfree,p.pool AS poolblock, a.city AS poolcit, a.rdepth AS poolrdepth ". 674 "FROM poolips p ". 675 "JOIN allocations a ON p.pool=a.cidr ". 676 "WHERE p.available='y' AND a.city = ? AND p.type LIKE ? ". 677 "GROUP BY p.pool,a.city,a.rdepth", 765 my $plist = $dbh->selectall_arrayref( q( 766 SELECT count(*) AS poolfree,p.pool AS poolblock, a.city AS poolcit 767 FROM poolips p 768 JOIN allocations a ON p.parent_id=a.id 769 WHERE p.available='y' AND a.city = ? AND p.type LIKE ? 770 GROUP BY p.pool,a.city 771 ), 678 772 { Slice => {} }, ($pcity, $ptype) ); 679 773 return $plist;
Note:
See TracChangeset
for help on using the changeset viewer.