|
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(:link_aggregation).provide(:link_aggregation) do |
|
27 desc "Provider for creating Oracle Solaris link aggregations" |
|
28 confine :operatingsystem => [:solaris] |
|
29 defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12'] |
|
30 commands :dladm => '/usr/sbin/dladm' |
|
31 |
|
32 def self.instances |
|
33 dladm("show-aggr", "-p", "-o", |
|
34 "link,mode,policy,addrpolicy,lacpactivity,lacptimer").split( |
|
35 "\n").collect do |line| |
|
36 link, mode, policy, addrpolicy, lacpactivity, lacptimer = \ |
|
37 line.split(":") |
|
38 |
|
39 links = [] |
|
40 dladm("show-aggr", "-x", "-p", "-o", "port").split( |
|
41 "\n").each do |portline| |
|
42 next if portline.strip() == "" |
|
43 links << portline.strip() |
|
44 end |
|
45 |
|
46 new(:name => link, |
|
47 :ensure => :present, |
|
48 :lower_links => links.join(" "), |
|
49 :mode => mode, |
|
50 :policy => policy, |
|
51 :address => addrpolicy, |
|
52 :lacpmode => lacpactivity, |
|
53 :lacptimer => lacptimer) |
|
54 end |
|
55 end |
|
56 |
|
57 def self.prefetch(resources) |
|
58 # pull the instances on the system |
|
59 aggrs = instances |
|
60 |
|
61 # set the provider for the resource to set the property_hash |
|
62 resources.keys.each do |name| |
|
63 if provider = aggrs.find{ |aggr| aggr.name == name} |
|
64 resources[name].provider = provider |
|
65 end |
|
66 end |
|
67 end |
|
68 |
|
69 # property getters |
|
70 [:lower_links, :mode, :policy, :lacpmode, :lacptimer, |
|
71 :address].each do |field| |
|
72 define_method(field) do |
|
73 @property_hash[field] |
|
74 end |
|
75 end |
|
76 |
|
77 # property setters |
|
78 def lower_links=(value) |
|
79 is_temporary?(@resource[:name]) |
|
80 current = self.lower_links.split() |
|
81 remove_list = [] |
|
82 for entry in current - value |
|
83 remove_list << "-l" << entry |
|
84 end |
|
85 |
|
86 add_list = [] |
|
87 for entry in value - current |
|
88 add_list << "-l" << entry |
|
89 end |
|
90 |
|
91 if not add_list.empty? |
|
92 dladm("add-aggr", add_list, @resource[:name]) |
|
93 end |
|
94 |
|
95 if not remove_list.empty? |
|
96 dladm("remove-aggr", remove_list, @resource[:name]) |
|
97 end |
|
98 end |
|
99 |
|
100 def mode=(value) |
|
101 is_temporary?(@resource[:name]) |
|
102 dladm("modify-aggr", "-m", value, @resource[:name]) |
|
103 end |
|
104 |
|
105 def policy=(value) |
|
106 is_temporary?(@resource[:name]) |
|
107 dladm("modify-aggr", "-P", value, @resource[:name]) |
|
108 end |
|
109 |
|
110 def lacpmode=(value) |
|
111 is_temporary?(@resource[:name]) |
|
112 dladm("modify-aggr", "-L", value, @resource[:name]) |
|
113 end |
|
114 |
|
115 def lacptimer=(value) |
|
116 is_temporary?(@resource[:name]) |
|
117 dladm("modify-aggr", "-T", value, @resource[:name]) |
|
118 end |
|
119 |
|
120 def address=(value) |
|
121 is_temporary?(@resource[:name]) |
|
122 dladm("modify-aggr", "-u", value, @resource[:name]) |
|
123 end |
|
124 |
|
125 def add_options |
|
126 options = [] |
|
127 if @resource[:temporary] == :true |
|
128 options << "-t" |
|
129 end |
|
130 |
|
131 if lowerlinks = @resource[:lower_links] |
|
132 if lowerlinks.is_a? Array |
|
133 for link in lowerlinks |
|
134 options << "-l" << link |
|
135 end |
|
136 else |
|
137 options << "-l" << lowerlinks |
|
138 end |
|
139 end |
|
140 |
|
141 if mode = @resource[:mode] |
|
142 options << "-m" << mode |
|
143 end |
|
144 |
|
145 if policy = @resource[:policy] |
|
146 options << "-P" << policy |
|
147 end |
|
148 |
|
149 if lacpmode = @resource[:lacpmode] |
|
150 options << "-L" << lacpmode |
|
151 end |
|
152 |
|
153 if lacptimer = @resource[:lacptimer] |
|
154 options << "-T" << lacptimer |
|
155 end |
|
156 |
|
157 if address = @resource[:address] |
|
158 options << "-u" << address |
|
159 end |
|
160 options |
|
161 end |
|
162 |
|
163 def exists? |
|
164 @property_hash[:ensure] == :present |
|
165 end |
|
166 |
|
167 def create |
|
168 dladm("create-aggr", add_options, @resource[:name]) |
|
169 end |
|
170 |
|
171 def destroy |
|
172 dladm("delete-aggr", add_options, @resource[:name]) |
|
173 end |
|
174 |
|
175 def is_temporary?(name) |
|
176 p = exec_cmd(command(:dladm), "show-aggr", "-P", name) |
|
177 raise Puppet::Error, "Unable to change attributes of temporary " \ |
|
178 "aggregation #{@resource[:name]}" if p[:exit] == 1 |
|
179 end |
|
180 |
|
181 def exec_cmd(*cmd) |
|
182 output = Puppet::Util::Execution.execute(cmd, :failonfail => false) |
|
183 {:out => output, :exit => $CHILD_STATUS.exitstatus} |
|
184 end |
|
185 end |
|
186 |