|
99 | 99 |
|
100 | 100 | $args = join(delete($cmd_args, ''), ' ') |
101 | 101 |
|
102 | | - if getvar('::gluster_binary'){ |
| 102 | + $_gluster_binary = $facts.dig('gluster_binary') |
| 103 | + if $_gluster_binary { |
103 | 104 | # we need the Gluster binary to do anything! |
104 | 105 |
|
105 | | - if getvar('::gluster_volume_list') and member( split( $::gluster_volume_list, ',' ), $title ) { |
106 | | - $already_exists = true |
107 | | - } else { |
108 | | - $already_exists = false |
109 | | - } |
| 106 | + $_gluster_volume_list = $facts.dig('gluster_volume_list') |
| 107 | + $already_exists = $_gluster_volume_list and $title in $_gluster_volume_list.split(',') |
110 | 108 |
|
111 | | - if $already_exists == false { |
| 109 | + unless $already_exists { |
112 | 110 | # this volume has not yet been created |
113 | 111 |
|
114 | 112 | exec { "gluster create volume ${title}": |
115 | | - command => "${::gluster_binary} volume create ${title} ${args}", |
| 113 | + command => "${_gluster_binary} volume create ${title} ${args}", |
116 | 114 | } |
117 | 115 |
|
118 | 116 | # if we have volume options, activate them now |
|
144 | 142 | before => Exec["gluster start volume ${title}"], |
145 | 143 | } |
146 | 144 |
|
147 | | - create_resources(::gluster::volume::option, $hoh, $new_volume_defaults) |
| 145 | + create_resources('::gluster::volume::option', $hoh, $new_volume_defaults) |
148 | 146 | } |
149 | 147 |
|
150 | 148 | # don't forget to start the new volume! |
151 | 149 | exec { "gluster start volume ${title}": |
152 | | - command => "${::gluster_binary} volume start ${title}", |
| 150 | + command => "${_gluster_binary} volume start ${title}", |
153 | 151 | require => Exec["gluster create volume ${title}"], |
154 | 152 | } |
155 | 153 |
|
156 | 154 | } elsif $already_exists { |
157 | 155 | # this volume exists |
158 | 156 |
|
159 | 157 | # our fact lists bricks comma-separated, but we need an array |
160 | | - $vol_bricks = split( getvar( "::gluster_volume_${title}_bricks" ), ',') |
| 158 | + $vol_bricks = $facts.dig("gluster_volume_${title}_bricks").then |$bs| { |
| 159 | + $bs.split(',') |
| 160 | + } |
161 | 161 | if $bricks != $vol_bricks { |
162 | 162 | # this resource's list of bricks does not match the existing |
163 | 163 | # volume's list of bricks |
|
193 | 193 |
|
194 | 194 | $new_bricks_list = join($new_bricks, ' ') |
195 | 195 | exec { "gluster add bricks to ${title}": |
196 | | - command => "${::gluster_binary} volume add-brick ${title} ${s} ${r} ${new_bricks_list} ${_force}", |
| 196 | + command => "${_gluster_binary} volume add-brick ${title} ${s} ${r} ${new_bricks_list} ${_force}", |
197 | 197 | } |
198 | 198 |
|
199 | 199 | if $rebalance { |
200 | 200 | exec { "gluster rebalance ${title}": |
201 | | - command => "${::gluster_binary} volume rebalance ${title} start", |
| 201 | + command => "${_gluster_binary} volume rebalance ${title} start", |
202 | 202 | require => Exec["gluster add bricks to ${title}"], |
203 | 203 | } |
204 | 204 | } |
|
208 | 208 | # the self heal daemon comes back to life. |
209 | 209 | # as such, we sleep 5 here before starting the heal |
210 | 210 | exec { "gluster heal ${title}": |
211 | | - command => "/bin/sleep 5; ${::gluster_binary} volume heal ${title} full", |
| 211 | + command => "/bin/sleep 5; ${_gluster_binary} volume heal ${title} full", |
212 | 212 | require => Exec["gluster add bricks to ${title}"], |
213 | 213 | } |
214 | 214 | } |
|
222 | 222 | } |
223 | 223 |
|
224 | 224 | # did the options change? |
225 | | - $current_options_hash = pick(fact("gluster_volumes.${title}.options"), {}) |
226 | | - $_current = sort(join_keys_to_values($current_options_hash, ': ')) |
227 | | - |
| 225 | + $current_options = $facts.dig("gluster_volume_${title}.options").pick({}) |
| 226 | + $_current = sort(join_keys_to_values($current_options, ': ')) |
228 | 227 | if $_current != $_options { |
229 | 228 | # |
230 | 229 | # either of $current_options or $_options may be empty. |
231 | 230 | # we need to account for this situation |
232 | 231 | # |
233 | | - if is_array($_current) and is_array($_options) { |
| 232 | + if $_current =~ Array and $_options =~ Array { |
234 | 233 | $to_remove = difference($_current, $_options) |
235 | 234 | $to_add = difference($_options, $_current) |
236 | 235 | } else { |
|
242 | 241 | $to_add = $_options |
243 | 242 | } |
244 | 243 | } |
245 | | - if ! empty($to_remove) { |
| 244 | + unless $to_remove.empty { |
246 | 245 | # we have some options active that are not defined here. Remove them |
247 | 246 | # |
248 | 247 | # the syntax to remove ::gluster::volume::options is a little different |
|
252 | 251 | $remove_yaml = join( regsubst( $remove_opts, ': .+$', ":\n ensure: absent", 'G' ), "\n" ) |
253 | 252 | $remove = parseyaml($remove_yaml) |
254 | 253 | if $remove_options { |
255 | | - create_resources( ::gluster::volume::option, $remove ) |
| 254 | + create_resources('::gluster::volume::option', $remove ) |
256 | 255 | } else { |
257 | 256 | $remove_str = join( keys($remove), ', ' ) |
258 | 257 | notice("NOT REMOVING the following options for volume ${title}: ${remove_str}.") |
259 | 258 | } |
260 | 259 | } |
261 | | - if ! empty($to_add) { |
| 260 | + unless $to_add.empty { |
262 | 261 | # we have some options defined that are not active. Add them |
263 | 262 | $add_opts = prefix( $to_add, "${title}:" ) |
264 | 263 | $add_yaml = join( regsubst( $add_opts, ': ', ":\n value: ", 'G' ), "\n" ) |
265 | 264 | $add = parseyaml($add_yaml) |
266 | | - create_resources( ::gluster::volume::option, $add ) |
| 265 | + create_resources('::gluster::volume::option', $add ) |
267 | 266 | } |
268 | 267 | } |
269 | 268 | } |
|
0 commit comments