components/puppet/files/solaris/lib/puppet/provider/pkg_facet/solaris.rb
branchs11-update
changeset 3458 4912663e9858
parent 3455 6bba35ecb6b8
child 3459 e1b247c39c22
equal deleted inserted replaced
3455:6bba35ecb6b8 3458:4912663e9858
     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_facet).provide(:pkg_facet) do
       
    27     desc "Provider for Oracle Solaris facets"
       
    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(:facet, "-H", "-F", "tsv").split("\n").collect do |line|
       
    34             name, value = line.split
       
    35             new(:name => name,
       
    36                 :ensure => :present,
       
    37                 :value => value.downcase)
       
    38         end 
       
    39     end
       
    40 
       
    41     def self.prefetch(resources)
       
    42         # pull the instances on the system
       
    43         facets = instances
       
    44 
       
    45         # set the provider for the resource to set the property_hash
       
    46         resources.keys.each do |name|
       
    47             if provider = facets.find{ |facet| facet.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             # retrieve the string representation of @resource[:value] since it
       
    61             # gets translated to an object by Puppet
       
    62             return (@property_hash[:ensure] == :present and \
       
    63                     @property_hash[:value].downcase == \
       
    64                         @resource[:value].downcase)
       
    65         end
       
    66         @property_hash[:ensure] == :present
       
    67     end
       
    68 
       
    69     # required puppet functions
       
    70     def create
       
    71         pkg("change-facet", "#{@resource[:name]}=#{@resource[:value]}")
       
    72     end
       
    73 
       
    74     def destroy
       
    75         pkg("change-facet", "#{@resource[:name]}=None")
       
    76     end
       
    77 end