Changeset 562


Ignore:
Timestamp:
12/19/12 16:18:39 (11 years ago)
Author:
Kris Deugau
Message:

/trunk

Work in progress, see #5:
Update listFree() to handle new table logic and fields

File:
1 edited

Legend:

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

    r561 r562  
    472472
    473473## IPDB::listFree()
    474 # Gets a list of free blocks in the requested parent/master in both CIDR and range notation
    475 # Takes a parent/master and an optional "routed or unrouted" flag that defaults to unrouted.
     474# Gets a list of free blocks in the requested parent/master and VRF instance in both CIDR and range notation
     475# Takes a parent/master and an optional VRF specifier that defaults to empty.
    476476# Returns an arrayref to a list of hashrefs containing the CIDR and range-notation blocks
    477477# Returns some extra flags in the hashrefs for routed blocks, since those can have several subtypes
    478478sub listFree {
    479479  my $dbh = shift;
    480   my $master = shift;
    481   my $routed = shift || 'n';
     480
     481  my %args = @_;
     482  # Just In Case
     483  $args{vrf} = '' if !$args{vrf};
     484  $args{rdepth} = 1 if !$args{rdepth};
    482485
    483486  # do it this way so we can waste a little less time iterating
    484   my $sth = $dbh->prepare("SELECT cidr,routed FROM freeblocks WHERE cidr <<= ? AND ".
    485         ($routed eq 'n' ? '' : 'NOT')." routed = 'n' ORDER BY cidr");
    486   $sth->execute($master);
     487  my $sth = $dbh->prepare("SELECT cidr FROM freeblocks WHERE parent = ? AND rdepth = ? AND vrf = ? ".
     488        "ORDER BY cidr");
     489  $sth->execute($args{master}, $args{rdepth}, $args{vrf});
    487490  my @flist;
    488   while (my ($cidr,$rtype) = $sth->fetchrow_array()) {
     491  while (my ($cidr) = $sth->fetchrow_array()) {
    489492    $cidr = new NetAddr::IP $cidr;
    490493    my %row = (
     
    492495        frange => $cidr->range,
    493496        );
    494     if ($routed eq 'y') {
    495       $row{subblock} = ($rtype ne 'y' && $rtype ne 'n');
    496       $row{fbtype} = $rtype;
    497     }
    498497    push @flist, \%row;
    499498  }
Note: See TracChangeset for help on using the changeset viewer.