components/puppet/files/solaris/lib/puppet/provider/pkg_variant/solaris.rb
branchs11u2-sru
changeset 3460 5c5af6e58474
parent 3457 6358358b4186
child 3461 1240b4c4e38d
equal deleted inserted replaced
3457:6358358b4186 3460:5c5af6e58474
     1 #
       
     2 # CDDL HEADER START
       
     3 #
       
     4 # The contents of this file are subject to the terms of the
       
     5 # Common Development and Distribution License (the "License").
       
     6 # You may not use this file except in compliance with the License.
       
     7 #
       
     8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9 # or http://www.opensolaris.org/os/licensing.
       
    10 # See the License for the specific language governing permissions
       
    11 # and limitations under the License.
       
    12 #
       
    13 # When distributing Covered Code, include this CDDL HEADER in each
       
    14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15 # If applicable, add the following below this CDDL HEADER, with the
       
    16 # fields enclosed by brackets "[]" replaced with your own identifying
       
    17 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    18 #
       
    19 # CDDL HEADER END
       
    20 #
       
    21 
       
    22 #
       
    23 # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
       
    24 #
       
    25 
       
    26 Puppet::Type.type(:pkg_variant).provide(:pkg_variant) do
       
    27     desc "Provider for Oracle Solaris variants"
       
    28     confine :operatingsystem => [:solaris]
       
    29     defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12']
       
    30     commands :pkg => '/usr/bin/pkg'
       
    31 
       
    32     def self.instances
       
    33         pkg(:variant, "-H", "-F", "tsv").split("\n").collect do |line|
       
    34             name, value = line.split
       
    35             new(:name => name,
       
    36                 :ensure => :present,
       
    37                 :value => value)
       
    38         end 
       
    39     end
       
    40 
       
    41     def self.prefetch(resources)
       
    42         # pull the instances on the system
       
    43         variants = instances
       
    44 
       
    45         # set the provider for the resource to set the property_hash
       
    46         resources.keys.each do |name|
       
    47             if provider = variants.find{ |variant| variant.name == name}
       
    48                 resources[name].provider = provider
       
    49             end
       
    50         end
       
    51     end
       
    52 
       
    53     def value
       
    54         @property_hash[:value]
       
    55     end
       
    56 
       
    57     def exists?
       
    58         # only compare against @resource if one is provided via manifests
       
    59         if @property_hash[:ensure] == :present and @resource[:value] != nil
       
    60             # cast @resource[:value] to a string since it gets translated to an
       
    61             # object by Puppet
       
    62             return (@property_hash[:ensure] == :present and \
       
    63                     @property_hash[:value] == @resource[:value].to_s)
       
    64         end
       
    65         @property_hash[:ensure] == :present
       
    66     end
       
    67 
       
    68     def create
       
    69         pkg("change-variant", "#{@resource[:name]}=#{@resource[:value]}")
       
    70     end
       
    71 end