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