Update manpages and other documents with editor settings
[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 all the required information to perform the operation. We explain the
72 contents of this dictionary in two parts: common information that every
73 type of operation requires, and operation-specific information.
74
75 Common information
76 ++++++++++++++++++
77
78 All input dictionaries to the IAllocator must carry the following keys:
79
80 version
81   the version of the protocol; this document
82   specifies version 2
83
84 cluster_name
85   the cluster name
86
87 cluster_tags
88   the list of cluster tags
89
90 enabled_hypervisors
91   the list of enabled hypervisors
92
93 request
94   a dictionary containing the details of the request; the keys vary
95   depending on the type of operation that's being requested, as
96   explained in `Operation-specific input`_ below.
97
98 nodegroups
99   a dictionary with the data for the cluster's node groups; it is keyed
100   on the group UUID, and the values are a dictionary with the following
101   keys:
102
103   name
104     the node group name
105   alloc_policy
106     the allocation policy of the node group (consult the semantics of
107     this attribute in the :manpage:`gnt-group(8)` manpage)
108
109 instances
110   a dictionary with the data for the current existing instance on the
111   cluster, indexed by instance name; the contents are similar to the
112   instance definitions for the allocate mode, with the addition of:
113
114   admin_up
115     if this instance is set to run (but not the actual status of the
116     instance)
117
118   nodes
119     list of nodes on which this instance is placed; the primary node
120     of the instance is always the first one
121
122 nodes
123   dictionary with the data for the nodes in the cluster, indexed by
124   the node name; the dict contains [*]_ :
125
126   total_disk
127     the total disk size of this node (mebibytes)
128
129   free_disk
130     the free disk space on the node
131
132   total_memory
133     the total memory size
134
135   free_memory
136     free memory on the node; note that currently this does not take
137     into account the instances which are down on the node
138
139   total_cpus
140     the physical number of CPUs present on the machine; depending on
141     the hypervisor, this might or might not be equal to how many CPUs
142     the node operating system sees;
143
144   primary_ip
145     the primary IP address of the node
146
147   secondary_ip
148     the secondary IP address of the node (the one used for the DRBD
149     replication); note that this can be the same as the primary one
150
151   tags
152     list with the tags of the node
153
154   master_candidate:
155     a boolean flag denoting whether this node is a master candidate
156
157   drained:
158     a boolean flag denoting whether this node is being drained
159
160   offline:
161     a boolean flag denoting whether this node is offline
162
163   i_pri_memory:
164     total memory required by primary instances
165
166   i_pri_up_memory:
167     total memory required by running primary instances
168
169   group:
170     the node group that this node belongs to
171
172   No allocations should be made on nodes having either the ``drained``
173   or ``offline`` flags set. More details about these of node status
174   flags is available in the manpage :manpage:`ganeti(7)`.
175
176 .. [*] Note that no run-time data is present for offline, drained or
177    non-vm_capable nodes; this means the tags total_memory,
178    reserved_memory, free_memory, total_disk, free_disk, total_cpus,
179    i_pri_memory and i_pri_up memory will be absent
180
181 Operation-specific input
182 ++++++++++++++++++++++++
183
184 All input dictionaries to the IAllocator carry, in the ``request``
185 dictionary, detailed information about the operation that's being
186 requested. The required keys vary depending on the type of operation, as
187 follows.
188
189 In all cases, it includes:
190
191   type
192     the request type; this can be either ``allocate``, ``relocate``,
193     ``multi-relocate`` or ``multi-evacuate``. The ``allocate`` request
194     is used when a new instance needs to be placed on the cluster. The
195     ``relocate`` request is used when an existing instance needs to be
196     moved within its node group, while the ``multi-relocate`` one is
197     able to relocate multiple instances across multiple node groups. The
198     ``multi-evacuate`` protocol requests that the script computes the
199     optimal relocate solution for all secondary instances of the given
200     nodes.
201
202 For both allocate and relocate mode, the following extra keys are needed
203 in the ``request`` dictionary:
204
205   name
206     the name of the instance; if the request is a realocation, then this
207     name will be found in the list of instances (see below), otherwise
208     is the FQDN of the new instance
209
210   required_nodes
211     how many nodes should the algorithm return; while this information
212     can be deduced from the instace's disk template, it's better if
213     this computation is left to Ganeti as then allocator scripts are
214     less sensitive to changes to the disk templates
215
216   disk_space_total
217     the total disk space that will be used by this instance on the
218     (new) nodes; again, this information can be computed from the list
219     of instance disks and its template type, but Ganeti is better
220     suited to compute it
221
222 Allocation needs, in addition:
223
224   disks
225     list of dictionaries holding the disk definitions for this
226     instance (in the order they are exported to the hypervisor):
227
228     mode
229       either ``r`` or ``w`` denoting if the disk is read-only or
230       writable
231
232     size
233       the size of this disk in mebibytes
234
235   nics
236     a list of dictionaries holding the network interfaces for this
237     instance, containing:
238
239     ip
240       the IP address that Ganeti know for this instance, or null
241
242     mac
243       the MAC address for this interface
244
245     bridge
246       the bridge to which this interface will be connected
247
248   vcpus
249     the number of VCPUs for the instance
250
251   disk_template
252     the disk template for the instance
253
254   memory
255    the memory size for the instance
256
257   os
258    the OS type for the instance
259
260   tags
261     the list of the instance's tags
262
263   hypervisor
264     the hypervisor of this instance
265
266 Relocation:
267
268   relocate_from
269      a list of nodes to move the instance away from (note that with
270      Ganeti 2.0, this list will always contain a single node, the
271      current secondary of the instance)
272
273 As for ``multi-relocate``, it needs the three following request
274 arguments:
275
276   instances
277     a list of instance names to relocate
278
279   reloc_mode
280     a string indicating the relocation mode; there are three possible
281     values for this string: *keep_group*, *change_group*, and
282     *any_group*, the semantics or which are explained in :ref:`the
283     design doc <multi-reloc-detailed-design>`
284
285   target_groups
286     this argument is only accepted when ``reloc_mode``, as explained
287     above, is *change_group*; if present, it must either be the empty
288     list, or contain a list of group UUIDs that should be considered for
289     relocating instances to
290
291 Finally, in the case of multi-evacuate, there's one single request
292 argument (in addition to ``type``):
293
294   evac_nodes
295     the names of the nodes to be evacuated
296
297 Response message
298 ~~~~~~~~~~~~~~~~
299
300 The response message is much more simple than the input one. It is
301 also a dict having three keys:
302
303 success
304   a boolean value denoting if the allocation was successful or not
305
306 info
307   a string with information from the scripts; if the allocation fails,
308   this will be shown to the user
309
310 result
311   the output of the algorithm; even if the algorithm failed
312   (i.e. success is false), this must be returned as an empty list
313
314   for allocate/relocate, this is the list of node(s) for the instance;
315   note that the length of this list must equal the ``requested_nodes``
316   entry in the input message, otherwise Ganeti will consider the result
317   as failed
318
319   for multi-relocate mode, this is a list of 2-tuples in which the first
320   element of the tuple will be an instance name, and the second element
321   a list of operations to perform in order to relocate the instance
322
323   for multi-evacuation mode, this is a list of lists; each element of
324   the list is a list of instance name and the new secondary node
325
326 .. note:: Current Ganeti version accepts either ``result`` or ``nodes``
327    as a backwards-compatibility measure (older versions only supported
328    ``nodes``)
329
330 Examples
331 --------
332
333 Input messages to scripts
334 ~~~~~~~~~~~~~~~~~~~~~~~~~
335
336 Input message, new instance allocation (common elements are listed this
337 time, but not included in further examples below)::
338
339   {
340     "version": 2,
341     "cluster_name": "cluster1.example.com",
342     "cluster_tags": [],
343     "enabled_hypervisors": [
344       "xen-pvm"
345     ],
346     "nodegroups": {
347       "f4e06e0d-528a-4963-a5ad-10f3e114232d": {
348         "name": "default",
349         "alloc_policy": "preferred"
350       }
351     },
352     "instances": {
353       "instance1.example.com": {
354         "tags": [],
355         "should_run": false,
356         "disks": [
357           {
358             "mode": "w",
359             "size": 64
360           },
361           {
362             "mode": "w",
363             "size": 512
364           }
365         ],
366         "nics": [
367           {
368             "ip": null,
369             "mac": "aa:00:00:00:60:bf",
370             "bridge": "xen-br0"
371           }
372         ],
373         "vcpus": 1,
374         "disk_template": "plain",
375         "memory": 128,
376         "nodes": [
377           "nodee1.com"
378         ],
379         "os": "debootstrap+default"
380       },
381       "instance2.example.com": {
382         "tags": [],
383         "should_run": false,
384         "disks": [
385           {
386             "mode": "w",
387             "size": 512
388           },
389           {
390             "mode": "w",
391             "size": 256
392           }
393         ],
394         "nics": [
395           {
396             "ip": null,
397             "mac": "aa:00:00:55:f8:38",
398             "bridge": "xen-br0"
399           }
400         ],
401         "vcpus": 1,
402         "disk_template": "drbd",
403         "memory": 512,
404         "nodes": [
405           "node2.example.com",
406           "node3.example.com"
407         ],
408         "os": "debootstrap+default"
409       }
410     },
411     "nodes": {
412       "node1.example.com": {
413         "total_disk": 858276,
414         "primary_ip": "198.51.100.1",
415         "secondary_ip": "192.0.2.1",
416         "tags": [],
417         "group": "f4e06e0d-528a-4963-a5ad-10f3e114232d",
418         "free_memory": 3505,
419         "free_disk": 856740,
420         "total_memory": 4095
421       },
422       "node2.example.com": {
423         "total_disk": 858240,
424         "primary_ip": "198.51.100.2",
425         "secondary_ip": "192.0.2.2",
426         "tags": ["test"],
427         "group": "f4e06e0d-528a-4963-a5ad-10f3e114232d",
428         "free_memory": 3505,
429         "free_disk": 848320,
430         "total_memory": 4095
431       },
432       "node3.example.com.com": {
433         "total_disk": 572184,
434         "primary_ip": "198.51.100.3",
435         "secondary_ip": "192.0.2.3",
436         "tags": [],
437         "group": "f4e06e0d-528a-4963-a5ad-10f3e114232d",
438         "free_memory": 3505,
439         "free_disk": 570648,
440         "total_memory": 4095
441       }
442     },
443     "request": {
444       "type": "allocate",
445       "name": "instance3.example.com",
446       "required_nodes": 2,
447       "disk_space_total": 3328,
448       "disks": [
449         {
450           "mode": "w",
451           "size": 1024
452         },
453         {
454           "mode": "w",
455           "size": 2048
456         }
457       ],
458       "nics": [
459         {
460           "ip": null,
461           "mac": "00:11:22:33:44:55",
462           "bridge": null
463         }
464       ],
465       "vcpus": 1,
466       "disk_template": "drbd",
467       "memory": 2048,
468       "os": "debootstrap+default",
469       "tags": [
470         "type:test",
471         "owner:foo"
472       ],
473       hypervisor: "xen-pvm"
474     }
475   }
476
477 Input message, reallocation::
478
479   {
480     "version": 2,
481     ...
482     "request": {
483       "type": "relocate",
484       "name": "instance2.example.com",
485       "required_nodes": 1,
486       "disk_space_total": 832,
487       "relocate_from": [
488         "node3.example.com"
489       ]
490     }
491   }
492
493 Input message, node evacuation::
494
495   {
496     "version": 2,
497     ...
498     "request": {
499       "type": "multi-evacuate",
500       "evac_nodes": [
501         "node2"
502       ],
503     }
504   }
505
506
507 Response messages
508 ~~~~~~~~~~~~~~~~~
509 Successful response message::
510
511   {
512     "success": true,
513     "info": "Allocation successful",
514     "result": [
515       "node2.example.com",
516       "node1.example.com"
517     ]
518   }
519
520 Failed response message::
521
522   {
523     "success": false,
524     "info": "Can't find a suitable node for position 2 (already selected: node2.example.com)",
525     "result": []
526   }
527
528 Successful node evacuation message::
529
530   {
531     "success": true,
532     "info": "Request successful",
533     "result": [
534       [
535         "instance1",
536         "node3"
537       ],
538       [
539         "instance2",
540         "node1"
541       ]
542     ]
543   }
544
545
546 Command line messages
547 ~~~~~~~~~~~~~~~~~~~~~
548 ::
549
550   # gnt-instance add -t plain -m 2g --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance3
551   Selected nodes for the instance: node1.example.com
552   * creating instance disks...
553   [...]
554
555   # gnt-instance add -t plain -m 3400m --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance4
556   Failure: prerequisites not met for this operation:
557   Can't compute nodes using iallocator 'hail': Can't find a suitable node for position 1 (already selected: )
558
559   # gnt-instance add -t drbd -m 1400m --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance5
560   Failure: prerequisites not met for this operation:
561   Can't compute nodes using iallocator 'hail': Can't find a suitable node for position 2 (already selected: node1.example.com)
562
563 Reference implementation
564 ~~~~~~~~~~~~~~~~~~~~~~~~
565
566 Ganeti's default iallocator is "hail" which is available when "htools"
567 components have been enabled at build time (see :doc:`install-quick` for
568 more details).
569
570 .. vim: set textwidth=72 :
571 .. Local Variables:
572 .. mode: rst
573 .. fill-column: 72
574 .. End: