|
117 | 117 | if $minimal_requirements and $already_exists == false { |
118 | 118 | # this volume has not yet been created |
119 | 119 |
|
120 | | - # before we can create it, we need to ensure that all the |
121 | | - # servers hosting bricks are members of the storage pool |
| 120 | + exec { "gluster create volume ${title}": |
| 121 | + command => "${::gluster_binary} volume create ${title} ${args}", |
| 122 | + } |
| 123 | + |
| 124 | + # if we have volume options, activate them now |
| 125 | + # |
| 126 | + # Note: $options is an array, but create_resources requires |
| 127 | + # a hash of hashes. We do some contortions to get the |
| 128 | + # array into the hash of hashes that looks like: |
| 129 | + # |
| 130 | + # option.name: |
| 131 | + # value: value |
122 | 132 | # |
123 | | - # first, get a list of unique server names hosting bricks |
124 | | - $brick_hosts = unique( regsubst( $bricks, '^([^:]+):(.+)$', '\1') ) |
125 | | - # now get a list of all peers, including ourself |
126 | | - $pool_members = concat( split( $::gluster_peer_list, ','), [ $::fqdn ] ) |
127 | | - # now see what the difference is |
128 | | - $missing_bricks = difference( $brick_hosts, $pool_members) |
| 133 | + # Note 2: we're using the $_options variable, which contains the |
| 134 | + # sorted list of options. |
| 135 | + if $_options { |
| 136 | + # first we need to prefix each array element with the volume name |
| 137 | + # so that we match the gluster::volume::option title format of |
| 138 | + # volume:option |
| 139 | + $vol_opts = prefix( $_options, "${title}:" ) |
| 140 | + # now we make some YAML, and then parse that to get a Puppet hash |
| 141 | + $yaml = join( regsubst( $vol_opts, ': ', ":\n value: ", 'G'), "\n") |
| 142 | + $hoh = parseyaml($yaml) |
129 | 143 |
|
130 | | - if ! empty($missing_bricks) { |
131 | | - notice("Not creating Gluster volume ${title}: some bricks are not in the pool") |
132 | | - } else { |
133 | | - exec { "gluster create volume ${title}": |
134 | | - command => "${::gluster_binary} volume create ${title} ${args}", |
| 144 | + # safety check |
| 145 | + assert_type(Hash, $hoh) |
| 146 | + # we need to ensure that these are applied AFTER the volume is created |
| 147 | + # but BEFORE the volume is started |
| 148 | + $new_volume_defaults = { |
| 149 | + require => Exec["gluster create volume ${title}"], |
| 150 | + before => Exec["gluster start volume ${title}"], |
135 | 151 | } |
136 | 152 |
|
137 | | - # if we have volume options, activate them now |
138 | | - # |
139 | | - # Note: $options is an array, but create_resources requires |
140 | | - # a hash of hashes. We do some contortions to get the |
141 | | - # array into the hash of hashes that looks like: |
142 | | - # |
143 | | - # option.name: |
144 | | - # value: value |
145 | | - # |
146 | | - # Note 2: we're using the $_options variable, which contains the |
147 | | - # sorted list of options. |
148 | | - if $_options { |
149 | | - # first we need to prefix each array element with the volume name |
150 | | - # so that we match the gluster::volume::option title format of |
151 | | - # volume:option |
152 | | - $vol_opts = prefix( $_options, "${title}:" ) |
153 | | - # now we make some YAML, and then parse that to get a Puppet hash |
154 | | - $yaml = join( regsubst( $vol_opts, ': ', ":\n value: ", 'G'), "\n") |
155 | | - $hoh = parseyaml($yaml) |
156 | | - |
157 | | - # safety check |
158 | | - assert_type(Hash, $hoh) |
159 | | - # we need to ensure that these are applied AFTER the volume is created |
160 | | - # but BEFORE the volume is started |
161 | | - $new_volume_defaults = { |
162 | | - require => Exec["gluster create volume ${title}"], |
163 | | - before => Exec["gluster start volume ${title}"], |
164 | | - } |
165 | | - |
166 | | - create_resources(::gluster::volume::option, $hoh, $new_volume_defaults) |
167 | | - } |
| 153 | + create_resources(::gluster::volume::option, $hoh, $new_volume_defaults) |
| 154 | + } |
168 | 155 |
|
169 | | - # don't forget to start the new volume! |
170 | | - exec { "gluster start volume ${title}": |
171 | | - command => "${::gluster_binary} volume start ${title}", |
172 | | - require => Exec["gluster create volume ${title}"], |
173 | | - } |
| 156 | + # don't forget to start the new volume! |
| 157 | + exec { "gluster start volume ${title}": |
| 158 | + command => "${::gluster_binary} volume start ${title}", |
| 159 | + require => Exec["gluster create volume ${title}"], |
174 | 160 | } |
175 | 161 |
|
176 | 162 | } elsif $already_exists { |
|
0 commit comments