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(:dns).provide(:dns) do |
26 Puppet::Type.type(:dns).provide(:dns) do |
27 desc "Provider for management of DNS for Oracle Solaris" |
27 desc "Provider for management of DNS for Oracle Solaris" |
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 :dns_fmri end |
32 Dns_fmri = "svc:/network/dns/client" |
33 @@dns_fmri = "svc:/network/dns/client" |
|
34 |
33 |
35 def self.instances |
34 def self.instances |
36 props = {} |
35 props = {} |
37 svcprop("-p", "config", @@dns_fmri).split("\n").each do |line| |
36 svcprop("-p", "config", Dns_fmri).split("\n").each do |line| |
38 fullprop, type, value = line.split(" ", 2) |
37 fullprop, type, value = line.split(" ", 2) |
39 pg, prop = fullprop.split("/") |
38 pg, prop = fullprop.split("/") |
40 props[prop] = value \ |
39 props[prop] = value \ |
41 if Puppet::Type.type(:dns).validproperties.include? prop |
40 if Puppet::Type.type(:dns).validproperties.include? prop |
42 end |
41 end |
46 end |
45 end |
47 |
46 |
48 Puppet::Type.type(:dns).validproperties.each do |field| |
47 Puppet::Type.type(:dns).validproperties.each do |field| |
49 define_method(field) do |
48 define_method(field) do |
50 begin |
49 begin |
51 svcprop("-p", "config/" + field.to_s, @@dns_fmri).strip() |
50 svcprop("-p", "config/" + field.to_s, Dns_fmri).strip() |
52 rescue |
51 rescue |
53 # if the property isn't set, don't raise an error |
52 # if the property isn't set, don't raise an error |
54 nil |
53 nil |
55 end |
54 end |
56 end |
55 end |
57 |
56 |
58 define_method(field.to_s + "=") do |should| |
57 define_method(field.to_s + "=") do |should| |
59 begin |
58 begin |
60 if should.is_a? Array |
59 if should.is_a? Array |
61 # the first entry needs the open paren and the last entry |
60 # in Solaris 11, the list of values needs to be single |
62 # needs the close paren |
61 # argument to svccfg. |
63 should[0] = "(" + should[0] |
62 values = "" |
64 should[-1] = should[-1] + ")" |
63 for entry in should |
65 |
64 values += "\"#{entry}\" " |
66 svccfg("-s", @@dns_fmri, "setprop", |
65 end |
67 "config/" + field.to_s, "=", should) |
66 values = "(" + values + ")" |
|
67 svccfg("-s", Dns_fmri, "setprop", |
|
68 "config/" + field.to_s, "=", values) |
68 else |
69 else |
69 svccfg("-s", @@dns_fmri, "setprop", |
70 # Puppet seems to get confused about when to pass an empty |
70 "config/" + field.to_s, "=", '"' + should + '"') |
71 # string or "\"\"". Catch either condition to handle |
|
72 # passing values to SMF correctly |
|
73 if should.to_s.empty? or should.to_s == '""' |
|
74 value = should.to_s |
|
75 else |
|
76 value = "\"" + should.to_s + "\"" |
|
77 end |
|
78 svccfg("-s", Dns_fmri, "setprop", |
|
79 "config/" + field.to_s, "=", value) |
71 end |
80 end |
72 svccfg("-s", @@dns_fmri, "refresh") |
|
73 rescue => detail |
81 rescue => detail |
74 raise Puppet::Error, |
82 raise Puppet::Error, |
75 "Unable to set #{field.to_s} to #{should.inspect}\n" |
83 "Unable to set #{field.to_s} to #{should.inspect}\n" |
76 "#{detail}\n" |
84 "#{detail}\n" |
77 end |
85 end |
78 end |
86 end |
79 end |
87 end |
|
88 |
|
89 def flush |
|
90 svccfg("-s", Dns_fmri, "refresh") |
|
91 end |
80 end |
92 end |