|
33 | 33 | inherit utils_env; |
34 | 34 | }; |
35 | 35 |
|
36 | | - cinderConf = pkgs.writeText "cinder.conf" '' |
| 36 | + cinderConfLvm = pkgs.writeText "cinder.conf" '' |
37 | 37 | [DEFAULT] |
38 | 38 | transport_url = rabbit://openstack:openstack@controller |
39 | 39 | auth_strategy = keystone |
|
78 | 78 | iscsi_target_prefix = iqn.2010-10.org.openstack: |
79 | 79 | ''; |
80 | 80 |
|
| 81 | + cinderConfNfs = pkgs.writeText "cinder.conf" '' |
| 82 | + [DEFAULT] |
| 83 | + transport_url = rabbit://openstack:openstack@controller |
| 84 | + auth_strategy = keystone |
| 85 | + my_ip = 10.0.0.20 |
| 86 | + enabled_backends = nfs |
| 87 | + volumes_dir = /var/lib/cinder/volumes |
| 88 | + state_path = /var/lib/cinder |
| 89 | + rootwrap_config = ${rootwrapConf} |
| 90 | + glance_api_servers = http://controller:9292 |
| 91 | + verify_glance_signatures = disabled |
| 92 | + log_dir = /var/log/cinder |
| 93 | +
|
| 94 | + [database] |
| 95 | + connection = mysql+pymysql://cinder:cinder@controller/cinder |
| 96 | +
|
| 97 | + [keystone_authtoken] |
| 98 | + www_authenticate_uri = http://controller:5000 |
| 99 | + auth_url = http://controller:5000 |
| 100 | + memcached_servers = controller:11211 |
| 101 | + auth_type = password |
| 102 | + project_domain_name = default |
| 103 | + user_domain_name = default |
| 104 | + project_name = service |
| 105 | + username = cinder |
| 106 | + password = cinder |
| 107 | +
|
| 108 | + [oslo_concurrency] |
| 109 | + lock_path = /var/lib/cinder/tmp |
| 110 | +
|
| 111 | + [nfs] |
| 112 | + volume_driver = cinder.volume.drivers.nfs.NfsDriver |
| 113 | + nfs_shares_config = /etc/cinder/nfs_shares |
| 114 | + nfs_mount_options = vers=3 |
| 115 | + ''; |
| 116 | + |
81 | 117 | cinderTgtConf = pkgs.writeText "cinder.conf" '' |
82 | 118 | include /var/lib/cinder/volumes/* |
83 | 119 | ''; |
|
92 | 128 | default = true; |
93 | 129 | }; |
94 | 130 | config = mkOption { |
95 | | - default = cinderConf; |
| 131 | + default = if (cfg.backend == "lvm") then cinderConfLvm else cinderConfNfs; |
96 | 132 | description = '' |
97 | 133 | The Cinder config. |
98 | 134 | ''; |
|
104 | 140 | The OpenStack Cinder package to use. |
105 | 141 | ''; |
106 | 142 | }; |
| 143 | + backend = mkOption { |
| 144 | + default = "nfs"; |
| 145 | + type = |
| 146 | + with types; |
| 147 | + enum [ |
| 148 | + "lvm" |
| 149 | + "nfs" |
| 150 | + ]; |
| 151 | + description = '' |
| 152 | + Type of Cinder Storage backend. |
| 153 | + Possible options: [ lvm | nfs ] |
| 154 | + ''; |
| 155 | + }; |
107 | 156 | }; |
108 | 157 |
|
109 | 158 | config = mkIf cfg.enable { |
|
146 | 195 | }; |
147 | 196 | "/etc/cinder/cinder.conf" = { |
148 | 197 | L = { |
149 | | - argument = "${cinderConf}"; |
150 | | - }; |
151 | | - }; |
152 | | - "/etc/tgt/conf.d/cinder.conf" = { |
153 | | - L = { |
154 | | - argument = "${cinderTgtConf}"; |
155 | | - }; |
156 | | - }; |
157 | | - "/etc/tgt/targets.conf" = { |
158 | | - L = { |
159 | | - argument = "${pkgs.tgt}/etc/tgt/targets.conf"; |
| 198 | + argument = "${cfg.config}"; |
160 | 199 | }; |
161 | 200 | }; |
162 | 201 | }; |
| 202 | + "20-cinder-backend" = |
| 203 | + if (cfg.backend == "lvm") then |
| 204 | + # LVM configuration files |
| 205 | + { |
| 206 | + "/etc/tgt/conf.d/cinder.conf" = { |
| 207 | + L = { |
| 208 | + argument = "${cinderTgtConf}"; |
| 209 | + }; |
| 210 | + }; |
| 211 | + "/etc/tgt/targets.conf" = { |
| 212 | + L = { |
| 213 | + argument = "${pkgs.tgt}/etc/tgt/targets.conf"; |
| 214 | + }; |
| 215 | + }; |
| 216 | + } |
| 217 | + else |
| 218 | + # NFS configuration files |
| 219 | + { |
| 220 | + "/etc/cinder/nfs_shares" = { |
| 221 | + f = { |
| 222 | + user = "cinder"; |
| 223 | + group = "cinder"; |
| 224 | + mode = "0644"; |
| 225 | + argument = '' |
| 226 | + 10.0.0.20:/exports |
| 227 | + ''; |
| 228 | + }; |
| 229 | + }; |
| 230 | + }; |
163 | 231 | }; |
164 | 232 |
|
165 | 233 | # start iSCSI target daemon |
166 | 234 | # we expose LVM block storage as iSCSI to compute hosts |
167 | 235 | systemd.services.tgtd = { |
168 | | - enable = true; |
| 236 | + enable = if (cfg.backend == "lvm") then true else false; |
169 | 237 | description = "iSCSI target framework daemon"; |
170 | 238 | wantedBy = [ "multi-user.target" ]; |
171 | 239 | after = [ |
|
197 | 265 | }; |
198 | 266 | }; |
199 | 267 |
|
| 268 | + services.nfs.server.enable = if (cfg.backend == "lvm") then false else true; |
| 269 | + services.nfs.server.exports = '' |
| 270 | + /exports 10.0.0.0/24(rw,no_root_squash,insecure) |
| 271 | + ''; |
| 272 | + |
200 | 273 | systemd.services.cinder-volume-group-setup = { |
201 | 274 | description = "OpenStack Cinder volume group setup"; |
202 | 275 | wantedBy = [ "multi-user.target" ]; |
203 | | - path = [ |
204 | | - pkgs.lvm2 |
205 | | - pkgs.util-linux |
| 276 | + path = with pkgs; [ |
| 277 | + lvm2 |
| 278 | + util-linux |
| 279 | + e2fsprogs |
| 280 | + nfs-utils |
206 | 281 | ]; |
207 | 282 | serviceConfig = { |
208 | 283 | Type = "oneshot"; |
209 | | - ExecStart = pkgs.writeShellScript "cinder-volume-group.sh" '' |
210 | | - set -euxo pipefail |
| 284 | + ExecStart = |
| 285 | + if (cfg.backend == "lvm") then |
| 286 | + pkgs.writeShellScript "cinder-volume-group.sh" '' |
| 287 | + set -euxo pipefail |
211 | 288 |
|
212 | | - # create a new LVM volume group on second disk |
213 | | - pvcreate /dev/vdb |
214 | | - vgcreate cinder-volumes /dev/vdb |
215 | | - ''; |
| 289 | + # create a new LVM volume group on second disk |
| 290 | + pvcreate /dev/vdb |
| 291 | + vgcreate cinder-volumes /dev/vdb |
| 292 | + '' |
| 293 | + else |
| 294 | + pkgs.writeShellScript "cinder-volume-group.sh" '' |
| 295 | + set -euxo pipefail |
| 296 | +
|
| 297 | + # create a filesystem and mount and export it |
| 298 | + mkdir /exports |
| 299 | + mkfs.ext4 -F -m 0 /dev/vdb |
| 300 | + mount /dev/vdb /exports |
| 301 | + exportfs -rv |
| 302 | + ''; |
216 | 303 | }; |
217 | 304 | }; |
218 | 305 |
|
219 | 306 | # It seems regardless of what we do, the cinder-volume service does not |
220 | 307 | # find the qemu-img command it requires for non-raw images. As a |
221 | 308 | # workaround, add it as a systemPackage. |
222 | 309 | # Update: still does not work -.- |
223 | | - environment.systemPackages = [ |
224 | | - pkgs.qemu |
225 | | - pkgs.tgt |
226 | | - ]; |
| 310 | + |
| 311 | + environment.systemPackages = |
| 312 | + if (cfg.backend == "lvm") then |
| 313 | + with pkgs; |
| 314 | + [ |
| 315 | + qemu |
| 316 | + tgt |
| 317 | + ] |
| 318 | + else |
| 319 | + with pkgs; |
| 320 | + [ |
| 321 | + qemu |
| 322 | + nfs-utils |
| 323 | + e2fsprogs |
| 324 | + ]; |
227 | 325 |
|
228 | 326 | systemd.services.cinder-volume = { |
229 | 327 | description = "OpenStack Cinder Volume"; |
230 | 328 | after = [ |
231 | 329 | "cinder-volume-group-setup.service" |
232 | 330 | ]; |
233 | | - path = with pkgs; [ |
234 | | - cinder_env |
235 | | - lvm2 |
236 | | - tgt |
237 | | - qemu-utils |
238 | | - # sudo must be in the path and only sudo in /run/wrappers has the |
239 | | - # correct owner and rights |
240 | | - "/run/wrappers" |
241 | | - ]; |
| 331 | + path = |
| 332 | + if (cfg.backend == "lvm") then |
| 333 | + with pkgs; |
| 334 | + [ |
| 335 | + cinder_env |
| 336 | + lvm2 |
| 337 | + tgt |
| 338 | + qemu-utils |
| 339 | + # sudo must be in the path and only sudo in /run/wrappers has the |
| 340 | + # correct owner and rights |
| 341 | + "/run/wrappers" |
| 342 | + ] |
| 343 | + else |
| 344 | + with pkgs; |
| 345 | + [ |
| 346 | + cinder_env |
| 347 | + lvm2 |
| 348 | + qemu-utils |
| 349 | + # sudo must be in the path and only sudo in /run/wrappers has the |
| 350 | + # correct owner and rights |
| 351 | + "/run/wrappers" |
| 352 | + ]; |
| 353 | + |
242 | 354 | environment.PYTHONPATH = "${cinder_env}/${pkgs.python3.sitePackages}"; |
243 | 355 | wantedBy = [ "multi-user.target" ]; |
244 | 356 | serviceConfig = { |
|
0 commit comments