19547272 PUPPET pkg_publisher resource provider type fails
authorCharly Abraham <Charly.Abraham@oracle.COM>
Mon, 13 Apr 2015 03:04:30 -0700
changeset 4106 ac78e6a526fe
parent 4104 3dc5412c5fb1
child 4107 fc74767e62e5
19547272 PUPPET pkg_publisher resource provider type fails
components/ruby/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb
components/ruby/puppet/files/solaris/lib/puppet/type/pkg_publisher.rb
--- a/components/ruby/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb	Fri Apr 10 16:26:11 2015 -0700
+++ b/components/ruby/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb	Mon Apr 13 03:04:30 2015 -0700
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
 #
 
 Puppet::Type.type(:pkg_publisher).provide(:pkg_publisher) do
@@ -40,7 +40,6 @@
             if not publisher_order.include?("name")
                 publisher_order << name
             end
-
             # strip off any trailing "/" characters
             if origin.end_with?("/")
                 origin = origin[0..-2]
@@ -49,11 +48,24 @@
             if publishers.has_key?(name)
                 # if we've seen this publisher before, simply update the origin
                 # array
-                publishers[name]["origin"] << origin
+	        if type.eql? "mirror"
+                    publishers[name]["mirror"] << origin
+		else
+                    publishers[name]["origin"] << origin
+		end
+
             else
                 # create a new hash entry for this publisher
                 publishers[name] = {'sticky' => sticky, 'enable' => enabled,
-                                    'origin' => Array[origin]}
+                                    'origin' => Array[],
+				    'mirror' => Array[]}
+					
+		if type.eql? "mirror"
+                    publishers[name]["mirror"] << origin
+		else
+                    publishers[name]["origin"] << origin
+		end
+
                 publishers[name]["proxy"] = proxy if proxy != "-"
 
                 index = publisher_order.index(name)
@@ -66,7 +78,6 @@
                 end
             end
         end
-
         # create new entries for the system
         publishers.keys.collect do |publisher|
             new(:name => publisher,
@@ -74,6 +85,7 @@
                 :sticky => publishers[publisher]["sticky"],
                 :enable => publishers[publisher]["enable"],
                 :origin => publishers[publisher]["origin"],
+                :mirror => publishers[publisher]["mirror"],
                 :proxy => publishers[publisher]["proxy"],
                 :searchfirst => publishers[publisher]["searchfirst"],
                 :searchafter => publishers[publisher]["searchafter"],
@@ -97,7 +109,7 @@
 
     # property getters - each getter does exactly the same thing so create
     # dynamic methods to handle them
-    [:sticky, :enable, :origin, :proxy, :searchfirst, :searchafter,
+    [:sticky, :enable, :origin, :mirror, :proxy, :searchfirst, :searchafter,
      :searchbefore, :sslkey, :sslcert].each do |property|
         define_method(property) do
             begin
@@ -117,17 +129,32 @@
 
     def build_origin
         origins = []
-        
-        # add all the origins from the manifest
-        for o in @resource[:origin] do
-            origins << "-g" << o
-        end
+	
+        # add all the origins from the manifest 
+        if [email protected][:origin].nil?
+	   for o in @resource[:origin] do
+               origins << "-g" << o
+           end
+	end
 
-        # remove all the existing origins
+        # add all the mirrors from the manifest 
+	if [email protected][:mirror].nil?
+	    for o in @resource[:mirror] do
+                origins << "-m" << o
+            end
+	end
+        # remove all the existing origins and mirrors
         if @property_hash != {}
-            for o in @property_hash[:origin] do
-                origins << "-G" << o
-            end
+           if [email protected]_hash[:origin].nil?
+              for o in @property_hash[:origin] do
+                  origins << "-G" << o
+              end
+	   end
+           if [email protected]_hash[:mirror].nil?
+              for o in @property_hash[:mirror] do
+                  origins << "-M" << o
+              end
+           end
         end
         origins
     end
@@ -237,6 +264,10 @@
             end
         end
     end
+    
+    def mirror=(value)
+        create
+    end
 
     def destroy
         pkg("unset-publisher", @resource[:name])
--- a/components/ruby/puppet/files/solaris/lib/puppet/type/pkg_publisher.rb	Fri Apr 10 16:26:11 2015 -0700
+++ b/components/ruby/puppet/files/solaris/lib/puppet/type/pkg_publisher.rb	Mon Apr 13 03:04:30 2015 -0700
@@ -20,7 +20,7 @@
 #
 
 #
-# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
 #
 
 require 'puppet/property/list'
@@ -61,7 +61,6 @@
             end
         end
     end
-
     newproperty(:enable) do
         desc "Enable the publisher"
         newvalues(:true, :false)
@@ -99,4 +98,31 @@
     newproperty(:sslcert) do
         desc "Specify the client SSL certificate"
     end
+
+    newproperty(:mirror, :parent => Puppet::Property::List) do
+        desc "Which mirror URI(s) to set.  For multiple mirrors, specify them
+              as a list"
+	
+        # ensure should remains an array
+        def should
+            @should
+        end
+
+        def insync?(is)
+            is = [] if is == :absent or is.nil?
+            is.sort == self.should.sort
+        end
+
+        def retrieve
+            provider.mirror
+        end
+        
+        munge do |value|
+            if value.start_with? "file" and value.end_with? "/"
+                value = value.chomp("/")
+            else
+                value
+            end
+        end
+    end
 end