Class: RedZone::Zone
- Inherits:
-
Object
- Object
- RedZone::Zone
- Defined in:
- lib/redzone/zone.rb
Overview
Represents a zone configuraton for a domain.
Takes a zone configuration in the form of a hash. this is usually read from a yaml file. The schema for the yaml file can be found in the resources
Instance Attribute Summary collapse
-
#altnames ⇒ Array<Machine>
readonly
Returns a list of alternate names for machines.
-
#cnames ⇒ Array<Record>
readonly
Returns a list of domain-name aliases.
-
#default ⇒ Machine
readonly
Returns the default machine for the domain when no subdomain is supplied.
-
#machines ⇒ Array<Machine>
readonly
Return the a list of machines.
-
#mailservers ⇒ Array<Machine>
readonly
Returns a list of mail servers.
-
#name ⇒ String
readonly
Returns the domain name of the zone.
-
#nameservers ⇒ Array<Machine>
readonly
Returns a list of name servers that service the zone.
-
#records ⇒ Array<Record>
readonly
Returns a list of additional zone records.
-
#soa ⇒ SOA
readonly
Return the SOA record.
-
#wildcard ⇒ Machine
readonly
Returns the wildcard entry - the catch-all machine for dns queries not matching any other subdomain entry.
Instance Method Summary collapse
-
#generate_arpa_list ⇒ Array<Arpa>
Generates a list of Arpas for this zone.
-
#initialize(name, config) ⇒ Zone
constructor
Create a new Zone config.
-
#write(io) ⇒ Object
Writes the entre zonefile to the target IO.
-
#write_machines(io, machines, comment = nil) ⇒ Object
Writes the list of machines to the target IO.
-
#write_records(io, records) ⇒ Object
Writes a given set of Records to the target IO.
Constructor Details
#initialize(name, config) ⇒ Zone
Create a new Zone config
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/redzone/zone.rb', line 62 def initialize(name,config) @name = name @config = config generate_machines() generate_aliases() generate_nameservers() generate_mailservers() generate_cnames() generate_records() @soa = generate_soa(@name) d = get_machine('default') wc = get_machine('wildcard') if d @default = d.alias("@") end if wc @wildcard = wc.alias("*") end end |
Instance Attribute Details
#altnames ⇒ Array<Machine> (readonly)
Returns a list of alternate names for machines. These are additional A/AAAA records to the same IP Address
44 45 46 |
# File 'lib/redzone/zone.rb', line 44 def altnames @altnames end |
#cnames ⇒ Array<Record> (readonly)
Returns a list of domain-name aliases
48 49 50 |
# File 'lib/redzone/zone.rb', line 48 def cnames @cnames end |
#default ⇒ Machine (readonly)
Returns the default machine for the domain when no subdomain is supplied
30 31 32 |
# File 'lib/redzone/zone.rb', line 30 def default @default end |
#machines ⇒ Array<Machine> (readonly)
Return the a list of machines
22 23 24 |
# File 'lib/redzone/zone.rb', line 22 def machines @machines end |
#mailservers ⇒ Array<Machine> (readonly)
Returns a list of mail servers
38 39 40 |
# File 'lib/redzone/zone.rb', line 38 def mailservers @mailservers end |
#name ⇒ String (readonly)
Returns the domain name of the zone
18 19 20 |
# File 'lib/redzone/zone.rb', line 18 def name @name end |
#nameservers ⇒ Array<Machine> (readonly)
Returns a list of name servers that service the zone
34 35 36 |
# File 'lib/redzone/zone.rb', line 34 def nameservers @nameservers end |
#records ⇒ Array<Record> (readonly)
Returns a list of additional zone records
57 58 59 |
# File 'lib/redzone/zone.rb', line 57 def records @records end |
#soa ⇒ SOA (readonly)
Return the SOA record
26 27 28 |
# File 'lib/redzone/zone.rb', line 26 def soa @soa end |
#wildcard ⇒ Machine (readonly)
Returns the wildcard entry - the catch-all machine for dns queries not matching any other subdomain entry.
53 54 55 |
# File 'lib/redzone/zone.rb', line 53 def wildcard @wildcard end |
Instance Method Details
#generate_arpa_list ⇒ Array<Arpa>
Generates a list of Arpas for this zone
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/redzone/zone.rb', line 136 def generate_arpa_list arpas = [] if @config.has_key?('arpa') @config['arpa'].each do |cfg| opts = symbolize(cfg) soa = generate_soa(opts[:name]) opts[:soa] = soa an = Arpa.new(opts) arpas << an @nameservers.each do |ns| an.add_record(Record.new(:name => '@', :type => 'NS', :data => ns.name + ".#{@name}." )) end @machines.each do |machine| an.add(machine,@name) end end end arpas end |
#write(io) ⇒ Object
Writes the entre zonefile to the target IO
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/redzone/zone.rb', line 109 def write(io) io << soa unless default.nil? write_machines(io,[default],"Default Machine") end write_machines(io,nameservers,"Name Servers") write_machines(io,mailservers,"Mail Servers") write_machines(io,machines,"Primary Machine names") write_machines(io,altnames,"Alternate Machine Names") unless wildcard.nil? write_machines(io,[wildcard],"Wildcard Machine") end unless cnames.empty? io << "; Canonical Names\n" write_records(io,cnames) io << "\n" end unless records.nil? or records.empty? io << "; Extra Records\n" write_records(io,records) io << "\n" end end |
#write_machines(io, machines, comment = nil) ⇒ Object
Writes the list of machines to the target IO
97 98 99 100 101 102 103 104 105 |
# File 'lib/redzone/zone.rb', line 97 def write_machines(io,machines,comment=nil) unless machines.nil? or machines.empty? io << "; #{comment}\n" unless comment.nil? machines.each do |m| write_records(io,m.records) end io << "\n" end end |
#write_records(io, records) ⇒ Object
Writes a given set of Records to the target IO
85 86 87 88 89 90 91 |
# File 'lib/redzone/zone.rb', line 85 def write_records(io,records) unless records.nil? or records.empty? records.each do |r| io << r end end end |