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