Skip to content

Commit e0fea8e

Browse files
committed
Make code more idiomatic, replace use of getvar
1 parent 92f0f20 commit e0fea8e

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

functions/cmd_volume_get_option.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function gluster::cmd_volume_get_option(
1818
Gluster::VolumeOption $opt,
1919
Optional[Any] $comparison = undef,
2020
) {
21-
$_cmd = "${::gluster_binary} volume get ${vol} ${opt}"
21+
$_cmd = "${facts['gluster_binary']} volume get ${vol} ${opt}"
2222

2323
unless $comparison {
2424
return $_cmd

manifests/peer.pp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@
3939
$fqdn = $::fqdn,
4040
) {
4141

42-
# we can't do much without the Gluster binary
43-
# but we don't necessarily want the Puppet run to fail if the
44-
# gluster_binary fact is absent!
45-
if getvar('::gluster_binary') {
42+
# we can't do much without the Gluster binary but we don't necessarily want
43+
# the Puppet run to fail if the gluster_binary fact is absent!
44+
$_gluster_binary = $facts.dig('gluster_binary')
45+
if $_gluster_binary {
4646
# we can't join to ourselves, so it only makes sense to operate
4747
# on other gluster servers in the same pool
4848
if $fqdn != $::fqdn {
4949

50-
# and we don't want to attach a server that is already a member
51-
# of the current pool
52-
if getvar('::gluster_peer_list') {
53-
$peers = split($::gluster_peer_list, ',' )
54-
if ! member($peers, $title) {
50+
# and we don't want to attach a server that is already a member of the
51+
# current pool
52+
$_gluster_peer_list = $facts.dig('gluster_peer_list')
53+
if $_gluster_peer_list {
54+
$peers = split($_gluster_peer_list, ',' )
55+
if $title in $peers {
5556
$already_in_pool = false
5657
} else {
5758
$already_in_pool = true
@@ -61,7 +62,7 @@
6162
}
6263
if !$already_in_pool {
6364
exec { "gluster peer probe ${title}":
64-
command => "${::gluster_binary} peer probe ${title}",
65+
command => "${_gluster_binary} peer probe ${title}",
6566
}
6667
}
6768
}

manifests/volume.pp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,18 @@
9999

100100
$args = join(delete($cmd_args, ''), ' ')
101101

102-
if getvar('::gluster_binary'){
102+
$_gluster_binary = $facts.dig('gluster_binary')
103+
if $_gluster_binary {
103104
# we need the Gluster binary to do anything!
104105

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(',')
110108

111-
if $already_exists == false {
109+
unless $already_exists {
112110
# this volume has not yet been created
113111

114112
exec { "gluster create volume ${title}":
115-
command => "${::gluster_binary} volume create ${title} ${args}",
113+
command => "${_gluster_binary} volume create ${title} ${args}",
116114
}
117115

118116
# if we have volume options, activate them now
@@ -144,20 +142,22 @@
144142
before => Exec["gluster start volume ${title}"],
145143
}
146144

147-
create_resources(::gluster::volume::option, $hoh, $new_volume_defaults)
145+
create_resources('::gluster::volume::option', $hoh, $new_volume_defaults)
148146
}
149147

150148
# don't forget to start the new volume!
151149
exec { "gluster start volume ${title}":
152-
command => "${::gluster_binary} volume start ${title}",
150+
command => "${_gluster_binary} volume start ${title}",
153151
require => Exec["gluster create volume ${title}"],
154152
}
155153

156-
} elsif $already_exists {
154+
} else {
157155
# this volume exists
158156

159157
# 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+
}
161161
if $bricks != $vol_bricks {
162162
# this resource's list of bricks does not match the existing
163163
# volume's list of bricks
@@ -193,12 +193,12 @@
193193

194194
$new_bricks_list = join($new_bricks, ' ')
195195
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}",
197197
}
198198

199199
if $rebalance {
200200
exec { "gluster rebalance ${title}":
201-
command => "${::gluster_binary} volume rebalance ${title} start",
201+
command => "${_gluster_binary} volume rebalance ${title} start",
202202
require => Exec["gluster add bricks to ${title}"],
203203
}
204204
}
@@ -208,7 +208,7 @@
208208
# the self heal daemon comes back to life.
209209
# as such, we sleep 5 here before starting the heal
210210
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",
212212
require => Exec["gluster add bricks to ${title}"],
213213
}
214214
}
@@ -222,15 +222,14 @@
222222
}
223223

224224
# 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, ': '))
228227
if $_current != $_options {
229228
#
230229
# either of $current_options or $_options may be empty.
231230
# we need to account for this situation
232231
#
233-
if is_array($_current) and is_array($_options) {
232+
if $_current =~ Array and $_options =~ Array {
234233
$to_remove = difference($_current, $_options)
235234
$to_add = difference($_options, $_current)
236235
} else {
@@ -242,7 +241,7 @@
242241
$to_add = $_options
243242
}
244243
}
245-
if ! empty($to_remove) {
244+
unless $to_remove.empty {
246245
# we have some options active that are not defined here. Remove them
247246
#
248247
# the syntax to remove ::gluster::volume::options is a little different
@@ -252,18 +251,18 @@
252251
$remove_yaml = join( regsubst( $remove_opts, ': .+$', ":\n ensure: absent", 'G' ), "\n" )
253252
$remove = parseyaml($remove_yaml)
254253
if $remove_options {
255-
create_resources( ::gluster::volume::option, $remove )
254+
create_resources('::gluster::volume::option', $remove )
256255
} else {
257256
$remove_str = join( keys($remove), ', ' )
258257
notice("NOT REMOVING the following options for volume ${title}: ${remove_str}.")
259258
}
260259
}
261-
if ! empty($to_add) {
260+
unless $to_add.empty {
262261
# we have some options defined that are not active. Add them
263262
$add_opts = prefix( $to_add, "${title}:" )
264263
$add_yaml = join( regsubst( $add_opts, ': ', ":\n value: ", 'G' ), "\n" )
265264
$add = parseyaml($add_yaml)
266-
create_resources( ::gluster::volume::option, $add )
265+
create_resources('::gluster::volume::option', $add )
267266
}
268267
}
269268
}

manifests/volume/option.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
exec { "gluster option ${vol} ${opt} ${_value}":
5353
path => '/usr/bin:/usr/sbin:/bin',
54-
command => "${::gluster_binary} volume ${cmd}",
54+
command => "${facts['gluster_binary']} volume ${cmd}",
5555
unless => unless $ensure == 'absent' {
5656
gluster::cmd_volume_get_option($vol, $opt, $_value)
5757
},

0 commit comments

Comments
 (0)