|
| 1 | +{ |
| 2 | + cinder, |
| 3 | +}: |
| 4 | +{ |
| 5 | + config, |
| 6 | + pkgs, |
| 7 | + lib, |
| 8 | + ... |
| 9 | +}: |
| 10 | +with lib; |
| 11 | +let |
| 12 | + # adminEnv = { |
| 13 | + # OS_USERNAME = "admin"; |
| 14 | + # OS_PASSWORD = "admin"; |
| 15 | + # OS_PROJECT_NAME = "admin"; |
| 16 | + # OS_USER_DOMAIN_NAME = "Default"; |
| 17 | + # OS_PROJECT_DOMAIN_NAME = "Default"; |
| 18 | + # OS_AUTH_URL = "http://controller:5000/v3"; |
| 19 | + # OS_IDENTITY_API_VERSION = "3"; |
| 20 | + # }; |
| 21 | + cfg = config.cinder-storage-node; |
| 22 | + |
| 23 | + cinder_env = pkgs.python3.buildEnv.override { |
| 24 | + extraLibs = [ |
| 25 | + cfg.cinderPackage |
| 26 | + pkgs.qemu |
| 27 | + ]; |
| 28 | + }; |
| 29 | + |
| 30 | + utils_env = pkgs.buildEnv { |
| 31 | + name = "utils"; |
| 32 | + paths = [ |
| 33 | + cinder_env |
| 34 | + pkgs.qemu |
| 35 | + ]; |
| 36 | + }; |
| 37 | + |
| 38 | + rootwrapConf = pkgs.callPackage ../../lib/rootwrap-conf.nix { |
| 39 | + package = cinder_env; |
| 40 | + filterPath = "/etc/cinder/rootwrap.d"; |
| 41 | + inherit utils_env; |
| 42 | + }; |
| 43 | + |
| 44 | + cinderConf = pkgs.writeText "cinder.conf" '' |
| 45 | + [DEFAULT] |
| 46 | + transport_url = rabbit://openstack:openstack@controller |
| 47 | + auth_strategy = keystone |
| 48 | + my_ip = controller |
| 49 | + enabled_backends = lvm |
| 50 | + volumes_dir = /var/lib/cinder/volumes |
| 51 | + state_path = /var/lib/cinder |
| 52 | + rootwrap_config = ${rootwrapConf} |
| 53 | + glance_api_servers = http://controller:9292 |
| 54 | +
|
| 55 | + [database] |
| 56 | + connection = mysql+pymysql://cinder:cinder@controller/cinder |
| 57 | +
|
| 58 | + [keystone_authtoken] |
| 59 | + www_authenticate_uri = http://controller:5000 |
| 60 | + auth_url = http://controller:5000 |
| 61 | + memcached_servers = controller:11211 |
| 62 | + auth_type = password |
| 63 | + project_domain_name = default |
| 64 | + user_domain_name = default |
| 65 | + project_name = service |
| 66 | + username = cinder |
| 67 | + password = cinder |
| 68 | +
|
| 69 | + [oslo_concurrency] |
| 70 | + lock_path = /var/lib/cinder/tmp |
| 71 | +
|
| 72 | + [lvm] |
| 73 | + volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver |
| 74 | + volume_group = cinder-volumes |
| 75 | + volume_backend_name = lvm |
| 76 | + lvm_type = default |
| 77 | + ''; |
| 78 | +in |
| 79 | +{ |
| 80 | + imports = [ |
| 81 | + ../generic/controller-host-entry.nix |
| 82 | + ]; |
| 83 | + |
| 84 | + options.cinder-storage-node = { |
| 85 | + enable = mkEnableOption "Enable OpenStack Cinder storage node." // { |
| 86 | + default = true; |
| 87 | + }; |
| 88 | + config = mkOption { |
| 89 | + default = cinderConf; |
| 90 | + description = '' |
| 91 | + The Cinder config. |
| 92 | + ''; |
| 93 | + }; |
| 94 | + cinderPackage = mkOption { |
| 95 | + default = cinder; |
| 96 | + type = types.package; |
| 97 | + description = '' |
| 98 | + The OpenStack Cinder package to use. |
| 99 | + ''; |
| 100 | + }; |
| 101 | + }; |
| 102 | + |
| 103 | + config = mkIf cfg.enable { |
| 104 | + users.extraUsers.cinder = { |
| 105 | + group = "cinder"; |
| 106 | + isSystemUser = true; |
| 107 | + }; |
| 108 | + users.groups.cinder = { |
| 109 | + name = "cinder"; |
| 110 | + members = [ "cinder" ]; |
| 111 | + }; |
| 112 | + |
| 113 | + security.sudo.enable = true; |
| 114 | + security.sudo.extraConfig = '' |
| 115 | + cinder ALL = (root) NOPASSWD: ${cinder_env}/bin/cinder-rootwrap ${rootwrapConf} * |
| 116 | + ''; |
| 117 | + |
| 118 | + systemd.tmpfiles.settings = { |
| 119 | + "20-cinder" = { |
| 120 | + "/var/lib/cinder/" = { |
| 121 | + D = { |
| 122 | + user = "cinder"; |
| 123 | + group = "cinder"; |
| 124 | + mode = "0755"; |
| 125 | + }; |
| 126 | + }; |
| 127 | + "/var/lib/cinder/volumes" = { |
| 128 | + D = { |
| 129 | + user = "cinder"; |
| 130 | + group = "cinder"; |
| 131 | + mode = "0755"; |
| 132 | + }; |
| 133 | + }; |
| 134 | + "/var/log/cinder/" = { |
| 135 | + D = { |
| 136 | + user = "cinder"; |
| 137 | + group = "cinder"; |
| 138 | + mode = "0755"; |
| 139 | + }; |
| 140 | + }; |
| 141 | + }; |
| 142 | + }; |
| 143 | + |
| 144 | + systemd.services.cinder-volume-group = { |
| 145 | + description = "OpenStack Cinder volume group setup"; |
| 146 | + wantedBy = [ "multi-user.target" ]; |
| 147 | + path = [ |
| 148 | + pkgs.lvm2 |
| 149 | + pkgs.util-linux |
| 150 | + ]; |
| 151 | + serviceConfig = { |
| 152 | + Type = "oneshot"; |
| 153 | + ExecStart = pkgs.writeShellScript "cinder-volume-group.sh" '' |
| 154 | + set -euxo pipefail |
| 155 | +
|
| 156 | + # Setup some lvm volume group required by cinder |
| 157 | + dd if=/dev/zero of=/tmp/cinder-volumes bs=1G count=2 |
| 158 | +
|
| 159 | + losetup /dev/loop0 /tmp/cinder-volumes |
| 160 | +
|
| 161 | + # Create physical volume and volume group |
| 162 | + pvcreate /dev/loop0 |
| 163 | + vgcreate cinder-volumes /dev/loop0 |
| 164 | + ''; |
| 165 | + }; |
| 166 | + }; |
| 167 | + |
| 168 | + # It seems regardless of what we do, the cinder-volume service does not |
| 169 | + # find the qemu-img command it requires for non-raw images. As a |
| 170 | + # workaround, add it as a systemPackage. |
| 171 | + # Update: still does not work -.- |
| 172 | + environment.systemPackages = [ |
| 173 | + pkgs.qemu |
| 174 | + ]; |
| 175 | + |
| 176 | + systemd.services.cinder-volume = { |
| 177 | + description = "OpenStack Cinder Volume"; |
| 178 | + after = [ |
| 179 | + "cinder-volume-group.service" |
| 180 | + ]; |
| 181 | + path = with pkgs; [ |
| 182 | + cinder_env |
| 183 | + lvm2 |
| 184 | + # sudo must be in the path and only sudo in /run/wrappers has the |
| 185 | + # correct owner and rights |
| 186 | + "/run/wrappers" |
| 187 | + ]; |
| 188 | + wantedBy = [ "multi-user.target" ]; |
| 189 | + serviceConfig = { |
| 190 | + User = "cinder"; |
| 191 | + Group = "cinder"; |
| 192 | + ExecStart = pkgs.writeShellScript "cinder-volume.sh" '' |
| 193 | + .cinder-volume-wrapped --config-file ${cfg.config} |
| 194 | + ''; |
| 195 | + # The volume service requires some cinder setup to be done already and |
| 196 | + # manifested in the DB. As the storage node might run on a different |
| 197 | + # node and we cannot simply wait for some other service to complete, we |
| 198 | + # add a retry mechanism with some sensible delay. |
| 199 | + Restart = "on-failure"; |
| 200 | + RestartSec = 20; |
| 201 | + }; |
| 202 | + }; |
| 203 | + }; |
| 204 | +} |
0 commit comments