CIDR-Assign
view release on metacpan or search on metacpan
$hash{'date'} = $today;
$hash{'customer'} = $customer if defined $customer;
$hash{'location'} = $location
if $length > 24 && defined $location && $location ne '';
$self->{DB}->put($allocation, join($separator, %hash) );
$self->{DB}->sync;
# Should try to merge with surrounding nets if possible
return $self->mergeNetwork( $allocation );
}
# It would be nice to use the cursor to just search the subtree
# where the allocation would be located but it will return the
# element in the tree after the one we want, since it returns
# equal or greater than. As a consequence we need to run through
# the whole of the tree looking for the bit we want.
#
for ( $status = $self->{DB}->seq($network, $value, R_FIRST);
$status == 0;
$status = $self->{DB}->seq($network, $value, R_NEXT) ) {
push @candidates, $network if overlap($allocation, $network);
}
# Should try to merge networks into larger CIDR blocks if surrounding
# blocks are free or have the same customer ID
#
$bits = $length - 1;
$larger = join('.', unpack('C4', ( pack('L', $network) &
pack('B32', scalar('1' x $bits) .
scalar('0' x (32 - $bits))))));
$network = sprintf "%s/%d", $larger, $bits;
# Initialise the cursor, this shouldn't be necessary but the for loop
# below doesn't work as I expected without it for the last subtree :-(
#
$status = $self->{DB}->seq($dummy, $value, R_FIRST);
# Just run through the subtree checking that the components are the
# same, we don't care if the "free" date is different.
#
$merge = 1;
for ( $status = $self->{DB}->seq($network, $value, R_CURSOR);
$status == 0 && $merge;
( run in 0.231 second using v1.01-cache-2.11-cpan-4d50c553e7e )