author | Drew Fisher <drew.fisher@oracle.com> |
Fri, 31 Jan 2014 14:12:10 -0700 | |
branch | s11-update |
changeset 2928 | 43b3da52b84a |
parent 2771 | 8e4227dc2fc4 |
permissions | -rw-r--r-- |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
1 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
2 |
# CDDL HEADER START |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
3 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
4 |
# The contents of this file are subject to the terms of the |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
5 |
# Common Development and Distribution License (the "License"). |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
6 |
# You may not use this file except in compliance with the License. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
7 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
8 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
9 |
# or http://www.opensolaris.org/os/licensing. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
10 |
# See the License for the specific language governing permissions |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
11 |
# and limitations under the License. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
12 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
13 |
# When distributing Covered Code, include this CDDL HEADER in each |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
14 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
15 |
# If applicable, add the following below this CDDL HEADER, with the |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
16 |
# fields enclosed by brackets "[]" replaced with your own identifying |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
17 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
18 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
19 |
# CDDL HEADER END |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
20 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
21 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
22 |
# |
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
23 |
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
24 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
25 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
26 |
Puppet::Type.type(:dns).provide(:dns) do |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
27 |
desc "Provider for management of DNS for Oracle Solaris" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
28 |
confine :operatingsystem => [:solaris] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
29 |
defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
30 |
commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop' |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
31 |
|
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
32 |
Dns_fmri = "svc:/network/dns/client" |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
33 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
34 |
def self.instances |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
35 |
props = {} |
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
36 |
svcprop("-p", "config", Dns_fmri).split("\n").each do |line| |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
37 |
fullprop, type, value = line.split(" ", 2) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
38 |
pg, prop = fullprop.split("/") |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
39 |
props[prop] = value \ |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
40 |
if Puppet::Type.type(:dns).validproperties.include? prop |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
41 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
42 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
43 |
props[:name] = "current" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
44 |
return Array new(props) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
45 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
46 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
47 |
Puppet::Type.type(:dns).validproperties.each do |field| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
48 |
define_method(field) do |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
49 |
begin |
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
50 |
svcprop("-p", "config/" + field.to_s, Dns_fmri).strip() |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
51 |
rescue |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
52 |
# if the property isn't set, don't raise an error |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
53 |
nil |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
54 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
55 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
56 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
57 |
define_method(field.to_s + "=") do |should| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
58 |
begin |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
59 |
if should.is_a? Array |
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
60 |
# in Solaris 11, the list of values needs to be single |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
61 |
# argument to svccfg. |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
62 |
values = "" |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
63 |
for entry in should |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
64 |
values += "\"#{entry}\" " |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
65 |
end |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
66 |
values = "(" + values + ")" |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
67 |
svccfg("-s", Dns_fmri, "setprop", |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
68 |
"config/" + field.to_s, "=", values) |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
69 |
else |
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
70 |
# Puppet seems to get confused about when to pass an empty |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
71 |
# string or "\"\"". Catch either condition to handle |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
72 |
# passing values to SMF correctly |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
73 |
if should.to_s.empty? or should.to_s == '""' |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
74 |
value = should.to_s |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
75 |
else |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
76 |
value = "\"" + should.to_s + "\"" |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
77 |
end |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
78 |
svccfg("-s", Dns_fmri, "setprop", |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
79 |
"config/" + field.to_s, "=", value) |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
80 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
81 |
rescue => detail |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
82 |
raise Puppet::Error, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
83 |
"Unable to set #{field.to_s} to #{should.inspect}\n" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
84 |
"#{detail}\n" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
85 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
86 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
87 |
end |
2928
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
88 |
|
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
89 |
def flush |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
90 |
svccfg("-s", Dns_fmri, "refresh") |
43b3da52b84a
PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents:
2771
diff
changeset
|
91 |
end |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
92 |
end |