author | Kristina Tripp <Kristina.Tripp@oracle.com> |
Fri, 07 Nov 2014 17:33:48 -0800 | |
branch | s11-update |
changeset 3458 | 4912663e9858 |
parent 2771 | components/puppet/files/solaris/lib/puppet/provider/address_properties/solaris.rb@8e4227dc2fc4 |
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 |
# |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
23 |
# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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(:address_properties).provide(:address_properties) do |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
27 |
desc "Provider for managing Oracle Solaris address object properties" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
28 |
confine :operatingsystem => [:solaris] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
29 |
defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
30 |
commands :ipadm => '/usr/sbin/ipadm' |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
31 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
32 |
def initialize(value={}) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
33 |
super(value) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
34 |
@addrprops = {} |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
35 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
36 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
37 |
def self.instances |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
38 |
props = {} |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
39 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
40 |
ipadm("show-addrprop", "-c", "-o", "ADDROBJ,PROPERTY,CURRENT").split( |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
41 |
"\n").collect do |line| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
42 |
addrobj, property, value = line.strip().split(":") |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
43 |
next if value == nil |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
44 |
if not props.has_key? addrobj |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
45 |
props[addrobj] = {} |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
46 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
47 |
props[addrobj][property] = value |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
48 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
49 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
50 |
addresses = [] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
51 |
props.each do |key, value| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
52 |
addresses << new(:name => key, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
53 |
:ensure => :present, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
54 |
:properties => value) |
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 |
addresses |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
57 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
58 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
59 |
def self.prefetch(resources) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
60 |
# pull the instances on the system |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
61 |
props = instances |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
62 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
63 |
# set the provider for the resource to set the property_hash |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
64 |
resources.keys.each do |name| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
65 |
if provider = props.find{ |prop| prop.name == name} |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
66 |
resources[name].provider = provider |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
67 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
68 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
69 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
70 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
71 |
def properties |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
72 |
@property_hash[:properties] |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
73 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
74 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
75 |
def properties=(value) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
76 |
value.each do |key, value| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
77 |
ipadm("set-addrprop", "-p", "#{key}=#{value}", @resource[:name]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
78 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
79 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
80 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
81 |
def exists? |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
82 |
if @resource[:properties] == nil |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
83 |
return :false |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
84 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
85 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
86 |
@resource[:properties].each do |key, value| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
87 |
p = exec_cmd(command(:ipadm), "show-addrprop","-c", "-p", key, |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
88 |
"-o", "CURRENT", @resource[:address]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
89 |
if p[:exit] == 1 |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
90 |
Puppet.warning "Property '#{key}' not found for address " \ |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
91 |
"#{@resource[:address]}" |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
92 |
next |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
93 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
94 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
95 |
if p[:out].strip != value |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
96 |
@addrprops[key] = value |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
97 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
98 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
99 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
100 |
return @addrprops.empty? |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
101 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
102 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
103 |
def create |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
104 |
@addrprops.each do |key, value| |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
105 |
ipadm("set-addrprop", "-p", "#{key}=#{value}", @resource[:address]) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
106 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
107 |
end |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
108 |
|
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
109 |
def exec_cmd(*cmd) |
8e4227dc2fc4
16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff
changeset
|
110 |
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
|
111 |
{:out => output, :exit => $CHILD_STATUS.exitstatus} |
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 |
end |