|
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(:nsswitch).provide(:nsswitch) do |
|
27 desc "Provider for name service switch configuration data" |
|
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 Nsswitch_fmri = "svc:/system/name-service/switch" |
|
33 |
|
34 def self.instances |
|
35 props = {} |
|
36 svcprop("-p", "config", Nsswitch_fmri).each_line.collect do |line| |
|
37 fullprop, type, value = line.split(" ", 2) |
|
38 pg, prop = fullprop.split("/") |
|
39 props[prop] = value \ |
|
40 if Puppet::Type.type(:nsswitch).validproperties.include? prop |
|
41 end |
|
42 |
|
43 props[:name] = "current" |
|
44 return Array new(props) |
|
45 end |
|
46 |
|
47 Puppet::Type.type(:nsswitch).validproperties.each do |field| |
|
48 define_method(field) do |
|
49 begin |
|
50 out = svcprop("-p", "config/" + field.to_s, |
|
51 Nsswitch_fmri).strip() |
|
52 out = out.delete("\\") |
|
53 rescue |
|
54 # if the property isn't set, don't raise an error |
|
55 nil |
|
56 end |
|
57 end |
|
58 |
|
59 define_method(field.to_s + "=") do |should| |
|
60 begin |
|
61 svccfg("-s", Nsswitch_fmri, "setprop", |
|
62 "config/" + field.to_s, "=", '"' + should + '"') |
|
63 rescue => detail |
|
64 raise Puppet::Error, |
|
65 "Unable to set #{field.to_s} to #{should.inspect}\n" |
|
66 "#{detail}\n" |
|
67 end |
|
68 end |
|
69 end |
|
70 |
|
71 def flush |
|
72 svccfg("-s", Nsswitch_fmri, "refresh") |
|
73 end |
|
74 end |