|
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 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 self.instances |
|
37 props = {} |
|
38 validprops = Puppet::Type.type(:nis).validproperties |
|
39 |
|
40 [@@client_fmri, @@domain_fmri].each do |svc| |
|
41 svcprop("-p", "config", svc).split("\n").collect do |line| |
|
42 data = line.split() |
|
43 fullprop = data[0] |
|
44 type = data[1] |
|
45 if data.length > 2 |
|
46 value = data[2..-1].join(" ") |
|
47 else |
|
48 value = nil |
|
49 end |
|
50 |
|
51 pg, prop = fullprop.split("/") |
|
52 |
|
53 # handle the domainname differently as it's not in validprops |
|
54 if prop == "domainname" |
|
55 props[:name] = value |
|
56 else |
|
57 props[prop] = value if validprops.include? prop.to_sym |
|
58 end |
|
59 end |
|
60 end |
|
61 return Array new(props) |
|
62 end |
|
63 |
|
64 # svc:/network/nis/client properties |
|
65 [:use_broadcast, :use_ypsetme].each do |field| |
|
66 define_method(field) do |
|
67 begin |
|
68 svcprop("-p", "config/" + field.to_s, @@client_fmri).strip() |
|
69 rescue |
|
70 # if the property isn't set, don't raise an error |
|
71 nil |
|
72 end |
|
73 end |
|
74 |
|
75 define_method(field.to_s + "=") do |should| |
|
76 begin |
|
77 svccfg("-s", @@client_fmri, "setprop", "config/" + field.to_s, |
|
78 "=", '"' + should.to_s + '"') |
|
79 svccfg("-s", @@client_fmri, "refresh") |
|
80 rescue => detail |
|
81 raise Puppet::Error, |
|
82 "Unable to set #{field.to_s} to #{should.inspect}\n" |
|
83 "#{detail}\n" |
|
84 end |
|
85 end |
|
86 end |
|
87 |
|
88 # svc:/network/nis/domain properties |
|
89 [:domainname, :ypservers, :securenets].each do |field| |
|
90 define_method(field) do |
|
91 begin |
|
92 svcprop("-p", "config/" + field.to_s, @@domain_fmri).strip() |
|
93 rescue |
|
94 # if the property isn't set, don't raise an error |
|
95 nil |
|
96 end |
|
97 end |
|
98 |
|
99 define_method(field.to_s + "=") do |should| |
|
100 begin |
|
101 if should.is_a? Array |
|
102 # the first entry needs the open paren and the last entry |
|
103 # needs the close paren |
|
104 should[0] = "(" + should[0] |
|
105 should[-1] = should[-1] + ")" |
|
106 |
|
107 svccfg("-s", @@domain_fmri, "setprop", |
|
108 "config/" + field.to_s, "=", should) |
|
109 else |
|
110 svccfg("-s", @@domain_fmri, "setprop", |
|
111 "config/" + field.to_s, "=", '"' + should + '"') |
|
112 end |
|
113 svccfg("-s", @@domain_fmri, "refresh") |
|
114 rescue => detail |
|
115 raise Puppet::Error, |
|
116 "Unable to set #{field.to_s} to #{should.inspect}\n" |
|
117 "#{detail}\n" |
|
118 end |
|
119 end |
|
120 end |
|
121 end |