gnt-instance 45 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/python
#

# Copyright (C) 2006, 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


22
23
24
25
# pylint: disable-msg=W0401,W0614
# W0401: Wildcard import ganeti.cli
# W0614: Unused import %s from wildcard import (since we need cli)

Iustin Pop's avatar
Iustin Pop committed
26
27
import sys
import os
28
import itertools
29
import simplejson
30
import time
Iustin Pop's avatar
Iustin Pop committed
31
32
33
34
35
36
from cStringIO import StringIO

from ganeti.cli import *
from ganeti import opcodes
from ganeti import constants
from ganeti import utils
37
38
39
40
41
42
43
44
45
from ganeti import errors


_SHUTDOWN_CLUSTER = "cluster"
_SHUTDOWN_NODES_BOTH = "nodes"
_SHUTDOWN_NODES_PRI = "nodes-pri"
_SHUTDOWN_NODES_SEC = "nodes-sec"
_SHUTDOWN_INSTANCES = "instances"

46

47
48
_VALUE_TRUE = "true"

49
#: default list of options for L{ListInstances}
50
_LIST_DEF_FIELDS = [
51
  "name", "hypervisor", "os", "pnode", "status", "oper_ram",
52
53
  ]

54

55
def _ExpandMultiNames(mode, names, client=None):
56
57
58
59
  """Expand the given names using the passed mode.

  For _SHUTDOWN_CLUSTER, all instances will be returned. For
  _SHUTDOWN_NODES_PRI/SEC, all instances having those nodes as
60
  primary/secondary will be returned. For _SHUTDOWN_NODES_BOTH, all
61
62
63
64
  instances having those nodes as either primary or secondary will be
  returned. For _SHUTDOWN_INSTANCES, the given instances will be
  returned.

65
66
67
68
69
70
71
72
73
74
75
76
  @param mode: one of L{_SHUTDOWN_CLUSTER}, L{_SHUTDOWN_NODES_BOTH},
      L{_SHUTDOWN_NODES_PRI}, L{_SHUTDOWN_NODES_SEC} or
      L{_SHUTDOWN_INSTANCES}
  @param names: a list of names; for cluster, it must be empty,
      and for node and instance it must be a list of valid item
      names (short names are valid as usual, e.g. node1 instead of
      node1.example.com)
  @rtype: list
  @return: the list of names after the expansion
  @raise errors.ProgrammerError: for unknown selection type
  @raise errors.OpPrereqError: for invalid input parameters

77
  """
78
79
  if client is None:
    client = GetClient()
80
81
82
  if mode == _SHUTDOWN_CLUSTER:
    if names:
      raise errors.OpPrereqError("Cluster filter mode takes no arguments")
83
    idata = client.QueryInstances([], ["name"], False)
84
85
86
87
88
89
90
    inames = [row[0] for row in idata]

  elif mode in (_SHUTDOWN_NODES_BOTH,
                _SHUTDOWN_NODES_PRI,
                _SHUTDOWN_NODES_SEC):
    if not names:
      raise errors.OpPrereqError("No node names passed")
91
    ndata = client.QueryNodes(names, ["name", "pinst_list", "sinst_list"],
92
                              False)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    ipri = [row[1] for row in ndata]
    pri_names = list(itertools.chain(*ipri))
    isec = [row[2] for row in ndata]
    sec_names = list(itertools.chain(*isec))
    if mode == _SHUTDOWN_NODES_BOTH:
      inames = pri_names + sec_names
    elif mode == _SHUTDOWN_NODES_PRI:
      inames = pri_names
    elif mode == _SHUTDOWN_NODES_SEC:
      inames = sec_names
    else:
      raise errors.ProgrammerError("Unhandled shutdown type")

  elif mode == _SHUTDOWN_INSTANCES:
    if not names:
      raise errors.OpPrereqError("No instance names passed")
109
    idata = client.QueryInstances(names, ["name"], False)
110
111
112
113
114
115
    inames = [row[0] for row in idata]

  else:
    raise errors.OpPrereqError("Unknown mode '%s'" % mode)

  return inames
Iustin Pop's avatar
Iustin Pop committed
116
117


118
def _ConfirmOperation(inames, text, extra=""):
119
120
121
122
123
  """Ask the user to confirm an operation on a list of instances.

  This function is used to request confirmation for doing an operation
  on a given list of instances.

124
125
126
127
128
129
130
131
  @type inames: list
  @param inames: the list of names that we display when
      we ask for confirmation
  @type text: str
  @param text: the operation that the user should confirm
      (e.g. I{shutdown} or I{startup})
  @rtype: boolean
  @return: True or False depending on user's confirmation.
132
133
134

  """
  count = len(inames)
135
136
  msg = ("The %s will operate on %d instances.\n%s"
         "Do you want to continue?" % (text, count, extra))
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  affected = ("\nAffected instances:\n" +
              "\n".join(["  %s" % name for name in inames]))

  choices = [('y', True, 'Yes, execute the %s' % text),
             ('n', False, 'No, abort the %s' % text)]

  if count > 20:
    choices.insert(1, ('v', 'v', 'View the list of affected instances'))
    ask = msg
  else:
    ask = msg + affected

  choice = AskUser(ask, choices)
  if choice == 'v':
    choices.pop(1)
152
    choice = AskUser(msg + affected, choices)
153
154
155
  return choice


156
157
158
159
160
161
def _EnsureInstancesExist(client, names):
  """Check for and ensure the given instance names exist.

  This function will raise an OpPrereqError in case they don't
  exist. Otherwise it will exit cleanly.

Iustin Pop's avatar
Iustin Pop committed
162
  @type client: L{ganeti.luxi.Client}
163
164
165
166
167
168
169
170
  @param client: the client to use for the query
  @type names: list
  @param names: the list of instance names to query
  @raise errors.OpPrereqError: in case any instance is missing

  """
  # TODO: change LUQueryInstances to that it actually returns None
  # instead of raising an exception, or devise a better mechanism
171
  result = client.QueryInstances(names, ["name"], False)
172
173
174
175
176
  for orig_name, row in zip(names, result):
    if row[0] is None:
      raise errors.OpPrereqError("Instance '%s' does not exist" % orig_name)


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def GenericManyOps(operation, fn):
  """Generic multi-instance operations.

  The will return a wrapper that processes the options and arguments
  given, and uses the passed function to build the opcode needed for
  the specific operation. Thus all the generic loop/confirmation code
  is abstracted into this function.

  """
  def realfn(opts, args):
    if opts.multi_mode is None:
      opts.multi_mode = _SHUTDOWN_INSTANCES
    cl = GetClient()
    inames = _ExpandMultiNames(opts.multi_mode, args, client=cl)
    if not inames:
      raise errors.OpPrereqError("Selection filter does not match"
                                 " any instances")
    multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
    if not (opts.force_multi or not multi_on
            or _ConfirmOperation(inames, operation)):
      return 1
    jex = JobExecutor(verbose=multi_on, cl=cl)
    for name in inames:
      op = fn(name, opts)
      jex.QueueJob(name, op)
    jex.WaitOrShow(not opts.submit_only)
    return 0
  return realfn


Iustin Pop's avatar
Iustin Pop committed
207
def ListInstances(opts, args):
Oleksiy Mishchenko's avatar
Oleksiy Mishchenko committed
208
  """List instances and their properties.
Iustin Pop's avatar
Iustin Pop committed
209

210
211
212
213
214
215
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should be an empty list
  @rtype: int
  @return: the desired exit code

Iustin Pop's avatar
Iustin Pop committed
216
217
  """
  if opts.output is None:
218
219
220
    selected_fields = _LIST_DEF_FIELDS
  elif opts.output.startswith("+"):
    selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",")
Iustin Pop's avatar
Iustin Pop committed
221
222
223
  else:
    selected_fields = opts.output.split(",")

224
  output = GetClient().QueryInstances(args, selected_fields, opts.do_locking)
Iustin Pop's avatar
Iustin Pop committed
225
226

  if not opts.no_headers:
227
228
229
    headers = {
      "name": "Instance", "os": "OS", "pnode": "Primary_node",
      "snodes": "Secondary_Nodes", "admin_state": "Autostart",
Iustin Pop's avatar
Iustin Pop committed
230
      "oper_state": "Running",
231
      "oper_ram": "Memory", "disk_template": "Disk_template",
232
      "ip": "IP_address", "mac": "MAC_address",
233
      "nic_mode": "NIC_Mode", "nic_link": "NIC_Link",
Iustin Pop's avatar
Iustin Pop committed
234
      "bridge": "Bridge",
235
      "sda_size": "Disk/0", "sdb_size": "Disk/1",
236
      "disk_usage": "DiskUsage",
237
      "status": "Status", "tags": "Tags",
238
      "network_port": "Network_port",
239
240
241
242
243
244
245
246
      "hv/kernel_path": "Kernel_path",
      "hv/initrd_path": "Initrd_path",
      "hv/boot_order": "HVM_boot_order",
      "hv/acpi": "HVM_ACPI",
      "hv/pae": "HVM_PAE",
      "hv/cdrom_image_path": "HVM_CDROM_image_path",
      "hv/nic_type": "HVM_NIC_type",
      "hv/disk_type": "HVM_Disk_type",
247
      "hv/vnc_bind_address": "VNC_bind_address",
248
      "serial_no": "SerialNo", "hypervisor": "Hypervisor",
249
      "hvparams": "Hypervisor_parameters",
Iustin Pop's avatar
Iustin Pop committed
250
251
      "be/memory": "Configured_memory",
      "be/vcpus": "VCPUs",
252
      "vcpus": "VCPUs",
253
      "be/auto_balance": "Auto_balance",
Iustin Pop's avatar
Iustin Pop committed
254
255
      "disk.count": "Disks", "disk.sizes": "Disk_sizes",
      "nic.count": "NICs", "nic.ips": "NIC_IPs",
256
      "nic.modes": "NIC_modes", "nic.links": "NIC_links",
Iustin Pop's avatar
Iustin Pop committed
257
      "nic.bridges": "NIC_bridges", "nic.macs": "NIC_MACs",
258
      "ctime": "CTime", "mtime": "MTime",
259
      }
260
261
262
  else:
    headers = None

263
  unitfields = ["be/memory", "oper_ram", "sd(a|b)_size", "disk\.size/.*"]
264
  numfields = ["be/memory", "oper_ram", "sd(a|b)_size", "be/vcpus",
Iustin Pop's avatar
Iustin Pop committed
265
               "serial_no", "(disk|nic)\.count", "disk\.size/.*"]
266

267
268
  list_type_fields = ("tags", "disk.sizes", "nic.macs", "nic.ips",
                      "nic.modes", "nic.links", "nic.bridges")
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
  # change raw values to nicer strings
  for row in output:
    for idx, field in enumerate(selected_fields):
      val = row[idx]
      if field == "snodes":
        val = ",".join(val) or "-"
      elif field == "admin_state":
        if val:
          val = "yes"
        else:
          val = "no"
      elif field == "oper_state":
        if val is None:
          val = "(node down)"
        elif val: # True
          val = "running"
        else:
          val = "stopped"
      elif field == "oper_ram":
        if val is None:
          val = "(node down)"
      elif field == "sda_size" or field == "sdb_size":
        if val is None:
          val = "N/A"
293
294
      elif field == "ctime" or field == "mtime":
        val = utils.FormatTime(val)
295
      elif field in list_type_fields:
Iustin Pop's avatar
Iustin Pop committed
296
        val = ",".join(str(item) for item in val)
297
298
      elif val is None:
        val = "-"
299
300
      row[idx] = str(val)

301
302
  data = GenerateTable(separator=opts.separator, headers=headers,
                       fields=selected_fields, unitfields=unitfields,
303
                       numfields=numfields, data=output, units=opts.units)
304
305

  for line in data:
306
    ToStdout(line)
Iustin Pop's avatar
Iustin Pop committed
307
308
309
310
311
312
313

  return 0


def AddInstance(opts, args):
  """Add an instance to the cluster.

Iustin Pop's avatar
Iustin Pop committed
314
  This is just a wrapper over GenericInstanceCreate.
Iustin Pop's avatar
Iustin Pop committed
315
316

  """
Iustin Pop's avatar
Iustin Pop committed
317
  return GenericInstanceCreate(constants.INSTANCE_CREATE, opts, args)
Iustin Pop's avatar
Iustin Pop committed
318
319
320
  return 0


321
def BatchCreate(opts, args):
322
323
324
325
326
327
  """Create instances using a definition file.

  This function reads a json file with instances defined
  in the form::

    {"instance-name":{
328
      "disk_size": [20480],
329
330
331
332
      "template": "drbd",
      "backend": {
        "memory": 512,
        "vcpus": 1 },
333
      "os": "debootstrap",
334
335
336
337
338
339
340
341
342
343
344
345
346
      "primary_node": "firstnode",
      "secondary_node": "secondnode",
      "iallocator": "dumb"}
    }

  Note that I{primary_node} and I{secondary_node} have precedence over
  I{iallocator}.

  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain one element, the json filename
  @rtype: int
  @return: the desired exit code
347
348

  """
349
  _DEFAULT_SPECS = {"disk_size": [20 * 1024],
350
351
352
353
                    "backend": {},
                    "iallocator": None,
                    "primary_node": None,
                    "secondary_node": None,
354
                    "nics": None,
355
356
357
                    "start": True,
                    "ip_check": True,
                    "hypervisor": None,
Iustin Pop's avatar
Iustin Pop committed
358
                    "hvparams": {},
359
360
361
362
363
                    "file_storage_dir": None,
                    "file_driver": 'loop'}

  def _PopulateWithDefaults(spec):
    """Returns a new hash combined with default values."""
364
365
366
    mydict = _DEFAULT_SPECS.copy()
    mydict.update(spec)
    return mydict
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384

  def _Validate(spec):
    """Validate the instance specs."""
    # Validate fields required under any circumstances
    for required_field in ('os', 'template'):
      if required_field not in spec:
        raise errors.OpPrereqError('Required field "%s" is missing.' %
                                   required_field)
    # Validate special fields
    if spec['primary_node'] is not None:
      if (spec['template'] in constants.DTS_NET_MIRROR and
          spec['secondary_node'] is None):
        raise errors.OpPrereqError('Template requires secondary node, but'
                                   ' there was no secondary provided.')
    elif spec['iallocator'] is None:
      raise errors.OpPrereqError('You have to provide at least a primary_node'
                                 ' or an iallocator.')

Iustin Pop's avatar
Iustin Pop committed
385
386
    if (spec['hvparams'] and
        not isinstance(spec['hvparams'], dict)):
387
388
389
390
      raise errors.OpPrereqError('Hypervisor parameters must be a dict.')

  json_filename = args[0]
  try:
391
    instance_data = simplejson.loads(utils.ReadFile(json_filename))
Iustin Pop's avatar
Iustin Pop committed
392
393
394
  except Exception, err:
    ToStderr("Can't parse the instance definition file: %s" % str(err))
    return 1
395

396
397
  jex = JobExecutor()

398
399
400
  # Iterate over the instances and do:
  #  * Populate the specs with default value
  #  * Validate the instance specs
401
402
403
  i_names = utils.NiceSort(instance_data.keys())
  for name in i_names:
    specs = instance_data[name]
404
405
406
    specs = _PopulateWithDefaults(specs)
    _Validate(specs)

Iustin Pop's avatar
Iustin Pop committed
407
408
    hypervisor = specs['hypervisor']
    hvparams = specs['hvparams']
409

410
411
412
413
414
415
416
417
418
419
    disks = []
    for elem in specs['disk_size']:
      try:
        size = utils.ParseUnit(elem)
      except ValueError, err:
        raise errors.OpPrereqError("Invalid disk size '%s' for"
                                   " instance %s: %s" %
                                   (elem, name, err))
      disks.append({"size": size})

420
421
422
    utils.ForceDictType(specs['backend'], constants.BES_PARAMETER_TYPES)
    utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES)

423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
    tmp_nics = []
    for field in ('ip', 'mac', 'mode', 'link', 'bridge'):
      if field in specs:
        if not tmp_nics:
          tmp_nics.append({})
        tmp_nics[0][field] = specs[field]

    if specs['nics'] is not None and tmp_nics:
      raise errors.OpPrereqError("'nics' list incompatible with using"
                                 " individual nic fields as well")
    elif specs['nics'] is not None:
      tmp_nics = specs['nics']
    elif not tmp_nics:
      tmp_nics = [{}]

438
    op = opcodes.OpCreateInstance(instance_name=name,
439
                                  disks=disks,
440
441
442
443
444
                                  disk_template=specs['template'],
                                  mode=constants.INSTANCE_CREATE,
                                  os_type=specs['os'],
                                  pnode=specs['primary_node'],
                                  snode=specs['secondary_node'],
445
                                  nics=tmp_nics,
446
447
448
449
450
451
452
453
454
455
                                  start=specs['start'],
                                  ip_check=specs['ip_check'],
                                  wait_for_sync=True,
                                  iallocator=specs['iallocator'],
                                  hypervisor=hypervisor,
                                  hvparams=hvparams,
                                  beparams=specs['backend'],
                                  file_storage_dir=specs['file_storage_dir'],
                                  file_driver=specs['file_driver'])

456
457
458
    jex.QueueJob(name, op)
  # we never want to wait, just show the submitted job IDs
  jex.WaitOrShow(False)
459
460
461
462

  return 0


463
464
465
def ReinstallInstance(opts, args):
  """Reinstall an instance.

466
467
468
469
470
471
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the name of the
      instance to be reinstalled
  @rtype: int
  @return: the desired exit code
472
473

  """
474
475
476
477
478
479
480
  # first, compute the desired name list
  if opts.multi_mode is None:
    opts.multi_mode = _SHUTDOWN_INSTANCES

  inames = _ExpandMultiNames(opts.multi_mode, args)
  if not inames:
    raise errors.OpPrereqError("Selection filter does not match any instances")
481

482
  # second, if requested, ask for an OS
483
484
485
486
487
  if opts.select_os is True:
    op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
    result = SubmitOpCode(op)

    if not result:
488
      ToStdout("Can't get the OS list")
489
490
      return 1

491
    ToStdout("Available OS templates:")
492
493
494
    number = 0
    choices = []
    for entry in result:
495
      ToStdout("%3s: %s", number, entry[0])
496
497
498
499
      choices.append(("%s" % number, entry[0], entry[0]))
      number = number + 1

    choices.append(('x', 'exit', 'Exit gnt-instance reinstall'))
500
    selected = AskUser("Enter OS template number (or x to abort):",
501
502
503
                       choices)

    if selected == 'exit':
504
      ToStderr("User aborted reinstall, exiting")
505
506
      return 1

507
    os_name = selected
508
  else:
509
    os_name = opts.os
510

511
512
513
514
515
516
517
  # third, get confirmation: multi-reinstall requires --force-multi
  # *and* --force, single-reinstall just --force
  multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
  if multi_on:
    warn_msg = "Note: this will remove *all* data for the below instances!\n"
    if not ((opts.force_multi and opts.force) or
            _ConfirmOperation(inames, "reinstall", extra=warn_msg)):
518
      return 1
519
520
521
  else:
    if not opts.force:
      usertext = ("This will reinstall the instance %s and remove"
Iustin Pop's avatar
Iustin Pop committed
522
                  " all data. Continue?") % inames[0]
523
524
525
526
527
528
529
530
      if not AskUser(usertext):
        return 1

  jex = JobExecutor(verbose=multi_on)
  for instance_name in inames:
    op = opcodes.OpReinstallInstance(instance_name=instance_name,
                                     os_type=os_name)
    jex.QueueJob(instance_name, op)
531

532
  jex.WaitOrShow(not opts.submit_only)
533
534
535
  return 0


Iustin Pop's avatar
Iustin Pop committed
536
537
538
def RemoveInstance(opts, args):
  """Remove an instance.

539
540
541
542
543
544
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the name of
      the instance to be removed
  @rtype: int
  @return: the desired exit code
Iustin Pop's avatar
Iustin Pop committed
545
546
547
548

  """
  instance_name = args[0]
  force = opts.force
549
  cl = GetClient()
Iustin Pop's avatar
Iustin Pop committed
550
551

  if not force:
552
553
    _EnsureInstancesExist(cl, [instance_name])

Iustin Pop's avatar
Iustin Pop committed
554
555
556
    usertext = ("This will remove the volumes of the instance %s"
                " (including mirrors), thus removing all the data"
                " of the instance. Continue?") % instance_name
557
    if not AskUser(usertext):
Iustin Pop's avatar
Iustin Pop committed
558
559
      return 1

Iustin Pop's avatar
Iustin Pop committed
560
561
  op = opcodes.OpRemoveInstance(instance_name=instance_name,
                                ignore_failures=opts.ignore_failures)
562
  SubmitOrSend(op, opts, cl=cl)
Iustin Pop's avatar
Iustin Pop committed
563
564
565
  return 0


566
def RenameInstance(opts, args):
Guido Trotter's avatar
Guido Trotter committed
567
  """Rename an instance.
568

569
570
571
572
573
574
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain two elements, the old and the
      new instance names
  @rtype: int
  @return: the desired exit code
575
576
577
578
579

  """
  op = opcodes.OpRenameInstance(instance_name=args[0],
                                new_name=args[1],
                                ignore_ip=opts.ignore_ip)
580
  SubmitOrSend(op, opts)
581
582
583
  return 0


Iustin Pop's avatar
Iustin Pop committed
584
585
586
587
def ActivateDisks(opts, args):
  """Activate an instance's disks.

  This serves two purposes:
588
589
    - it allows (as long as the instance is not running)
      mounting the disks and modifying them from the node
Iustin Pop's avatar
Iustin Pop committed
590
591
    - it repairs inactive secondary drbds

592
593
594
595
596
597
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code

Iustin Pop's avatar
Iustin Pop committed
598
599
  """
  instance_name = args[0]
600
601
  op = opcodes.OpActivateInstanceDisks(instance_name=instance_name,
                                       ignore_size=opts.ignore_size)
602
  disks_info = SubmitOrSend(op, opts)
Iustin Pop's avatar
Iustin Pop committed
603
  for host, iname, nname in disks_info:
604
    ToStdout("%s:%s:%s", host, iname, nname)
Iustin Pop's avatar
Iustin Pop committed
605
606
607
608
  return 0


def DeactivateDisks(opts, args):
Iustin Pop's avatar
Iustin Pop committed
609
  """Deactivate an instance's disks.
Iustin Pop's avatar
Iustin Pop committed
610
611
612
613

  This function takes the instance name, looks for its primary node
  and the tries to shutdown its block devices on that node.

614
615
616
617
618
619
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code

Iustin Pop's avatar
Iustin Pop committed
620
621
622
  """
  instance_name = args[0]
  op = opcodes.OpDeactivateInstanceDisks(instance_name=instance_name)
623
  SubmitOrSend(op, opts)
Iustin Pop's avatar
Iustin Pop committed
624
625
626
  return 0


Iustin Pop's avatar
Iustin Pop committed
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
def RecreateDisks(opts, args):
  """Recreate an instance's disks.

  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code

  """
  instance_name = args[0]
  if opts.disks:
    try:
      opts.disks = [int(v) for v in opts.disks.split(",")]
    except (ValueError, TypeError), err:
      ToStderr("Invalid disks value: %s" % str(err))
      return 1
  else:
    opts.disks = []

  op = opcodes.OpRecreateInstanceDisks(instance_name=instance_name,
                                       disks=opts.disks)
  SubmitOrSend(op, opts)
  return 0


Iustin Pop's avatar
Iustin Pop committed
653
def GrowDisk(opts, args):
654
  """Grow an instance's disks.
Iustin Pop's avatar
Iustin Pop committed
655

656
657
658
659
660
661
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain two elements, the instance name
      whose disks we grow and the disk name, e.g. I{sda}
  @rtype: int
  @return: the desired exit code
Iustin Pop's avatar
Iustin Pop committed
662
663
664
665

  """
  instance = args[0]
  disk = args[1]
666
667
668
669
  try:
    disk = int(disk)
  except ValueError, err:
    raise errors.OpPrereqError("Invalid disk index: %s" % str(err))
Iustin Pop's avatar
Iustin Pop committed
670
  amount = utils.ParseUnit(args[2])
671
672
  op = opcodes.OpGrowDisk(instance_name=instance, disk=disk, amount=amount,
                          wait_for_sync=opts.wait_for_sync)
673
  SubmitOrSend(op, opts)
Iustin Pop's avatar
Iustin Pop committed
674
675
676
  return 0


677
def _StartupInstance(name, opts):
678
  """Startup instances.
Iustin Pop's avatar
Iustin Pop committed
679

680
681
  This returns the opcode to start an instance, and its decorator will
  wrap this into a loop starting all desired instances.
682

683
  @param name: the name of the instance to act on
684
  @param opts: the command line options selected by the user
685
  @return: the opcode needed for the operation
Iustin Pop's avatar
Iustin Pop committed
686
687

  """
688
689
690
691
692
693
694
695
  op = opcodes.OpStartupInstance(instance_name=name,
                                 force=opts.force)
  # do not add these parameters to the opcode unless they're defined
  if opts.hvparams:
    op.hvparams = opts.hvparams
  if opts.beparams:
    op.beparams = opts.beparams
  return op
Iustin Pop's avatar
Iustin Pop committed
696

697

698
def _RebootInstance(name, opts):
699
700
  """Reboot instance(s).

701
702
  This returns the opcode to reboot an instance, and its decorator
  will wrap this into a loop rebooting all desired instances.
703

704
  @param name: the name of the instance to act on
705
  @param opts: the command line options selected by the user
706
  @return: the opcode needed for the operation
707
708

  """
709
  return opcodes.OpRebootInstance(instance_name=name,
710
711
                                  reboot_type=opts.reboot_type,
                                  ignore_secondaries=opts.ignore_secondaries)
Iustin Pop's avatar
Iustin Pop committed
712

713

714
def _ShutdownInstance(name, opts):
Iustin Pop's avatar
Iustin Pop committed
715
716
  """Shutdown an instance.

717
718
719
720
  This returns the opcode to shutdown an instance, and its decorator
  will wrap this into a loop shutting down all desired instances.

  @param name: the name of the instance to act on
721
  @param opts: the command line options selected by the user
722
  @return: the opcode needed for the operation
Iustin Pop's avatar
Iustin Pop committed
723
724

  """
725
  return opcodes.OpShutdownInstance(instance_name=name)
Iustin Pop's avatar
Iustin Pop committed
726
727
728
729
730


def ReplaceDisks(opts, args):
  """Replace the disks of an instance

731
732
733
734
735
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code
Iustin Pop's avatar
Iustin Pop committed
736
737
738

  """
  instance_name = args[0]
739
  new_2ndary = opts.dst_node
740
  iallocator = opts.iallocator
741
  if opts.disks is None:
742
    disks = []
743
  else:
744
745
746
747
    try:
      disks = [int(i) for i in opts.disks.split(",")]
    except ValueError, err:
      raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err))
748
  cnt = [opts.on_primary, opts.on_secondary, opts.auto,
749
750
         new_2ndary is not None, iallocator is not None].count(True)
  if cnt != 1:
751
    raise errors.OpPrereqError("One and only one of the -p, -s, -a, -n and -i"
752
753
                               " options must be passed")
  elif opts.on_primary:
754
    mode = constants.REPLACE_DISK_PRI
755
  elif opts.on_secondary:
756
    mode = constants.REPLACE_DISK_SEC
757
758
759
760
761
  elif opts.auto:
    mode = constants.REPLACE_DISK_AUTO
    if disks:
      raise errors.OpPrereqError("Cannot specify disks when using automatic"
                                 " mode")
762
763
764
  elif new_2ndary is not None or iallocator is not None:
    # replace secondary
    mode = constants.REPLACE_DISK_CHG
765
766

  op = opcodes.OpReplaceDisks(instance_name=args[0], disks=disks,
767
768
                              remote_node=new_2ndary, mode=mode,
                              iallocator=iallocator)
769
  SubmitOrSend(op, opts)
Iustin Pop's avatar
Iustin Pop committed
770
771
772
773
774
775
776
777
778
  return 0


def FailoverInstance(opts, args):
  """Failover an instance.

  The failover is done by shutting it down on its present node and
  starting it on the secondary.

779
780
781
782
783
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code
Iustin Pop's avatar
Iustin Pop committed
784
785

  """
786
  cl = GetClient()
787
788
  instance_name = args[0]
  force = opts.force
Iustin Pop's avatar
Iustin Pop committed
789

790
  if not force:
791
792
    _EnsureInstancesExist(cl, [instance_name])

793
794
795
796
797
    usertext = ("Failover will happen to image %s."
                " This requires a shutdown of the instance. Continue?" %
                (instance_name,))
    if not AskUser(usertext):
      return 1
Iustin Pop's avatar
Iustin Pop committed
798

799
800
  op = opcodes.OpFailoverInstance(instance_name=instance_name,
                                  ignore_consistency=opts.ignore_consistency)
801
  SubmitOrSend(op, opts, cl=cl)
802
  return 0
Iustin Pop's avatar
Iustin Pop committed
803
804


805
806
807
808
809
def MigrateInstance(opts, args):
  """Migrate an instance.

  The migrate is done without shutdown.

Iustin Pop's avatar
Iustin Pop committed
810
811
812
813
814
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code
815
816

  """
817
  cl = GetClient()
818
819
820
821
  instance_name = args[0]
  force = opts.force

  if not force:
822
823
    _EnsureInstancesExist(cl, [instance_name])

824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
    if opts.cleanup:
      usertext = ("Instance %s will be recovered from a failed migration."
                  " Note that the migration procedure (including cleanup)" %
                  (instance_name,))
    else:
      usertext = ("Instance %s will be migrated. Note that migration" %
                  (instance_name,))
    usertext += (" is **experimental** in this version."
                " This might impact the instance if anything goes wrong."
                " Continue?")
    if not AskUser(usertext):
      return 1

  op = opcodes.OpMigrateInstance(instance_name=instance_name, live=opts.live,
                                 cleanup=opts.cleanup)
839
  SubmitOpCode(op, cl=cl)
840
841
842
  return 0


Iustin Pop's avatar
Iustin Pop committed
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
def MoveInstance(opts, args):
  """Move an instance.

  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code

  """
  cl = GetClient()
  instance_name = args[0]
  force = opts.force

  if not force:
    usertext = ("Instance %s will be moved."
                " This requires a shutdown of the instance. Continue?" %
                (instance_name,))
    if not AskUser(usertext):
      return 1

  op = opcodes.OpMoveInstance(instance_name=instance_name,
865
                              target_node=opts.node)
Iustin Pop's avatar
Iustin Pop committed
866
867
868
869
  SubmitOrSend(op, opts, cl=cl)
  return 0


Iustin Pop's avatar
Iustin Pop committed
870
871
872
def ConnectToInstanceConsole(opts, args):
  """Connect to the console of an instance.

873
874
875
876
877
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code
Iustin Pop's avatar
Iustin Pop committed
878
879
880
881
882

  """
  instance_name = args[0]

  op = opcodes.OpConnectConsole(instance_name=instance_name)
883
  cmd = SubmitOpCode(op)
884
885

  if opts.show_command:
886
    ToStdout("%s", utils.ShellQuoteArgs(cmd))
887
888
889
890
  else:
    try:
      os.execvp(cmd[0], cmd)
    finally:
891
      ToStderr("Can't run console command %s with arguments:\n'%s'",
892
               cmd[0], " ".join(cmd))
893
      os._exit(1)
Iustin Pop's avatar
Iustin Pop committed
894
895


896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
def _FormatLogicalID(dev_type, logical_id):
  """Formats the logical_id of a disk.

  """
  if dev_type == constants.LD_DRBD8:
    node_a, node_b, port, minor_a, minor_b, key = logical_id
    data = [
      ("nodeA", "%s, minor=%s" % (node_a, minor_a)),
      ("nodeB", "%s, minor=%s" % (node_b, minor_b)),
      ("port", port),
      ("auth key", key),
      ]
  elif dev_type == constants.LD_LV:
    vg_name, lv_name = logical_id
    data = ["%s/%s" % (vg_name, lv_name)]
  else:
    data = [str(logical_id)]

  return data


def _FormatBlockDevInfo(idx, top_level, dev, static):
Iustin Pop's avatar
Iustin Pop committed
918
919
  """Show block device information.

920
  This is only used by L{ShowInstanceConfig}, but it's too big to be
Iustin Pop's avatar
Iustin Pop committed
921
922
  left for an inline definition.

923
924
925
926
  @type idx: int
  @param idx: the index of the current disk
  @type top_level: boolean
  @param top_level: if this a top-level disk?
927
928
929
930
931
  @type dev: dict
  @param dev: dictionary with disk information
  @type static: boolean
  @param static: wheter the device information doesn't contain
      runtime information but only static data
932
933
  @return: a list of either strings, tuples or lists
      (which should be formatted at a higher indent level)
934

Iustin Pop's avatar
Iustin Pop committed
935
  """
936
  def helper(dtype, status):
937
938
939
940
941
942
    """Format one line for physical device status.

    @type dtype: str
    @param dtype: a constant from the L{constants.LDS_BLOCK} set
    @type status: tuple
    @param status: a tuple as returned from L{backend.FindBlockDevice}
943
    @return: the string representing the status
944
945

    """
Iustin Pop's avatar
Iustin Pop committed
946
    if not status:
947
948
      return "not active"
    txt = ""
949
    (path, major, minor, syncp, estt, degr, ldisk_status) = status
950
951
    if major is None:
      major_string = "N/A"
Iustin Pop's avatar
Iustin Pop committed
952
    else:
953
      major_string = str(major)
954

955
956
957
958
959
960
961
962
963
964
965
    if minor is None:
      minor_string = "N/A"
    else:
      minor_string = str(minor)

    txt += ("%s (%s:%s)" % (path, major_string, minor_string))
    if dtype in (constants.LD_DRBD8, ):
      if syncp is not None:
        sync_text = "*RECOVERING* %5.2f%%," % syncp
        if estt:
          sync_text += " ETA %ds" % estt
966
        else:
967
968
969
970
971
972
973
          sync_text += " ETA unknown"
      else:
        sync_text = "in sync"
      if degr:
        degr_text = "*DEGRADED*"
      else:
        degr_text = "ok"
974
      if ldisk_status == constants.LDS_FAULTY:
975
        ldisk_text = " *MISSING DISK*"
976
977
      elif ldisk_status == constants.LDS_UNKNOWN:
        ldisk_text = " *UNCERTAIN STATE*"
978
979
980
981
      else:
        ldisk_text = ""
      txt += (" %s, status %s%s" % (sync_text, degr_text, ldisk_text))
    elif dtype == constants.LD_LV:
982
      if ldisk_status == constants.LDS_FAULTY:
983
984
985
986
987
988
989
990
991
992
993
994
        ldisk_text = " *FAILED* (failed drive?)"
      else:
        ldisk_text = ""
      txt += ldisk_text
    return txt

  # the header
  if top_level:
    if dev["iv_name"] is not None:
      txt = dev["iv_name"]
    else:
      txt = "disk %d" % idx
Iustin Pop's avatar
Iustin Pop committed
995
  else:
996
    txt = "child %d" % idx
Iustin Pop's avatar
Iustin Pop committed
997
998
999
1000
1001
  if isinstance(dev["size"], int):
    nice_size = utils.FormatUnit(dev["size"], "h")
  else:
    nice_size = dev["size"]
  d1 = ["- %s: %s, size %s" % (txt, dev["dev_type"], nice_size)]
1002
1003
1004
  data = []
  if top_level:
    data.append(("access mode", dev["mode"]))
Iustin Pop's avatar
Iustin Pop committed
1005
  if dev["logical_id"] is not None:
1006
1007
1008
1009
1010
1011
1012
1013
    try:
      l_id = _FormatLogicalID(dev["dev_type"], dev["logical_id"])
    except ValueError:
      l_id = [str(dev["logical_id"])]
    if len(l_id) == 1:
      data.append(("logical_id", l_id[0]))
    else:
      data.extend(l_id)
Iustin Pop's avatar
Iustin Pop committed
1014
  elif dev["physical_id"] is not None:
1015
1016
    data.append("physical_id:")
    data.append([dev["physical_id"]])
1017
  if not static:
1018
    data.append(("on primary", helper(dev["dev_type"], dev["pstatus"])))
1019
  if dev["sstatus"] and not static:
1020
    data.append(("on secondary", helper(dev["dev_type"], dev["sstatus"])))
Iustin Pop's avatar
Iustin Pop committed
1021
1022

  if dev["children"]:
1023
1024
1025
1026
1027
    data.append("child devices:")
    for c_idx, child in enumerate(dev["children"]):
      data.append(_FormatBlockDevInfo(c_idx, False, child, static))
  d1.append(data)
  return d1
Iustin Pop's avatar
Iustin Pop committed
1028
1029


1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
def _FormatList(buf, data, indent_level):
  """Formats a list of data at a given indent level.

  If the element of the list is:
    - a string, it is simply formatted as is
    - a tuple, it will be split into key, value and the all the
      values in a list will be aligned all at the same start column
    - a list, will be recursively formatted

  @type buf: StringIO
  @param buf: the buffer into which we write the output
  @param data: the list to format
  @type indent_level: int
  @param indent_level: the indent level to format at

  """
  max_tlen = max([len(elem[0]) for elem in data
                 if isinstance(elem, tuple)] or [0])
  for elem in data:
    if isinstance(elem, basestring):
      buf.write("%*s%s\n" % (2*indent_level, "", elem))
    elif isinstance(elem, tuple):
      key, value = elem
      spacer = "%*s" % (max_tlen - len(key), "")
      buf.write("%*s%s:%s %s\n" % (2*indent_level, "", key, spacer, value))
    elif isinstance(elem, list):
      _FormatList(buf, elem, indent_level+1)

1058

Iustin Pop's avatar
Iustin Pop committed
1059
1060
1061
def ShowInstanceConfig(opts, args):
  """Compute instance run-time status.

1062
1063
1064
1065
1066
1067
1068
  @param opts: the command line options selected by the user
  @type args: list
  @param args: either an empty list, and then we query all
      instances, or should contain a list of instance names
  @rtype: int
  @return: the desired exit code

Iustin Pop's avatar
Iustin Pop committed
1069
  """
Guido Trotter's avatar
Guido Trotter committed
1070
1071
1072
1073
1074
1075
1076
1077
1078
  if not args and not opts.show_all:
    ToStderr("No instance selected."
             " Please pass in --all if you want to query all instances.\n"
             "Note that this can take a long time on a big cluster.")
    return 1
  elif args and opts.show_all:
    ToStderr("Cannot use --all if you specify instance names.")
    return 1

Iustin Pop's avatar
Iustin Pop committed
1079
  retcode = 0
1080
  op = opcodes.OpQueryInstanceData(instances=args, static=opts.static)
Iustin Pop's avatar
Iustin Pop committed
1081
1082
  result = SubmitOpCode(op)
  if not result:
1083
    ToStdout("No instances.")
Iustin Pop's avatar
Iustin Pop committed
1084
1085
1086
1087
1088
1089
1090
    return 1

  buf = StringIO()
  retcode = 0
  for instance_name in result:
    instance = result[instance_name]
    buf.write("Instance name: %s\n" % instance["name"])
1091
1092
1093
    buf.write("Serial number: %s\n" % instance["serial_no"])
    buf.write("Creation time: %s\n" % utils.FormatTime(instance["ctime"]))
    buf.write("Modification time: %s\n" % utils.FormatTime(instance["mtime"]))
1094
1095
1096
1097
1098
1099
    buf.write("State: configured to be %s" % instance["config_state"])
    if not opts.static:
      buf.write(", actual state is %s" % instance["run_state"])
    buf.write("\n")
    ##buf.write("Considered for memory checks in cluster verify: %s\n" %
    ##          instance["auto_balance"])
Iustin Pop's avatar
Iustin Pop committed
1100
1101
1102
1103
    buf.write("  Nodes:\n")
    buf.write("    - primary: %s\n" % instance["pnode"])
    buf.write("    - secondaries: %s\n" % ", ".join(instance["snodes"]))
    buf.write("  Operating system: %s\n" % instance["os"])
1104
1105
    if instance.has_key("network_port"):
      buf.write("  Allocated network port: %s\n" % instance["network_port"])
1106
    buf.write("  Hypervisor: %s\n" % instance["hypervisor"])
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121

    # custom VNC console information
    vnc_bind_address = instance["hv_actual"].get(constants.HV_VNC_BIND_ADDRESS,
                                                 None)
    if vnc_bind_address:
      port = instance["network_port"]
      display = int(port) - constants.VNC_BASE_PORT
      if display > 0 and vnc_bind_address == constants.BIND_ADDRESS_GLOBAL:
        vnc_console_port = "%s:%s (display %s)" % (instance["pnode"],
                                                   port,
                                                   display)
      elif display > 0 and utils.IsValidIP(vnc_bind_address):
        vnc_console_port = ("%s:%s (node %s) (display %s)" %
                             (vnc_bind_address, port,
                              instance["pnode"], display))
1122
      else:
1123
1124
1125
        # vnc bind address is a file
        vnc_console_port = "%s:%s" % (instance["pnode"],
                                      vnc_bind_address)
1126
1127
      buf.write("    - console connection: vnc to %s\n" % vnc_console_port)

1128
    for key in instance["hv_actual"]:
1129
1130
      if key in instance["hv_instance"]:
        val = instance["hv_instance"][key]
1131
      else:
1132
        val = "default (%s)" % instance["hv_actual"][key]
1133
      buf.write("    - %s: %s\n" % (key, val))
Iustin Pop's avatar
Iustin Pop committed
1134
    buf.write("  Hardware:\n")
Iustin Pop's avatar
Iustin Pop committed
1135
1136
1137
1138
    buf.write("    - VCPUs: %d\n" %
              instance["be_actual"][constants.BE_VCPUS])
    buf.write("    - memory: %dMiB\n" %
              instance["be_actual"][constants.BE_MEMORY])
1139
    buf.write("    - NICs:\n")
1140
    for idx, (ip, mac, mode, link) in enumerate(instance["nics"]):
1141
1142
      buf.write("      - nic/%d: MAC: %s, IP: %s, mode: %s, link: %s\n" %
                (idx, mac, ip, mode, link))
1143
    buf.write("  Disks:\n")
Iustin Pop's avatar
Iustin Pop committed
1144

1145
1146
    for idx, device in enumerate(instance["disks"]):
      _FormatList(buf, _FormatBlockDevInfo(idx, True, device, opts.static), 2)
Iustin Pop's avatar
Iustin Pop committed
1147

1148
  ToStdout(buf.getvalue().rstrip('\n'))
Iustin Pop's avatar
Iustin Pop committed
1149
1150
1151
  return retcode


1152
def SetInstanceParams(opts, args):
Iustin Pop's avatar
Iustin Pop committed
1153
1154
1155
1156
  """Modifies an instance.

  All parameters take effect only at the next restart of the instance.

1157
1158
1159
1160
1161
  @param opts: the command line options selected by the user
  @type args: list
  @param args: should contain only one element, the instance name
  @rtype: int
  @return: the desired exit code
Iustin Pop's avatar
Iustin Pop committed
1162
1163

  """
1164
  if not (opts.nics or opts.disks or
1165
          opts.hvparams or opts.beparams):
1166
    ToStderr("Please give at least one of the parameters.")
Iustin Pop's avatar
Iustin Pop committed
1167
1168
    return 1

1169
  for param in opts.beparams:
1170
1171
1172
    if isinstance(opts.beparams[param], basestring):
      if opts.beparams[param].lower() == "default":
        opts.beparams[param] = constants.VALUE_DEFAULT
1173
1174
1175

  utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES,
                      allowed_values=[constants.VALUE_DEFAULT])
1176

1177
1178
1179
1180
  for param in opts.hvparams:
    if isinstance(opts.hvparams[param], basestring):
      if opts.hvparams[param].lower() == "default":
        opts.hvparams[param] = constants.VALUE_DEFAULT
1181

1182
  utils.ForceDictType(opts.hvparams, constants.HVS_PARAMETER_TYPES,
1183
                      allowed_values=[constants.VALUE_DEFAULT])
1184

1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
  for idx, (nic_op, nic_dict) in enumerate(opts.nics):
    try:
      nic_op = int(nic_op)
      opts.nics[idx] = (nic_op, nic_dict)
    except ValueError:
      pass

  for idx, (disk_op, disk_dict) in enumerate(opts.disks):
    try:
      disk_op = int(disk_op)
      opts.disks[idx] = (disk_op, disk_dict)
    except ValueError:
      pass
    if disk_op == constants.DDM_ADD:
      if 'size' not in disk_dict:
        raise errors.OpPrereqError("Missing required parameter 'size'")
      disk_dict['size'] = utils.ParseUnit(disk_dict['size'])

Iustin Pop's avatar
Iustin Pop committed
1203
  op = opcodes.OpSetInstanceParams(instance_name=args[0],
1204
1205
                                   nics=opts.nics,
                                   disks=opts.disks,
1206
                                   hvparams=opts.hvparams,
Iustin Pop's avatar
Iustin Pop committed
1207
                                   beparams=opts.beparams,
1208
                                   force=opts.force)
1209

1210
1211
  # even if here we process the result, we allow submit only
  result = SubmitOrSend(op, opts)
Iustin Pop's avatar
Iustin Pop committed
1212
1213

  if result:
1214
    ToStdout("Modified instance %s", args[0])
Iustin Pop's avatar
Iustin Pop committed
1215
    for param, data in result:
1216
1217
1218
      ToStdout(" - %-5s -> %s", param, data)
    ToStdout("Please don't forget that these parameters take effect"
             " only at the next start of the instance.")