1# Module for Nova, a.k.a. OpenStack Compute.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8
9 cfg = config.virtualisation.nova;
10
11 nova = pkgs.nova;
12
13 novaConf = pkgs.writeText "nova.conf"
14 ''
15 --nodaemon
16 --verbose
17 ${cfg.extraConfig}
18 '';
19
20in
21
22{
23
24 ###### interface
25
26 options = {
27
28 virtualisation.nova.enableSingleNode =
29 mkOption {
30 default = false;
31 description =
32 ''
33 This option enables Nova, also known as OpenStack Compute,
34 a cloud computing system, as a single-machine
35 installation. That is, all of Nova's components are
36 enabled on this machine, using SQLite as Nova's database.
37 This is useful for evaluating and experimenting with Nova.
38 However, for a real cloud computing environment, you'll
39 want to enable some of Nova's services on other machines,
40 and use a database such as MySQL.
41 '';
42 };
43
44 virtualisation.nova.extraConfig =
45 mkOption {
46 default = "";
47 description =
48 ''
49 Additional text appended to <filename>nova.conf</filename>,
50 the main Nova configuration file.
51 '';
52 };
53
54 };
55
56
57 ###### implementation
58
59 config = mkIf cfg.enableSingleNode {
60
61 environment.systemPackages = [ nova pkgs.euca2ools pkgs.novaclient ];
62
63 environment.etc =
64 [ { source = novaConf;
65 target = "nova/nova.conf";
66 }
67 ];
68
69 # Nova requires libvirtd and RabbitMQ.
70 virtualisation.libvirtd.enable = true;
71 services.rabbitmq.enable = true;
72
73 # `qemu-nbd' required the `nbd' kernel module.
74 boot.kernelModules = [ "nbd" ];
75
76 system.activationScripts.nova =
77 ''
78 mkdir -m 755 -p /var/lib/nova
79 mkdir -m 755 -p /var/lib/nova/networks
80 mkdir -m 700 -p /var/lib/nova/instances
81 mkdir -m 700 -p /var/lib/nova/keys
82
83 # Allow the CA certificate generation script (called by
84 # nova-api) to work.
85 mkdir -m 700 -p /var/lib/nova/CA /var/lib/nova/CA/private
86
87 # Initialise the SQLite database.
88 ${nova}/bin/nova-manage db sync
89 '';
90
91 # `nova-api' receives and executes external client requests from
92 # tools such as euca2ools. It listens on port 8773 (XML) and 8774
93 # (JSON).
94 jobs.nova_api =
95 { name = "nova-api";
96
97 description = "Nova API service";
98
99 startOn = "ip-up";
100
101 # `openssl' is required to generate the CA. `openssh' is
102 # required to generate key pairs.
103 path = [ pkgs.openssl config.programs.ssh.package pkgs.bash ];
104
105 respawn = false;
106
107 exec = "${nova}/bin/nova-api --flagfile=${novaConf} --api_paste_config=${nova}/etc/nova/api-paste.ini";
108 };
109
110 # `nova-objectstore' is a simple image server. Useful if you're
111 # not running the OpenStack Imaging Service (Swift). It serves
112 # images placed in /var/lib/nova/images/.
113 jobs.nova_objectstore =
114 { name = "nova-objectstore";
115
116 description = "Nova Simple Object Store Service";
117
118 startOn = "ip-up";
119
120 preStart =
121 ''
122 mkdir -m 700 -p /var/lib/nova/images
123 '';
124
125 exec = "${nova}/bin/nova-objectstore --flagfile=${novaConf}";
126 };
127
128 # `nova-scheduler' schedules VM execution requests.
129 jobs.nova_scheduler =
130 { name = "nova-scheduler";
131
132 description = "Nova Scheduler Service";
133
134 startOn = "ip-up";
135
136 exec = "${nova}/bin/nova-scheduler --flagfile=${novaConf}";
137 };
138
139 # `nova-compute' starts and manages virtual machines.
140 jobs.nova_compute =
141 { name = "nova-compute";
142
143 description = "Nova Compute Service";
144
145 startOn = "ip-up";
146
147 path =
148 [ pkgs.sudo pkgs.vlan pkgs.nettools pkgs.iptables pkgs.qemu_kvm
149 pkgs.e2fsprogs pkgs.utillinux pkgs.multipath-tools pkgs.iproute
150 pkgs.bridge-utils
151 ];
152
153 exec = "${nova}/bin/nova-compute --flagfile=${novaConf}";
154 };
155
156 # `nova-network' manages networks and allocates IP addresses.
157 jobs.nova_network =
158 { name = "nova-network";
159
160 description = "Nova Network Service";
161
162 startOn = "ip-up";
163
164 path =
165 [ pkgs.sudo pkgs.vlan pkgs.dnsmasq pkgs.nettools pkgs.iptables
166 pkgs.iproute pkgs.bridge-utils pkgs.radvd
167 ];
168
169 exec = "${nova}/bin/nova-network --flagfile=${novaConf}";
170 };
171
172 };
173
174}