components/puppet/files/solaris/lib/puppet/provider/nis/solaris.rb
branchs11-update
changeset 2928 43b3da52b84a
parent 2771 8e4227dc2fc4
--- a/components/puppet/files/solaris/lib/puppet/provider/nis/solaris.rb	Thu Jan 09 03:35:51 2014 -0800
+++ b/components/puppet/files/solaris/lib/puppet/provider/nis/solaris.rb	Fri Jan 31 14:12:10 2014 -0700
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 #
 
 Puppet::Type.type(:nis).provide(:nis) do
@@ -30,14 +30,20 @@
     commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop'
 
     class << self; attr_accessor :client_fmri, :domain_fmri end
-    @@client_fmri = "svc:/network/nis/client"
-    @@domain_fmri = "svc:/network/nis/domain"
+    Client_fmri = "svc:/network/nis/client"
+    Domain_fmri = "svc:/network/nis/domain"
+
+    def initialize(value={})
+        super(value)
+        @client_refresh = false
+        @domain_refresh = false
+    end
 
     def self.instances
         props = {}
         validprops = Puppet::Type.type(:nis).validproperties
 
-        [@@client_fmri, @@domain_fmri].each do |svc|
+        [Client_fmri, Domain_fmri].each do |svc|
             svcprop("-p", "config", svc).split("\n").collect do |line|
                 data = line.split()
                 fullprop = data[0]
@@ -49,15 +55,10 @@
                 end
 
                 pg, prop = fullprop.split("/")
-
-                # handle the domainname differently as it's not in validprops
-                if prop == "domainname"
-                    props[:name] = value
-                else
-                    props[prop] = value if validprops.include? prop.to_sym
-                end
+                props[prop] = value if validprops.include? prop.to_sym
             end
         end
+        props[:name] = "current"
         return Array new(props)
     end
 
@@ -65,7 +66,7 @@
     [:use_broadcast, :use_ypsetme].each do |field|
         define_method(field) do
             begin
-                svcprop("-p", "config/" + field.to_s, @@client_fmri).strip()
+                svcprop("-p", "config/" + field.to_s, Client_fmri).strip()
             rescue
                 # if the property isn't set, don't raise an error
                 nil
@@ -74,14 +75,19 @@
 
         define_method(field.to_s + "=") do |should|
             begin
-                svccfg("-s", @@client_fmri, "setprop", "config/" + field.to_s,
-                       "=", '"' + should.to_s + '"')
-                svccfg("-s", @@client_fmri, "refresh")
+                if not should.to_s.empty?
+                    value = "\"" + should.to_s + "\""
+                else
+                    value = should.to_s
+                end
+                svccfg("-s", Client_fmri, "setprop", "config/" + field.to_s,
+                       "=", value)
             rescue => detail
                 raise Puppet::Error,
                     "Unable to set #{field.to_s} to #{should.inspect}\n"
                     "#{detail}\n"
             end
+            @client_refresh = true
         end
     end
 
@@ -89,7 +95,7 @@
     [:domainname, :ypservers, :securenets].each do |field|
         define_method(field) do
             begin
-                svcprop("-p", "config/" + field.to_s, @@domain_fmri).strip()
+                svcprop("-p", "config/" + field.to_s, Domain_fmri).strip()
             rescue
                 # if the property isn't set, don't raise an error
                 nil
@@ -99,23 +105,42 @@
         define_method(field.to_s + "=") do |should|
             begin
                 if should.is_a? Array
-                    # the first entry needs the open paren and the last entry
-                    # needs the close paren
-                    should[0] = "(" + should[0]
-                    should[-1] = should[-1] + ")"
-
-                    svccfg("-s", @@domain_fmri, "setprop",
-                           "config/" + field.to_s, "=", should)
+                    # in Solaris 11, the list of values needs to be single
+                    # argument to svccfg.
+                    values = ""
+                    for entry in should
+                        values += "\"#{entry}\" "
+                    end
+                    values = "(" + values + ")"
+                    svccfg("-s", Domain_fmri, "setprop",
+                           "config/" + field.to_s, "=", values)
                 else
-                    svccfg("-s", @@domain_fmri, "setprop",
-                           "config/" + field.to_s, "=", '"' + should + '"')
+                    # Puppet seems to get confused about when to pass an empty
+                    # string or "\"\"".  Catch either condition to handle
+                    # passing values to SMF correctly
+                    if should.to_s.empty? or should.to_s == '""'
+                        value = should.to_s
+                    else
+                        value = "\"" + should.to_s + "\""
+                    end
+                    svccfg("-s", Domain_fmri, "setprop",
+                           "config/" + field.to_s, "=", value)
                 end
-                svccfg("-s", @@domain_fmri, "refresh")
             rescue => detail
                 raise Puppet::Error,
                     "Unable to set #{field.to_s} to #{should.inspect}\n"
                     "#{detail}\n"
             end
+            @domain_refresh = true
+        end
+    end
+
+    def flush
+        if @domain_refresh == true
+            svccfg("-s", Domain_fmri, "refresh")
+        end
+        if @client_refresh == true
+            svccfg("-s", Client_fmri, "refresh")
         end
     end
 end