|
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_mediator).provide(:pkg_mediator) do |
|
27 desc "Provider for Oracle Solaris mediators" |
|
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(:mediator, "-H", "-F", "tsv").split("\n").collect do |line| |
|
34 name, ver_src, version, impl_src, impl, impl_ver = line.split("\t") |
|
35 |
|
36 # Because implementation is an optional parameter, it may not be set. |
|
37 # If the implementation is not set, that needs to be captured in |
|
38 # the output. |
|
39 if not impl |
|
40 impl = 'None' |
|
41 end |
|
42 |
|
43 new(:name => name, |
|
44 :ensure => :present, |
|
45 :implementation => impl, |
|
46 :version => version) |
|
47 end |
|
48 end |
|
49 |
|
50 def self.prefetch(resources) |
|
51 # pull the instances on the system |
|
52 mediators = instances |
|
53 |
|
54 # set the provider for the resource to set the property_hash |
|
55 resources.keys.each do |name| |
|
56 if provider = mediators.find{ |mediator| mediator.name == name} |
|
57 resources[name].provider = provider |
|
58 end |
|
59 end |
|
60 end |
|
61 |
|
62 def exists? |
|
63 # only compare against @resource if one is provided via manifests |
|
64 if @property_hash[:ensure] == :present and @resource[:version] != nil |
|
65 return (@property_hash[:ensure] == :present and \ |
|
66 @property_hash[:version] == @resource[:version]) |
|
67 end |
|
68 @property_hash[:ensure] == :present |
|
69 end |
|
70 |
|
71 def version |
|
72 @property_hash[:version] |
|
73 end |
|
74 |
|
75 def implementation |
|
76 @property_hash[:implementation] |
|
77 end |
|
78 |
|
79 def build_flags |
|
80 flags = [] |
|
81 if version = @resource[:version] and version != nil |
|
82 flags << "-V" << @resource[:version] |
|
83 end |
|
84 |
|
85 if implementation = @resource[:implementation] and implementation != nil |
|
86 flags << "-I" << @resource[:implementation] |
|
87 end |
|
88 flags |
|
89 end |
|
90 |
|
91 # required puppet functions |
|
92 def create |
|
93 pkg("set-mediator", build_flags, @resource[:name]) |
|
94 end |
|
95 |
|
96 def destroy |
|
97 pkg("unset-mediator", build_flags, @resource[:name]) |
|
98 end |
|
99 end |