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