Statistics
| Branch: | Tag: | Revision:

root / doc / iallocator.rst @ 5e9bcdf4

History | View | Annotate | Download (13.5 kB)

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
  evac_nodes
172
    the names of the nodes to be evacuated
173

    
174
nodegroups
175
  a dictionary with the data for the cluster's node groups; it is keyed
176
  on the group UUID, and the values are a dictionary with the following
177
  keys:
178

    
179
  name
180
    the node group name
181
  alloc_policy
182
    the allocation policy of the node group (consult the semantics of
183
    this attribute in the :manpage:`gnt-group(8)` manpage)
184

    
185
instances
186
  a dictionary with the data for the current existing instance on the
187
  cluster, indexed by instance name; the contents are similar to the
188
  instance definitions for the allocate mode, with the addition of:
189

    
190
  admin_up
191
    if this instance is set to run (but not the actual status of the
192
    instance)
193

    
194
  nodes
195
    list of nodes on which this instance is placed; the primary node
196
    of the instance is always the first one
197

    
198
nodes
199
  dictionary with the data for the nodes in the cluster, indexed by
200
  the node name; the dict contains [*]_ :
201

    
202
  total_disk
203
    the total disk size of this node (mebibytes)
204

    
205
  free_disk
206
    the free disk space on the node
207

    
208
  total_memory
209
    the total memory size
210

    
211
  free_memory
212
    free memory on the node; note that currently this does not take
213
    into account the instances which are down on the node
214

    
215
  total_cpus
216
    the physical number of CPUs present on the machine; depending on
217
    the hypervisor, this might or might not be equal to how many CPUs
218
    the node operating system sees;
219

    
220
  primary_ip
221
    the primary IP address of the node
222

    
223
  secondary_ip
224
    the secondary IP address of the node (the one used for the DRBD
225
    replication); note that this can be the same as the primary one
226

    
227
  tags
228
    list with the tags of the node
229

    
230
  master_candidate:
231
    a boolean flag denoting whether this node is a master candidate
232

    
233
  drained:
234
    a boolean flag denoting whether this node is being drained
235

    
236
  offline:
237
    a boolean flag denoting whether this node is offline
238

    
239
  i_pri_memory:
240
    total memory required by primary instances
241

    
242
  i_pri_up_memory:
243
    total memory required by running primary instances
244

    
245
  group:
246
    the node group that this node belongs to
247

    
248
  No allocations should be made on nodes having either the ``drained``
249
  or ``offline`` flags set. More details about these of node status
250
  flags is available in the manpage :manpage:`ganeti(7)`.
251

    
252
.. [*] Note that no run-time data is present for offline, drained or
253
   non-vm_capable nodes; this means the tags total_memory,
254
   reserved_memory, free_memory, total_disk, free_disk, total_cpus,
255
   i_pri_memory and i_pri_up memory will be absent
256

    
257

    
258
Response message
259
~~~~~~~~~~~~~~~~
260

    
261
The response message is much more simple than the input one. It is
262
also a dict having three keys:
263

    
264
success
265
  a boolean value denoting if the allocation was successful or not
266

    
267
info
268
  a string with information from the scripts; if the allocation fails,
269
  this will be shown to the user
270

    
271
result
272
  the output of the algorithm; even if the algorithm failed
273
  (i.e. success is false), this must be returned as an empty list
274

    
275
  for allocate/relocate, this is the list of node(s) for the instance;
276
  note that the length of this list must equal the ``requested_nodes``
277
  entry in the input message, otherwise Ganeti will consider the result
278
  as failed
279

    
280
  for multi-evacuation mode, this is a list of lists; each element of
281
  the list is a list of instance name and the new secondary node
282

    
283
.. note:: Current Ganeti version accepts either ``result`` or ``nodes``
284
   as a backwards-compatibility measure (older versions only supported
285
   ``nodes``)
286

    
287
Examples
288
--------
289

    
290
Input messages to scripts
291
~~~~~~~~~~~~~~~~~~~~~~~~~
292

    
293
Input message, new instance allocation::
294

    
295
  {
296
    "cluster_tags": [],
297
    "request": {
298
      "required_nodes": 2,
299
      "name": "instance3.example.com",
300
      "tags": [
301
        "type:test",
302
        "owner:foo"
303
      ],
304
      "type": "allocate",
305
      "disks": [
306
        {
307
          "mode": "w",
308
          "size": 1024
309
        },
310
        {
311
          "mode": "w",
312
          "size": 2048
313
        }
314
      ],
315
      "nics": [
316
        {
317
          "ip": null,
318
          "mac": "00:11:22:33:44:55",
319
          "bridge": null
320
        }
321
      ],
322
      "vcpus": 1,
323
      "disk_template": "drbd",
324
      "memory": 2048,
325
      "disk_space_total": 3328,
326
      "os": "debootstrap+default"
327
    },
328
    "cluster_name": "cluster1.example.com",
329
    "instances": {
330
      "instance1.example.com": {
331
        "tags": [],
332
        "should_run": false,
333
        "disks": [
334
          {
335
            "mode": "w",
336
            "size": 64
337
          },
338
          {
339
            "mode": "w",
340
            "size": 512
341
          }
342
        ],
343
        "nics": [
344
          {
345
            "ip": null,
346
            "mac": "aa:00:00:00:60:bf",
347
            "bridge": "xen-br0"
348
          }
349
        ],
350
        "vcpus": 1,
351
        "disk_template": "plain",
352
        "memory": 128,
353
        "nodes": [
354
          "nodee1.com"
355
        ],
356
        "os": "debootstrap+default"
357
      },
358
      "instance2.example.com": {
359
        "tags": [],
360
        "should_run": false,
361
        "disks": [
362
          {
363
            "mode": "w",
364
            "size": 512
365
          },
366
          {
367
            "mode": "w",
368
            "size": 256
369
          }
370
        ],
371
        "nics": [
372
          {
373
            "ip": null,
374
            "mac": "aa:00:00:55:f8:38",
375
            "bridge": "xen-br0"
376
          }
377
        ],
378
        "vcpus": 1,
379
        "disk_template": "drbd",
380
        "memory": 512,
381
        "nodes": [
382
          "node2.example.com",
383
          "node3.example.com"
384
        ],
385
        "os": "debootstrap+default"
386
      }
387
    },
388
    "version": 1,
389
    "nodes": {
390
      "node1.example.com": {
391
        "total_disk": 858276,
392
        "primary_ip": "198.51.100.1",
393
        "secondary_ip": "192.0.2.1",
394
        "tags": [],
395
        "free_memory": 3505,
396
        "free_disk": 856740,
397
        "total_memory": 4095
398
      },
399
      "node2.example.com": {
400
        "total_disk": 858240,
401
        "primary_ip": "198.51.100.2",
402
        "secondary_ip": "192.0.2.2",
403
        "tags": ["test"],
404
        "free_memory": 3505,
405
        "free_disk": 848320,
406
        "total_memory": 4095
407
      },
408
      "node3.example.com.com": {
409
        "total_disk": 572184,
410
        "primary_ip": "198.51.100.3",
411
        "secondary_ip": "192.0.2.3",
412
        "tags": [],
413
        "free_memory": 3505,
414
        "free_disk": 570648,
415
        "total_memory": 4095
416
      }
417
    }
418
  }
419

    
420
Input message, reallocation. Since only the request entry in the input
421
message is changed, we show only this changed entry::
422

    
423
  "request": {
424
    "relocate_from": [
425
      "node3.example.com"
426
    ],
427
    "required_nodes": 1,
428
    "type": "relocate",
429
    "name": "instance2.example.com",
430
    "disk_space_total": 832
431
  },
432

    
433

    
434
Input message, node evacuation::
435

    
436
  "request": {
437
    "evac_nodes": [
438
      "node2"
439
    ],
440
    "type": "multi-evacuate"
441
  },
442

    
443

    
444
Response messages
445
~~~~~~~~~~~~~~~~~
446
Successful response message::
447

    
448
  {
449
    "info": "Allocation successful",
450
    "result": [
451
      "node2.example.com",
452
      "node1.example.com"
453
    ],
454
    "success": true
455
  }
456

    
457
Failed response message::
458

    
459
  {
460
    "info": "Can't find a suitable node for position 2 (already selected: node2.example.com)",
461
    "result": [],
462
    "success": false
463
  }
464

    
465
Successful node evacuation message::
466

    
467
  {
468
    "info": "Request successful",
469
    "result": [
470
      [
471
        "instance1",
472
        "node3"
473
      ],
474
      [
475
        "instance2",
476
        "node1"
477
      ]
478
    ],
479
    "success": true
480
  }
481

    
482

    
483
Command line messages
484
~~~~~~~~~~~~~~~~~~~~~
485
::
486

    
487
  # gnt-instance add -t plain -m 2g --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance3
488
  Selected nodes for the instance: node1.example.com
489
  * creating instance disks...
490
  [...]
491

    
492
  # gnt-instance add -t plain -m 3400m --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance4
493
  Failure: prerequisites not met for this operation:
494
  Can't compute nodes using iallocator 'hail': Can't find a suitable node for position 1 (already selected: )
495

    
496
  # gnt-instance add -t drbd -m 1400m --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance5
497
  Failure: prerequisites not met for this operation:
498
  Can't compute nodes using iallocator 'hail': Can't find a suitable node for position 2 (already selected: node1.example.com)
499

    
500
Reference implementation
501
~~~~~~~~~~~~~~~~~~~~~~~~
502

    
503
Ganeti's default iallocator is "hail" which is part of the separate
504
ganeti-htools project. In order to see its source code please clone
505
``git://git.ganeti.org/htools.git``. Note that htools is implemented
506
using the Haskell programming language.
507

    
508
.. vim: set textwidth=72 :
509
.. Local Variables:
510
.. mode: rst
511
.. fill-column: 72
512
.. End: