Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factor out code to determine DNS address record label #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions htdocs/management/ip.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@
$BLOCK_VIEW_MAX = Netdot->config->get('CONTAINER_BLOCK_VIEW_MAX_PREFIX');
}
if ( $o->version == 4 ){
$dns_address_record_label = 'A';
if ( $view_format eq 'block' ){
if ( $BLOCK_VIEW_MAX && ($o->prefix < $BLOCK_VIEW_MAX) ){
$view_format = 'list';
}
}
}elsif ( $o->version == 6 ){
$dns_address_record_label = 'AAAA';
$view_format = 'list' if $view_format eq 'block';
}
$dns_address_record_label = $o->dns_address_record_label;

}else{
$title = "Search";
Expand Down Expand Up @@ -337,6 +336,7 @@
$id = $block->id;
if( $o->is_address ) {
$added_ip = 1;
$dns_address_record_label = $o->dns_address_record_label;
}else {
$added_block = 1;
}
Expand Down
31 changes: 31 additions & 0 deletions lib/Netdot/Model/Ipblock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,37 @@ sub is_address {

##################################################################

=head2 dns_address_record_label - A or AAAA

DNS address records have different labels for IPv4 or IPv6. Return the
correct label depending on the version of this object.

Arguments:
None
Returns:
'A' for IPv4
'AAAA' for IPv6
undef for anything else

=cut

sub dns_address_record_label {
my $self = shift;
$self->isa_object_method('dns_address_record_label');

if ($self->version == 4) {
return 'A';
}
elsif ($self->version == 6) {
return 'AAAA';
}
else {
return undef;
}
}

##################################################################

=head2 update - Update an Ipblock object in DB

Modify given fields of an Ipblock and (optionally) all its descendants.
Expand Down
10 changes: 10 additions & 0 deletions t/Ipblock.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ is($address->status->name, 'Static', 'insert address');

is($address->is_address, 1, 'is_address');

is($address->dns_address_record_label, 'A', 'DNS IPv4 address record label');

is($address->parent, $subnet, 'address/subnet hierarchy');
is($subnet->parent, $container, 'subnet/container hierarchy');

Expand Down Expand Up @@ -155,6 +157,14 @@ my $v6subnet = Ipblock->insert({
status => 'Subnet',
});

my $v6address = Ipblock->insert({
address => "2001:db8::beef:cafe",
prefix => '128',
version => 6,
status => 'Static',
});
is($v6address->dns_address_record_label, 'AAAA', 'DNS IPv6 address record label');

is($v6subnet->parent, $v6container, 'v6_parent');

is(($v6subnet->get_dot_arpa_names)[0], '0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa',
Expand Down