components/ruby/puppet/files/solaris/lib/puppet/provider/pkg_publisher/solaris.rb
branchs11u3-sru
changeset 5905 085130968f36
parent 3458 4912663e9858
equal deleted inserted replaced
5883:e4ca97d40c81 5905:085130968f36
    18 #
    18 #
    19 # CDDL HEADER END
    19 # CDDL HEADER END
    20 #
    20 #
    21 
    21 
    22 #
    22 #
    23 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
    23 # Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
    24 #
    24 #
    25 
    25 
    26 Puppet::Type.type(:pkg_publisher).provide(:pkg_publisher) do
    26 Puppet::Type.type(:pkg_publisher).provide(:pkg_publisher) do
    27     desc "Provider for Solaris publishers"
    27     desc "Provider for Solaris publishers"
    28     confine :operatingsystem => [:solaris]
    28     confine :operatingsystem => [:solaris]
    38 
    38 
    39             # set the order of the publishers
    39             # set the order of the publishers
    40             if not publisher_order.include?("name")
    40             if not publisher_order.include?("name")
    41                 publisher_order << name
    41                 publisher_order << name
    42             end
    42             end
    43 
       
    44             # strip off any trailing "/" characters
    43             # strip off any trailing "/" characters
    45             if origin.end_with?("/")
    44             if origin.end_with?("/")
    46                 origin = origin[0..-2]
    45                 origin = origin[0..-2]
    47             end
    46             end
    48 
    47 
    49             if publishers.has_key?(name)
    48             if publishers.has_key?(name)
    50                 # if we've seen this publisher before, simply update the origin
    49                 # if we've seen this publisher before, simply update the origin
    51                 # array
    50                 # array
    52                 publishers[name]["origin"] << origin
    51 	        if type.eql? "mirror"
       
    52                     publishers[name]["mirror"] << origin
       
    53 		else
       
    54                     publishers[name]["origin"] << origin
       
    55 		end
       
    56 
    53             else
    57             else
    54                 # create a new hash entry for this publisher
    58                 # create a new hash entry for this publisher
    55                 publishers[name] = {'sticky' => sticky, 'enable' => enabled,
    59                 publishers[name] = {'sticky' => sticky, 'enable' => enabled,
    56                                     'origin' => Array[origin]}
    60                                     'origin' => Array[],
       
    61 				    'mirror' => Array[]}
       
    62 					
       
    63 		if type.eql? "mirror"
       
    64                     publishers[name]["mirror"] << origin
       
    65 		else
       
    66                     publishers[name]["origin"] << origin
       
    67 		end
       
    68 
    57                 publishers[name]["proxy"] = proxy if proxy != "-"
    69                 publishers[name]["proxy"] = proxy if proxy != "-"
    58 
    70 
    59                 index = publisher_order.index(name)
    71                 index = publisher_order.index(name)
    60                 if index == 0
    72                 if index == 0
    61                     publishers[name]["searchfirst"] = true
    73                     publishers[name]["searchfirst"] = true
    64                     publishers[name]["searchfirst"] = nil
    76                     publishers[name]["searchfirst"] = nil
    65                     publishers[name]["searchafter"] = publisher_order[index-1]
    77                     publishers[name]["searchafter"] = publisher_order[index-1]
    66                 end
    78                 end
    67             end
    79             end
    68         end
    80         end
    69 
       
    70         # create new entries for the system
    81         # create new entries for the system
    71         publishers.keys.collect do |publisher|
    82         publishers.keys.collect do |publisher|
    72             new(:name => publisher,
    83             new(:name => publisher,
    73                 :ensure => :present,
    84                 :ensure => :present,
    74                 :sticky => publishers[publisher]["sticky"],
    85                 :sticky => publishers[publisher]["sticky"],
    75                 :enable => publishers[publisher]["enable"],
    86                 :enable => publishers[publisher]["enable"],
    76                 :origin => publishers[publisher]["origin"],
    87                 :origin => publishers[publisher]["origin"],
       
    88                 :mirror => publishers[publisher]["mirror"],
    77                 :proxy => publishers[publisher]["proxy"],
    89                 :proxy => publishers[publisher]["proxy"],
    78                 :searchfirst => publishers[publisher]["searchfirst"],
    90                 :searchfirst => publishers[publisher]["searchfirst"],
    79                 :searchafter => publishers[publisher]["searchafter"],
    91                 :searchafter => publishers[publisher]["searchafter"],
    80                 :searchbefore => nil,
    92                 :searchbefore => nil,
    81                 :sslkey => nil,
    93                 :sslkey => nil,
    95         end
   107         end
    96     end
   108     end
    97 
   109 
    98     # property getters - each getter does exactly the same thing so create
   110     # property getters - each getter does exactly the same thing so create
    99     # dynamic methods to handle them
   111     # dynamic methods to handle them
   100     [:sticky, :enable, :origin, :proxy, :searchfirst, :searchafter,
   112     [:sticky, :enable, :origin, :mirror, :proxy, :searchfirst, :searchafter,
   101      :searchbefore, :sslkey, :sslcert].each do |property|
   113      :searchbefore, :sslkey, :sslcert].each do |property|
   102         define_method(property) do
   114         define_method(property) do
   103             begin
   115             begin
   104                 @property_hash[property]
   116                 @property_hash[property]
   105             rescue
   117             rescue
   115         @property_hash[:ensure] == :present
   127         @property_hash[:ensure] == :present
   116     end
   128     end
   117 
   129 
   118     def build_origin
   130     def build_origin
   119         origins = []
   131         origins = []
   120         
   132 	
   121         # add all the origins from the manifest
   133         # add all the origins from the manifest 
   122         for o in @resource[:origin] do
   134         if !@resource[:origin].nil?
   123             origins << "-g" << o
   135 	   for o in @resource[:origin] do
   124         end
   136                origins << "-g" << o
   125 
   137            end
   126         # remove all the existing origins
   138 	end
       
   139 
       
   140         # add all the mirrors from the manifest 
       
   141 	if !@resource[:mirror].nil?
       
   142 	    for o in @resource[:mirror] do
       
   143                 origins << "-m" << o
       
   144             end
       
   145 	end
       
   146         # remove all the existing origins and mirrors
   127         if @property_hash != {}
   147         if @property_hash != {}
   128             for o in @property_hash[:origin] do
   148            if !@property_hash[:origin].nil?
   129                 origins << "-G" << o
   149               for o in @property_hash[:origin] do
   130             end
   150                   origins << "-G" << o
       
   151               end
       
   152 	   end
       
   153            if !@property_hash[:mirror].nil?
       
   154               for o in @property_hash[:mirror] do
       
   155                   origins << "-M" << o
       
   156               end
       
   157            end
   131         end
   158         end
   132         origins
   159         origins
   133     end
   160     end
   134 
   161 
   135     def build_flags
   162     def build_flags
   235             if enable == :false
   262             if enable == :false
   236                 pkg("set-publisher", "--disable", @resource[:name])
   263                 pkg("set-publisher", "--disable", @resource[:name])
   237             end
   264             end
   238         end
   265         end
   239     end
   266     end
       
   267     
       
   268     def mirror=(value)
       
   269         create
       
   270     end
   240 
   271 
   241     def destroy
   272     def destroy
   242         pkg("unset-publisher", @resource[:name])
   273         pkg("unset-publisher", @resource[:name])
   243     end
   274     end
   244 end
   275 end