1 # |
|
2 # CDDL HEADER START |
|
3 # |
|
4 # The contents of this file are subject to the terms of the |
|
5 # Common Development and Distribution License (the "License"). |
|
6 # You may not use this file except in compliance with the License. |
|
7 # |
|
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 # or http://www.opensolaris.org/os/licensing. |
|
10 # See the License for the specific language governing permissions |
|
11 # and limitations under the License. |
|
12 # |
|
13 # When distributing Covered Code, include this CDDL HEADER in each |
|
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 # If applicable, add the following below this CDDL HEADER, with the |
|
16 # fields enclosed by brackets "[]" replaced with your own identifying |
|
17 # information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 # |
|
19 # CDDL HEADER END |
|
20 # |
|
21 |
|
22 # |
|
23 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
|
24 # |
|
25 |
|
26 require 'ipaddr' |
|
27 require 'puppet/property/list' |
|
28 |
|
29 # DNS options |
|
30 simple_opts = ["debug", "rotate", "no-check-names", "inet6"] |
|
31 arg_opts = ["ndots", "timeout", "retrans", "attempts", "retry"] |
|
32 |
|
33 Puppet::Type.newtype(:dns) do |
|
34 @doc = "Manage the configuration of the DNS client for Oracle Solaris" |
|
35 |
|
36 newparam(:name) do |
|
37 desc "The symbolic name for the DNS client settings to use. This name |
|
38 is used for human reference only." |
|
39 isnamevar |
|
40 end |
|
41 |
|
42 newproperty(:nameserver, :parent => Puppet::Property::List) do |
|
43 desc "The IP address(es) the resolver is to query. A maximum of |
|
44 3 IP addresses may be specified. Specify multiple IP addresses |
|
45 as an array" |
|
46 |
|
47 # ensure should remains an array as long as there's more than 1 entry |
|
48 def should |
|
49 if @should.length == 1 |
|
50 @should[0] |
|
51 else |
|
52 @should |
|
53 end |
|
54 end |
|
55 |
|
56 def insync?(is) |
|
57 is = [] if is == :absent or is.nil? |
|
58 if should.is_a? Array |
|
59 is.sort == self.should.sort |
|
60 end |
|
61 end |
|
62 |
|
63 # svcprop returns multivalue entries delimited with a space |
|
64 def delimiter |
|
65 " " |
|
66 end |
|
67 |
|
68 validate do |value| |
|
69 begin |
|
70 ip = IPAddr.new(value) |
|
71 rescue ArgumentError |
|
72 raise Puppet::Error, "nameserver IP address: #{value} is |
|
73 invalid" |
|
74 end |
|
75 end |
|
76 end |
|
77 |
|
78 newproperty(:domain) do |
|
79 desc "The local domain name" |
|
80 end |
|
81 |
|
82 newproperty(:search, :parent => Puppet::Property::List) do |
|
83 desc "The search list for host name lookup. A maximum of 6 search |
|
84 entries may be specified. Specify multiple search entries as an |
|
85 array." |
|
86 |
|
87 # ensure should remains an array as long as there's more than 1 entry |
|
88 def should |
|
89 if @should.length == 1 |
|
90 @should[0] |
|
91 else |
|
92 @should |
|
93 end |
|
94 end |
|
95 |
|
96 def insync?(is) |
|
97 is = [] if is == :absent or is.nil? |
|
98 if should.is_a? Array |
|
99 is.sort == self.should.sort |
|
100 end |
|
101 end |
|
102 |
|
103 # svcprop returns multivalue entries delimited with a space |
|
104 def delimiter |
|
105 " " |
|
106 end |
|
107 end |
|
108 |
|
109 newproperty(:sortlist, :parent => Puppet::Property::List) do |
|
110 desc "Addresses returned by gethostbyname() to be sorted. Entries must |
|
111 be specified in IP 'slash notation'. A maximum of 10 sortlist |
|
112 entries may be specified. Specify multiple entries as an array." |
|
113 |
|
114 # ensure should remains an array as long as there's more than 1 entry |
|
115 def should |
|
116 if @should.length == 1 |
|
117 @should[0] |
|
118 else |
|
119 @should |
|
120 end |
|
121 end |
|
122 |
|
123 def insync?(is) |
|
124 is = [] if is == :absent or is.nil? |
|
125 if should.is_a? Array |
|
126 is.sort == self.should.sort |
|
127 end |
|
128 end |
|
129 |
|
130 # svcprop returns multivalue entries delimited with a space |
|
131 def delimiter |
|
132 " " |
|
133 end |
|
134 |
|
135 validate do |value| |
|
136 begin |
|
137 ip = IPAddr.new(value) |
|
138 rescue ArgumentError |
|
139 raise Puppet::Error, "sortlist IP address: #{value} is invalid" |
|
140 end |
|
141 end |
|
142 end |
|
143 |
|
144 newproperty(:options, :parent => Puppet::Property::List) do |
|
145 desc "Set internal resolver variables. Valid values are debug, |
|
146 ndots:n, timeout:n, retrans:n, attempts:n, retry:n, rotate, |
|
147 no-check-names, inet6. For values with 'n', specify 'n' as an |
|
148 integer. Specify multiple options as an array." |
|
149 |
|
150 # ensure should remains an array as long as there's more than 1 entry |
|
151 def should |
|
152 if @should.length == 1 |
|
153 @should[0] |
|
154 else |
|
155 @should |
|
156 end |
|
157 end |
|
158 |
|
159 def insync?(is) |
|
160 is = [] if is == :absent or is.nil? |
|
161 if should.is_a? Array |
|
162 is.sort == self.should.sort |
|
163 end |
|
164 end |
|
165 |
|
166 # svcprop returns multivalue entries delimited with a space |
|
167 def delimiter |
|
168 " " |
|
169 end |
|
170 |
|
171 validate do |value| |
|
172 data = value.split(":") |
|
173 if data.length == 1 |
|
174 raise Puppet::Error, "option #{value} is invalid" \ |
|
175 if not simple_opts.include? data[0] |
|
176 elsif data.length == 2 |
|
177 raise Puppet::Error, "option #{value} is invalid" \ |
|
178 if not arg_opts.include? data[0] |
|
179 |
|
180 # attempt to cast the integer specified |
|
181 begin |
|
182 check = Integer(data[1]) |
|
183 rescue ArgumentError |
|
184 raise Puppet::Error, "option #{value} is invalid" |
|
185 end |
|
186 else |
|
187 raise Puppet::Error, "option #{value} is invalid" |
|
188 end |
|
189 end |
|
190 end |
|
191 end |
|