18 # |
18 # |
19 # CDDL HEADER END |
19 # CDDL HEADER END |
20 # |
20 # |
21 |
21 |
22 # |
22 # |
23 # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
23 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
24 # |
24 # |
25 |
25 |
26 Puppet::Type.type(:nsswitch).provide(:nsswitch) do |
26 Puppet::Type.type(:nsswitch).provide(:nsswitch) do |
27 desc "Provider for name service switch configuration data" |
27 desc "Provider for name service switch configuration data" |
28 confine :operatingsystem => [:solaris] |
28 confine :operatingsystem => [:solaris] |
29 defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
29 defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
30 commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop' |
30 commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop' |
31 |
31 |
32 class << self; attr_accessor :nsswitch_fmri end |
32 class << self; attr_accessor :nsswitch_fmri end |
33 @@nsswitch_fmri = "svc:/system/name-service/switch" |
33 Nsswitch_fmri = "svc:/system/name-service/switch" |
34 |
34 |
35 def self.instances |
35 def self.instances |
36 props = {} |
36 props = {} |
37 svcprop("-p", "config", @@nsswitch_fmri).split("\n").collect do |line| |
37 svcprop("-p", "config", Nsswitch_fmri).each_line.collect do |line| |
38 fullprop, type, value = line.split(" ", 2) |
38 fullprop, type, value = line.split(" ", 2) |
39 pg, prop = fullprop.split("/") |
39 pg, prop = fullprop.split("/") |
40 props[prop] = value \ |
40 props[prop] = value \ |
41 if Puppet::Type.type(:nsswitch).validproperties.include? prop |
41 if Puppet::Type.type(:nsswitch).validproperties.include? prop |
42 end |
42 end |
47 |
47 |
48 Puppet::Type.type(:nsswitch).validproperties.each do |field| |
48 Puppet::Type.type(:nsswitch).validproperties.each do |field| |
49 define_method(field) do |
49 define_method(field) do |
50 begin |
50 begin |
51 out = svcprop("-p", "config/" + field.to_s, |
51 out = svcprop("-p", "config/" + field.to_s, |
52 @@nsswitch_fmri).strip() |
52 Nsswitch_fmri).strip() |
53 out = out.delete("\\") |
53 out = out.delete("\\") |
54 rescue |
54 rescue |
55 # if the property isn't set, don't raise an error |
55 # if the property isn't set, don't raise an error |
56 nil |
56 nil |
57 end |
57 end |
58 end |
58 end |
59 |
59 |
60 define_method(field.to_s + "=") do |should| |
60 define_method(field.to_s + "=") do |should| |
61 begin |
61 begin |
62 svccfg("-s", @@nsswitch_fmri, "setprop", |
62 svccfg("-s", Nsswitch_fmri, "setprop", |
63 "config/" + field.to_s, "=", '"' + should + '"') |
63 "config/" + field.to_s, "=", '"' + should + '"') |
64 rescue => detail |
64 rescue => detail |
65 raise Puppet::Error, |
65 raise Puppet::Error, |
66 "Unable to set #{field.to_s} to #{should.inspect}\n" |
66 "Unable to set #{field.to_s} to #{should.inspect}\n" |
67 "#{detail}\n" |
67 "#{detail}\n" |
68 end |
68 end |
69 end |
69 end |
70 end |
70 end |
71 |
71 |
72 def flush |
72 def flush |
73 svccfg("-s", @@nsswitch_fmri, "refresh") |
73 svccfg("-s", Nsswitch_fmri, "refresh") |
74 end |
74 end |
75 end |
75 end |