1package Netdot::Model::RRHINFO;
2
3use base 'Netdot::Model';
4use warnings;
5use strict;
6
7my $logger = Netdot->log->get_logger('Netdot::Model::DNS');
8
9=head1 Netdot::Model::RRHINFO - DNS HINFO record Class
10
11=head1 CLASS METHODS
12=cut
13
14############################################################################
15
16=head2 insert - Insert new RRHINFO object
17
18    We override the base method to:
19    - Check if owner is an alias
20    - Check if owner has any other HINFO records
21
22  Arguments:
23    See schema
24  Returns:
25    RRHINFO object
26  Example:
27    my $record = RRHINFO->insert(\%args)
28
29=cut
30
31sub insert {
32    my($class, $argv) = @_;
33    $class->isa_class_method('insert');
34
35    $class->throw_fatal('Missing required arguments: rr')
36	unless ( $argv->{rr} );
37
38    $class->throw_user("Missing required arguments: cpu and/or os")
39	unless ( $argv->{cpu} && $argv->{os} );
40
41    my $rr = (ref $argv->{rr})? $argv->{rr} : RR->retrieve($argv->{rr});
42    $class->throw_fatal("Invalid rr argument") unless $rr;
43
44    # TTL needs to be set and converted into integer
45    $argv->{ttl} = (defined($argv->{ttl}) && length($argv->{ttl}))? $argv->{ttl} : $rr->zone->default_ttl;
46    $argv->{ttl} = $class->ttl_from_text($argv->{ttl});
47
48    # Avoid the "CNAME and other records" error condition
49    if ( $rr->cnames ){
50	$class->throw_user($rr->name." Cannot add any other record to an alias");
51    }
52    if ( $rr->ptr_records ){
53	$class->throw_user($rr->name.": Cannot add HINFO records when PTR records exist");
54    }
55
56    if ( $rr->naptr_records ){
57	$class->throw_user($rr->name.": Cannot add HINFO records when NAPTR records exist");
58    }
59
60    if ( $rr->srv_records ){
61	$class->throw_user($rr->name.": Cannot add HINFO records when SRV records exist");
62    }
63
64    # Only one HINFO
65    if ( $rr->hinfo_records ){
66	$class->throw_user($rr->name.": Cannot add more than one HINFO record");
67    }
68
69    foreach my $field ( qw(cpu os) ){
70	# No spaces allowed
71	$argv->{$field} =~ s/\s+//g;
72    }
73
74    return $class->SUPER::insert($argv);
75
76}
77
78=head1 INSTANCE METHODS
79=cut
80
81############################################################################
82
83=head2 update
84
85    We override the base method to:
86     - Validate TTL
87
88  Arguments:
89    Hash with field/value pairs
90  Returns:
91    Number of rows updated or -1
92  Example:
93    $record->update(\%args)
94
95=cut
96
97sub update {
98    my($self, $argv) = @_;
99    $self->isa_object_method('update');
100
101    if ( defined $argv->{ttl} && length($argv->{ttl}) ){
102	$argv->{ttl} = $self->ttl_from_text($argv->{ttl});
103    }else{
104	delete $argv->{ttl};
105    }
106
107    return $self->SUPER::update($argv);
108}
109
110##################################################################
111
112=head2 as_text
113
114    Returns the text representation of this record
115
116  Arguments:
117    None
118  Returns:
119    string
120  Examples:
121    print $rr->as_text();
122
123=cut
124
125sub as_text {
126    my $self = shift;
127    $self->isa_object_method('as_text');
128
129    return $self->_net_dns->string();
130}
131
132
133##################################################################
134# Private methods
135##################################################################
136
137
138##################################################################
139sub _net_dns {
140    my $self = shift;
141
142    my $ndo = Net::DNS::RR->new(
143	name    => $self->rr->get_label,
144	ttl     => $self->ttl,
145	class   => 'IN',
146	type    => 'HINFO',
147	cpu     => $self->cpu,
148	os      => $self->os,
149	);
150
151    return $ndo;
152}
153
154=head1 AUTHOR
155
156Carlos Vicente, C<< <cvicente at ns.uoregon.edu> >>
157
158=head1 COPYRIGHT & LICENSE
159
160Copyright 2009 University of Oregon, all rights reserved.
161
162This program is free software; you can redistribute it and/or modify
163it under the terms of the GNU General Public License as published by
164the Free Software Foundation; either version 2 of the License, or
165(at your option) any later version.
166
167This program is distributed in the hope that it will be useful, but
168WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
169or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
170License for more details.
171
172You should have received a copy of the GNU General Public License
173along with this program; if not, write to the Free Software Foundation,
174Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
175
176=cut
177
178#Be sure to return 1
1791;
180
181