Statistics
| Branch: | Tag: | Revision:

root / doc / iallocator.rst @ 61791108

History | View | Annotate | Download (14.6 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
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`` or
193
    ``multi-evacuate``; the ``allocate`` request is used when a new
194
    instance needs to be placed on the cluster, while the ``relocate``
195
    request is used when an existing instance needs to be moved within
196
    the cluster; the ``multi-evacuate`` protocol requests that the
197
    script computes the optimal relocate solution for all secondary
198
    instances of the given nodes
199

    
200
For both allocate and relocate mode, the following extra keys are needed
201
in the ``request`` dictionary:
202

    
203
  name
204
    the name of the instance; if the request is a realocation, then this
205
    name will be found in the list of instances (see below), otherwise
206
    is the FQDN of the new instance
207

    
208
  required_nodes
209
    how many nodes should the algorithm return; while this information
210
    can be deduced from the instace's disk template, it's better if
211
    this computation is left to Ganeti as then allocator scripts are
212
    less sensitive to changes to the disk templates
213

    
214
  disk_space_total
215
    the total disk space that will be used by this instance on the
216
    (new) nodes; again, this information can be computed from the list
217
    of instance disks and its template type, but Ganeti is better
218
    suited to compute it
219

    
220
Allocation needs, in addition:
221

    
222
  disks
223
    list of dictionaries holding the disk definitions for this
224
    instance (in the order they are exported to the hypervisor):
225

    
226
    mode
227
      either ``r`` or ``w`` denoting if the disk is read-only or
228
      writable
229

    
230
    size
231
      the size of this disk in mebibytes
232

    
233
  nics
234
    a list of dictionaries holding the network interfaces for this
235
    instance, containing:
236

    
237
    ip
238
      the IP address that Ganeti know for this instance, or null
239

    
240
    mac
241
      the MAC address for this interface
242

    
243
    bridge
244
      the bridge to which this interface will be connected
245

    
246
  vcpus
247
    the number of VCPUs for the instance
248

    
249
  disk_template
250
    the disk template for the instance
251

    
252
  memory
253
   the memory size for the instance
254

    
255
  os
256
   the OS type for the instance
257

    
258
  tags
259
    the list of the instance's tags
260

    
261
  hypervisor
262
    the hypervisor of this instance
263

    
264
Relocation:
265

    
266
  relocate_from
267
     a list of nodes to move the instance away from (note that with
268
     Ganeti 2.0, this list will always contain a single node, the
269
     current secondary of the instance)
270

    
271
In the case of multi-evacuate, there's one single request argument (in
272
addition to ``type``):
273

    
274
  evac_nodes
275
    the names of the nodes to be evacuated
276

    
277
Response message
278
~~~~~~~~~~~~~~~~
279

    
280
The response message is much more simple than the input one. It is
281
also a dict having three keys:
282

    
283
success
284
  a boolean value denoting if the allocation was successful or not
285

    
286
info
287
  a string with information from the scripts; if the allocation fails,
288
  this will be shown to the user
289

    
290
result
291
  the output of the algorithm; even if the algorithm failed
292
  (i.e. success is false), this must be returned as an empty list
293

    
294
  for allocate/relocate, this is the list of node(s) for the instance;
295
  note that the length of this list must equal the ``requested_nodes``
296
  entry in the input message, otherwise Ganeti will consider the result
297
  as failed
298

    
299
  for multi-evacuation mode, this is a list of lists; each element of
300
  the list is a list of instance name and the new secondary node
301

    
302
.. note:: Current Ganeti version accepts either ``result`` or ``nodes``
303
   as a backwards-compatibility measure (older versions only supported
304
   ``nodes``)
305

    
306
Examples
307
--------
308

    
309
Input messages to scripts
310
~~~~~~~~~~~~~~~~~~~~~~~~~
311

    
312
Input message, new instance allocation (common elements are listed this
313
time, but not included in further examples below)::
314

    
315
  {
316
    "version": 2,
317
    "cluster_name": "cluster1.example.com",
318
    "cluster_tags": [],
319
    "enabled_hypervisors": [
320
      "xen-pvm"
321
    ],
322
    "nodegroups": {
323
      "f4e06e0d-528a-4963-a5ad-10f3e114232d": {
324
        "name": "default",
325
        "alloc_policy": "preferred"
326
      }
327
    },
328
    "instances": {
329
      "instance1.example.com": {
330
        "tags": [],
331
        "should_run": false,
332
        "disks": [
333
          {
334
            "mode": "w",
335
            "size": 64
336
          },
337
          {
338
            "mode": "w",
339
            "size": 512
340
          }
341
        ],
342
        "nics": [
343
          {
344
            "ip": null,
345
            "mac": "aa:00:00:00:60:bf",
346
            "bridge": "xen-br0"
347
          }
348
        ],
349
        "vcpus": 1,
350
        "disk_template": "plain",
351
        "memory": 128,
352
        "nodes": [
353
          "nodee1.com"
354
        ],
355
        "os": "debootstrap+default"
356
      },
357
      "instance2.example.com": {
358
        "tags": [],
359
        "should_run": false,
360
        "disks": [
361
          {
362
            "mode": "w",
363
            "size": 512
364
          },
365
          {
366
            "mode": "w",
367
            "size": 256
368
          }
369
        ],
370
        "nics": [
371
          {
372
            "ip": null,
373
            "mac": "aa:00:00:55:f8:38",
374
            "bridge": "xen-br0"
375
          }
376
        ],
377
        "vcpus": 1,
378
        "disk_template": "drbd",
379
        "memory": 512,
380
        "nodes": [
381
          "node2.example.com",
382
          "node3.example.com"
383
        ],
384
        "os": "debootstrap+default"
385
      }
386
    },
387
    "nodes": {
388
      "node1.example.com": {
389
        "total_disk": 858276,
390
        "primary_ip": "198.51.100.1",
391
        "secondary_ip": "192.0.2.1",
392
        "tags": [],
393
        "group": "f4e06e0d-528a-4963-a5ad-10f3e114232d",
394
        "free_memory": 3505,
395
        "free_disk": 856740,
396
        "total_memory": 4095
397
      },
398
      "node2.example.com": {
399
        "total_disk": 858240,
400
        "primary_ip": "198.51.100.2",
401
        "secondary_ip": "192.0.2.2",
402
        "tags": ["test"],
403
        "group": "f4e06e0d-528a-4963-a5ad-10f3e114232d",
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
        "group": "f4e06e0d-528a-4963-a5ad-10f3e114232d",
414
        "free_memory": 3505,
415
        "free_disk": 570648,
416
        "total_memory": 4095
417
      }
418
    },
419
    "request": {
420
      "type": "allocate",
421
      "name": "instance3.example.com",
422
      "required_nodes": 2,
423
      "disk_space_total": 3328,
424
      "disks": [
425
        {
426
          "mode": "w",
427
          "size": 1024
428
        },
429
        {
430
          "mode": "w",
431
          "size": 2048
432
        }
433
      ],
434
      "nics": [
435
        {
436
          "ip": null,
437
          "mac": "00:11:22:33:44:55",
438
          "bridge": null
439
        }
440
      ],
441
      "vcpus": 1,
442
      "disk_template": "drbd",
443
      "memory": 2048,
444
      "os": "debootstrap+default",
445
      "tags": [
446
        "type:test",
447
        "owner:foo"
448
      ],
449
      hypervisor: "xen-pvm"
450
    }
451
  }
452

    
453
Input message, reallocation::
454

    
455
  {
456
    "version": 2,
457
    ...
458
    "request": {
459
      "type": "relocate",
460
      "name": "instance2.example.com",
461
      "required_nodes": 1,
462
      "disk_space_total": 832,
463
      "relocate_from": [
464
        "node3.example.com"
465
      ]
466
    }
467
  }
468

    
469
Input message, node evacuation::
470

    
471
  {
472
    "version": 2,
473
    ...
474
    "request": {
475
      "type": "multi-evacuate",
476
      "evac_nodes": [
477
        "node2"
478
      ],
479
    }
480
  }
481

    
482

    
483
Response messages
484
~~~~~~~~~~~~~~~~~
485
Successful response message::
486

    
487
  {
488
    "success": true,
489
    "info": "Allocation successful",
490
    "result": [
491
      "node2.example.com",
492
      "node1.example.com"
493
    ]
494
  }
495

    
496
Failed response message::
497

    
498
  {
499
    "success": false,
500
    "info": "Can't find a suitable node for position 2 (already selected: node2.example.com)",
501
    "result": []
502
  }
503

    
504
Successful node evacuation message::
505

    
506
  {
507
    "success": true,
508
    "info": "Request successful",
509
    "result": [
510
      [
511
        "instance1",
512
        "node3"
513
      ],
514
      [
515
        "instance2",
516
        "node1"
517
      ]
518
    ]
519
  }
520

    
521

    
522
Command line messages
523
~~~~~~~~~~~~~~~~~~~~~
524
::
525

    
526
  # gnt-instance add -t plain -m 2g --os-size 1g --swap-size 512m --iallocator hail -o debootstrap+default instance3
527
  Selected nodes for the instance: node1.example.com
528
  * creating instance disks...
529
  [...]
530

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

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

    
539
Reference implementation
540
~~~~~~~~~~~~~~~~~~~~~~~~
541

    
542
Ganeti's default iallocator is "hail" which is part of the separate
543
ganeti-htools project. In order to see its source code please clone
544
``git://git.ganeti.org/htools.git``. Note that htools is implemented
545
using the Haskell programming language.
546

    
547
.. vim: set textwidth=72 :
548
.. Local Variables:
549
.. mode: rst
550
.. fill-column: 72
551
.. End: