summaryrefslogtreecommitdiff
path: root/lib/puppet/type/dns_record2.rb
blob: 98eaadbdc890caffb41cd4d6a0c8f3ce8017ee49 (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
Puppet::Type.newtype(:dns_record2) do
  @doc = <<~EOF
  A single DNS record.

  Doesn't have any effect on the system by itself, but instead
  registers data to the current catalog, which is later gathered by a
  coresponding dns_zone2 resource.
  EOF

  newproperty(:ensure) do
    newvalue(:present) do
      provider.create
    end

    newvalue(:absent) do
      provider.destroy
    end

    defaultto :present

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

  def exists?
    provider.exists?
  end

  newparam(:name) do
    desc <<~EOF
    Explicitly not used as the key, since each key can contain many
    EOF
  end

  newproperty(:type) do
    desc <<~EOF
    Resource Record type, such as A, AAAA, ...
    EOF
    munge { |v| v.to_sym }
  end

  newproperty(:value) do
    desc <<~EOF
    DNS payload. For example an IP address.
      EOF
  end

  newproperty(:key) do
    desc <<~EOF
    DNS key.
    Such as 'www'

    Will be treated as an absolute key if ending in a period, and
    relative to the zone otherwise.
    (NOTE this is handled by the provider)

    '@' is the "empty" key.
    EOF
  end

  newproperty(:zone) do
    desc <<~EOF
    Zone this record belongs to.
    EOF

    munge do |value|
      if value[-1] == '.'
        value
      else
        "#{value}."
      end
    end
  end

  newproperty(:cls) do
    desc <<~EOF
    DNS class of this record.
    Currently only IN works.
    EOF
  end

  newproperty(:ttl) do
    desc <<~EOF
    TTL of this record.
    EOF
  end

  # autobefore('dns::zone') { value(:zone) }
  autonotify('dns_zone2') { [value(:zone)] }
  # autobefore('dns_zone2') { [value(:zone)] }
  # TODO views
end