-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathopenstack-controller.nix
More file actions
284 lines (268 loc) · 10.4 KB
/
openstack-controller.nix
File metadata and controls
284 lines (268 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
{
nova,
neutron,
keystone,
glance,
placement,
horizon,
cinder,
barbican,
}:
{
config,
pkgs,
...
}:
let
adminEnv = {
OS_USERNAME = "admin";
OS_PASSWORD = "admin";
OS_PROJECT_NAME = "admin";
OS_USER_DOMAIN_NAME = "Default";
OS_PROJECT_DOMAIN_NAME = "Default";
OS_AUTH_URL = "http://controller:5000/v3";
OS_IDENTITY_API_VERSION = "3";
};
in
{
imports = [
./generic.nix
../generic/controller-host-entry.nix
(import ./keystone.nix { inherit keystone; })
(import ./glance.nix { inherit glance; })
(import ./placement.nix { inherit placement; })
(import ./nova.nix { inherit nova; })
(import ./neutron.nix { inherit neutron; })
(import ./horizon.nix { inherit horizon; })
(import ./cinder.nix { inherit cinder; }) # only cinder management component
(import ./barbican.nix { inherit barbican; }) # only cinder management component
];
config = {
systemd.services.database-setup = {
description = "OpenStack Database setup";
after = [
"mysql.service"
"network.target"
"uwsgi.service"
];
wantedBy = [ "multi-user.target" ];
path = [ pkgs.mariadb ];
serviceConfig = {
Type = "oneshot";
ExecStart = pkgs.writeShellScript "database-setup.sh" ''
# Keystone
mysql -N -e "drop database keystone;" || true
mysql -N -e "create database keystone;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'keystone';"
mysql -N -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'keystone';"
# Glance
mysql -N -e "drop database glance;" || true
mysql -N -e "create database glance;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';"
mysql -N -e "GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';"
# Cinder
mysql -N -e "drop database cinder;" || true
mysql -N -e "create database cinder;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'cinder';"
mysql -N -e "GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder';"
# barbican
mysql -N -e "drop database barbican;" || true
mysql -N -e "create database barbican;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON barbican.* TO 'barbican'@'localhost' IDENTIFIED BY 'barbican';"
mysql -N -e "GRANT ALL PRIVILEGES ON barbican.* TO 'barbican'@'%' IDENTIFIED BY 'barbican';"
# Placement
mysql -N -e "drop database placement;" || true
mysql -N -e "create database placement;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'localhost' IDENTIFIED BY 'placement';"
mysql -N -e "GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'%' IDENTIFIED BY 'placement';"
# Nova
mysql -N -e "drop database nova_api;" || true
mysql -N -e "drop database nova;" || true
mysql -N -e "drop database nova_cell0;" || true
mysql -N -e "create database nova_api;" || true
mysql -N -e "create database nova;" || true
mysql -N -e "create database nova_cell0;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';"
mysql -N -e "GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'nova';"
mysql -N -e "GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';"
mysql -N -e "GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'nova';"
mysql -N -e "GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';"
mysql -N -e "GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'nova';"
# Neutron
mysql -N -e "drop database neutron;" || true
mysql -N -e "create database neutron;" || true
mysql -N -e "GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'neutron';"
mysql -N -e "GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'neutron';"
'';
};
};
systemd.services.keystone-all = {
description = "OpenStack Keystone Daemon";
after = [ "database-setup.service" ];
path = [
keystone
pkgs.openstackclient
];
environment = adminEnv;
wantedBy = [ "multi-user.target" ];
preStart = ''
# Initialise the database
keystone-manage --config-file ${config.keystone.config} db_sync
# Set up the keystone's PKI infrastructure
keystone-manage --config-file ${config.keystone.config} fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage --config-file ${config.keystone.config} credential_setup --keystone-user keystone --keystone-group keystone
chown -R keystone:keystone /etc/keystone
chown -R keystone:keystone /var/log/keystone
'';
serviceConfig = {
PermissionsStartOnly = true;
User = "keystone";
Group = "keystone";
Type = "oneshot";
ExecStart = pkgs.writeShellScript "keystone-all.sh" ''
set -euxo pipefail
keystone-manage --config-file ${config.keystone.config} bootstrap \
--bootstrap-password admin\
--bootstrap-region-id RegionOne
openstack project create --domain default --description "Service Project" service
'';
};
};
systemd.services.glance = {
description = "OpenStack Glance setup";
after = [ "keystone-all.service" ];
wantedBy = [ "multi-user.target" ];
environment = adminEnv;
path = [
pkgs.openstackclient
glance
];
serviceConfig = {
Type = "oneshot";
User = "glance";
Group = "glance";
ExecStart = pkgs.writeShellScript "glance.sh" ''
set -euxo pipefail
openstack user create --domain default --password glance glance
openstack role add --project service --user glance admin
openstack role add --user glance --user-domain default --system all reader
glance-manage --config-file ${config.glance.config} db_sync
'';
};
};
systemd.services.barbican = {
description = "OpenStack barbican setup";
after = [ "keystone-all.service" ];
wantedBy = [ "multi-user.target" ];
environment = adminEnv;
path = [
pkgs.openstackclient
barbican
];
serviceConfig = {
Type = "oneshot";
User = "barbican";
Group = "barbican";
ExecStart = pkgs.writeShellScript "barbican.sh" ''
set -euxo pipefail
openstack user create --domain default --password barbican barbican
openstack role add --project service --user barbican admin
openstack role add --user barbican --user-domain default --system all reader
barbican-manage --config-file ${config.barbican.config} db upgrade
barbican-manage --config-file ${config.barbican.config} db sync_secret_stores
'';
};
};
systemd.services.cinder = {
description = "OpenStack Cinder setup";
after = [ "keystone-all.service" ];
wantedBy = [ "multi-user.target" ];
environment = adminEnv;
path = [
pkgs.openstackclient
cinder
];
serviceConfig = {
Type = "oneshot";
User = "cinder";
Group = "cinder";
ExecStart = pkgs.writeShellScript "cinder.sh" ''
set -euxo pipefail
openstack user create --domain default --password cinder cinder || true
openstack role add --project service --user cinder admin || true
openstack role add --user cinder --user-domain default --system all reader || true
cinder-manage --config-file ${config.cinder.config} db sync
'';
};
};
# Placement service can be tested by executing
# curl http://controller:8778
# and receive some json with version info as result.
systemd.services.placement = {
description = "OpenStack Placement setup";
after = [ "glance.service" ];
requiredBy = [ "multi-user.target" ];
environment = adminEnv;
path = [
pkgs.openstackclient
placement
];
serviceConfig = {
Type = "oneshot";
User = "placement";
Group = "placement";
ExecStart = pkgs.writeShellScript "placement.sh" ''
set -euxo pipefail
openstack user create --domain default --password placement placement
openstack role add --project service --user placement admin
placement-manage --config-file ${config.placement.config} db sync
'';
};
};
systemd.services.nova = {
description = "OpenStack Nova setup";
after = [ "neutron.service" ];
wantedBy = [ "multi-user.target" ];
environment = adminEnv;
path = [
pkgs.openstackclient
nova
];
serviceConfig = {
Type = "oneshot";
User = "nova";
Group = "nova";
ExecStart = pkgs.writeShellScript "nova.sh" ''
set -euxo pipefail
openstack user create --domain default --password nova nova
openstack role add --project service --user nova admin
nova-manage --config-file ${config.nova.config} api_db sync
nova-manage --config-file ${config.nova.config} cell_v2 map_cell0
nova-manage --config-file ${config.nova.config} cell_v2 create_cell --name=cell1 --verbose
nova-manage --config-file ${config.nova.config} db sync
'';
};
};
systemd.services.neutron = {
description = "OpenStack Neutron setup";
after = [ "placement.service" ];
wantedBy = [ "multi-user.target" ];
environment = adminEnv;
path = [
pkgs.openstackclient
neutron
];
serviceConfig = {
Type = "oneshot";
User = "neutron";
Group = "neutron";
ExecStart = pkgs.writeShellScript "neutron.sh" ''
set -euxo pipefail
openstack user create --domain default --password neutron neutron
openstack role add --project service --user neutron admin
neutron-db-manage --config-file ${config.neutron.config} --config-file ${config.neutron.ml2Config} upgrade head
'';
};
};
};
}