Update the IAllocator documentation
[ganeti-local] / doc / iallocator.rst
1 Ganeti automatic instance allocation
2 ====================================
3
4 Documents Ganeti version 2.1
5
6 .. contents::
7
8 Introduction
9 ------------
10
11 Currently in Ganeti the admin has to specify the exact locations for
12 an instance's node(s). This prevents a completely automatic node
13 evacuation, and is in general a nuisance.
14
15 The *iallocator* framework will enable automatic placement via
16 external scripts, which allows customization of the cluster layout per
17 the site's requirements.
18
19 User-visible changes
20 ~~~~~~~~~~~~~~~~~~~~
21
22 There are two parts of the ganeti operation that are impacted by the
23 auto-allocation: how the cluster knows what the allocator algorithms
24 are and how the admin uses these in creating instances.
25
26 An allocation algorithm is just the filename of a program installed in
27 a defined list of directories.
28
29 Cluster configuration
30 ~~~~~~~~~~~~~~~~~~~~~
31
32 At configure time, the list of the directories can be selected via the
33 ``--with-iallocator-search-path=LIST`` option, where *LIST* is a
34 comma-separated list of directories. If not given, this defaults to
35 ``$libdir/ganeti/iallocators``, i.e. for an installation under
36 ``/usr``, this will be ``/usr/lib/ganeti/iallocators``.
37
38 Ganeti will then search for allocator script in the configured list,
39 using the first one whose filename matches the one given by the user.
40
41 Command line interface changes
42 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44 The node selection options in instanece add and instance replace disks
45 can be replace by the new ``--iallocator=NAME`` option (shortened to
46 ``-I``), which will cause the auto-assignement of nodes with the
47 passed iallocator. The selected node(s) will be show as part of the
48 command output.
49
50 IAllocator API
51 --------------
52
53 The protocol for communication between Ganeti and an allocator script
54 will be the following:
55
56 #. ganeti launches the program with a single argument, a filename that
57    contains a JSON-encoded structure (the input message)
58
59 #. if the script finishes with exit code different from zero, it is
60    considered a general failure and the full output will be reported to
61    the users; this can be the case when the allocator can't parse the
62    input message
63
64 #. if the allocator finishes with exit code zero, it is expected to
65    output (on its stdout) a JSON-encoded structure (the response)
66
67 Input message
68 ~~~~~~~~~~~~~
69
70 The input message will be the JSON encoding of a dictionary containing
71 the following:
72
73 version
74   the version of the protocol; this document
75   specifies version 2
76
77 cluster_name
78   the cluster name
79
80 cluster_tags
81   the list of cluster tags
82
83 enabled_hypervisors
84   the list of enabled hypervisors
85
86 request
87   a dictionary containing the request data:
88
89   type
90     the request type; this can be either ``allocate``, ``relocate`` or
91     ``multi-evacuate``; the ``allocate`` request is used when a new
92     instance needs to be placed on the cluster, while the ``relocate``
93     request is used when an existing instance needs to be moved within
94     the cluster; the ``multi-evacuate`` protocol requests that the
95     script computes the optimal relocate solution for all secondary
96     instances of the given nodes
97
98   The following keys are needed in allocate/relocate mode:
99
100   name
101     the name of the instance; if the request is a realocation, then this
102     name will be found in the list of instances (see below), otherwise
103     is the FQDN of the new instance
104
105   required_nodes
106     how many nodes should the algorithm return; while this information
107     can be deduced from the instace's disk template, it's better if
108     this computation is left to Ganeti as then allocator scripts are
109     less sensitive to changes to the disk templates
110
111   disk_space_total
112     the total disk space that will be used by this instance on the
113     (new) nodes; again, this information can be computed from the list
114     of instance disks and its template type, but Ganeti is better
115     suited to compute it
116
117   If the request is an allocation, then there are extra fields in the
118   request dictionary:
119
120   disks
121     list of dictionaries holding the disk definitions for this
122     instance (in the order they are exported to the hypervisor):
123
124     mode
125       either ``r`` or ``w`` denoting if the disk is read-only or
126       writable
127
128     size
129       the size of this disk in mebibytes
130
131   nics
132     a list of dictionaries holding the network interfaces for this
133     instance, containing:
134
135     ip
136       the IP address that Ganeti know for this instance, or null
137
138     mac
139       the MAC address for this interface
140
141     bridge
142       the bridge to which this interface will be connected
143
144   vcpus
145     the number of VCPUs for the instance
146
147   disk_template
148     the disk template for the instance
149
150   memory
151    the memory size for the instance
152
153   os
154    the OS type for the instance
155
156   tags
157     the list of the instance's tags
158
159   hypervisor
160     the hypervisor of this instance
161
162
163   If the request is of type relocate, then there is one more entry in
164   the request dictionary, named ``relocate_from``, and it contains a
165   list of nodes to move the instance away from; note that with Ganeti
166   2.0, this list will always contain a single node, the current
167   secondary of the instance.
168
169   The multi-evacuate mode has instead a single request argument:
170
171   nodes
172     the names of the nodes to be evacuated
173
174 instances
175   a dictionary with the data for the current existing instance on the
176   cluster, indexed by instance name; the contents are similar to the
177   instance definitions for the allocate mode, with the addition of:
178
179   admin_up
180     if this instance is set to run (but not the actual status of the
181     instance)
182
183   nodes
184     list of nodes on which this instance is placed; the primary node
185     of the instance is always the first one
186
187 nodes
188   dictionary with the data for the nodes in the cluster, indexed by
189   the node name; the dict contains [*]_ :
190
191   total_disk
192     the total disk size of this node (mebibytes)
193
194   free_disk
195     the free disk space on the node
196
197   total_memory
198     the total memory size
199
200   free_memory
201     free memory on the node; note that currently this does not take
202     into account the instances which are down on the node
203
204   total_cpus
205     the physical number of CPUs present on the machine; depending on
206     the hypervisor, this might or might not be equal to how many CPUs
207     the node operating system sees;
208
209   primary_ip
210     the primary IP address of the node
211
212   secondary_ip
213     the secondary IP address of the node (the one used for the DRBD
214     replication); note that this can be the same as the primary one
215
216   tags
217     list with the tags of the node
218
219   master_candidate:
220     a boolean flag denoting whether this node is a master candidate
221
222   drained:
223     a boolean flag denoting whether this node is being drained
224
225   offline:
226     a boolean flag denoting whether this node is offline
227
228   i_pri_memory:
229     total memory required by primary instances
230
231   i_pri_up_memory:
232     total memory required by running primary instances
233
234   No allocations should be made on nodes having either the ``drained``
235   or ``offline`` flags set. More details about these of node status
236   flags is available in the manpage :manpage:`ganeti(7)`.
237
238 .. [*] Note that no run-time data is present for offline or drained
239    nodes; this means the tags total_memory, reserved_memory,
240    free_memory, total_disk, free_disk, total_cpus, i_pri_memory and
241    i_pri_up memory will be absent
242
243
244 Response message
245 ~~~~~~~~~~~~~~~~
246
247 The response message is much more simple than the input one. It is
248 also a dict having three keys:
249
250 success
251   a boolean value denoting if the allocation was successful or not
252
253 info
254   a string with information from the scripts; if the allocation fails,
255   this will be shown to the user
256
257 result
258   the output of the algorithm; even if the algorithm failed
259   (i.e. success is false), this must be returned as an empty list
260
261   for allocate/relocate, this is the list of node(s) for the instance;
262   note that the length of this list must equal the ``requested_nodes``
263   entry in the input message, otherwise Ganeti will consider the result
264   as failed
265
266   for multi-evacuation mode, this is a list of lists; each element of
267   the list is a list of instance name and the new secondary node
268
269 .. note:: Current Ganeti version accepts either ``result`` or ``nodes``
270    as a backwards-compatibility measure (older versions only supported
271    ``nodes``)
272
273 Examples
274 --------
275
276 Input messages to scripts
277 ~~~~~~~~~~~~~~~~~~~~~~~~~
278
279 Input message, new instance allocation::
280
281   {
282     "cluster_tags": [],
283     "request": {
284       "required_nodes": 2,
285       "name": "instance3.example.com",
286       "tags": [
287         "type:test",
288         "owner:foo"
289       ],
290       "type": "allocate",
291       "disks": [
292         {
293           "mode": "w",
294           "size": 1024
295         },
296         {
297           "mode": "w",
298           "size": 2048
299         }
300       ],
301       "nics": [
302         {
303           "ip": null,
304           "mac": "00:11:22:33:44:55",
305           "bridge": null
306         }
307       ],
308       "vcpus": 1,
309       "disk_template": "drbd",
310       "memory": 2048,
311       "disk_space_total": 3328,
312       "os": "etch-image"
313     },
314     "cluster_name": "cluster1.example.com",
315     "instances": {
316       "instance1.example.com": {
317         "tags": [],
318         "should_run": false,
319         "disks": [
320           {
321             "mode": "w",
322             "size": 64
323           },
324           {
325             "mode": "w",
326             "size": 512
327           }
328         ],
329         "nics": [
330           {
331             "ip": null,
332             "mac": "aa:00:00:00:60:bf",
333             "bridge": "xen-br0"
334           }
335         ],
336         "vcpus": 1,
337         "disk_template": "plain",
338         "memory": 128,
339         "nodes": [
340           "nodee1.com"
341         ],
342         "os": "etch-image"
343       },
344       "instance2.example.com": {
345         "tags": [],
346         "should_run": false,
347         "disks": [
348           {
349             "mode": "w",
350             "size": 512
351           },
352           {
353             "mode": "w",
354             "size": 256
355           }
356         ],
357         "nics": [
358           {
359             "ip": null,
360             "mac": "aa:00:00:55:f8:38",
361             "bridge": "xen-br0"
362           }
363         ],
364         "vcpus": 1,
365         "disk_template": "drbd",
366         "memory": 512,
367         "nodes": [
368           "node2.example.com",
369           "node3.example.com"
370         ],
371         "os": "etch-image"
372       }
373     },
374     "version": 1,
375     "nodes": {
376       "node1.example.com": {
377         "total_disk": 858276,
378         "primary_ip": "192.168.1.1",
379         "secondary_ip": "192.168.2.1",
380         "tags": [],
381         "free_memory": 3505,
382         "free_disk": 856740,
383         "total_memory": 4095
384       },
385       "node2.example.com": {
386         "total_disk": 858240,
387         "primary_ip": "192.168.1.3",
388         "secondary_ip": "192.168.2.3",
389         "tags": ["test"],
390         "free_memory": 3505,
391         "free_disk": 848320,
392         "total_memory": 4095
393       },
394       "node3.example.com.com": {
395         "total_disk": 572184,
396         "primary_ip": "192.168.1.3",
397         "secondary_ip": "192.168.2.3",
398         "tags": [],
399         "free_memory": 3505,
400         "free_disk": 570648,
401         "total_memory": 4095
402       }
403     }
404   }
405
406 Input message, reallocation. Since only the request entry in the input
407 message is changed, we show only this changed entry::
408
409   "request": {
410     "relocate_from": [
411       "node3.example.com"
412     ],
413     "required_nodes": 1,
414     "type": "relocate",
415     "name": "instance2.example.com",
416     "disk_space_total": 832
417   },
418
419
420 Input message, node evacuation::
421
422   "request": {
423     "evac_nodes": [
424       "node2"
425     ],
426     "type": "multi-evacuate"
427   },
428
429
430 Response messages
431 ~~~~~~~~~~~~~~~~~
432 Successful response message::
433
434   {
435     "info": "Allocation successful",
436     "result": [
437       "node2.example.com",
438       "node1.example.com"
439     ],
440     "success": true
441   }
442
443 Failed response message::
444
445   {
446     "info": "Can't find a suitable node for position 2 (already selected: node2.example.com)",
447     "result": [],
448     "success": false
449   }
450
451 Successful node evacuation message::
452
453   {
454     "info": "Request successful",
455     "result": [
456       [
457         "instance1",
458         "node3"
459       ],
460       [
461         "instance2",
462         "node1"
463       ]
464     ],
465     "success": true
466   }
467
468
469 Command line messages
470 ~~~~~~~~~~~~~~~~~~~~~
471 ::
472
473   # gnt-instance add -t plain -m 2g --os-size 1g --swap-size 512m --iallocator dumb-allocator -o etch-image instance3
474   Selected nodes for the instance: node1.example.com
475   * creating instance disks...
476   [...]
477
478   # gnt-instance add -t plain -m 3400m --os-size 1g --swap-size 512m --iallocator dumb-allocator -o etch-image instance4
479   Failure: prerequisites not met for this operation:
480   Can't compute nodes using iallocator 'dumb-allocator': Can't find a suitable node for position 1 (already selected: )
481
482   # gnt-instance add -t drbd -m 1400m --os-size 1g --swap-size 512m --iallocator dumb-allocator -o etch-image instance5
483   Failure: prerequisites not met for this operation:
484   Can't compute nodes using iallocator 'dumb-allocator': Can't find a suitable node for position 2 (already selected: node1.example.com)
485
486 .. vim: set textwidth=72 :
487 .. Local Variables:
488 .. mode: rst
489 .. fill-column: 72
490 .. End: