author | Kristina Tripp <Kristina.Tripp@oracle.com> |
Fri, 07 Nov 2014 17:33:48 -0800 | |
branch | s11-update |
changeset 3458 | 4912663e9858 |
parent 3415 | components/puppet/files/solaris/lib/puppet/provider/svccfg/solaris.rb@e7a2a94a22a2 |
permissions | -rw-r--r-- |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
1 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
2 |
# CDDL HEADER START |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
3 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
4 |
# The contents of this file are subject to the terms of the |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
5 |
# Common Development and Distribution License (the "License"). |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
6 |
# You may not use this file except in compliance with the License. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
7 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
8 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
9 |
# or http://www.opensolaris.org/os/licensing. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
10 |
# See the License for the specific language governing permissions |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
11 |
# and limitations under the License. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
12 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
13 |
# When distributing Covered Code, include this CDDL HEADER in each |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
14 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
15 |
# If applicable, add the following below this CDDL HEADER, with the |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
16 |
# fields enclosed by brackets "[]" replaced with your own identifying |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
17 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
18 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
19 |
# CDDL HEADER END |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
20 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
21 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
22 |
# |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
23 |
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
24 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
25 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
26 |
Puppet::Type.type(:svccfg).provide(:svccfg) do |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
27 |
desc "Provider for svccfg actions on Oracle Solaris" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
28 |
defaultfor :operatingsystem => :solaris |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
29 |
commands :svccfg => "/usr/sbin/svccfg", :svcprop => "/usr/bin/svcprop" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
30 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
31 |
def exists? |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
32 |
p = exec_cmd(command(:svcprop), "-p", @resource[:property], |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
33 |
@resource[:fmri]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
34 |
if @resource[:ensure] == :absent |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
35 |
# only test for the existance of the property and not the value |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
36 |
return p[:exit] == 0 |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
37 |
elsif @resource[:ensure] == :present |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
38 |
# if the property group or property doesn't exist at all, the exit |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
39 |
# code will be 1 |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
40 |
return false if p[:exit] != 0 |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
41 |
|
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
42 |
# turn @resource[:value] into a simple string by dropping the first |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
43 |
# and last array elements (the parens) and removing all double |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
44 |
# quotes |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
45 |
simple = @resource[:value][1..-2].join(" ")[1..-2].gsub(/\"/, "") |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
46 |
|
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
47 |
# For properties, check the value against what's in SMF. For |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
48 |
# property groups, svcprop already verified the PG exists by not |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
49 |
# failing |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
50 |
if @resource[:property].include? "/" |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
51 |
return p[:out].strip == simple |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
52 |
else |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
53 |
return p[:exit] == 0 |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
54 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
55 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
56 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
57 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
58 |
def create |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
59 |
# Check to see if the service instance exists |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
60 |
cmd = Array[command(:svccfg), "select", @resource[:fmri]] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
61 |
svc_exist = exec_cmd(cmd) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
62 |
|
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
63 |
# Raise an error if the entity does not exist |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
64 |
if svc_exist[:exit] != 0 |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
65 |
raise Puppet::Error, "SMF entity #{@resource[:fmri]} does not exist" |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
66 |
end |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
67 |
|
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
68 |
args = ["-s", @resource[:fmri]] |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
69 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
70 |
if @resource[:property].include? "/" |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
71 |
args << "setprop" << @resource[:property] << "=" |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
72 |
if type = @resource[:type] and type != nil |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
73 |
args << @resource[:type] + ":" |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
74 |
end |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
75 |
args << @resource[:value] |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
76 |
else |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
77 |
args << "addpg" << @resource[:property] << @resource[:type] |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
78 |
end |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
79 |
svccfg(args) |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
80 |
svccfg("-s", @resource[:fmri], "refresh") |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
81 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
82 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
83 |
def destroy |
3415
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
84 |
if @resource[:property].include? "/" |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
85 |
svccfg("-s", @resource[:fmri], "delprop", @resource[:property]) |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
86 |
else |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
87 |
svccfg("-s", @resource[:fmri], "delpg", @resource[:property]) |
e7a2a94a22a2
18197420 pkg publisher provider should handle set/disable combination
saurabh.vyas@oracle.com
parents:
2771
diff
changeset
|
88 |
end |
2771
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
89 |
svccfg("-s", @resource[:fmri], "refresh") |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
90 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
91 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
92 |
def delcust |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
93 |
list_cmd = Array[command(:svccfg), "-s", @resource[:fmri], "listprop", |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
94 |
"-l", "admin"] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
95 |
delcust_cmd = Array[command(:svccfg), "-s", @resource[:fmri]] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
96 |
if @resource[:property] != nil |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
97 |
list_cmd += Array[@resource[:property]] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
98 |
delcust_cmd += Array[@resource[:property]] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
99 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
100 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
101 |
# look for any admin layer customizations for this entity |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
102 |
p = exec_cmd(list_cmd) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
103 |
if p[:out].strip != '' |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
104 |
# there are admin customizations |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
105 |
if @resource[:property] == nil |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
106 |
svccfg("-s", @resource[:fmri], "delcust") |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
107 |
else |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
108 |
svccfg("-s", @resource[:fmri], "delcust", @resource[:property]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
109 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
110 |
svccfg("-s", @resource[:fmri], "refresh") |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
111 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
112 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
113 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
114 |
def exec_cmd(*cmd) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
115 |
output = Puppet::Util::Execution.execute(cmd, :failonfail => false) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
116 |
{:out => output, :exit => $CHILD_STATUS.exitstatus} |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
117 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
118 |
end |