|
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, 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 |
|
48 def should |
|
49 @should |
|
50 end |
|
51 |
|
52 def insync?(is) |
|
53 is = [] if is == :absent or is.nil? |
|
54 is.sort == self.should.sort |
|
55 end |
|
56 |
|
57 # svcprop returns multivalue entries delimited with a space |
|
58 def delimiter |
|
59 " " |
|
60 end |
|
61 |
|
62 validate do |value| |
|
63 begin |
|
64 ip = IPAddr.new(value) |
|
65 rescue ArgumentError |
|
66 raise Puppet::Error, "nameserver IP address: #{value} is |
|
67 invalid" |
|
68 end |
|
69 end |
|
70 end |
|
71 |
|
72 newproperty(:domain) do |
|
73 desc "The local domain name" |
|
74 end |
|
75 |
|
76 newproperty(:search, :parent => Puppet::Property::List) do |
|
77 desc "The search list for host name lookup. A maximum of 6 search |
|
78 entries may be specified. Specify multiple search entries as an |
|
79 array." |
|
80 |
|
81 # ensure should remains an array |
|
82 def should |
|
83 @should |
|
84 end |
|
85 |
|
86 def insync?(is) |
|
87 is = [] if is == :absent or is.nil? |
|
88 is.sort == self.should.sort |
|
89 end |
|
90 |
|
91 # svcprop returns multivalue entries delimited with a space |
|
92 def delimiter |
|
93 " " |
|
94 end |
|
95 end |
|
96 |
|
97 newproperty(:sortlist, :parent => Puppet::Property::List) do |
|
98 desc "Addresses returned by gethostbyname() to be sorted. Entries must |
|
99 be specified in IP 'slash notation'. A maximum of 10 sortlist |
|
100 entries may be specified. Specify multiple entries as an array." |
|
101 |
|
102 # ensure should remains an array |
|
103 def should |
|
104 @should |
|
105 end |
|
106 |
|
107 def insync?(is) |
|
108 is = [] if is == :absent or is.nil? |
|
109 is.sort == self.should.sort |
|
110 end |
|
111 |
|
112 # svcprop returns multivalue entries delimited with a space |
|
113 def delimiter |
|
114 " " |
|
115 end |
|
116 |
|
117 validate do |value| |
|
118 begin |
|
119 ip = IPAddr.new(value) |
|
120 rescue ArgumentError |
|
121 raise Puppet::Error, "sortlist IP address: #{value} is invalid" |
|
122 end |
|
123 end |
|
124 end |
|
125 |
|
126 newproperty(:options, :parent => Puppet::Property::List) do |
|
127 desc "Set internal resolver variables. Valid values are debug, |
|
128 ndots:n, timeout:n, retrans:n, attempts:n, retry:n, rotate, |
|
129 no-check-names, inet6. For values with 'n', specify 'n' as an |
|
130 integer. Specify multiple options as an array." |
|
131 |
|
132 # ensure should remains an array |
|
133 def should |
|
134 @should |
|
135 end |
|
136 |
|
137 def insync?(is) |
|
138 is = [] if is == :absent or is.nil? |
|
139 is.sort == self.should.sort |
|
140 end |
|
141 |
|
142 # svcprop returns multivalue entries delimited with a space |
|
143 def delimiter |
|
144 " " |
|
145 end |
|
146 |
|
147 validate do |value| |
|
148 data = value.split(":") |
|
149 if data.length == 1 |
|
150 raise Puppet::Error, "option #{value} is invalid" \ |
|
151 if not simple_opts.include? data[0] |
|
152 elsif data.length == 2 |
|
153 # XXX |
|
154 raise Puppet::Error, "svccfg is bugged with prop:N options" |
|
155 |
|
156 raise Puppet::Error, "option #{value} is invalid" \ |
|
157 if not arg_opts.include? data[0] |
|
158 |
|
159 # attempt to cast the integer specified |
|
160 begin |
|
161 check = Integer(data[1]) |
|
162 rescue ArgumentError |
|
163 raise Puppet::Error, "option #{value} is invalid" |
|
164 end |
|
165 else |
|
166 raise Puppet::Error, "option #{value} is invalid" |
|
167 end |
|
168 end |
|
169 end |
|
170 end |