Skip to content

Commit 0f9d5c2

Browse files
committed
feat: add nfs cinder configuration
Signed-off-by: Paul Kroeher <paul.kroeher@cyberus-technology.de> On-behalf-of: SAP paul.kroeher@sap.com
1 parent 8e0cfc7 commit 0f9d5c2

2 files changed

Lines changed: 153 additions & 37 deletions

File tree

modules/compute/nova.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ in
198198
name = "iqn.iscsi.${config.networking.hostName}";
199199
};
200200

201-
environment.systemPackages = [ pkgs.openiscsi ];
201+
environment.systemPackages = with pkgs; [
202+
openiscsi
203+
nfs-utils
204+
];
202205

203206
systemd.services.nova-compute = {
204207
description = "OpenStack Nova Scheduler Daemon";
@@ -216,6 +219,7 @@ in
216219
util-linux
217220
lvm2
218221
openiscsi
222+
nfs-utils
219223
]
220224
++ cfg.extraPkgs;
221225
environment.PYTHONPATH = "${nova_env}/${pkgs.python3.sitePackages}";

modules/storage/cinder-storage-node.nix

Lines changed: 148 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let
3333
inherit utils_env;
3434
};
3535

36-
cinderConf = pkgs.writeText "cinder.conf" ''
36+
cinderConfLvm = pkgs.writeText "cinder.conf" ''
3737
[DEFAULT]
3838
transport_url = rabbit://openstack:openstack@controller
3939
auth_strategy = keystone
@@ -78,6 +78,42 @@ let
7878
iscsi_target_prefix = iqn.2010-10.org.openstack:
7979
'';
8080

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+
81117
cinderTgtConf = pkgs.writeText "cinder.conf" ''
82118
include /var/lib/cinder/volumes/*
83119
'';
@@ -92,7 +128,7 @@ in
92128
default = true;
93129
};
94130
config = mkOption {
95-
default = cinderConf;
131+
default = if (cfg.backend == "lvm") then cinderConfLvm else cinderConfNfs;
96132
description = ''
97133
The Cinder config.
98134
'';
@@ -104,6 +140,19 @@ in
104140
The OpenStack Cinder package to use.
105141
'';
106142
};
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+
};
107156
};
108157

109158
config = mkIf cfg.enable {
@@ -146,26 +195,45 @@ in
146195
};
147196
"/etc/cinder/cinder.conf" = {
148197
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}";
160199
};
161200
};
162201
};
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+
};
163231
};
164232

165233
# start iSCSI target daemon
166234
# we expose LVM block storage as iSCSI to compute hosts
167235
systemd.services.tgtd = {
168-
enable = true;
236+
enable = if (cfg.backend == "lvm") then true else false;
169237
description = "iSCSI target framework daemon";
170238
wantedBy = [ "multi-user.target" ];
171239
after = [
@@ -197,48 +265,92 @@ in
197265
};
198266
};
199267

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+
200273
systemd.services.cinder-volume-group-setup = {
201274
description = "OpenStack Cinder volume group setup";
202275
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
206281
];
207282
serviceConfig = {
208283
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
211288
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+
'';
216303
};
217304
};
218305

219306
# It seems regardless of what we do, the cinder-volume service does not
220307
# find the qemu-img command it requires for non-raw images. As a
221308
# workaround, add it as a systemPackage.
222309
# 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+
];
227325

228326
systemd.services.cinder-volume = {
229327
description = "OpenStack Cinder Volume";
230328
after = [
231329
"cinder-volume-group-setup.service"
232330
];
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+
242354
environment.PYTHONPATH = "${cinder_env}/${pkgs.python3.sitePackages}";
243355
wantedBy = [ "multi-user.target" ];
244356
serviceConfig = {

0 commit comments

Comments
 (0)