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 Puppet::Type.type(:nis).provide(:nis) do |
|
27 desc "Provider for management of NIS client for Oracle Solaris" |
|
28 confine :operatingsystem => [:solaris] |
|
29 defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
|
30 commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop' |
|
31 |
|
32 class << self; attr_accessor :client_fmri, :domain_fmri end |
|
33 Client_fmri = "svc:/network/nis/client" |
|
34 Domain_fmri = "svc:/network/nis/domain" |
|
35 |
|
36 def initialize(value={}) |
|
37 super(value) |
|
38 @client_refresh = false |
|
39 @domain_refresh = false |
|
40 end |
|
41 |
|
42 def self.instances |
|
43 props = {} |
|
44 validprops = Puppet::Type.type(:nis).validproperties |
|
45 |
|
46 [Client_fmri, Domain_fmri].each do |svc| |
|
47 svcprop("-p", "config", svc).split("\n").collect do |line| |
|
48 data = line.split() |
|
49 fullprop = data[0] |
|
50 type = data[1] |
|
51 if data.length > 2 |
|
52 value = data[2..-1].join(" ") |
|
53 else |
|
54 value = nil |
|
55 end |
|
56 |
|
57 pg, prop = fullprop.split("/") |
|
58 props[prop] = value if validprops.include? prop.to_sym |
|
59 end |
|
60 end |
|
61 props[:name] = "current" |
|
62 return Array new(props) |
|
63 end |
|
64 |
|
65 # svc:/network/nis/client properties |
|
66 [:use_broadcast, :use_ypsetme].each do |field| |
|
67 define_method(field) do |
|
68 begin |
|
69 svcprop("-p", "config/" + field.to_s, Client_fmri).strip() |
|
70 rescue |
|
71 # if the property isn't set, don't raise an error |
|
72 nil |
|
73 end |
|
74 end |
|
75 |
|
76 define_method(field.to_s + "=") do |should| |
|
77 begin |
|
78 if not should.to_s.empty? |
|
79 value = "\"" + should.to_s + "\"" |
|
80 else |
|
81 value = should.to_s |
|
82 end |
|
83 svccfg("-s", Client_fmri, "setprop", "config/" + field.to_s, |
|
84 "=", value) |
|
85 rescue => detail |
|
86 raise Puppet::Error, |
|
87 "Unable to set #{field.to_s} to #{should.inspect}\n" |
|
88 "#{detail}\n" |
|
89 end |
|
90 @client_refresh = true |
|
91 end |
|
92 end |
|
93 |
|
94 # svc:/network/nis/domain properties |
|
95 [:domainname, :ypservers, :securenets].each do |field| |
|
96 define_method(field) do |
|
97 begin |
|
98 svcprop("-p", "config/" + field.to_s, Domain_fmri).strip() |
|
99 rescue |
|
100 # if the property isn't set, don't raise an error |
|
101 nil |
|
102 end |
|
103 end |
|
104 |
|
105 define_method(field.to_s + "=") do |should| |
|
106 begin |
|
107 if should.is_a? Array |
|
108 # in Solaris 11, the list of values needs to be single |
|
109 # argument to svccfg. |
|
110 values = "" |
|
111 for entry in should |
|
112 values += "\"#{entry}\" " |
|
113 end |
|
114 values = "(" + values + ")" |
|
115 svccfg("-s", Domain_fmri, "setprop", |
|
116 "config/" + field.to_s, "=", values) |
|
117 else |
|
118 # Puppet seems to get confused about when to pass an empty |
|
119 # string or "\"\"". Catch either condition to handle |
|
120 # passing values to SMF correctly |
|
121 if should.to_s.empty? or should.to_s == '""' |
|
122 value = should.to_s |
|
123 else |
|
124 value = "\"" + should.to_s + "\"" |
|
125 end |
|
126 svccfg("-s", Domain_fmri, "setprop", |
|
127 "config/" + field.to_s, "=", value) |
|
128 end |
|
129 rescue => detail |
|
130 raise Puppet::Error, |
|
131 "Unable to set #{field.to_s} to #{should.inspect}\n" |
|
132 "#{detail}\n" |
|
133 end |
|
134 @domain_refresh = true |
|
135 end |
|
136 end |
|
137 |
|
138 def flush |
|
139 if @domain_refresh == true |
|
140 svccfg("-s", Domain_fmri, "refresh") |
|
141 end |
|
142 if @client_refresh == true |
|
143 svccfg("-s", Client_fmri, "refresh") |
|
144 end |
|
145 end |
|
146 end |
|