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, 2014, Oracle and/or its affiliates. All rights reserved. |
|
24 # |
|
25 |
|
26 Puppet::Type.type(:svccfg).provide(:svccfg) do |
|
27 desc "Provider for svccfg actions on Oracle Solaris" |
|
28 defaultfor :operatingsystem => :solaris |
|
29 commands :svccfg => "/usr/sbin/svccfg", :svcprop => "/usr/bin/svcprop" |
|
30 |
|
31 def exists? |
|
32 p = exec_cmd(command(:svcprop), "-p", @resource[:property], |
|
33 @resource[:fmri]) |
|
34 if @resource[:ensure] == :absent |
|
35 # only test for the existance of the property and not the value |
|
36 return p[:exit] == 0 |
|
37 elsif @resource[:ensure] == :present |
|
38 # if the property group or property doesn't exist at all, the exit |
|
39 # code will be 1 |
|
40 return false if p[:exit] != 0 |
|
41 |
|
42 # turn @resource[:value] into a simple string by dropping the first |
|
43 # and last array elements (the parens) and removing all double |
|
44 # quotes |
|
45 simple = @resource[:value][1..-2].join(" ")[1..-2].gsub(/\"/, "") |
|
46 |
|
47 # For properties, check the value against what's in SMF. For |
|
48 # property groups, svcprop already verified the PG exists by not |
|
49 # failing |
|
50 if @resource[:property].include? "/" |
|
51 return p[:out].strip == simple |
|
52 else |
|
53 return p[:exit] == 0 |
|
54 end |
|
55 end |
|
56 end |
|
57 |
|
58 def create |
|
59 # Check to see if the service instance exists |
|
60 cmd = Array[command(:svccfg), "select", @resource[:fmri]] |
|
61 svc_exist = exec_cmd(cmd) |
|
62 |
|
63 # Raise an error if the entity does not exist |
|
64 if svc_exist[:exit] != 0 |
|
65 raise Puppet::Error, "SMF entity #{@resource[:fmri]} does not exist" |
|
66 end |
|
67 |
|
68 args = ["-s", @resource[:fmri]] |
|
69 |
|
70 if @resource[:property].include? "/" |
|
71 args << "setprop" << @resource[:property] << "=" |
|
72 if type = @resource[:type] and type != nil |
|
73 args << @resource[:type] + ":" |
|
74 end |
|
75 args << @resource[:value] |
|
76 else |
|
77 args << "addpg" << @resource[:property] << @resource[:type] |
|
78 end |
|
79 svccfg(args) |
|
80 svccfg("-s", @resource[:fmri], "refresh") |
|
81 end |
|
82 |
|
83 def destroy |
|
84 if @resource[:property].include? "/" |
|
85 svccfg("-s", @resource[:fmri], "delprop", @resource[:property]) |
|
86 else |
|
87 svccfg("-s", @resource[:fmri], "delpg", @resource[:property]) |
|
88 end |
|
89 svccfg("-s", @resource[:fmri], "refresh") |
|
90 end |
|
91 |
|
92 def delcust |
|
93 list_cmd = Array[command(:svccfg), "-s", @resource[:fmri], "listprop", |
|
94 "-l", "admin"] |
|
95 delcust_cmd = Array[command(:svccfg), "-s", @resource[:fmri]] |
|
96 if @resource[:property] != nil |
|
97 list_cmd += Array[@resource[:property]] |
|
98 delcust_cmd += Array[@resource[:property]] |
|
99 end |
|
100 |
|
101 # look for any admin layer customizations for this entity |
|
102 p = exec_cmd(list_cmd) |
|
103 if p[:out].strip != '' |
|
104 # there are admin customizations |
|
105 if @resource[:property] == nil |
|
106 svccfg("-s", @resource[:fmri], "delcust") |
|
107 else |
|
108 svccfg("-s", @resource[:fmri], "delcust", @resource[:property]) |
|
109 end |
|
110 svccfg("-s", @resource[:fmri], "refresh") |
|
111 end |
|
112 end |
|
113 |
|
114 def exec_cmd(*cmd) |
|
115 output = Puppet::Util::Execution.execute(cmd, :failonfail => false) |
|
116 {:out => output, :exit => $CHILD_STATUS.exitstatus} |
|
117 end |
|
118 end |
|