summaryrefslogtreecommitdiff
path: root/lib/puppet/type/dns_zone2.rb
blob: ff0cf0220df41d8131358050ccf921ad048a3e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Puppet::Type.newtype(:dns_zone2, self_refresh: true) do
  @doc = <<~EOF
  A complete DNS zonefile.

  The SOA record comes backed in, this for two reasons:
  1. A SOA record is REQUIRED in all zonefiles, so it doesn't make
     sense to allow it to be emitted.
  2. This is the only way to ensure that our serial is only updated
     when something else has actually changed in the zone.
  EOF

  newproperty(:ensure) do
    newvalue(:present) do
      # @resource.content = resource.should_content
      # provider.write_zone(resource.should_content)
      print("Present resource\n")
    end

    # This should ideally remove the zone. This is however managed
    # "higher" up in the puppet code.
    # dns::init has a purge on the directory, and the named
    # configuration file is fully managed by us.
    # This means that decomissioning is as simple as removing the zone
    # from the puppet environment.
    newvalue(:absent) do
      # provider.destroy
    end

    defaultto :present

    def retrieve
      if provider.exists?
        :present
      else
        :absent
      end
    end
  end

  def refresh
    print("Refreshing zone\n")
    catalog.resource("File[/var/named/zones/#{self[:name]}db]")[:content] = should_content
  end

  newparam(:origin, namevar: true) do
    munge do |value|
      if value[-1] == '.'
        value
      else
        "#{value}."
      end
    end
  end

  newparam(:cls) do
    defaultto :IN
  end

  newparam(:view) do
    defaultto '_default'
  end

  newparam(:type) do
    newvalues(:master, :slave,
              :mirror, :hint, :stub, :static_stub, :forward, :redirect)
    aliasvalue :primary, :master
    aliasvalue :secondary, :slave
    defaultto :master
  end

  newparam(:default_ttl) do
    defaultto '300'
  end

  newparam(:mname) do
    munge do |value|
      if value[-1] == '.'
        value
      else
        "#{value}."
      end
    end
  end

  newparam(:rname) do
    munge do |value|
      if value[-1] == '.'
        value
      else
        "#{value}."
      end
    end
  end

  newparam(:soa_ttl) do
  end

  newparam(:refresh) do
  end

  newparam(:retry) do
  end

  newparam(:expire) do
  end

  newparam(:negative_ttl) do
  end

  # List of all DNS records (at all)
  #
  # Should ideally be limited to records in this zone here instead of
  # further down.
  def records
    catalog.resources.filter do |r|
      r.is_a?(Puppet::Type.type(:dns_record2))
    end
  end

  # Create the file resource for us.
  def generate
    print("Generate\n")
    params = {
      ensure: :present,
      path: provider.filename,
      # notify: self[:notify],
    }

    [Puppet::Type.type(:file).new(params)]
  end

  def should_content
    print("Getting content\n")
    provider.zone_content(records)
  end

end