opcodes.py 45.6 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
#
Iustin Pop's avatar
Iustin Pop committed
2
3
#

4
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
Iustin Pop's avatar
Iustin Pop committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# 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.


"""OpCodes module

This module implements the data structures which define the cluster
operations - the so-called opcodes.

Iustin Pop's avatar
Iustin Pop committed
27
28
Every operation which modifies the cluster state is expressed via
opcodes.
Iustin Pop's avatar
Iustin Pop committed
29
30
31
32
33
34
35

"""

# this are practically structures, so disable the message about too
# few public methods:
# pylint: disable-msg=R0903

36
import logging
37
import re
38
import operator
39

40
41
42
43
44
45
46
47
from ganeti import constants
from ganeti import errors
from ganeti import ht


# Common opcode attributes

#: output fields for a query operation
48
_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
49
                  "Selected output fields")
50
51

#: the shutdown timeout
52
53
54
_PShutdownTimeout = \
  ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
   "How long to wait for instance to shut down")
55
56

#: the force parameter
57
_PForce = ("force", False, ht.TBool, "Whether to force the operation")
58
59

#: a required instance name (for single-instance LUs)
60
61
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
                  "Instance name")
62
63

#: Whether to ignore offline nodes
64
65
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
                        "Whether to ignore offline nodes")
66
67

#: a required node name (for single-node LUs)
68
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
69
70

#: a required node group name (for single-group LUs)
71
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
72
73
74

#: Migration type (live/non-live)
_PMigrationMode = ("mode", None,
75
                   ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
76
                   "Migration mode")
77
78

#: Obsolete 'live' migration mode (boolean)
79
80
_PMigrationLive = ("live", None, ht.TMaybeBool,
                   "Legacy setting for live migration, do not use")
81
82

#: Tag type
83
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None)
84
85

#: List of tag strings
86
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None)
87

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
_PForceVariant = ("force_variant", False, ht.TBool,
                  "Whether to force an unknown OS variant")

_PWaitForSync = ("wait_for_sync", True, ht.TBool,
                 "Whether to wait for the disk to synchronize")

_PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
                       "Whether to ignore disk consistency")

_PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")

_PUseLocking = ("use_locking", False, ht.TBool,
                "Whether to use synchronization")

_PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")

_PNodeGroupAllocPolicy = \
  ("alloc_policy", None,
   ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
   "Instance allocation policy")

_PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
                     "Default node parameters for group")

112
_PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
113
114
               "Resource(s) to query for")

115
116
_PIpCheckDoc = "Whether to ensure instance's IP address is inactive"

117
118
119
#: OP_ID conversion regular expression
_OPID_RE = re.compile("([a-z])([A-Z])")

120
121
122
123
124
125
#: Utility function for L{OpClusterSetParams}
_TestClusterOsList = ht.TOr(ht.TNone,
  ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
    ht.TMap(ht.WithDesc("GetFirstItem")(operator.itemgetter(0)),
            ht.TElemOf(constants.DDMS_VALUES)))))

126

127
128
129
130
131
# TODO: Generate check from constants.INIC_PARAMS_TYPES
#: Utility function for testing NIC definitions
_TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
                         ht.TOr(ht.TNone, ht.TNonEmptyString))

132
133
134
135
136
137
138
_SUMMARY_PREFIX = {
  "CLUSTER_": "C_",
  "GROUP_": "G_",
  "NODE_": "N_",
  "INSTANCE_": "I_",
  }

139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def _NameToId(name):
  """Convert an opcode class name to an OP_ID.

  @type name: string
  @param name: the class name, as OpXxxYyy
  @rtype: string
  @return: the name in the OP_XXXX_YYYY format

  """
  if not name.startswith("Op"):
    return None
  # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
  # consume any input, and hence we would just have all the elements
  # in the list, one by one; but it seems that split doesn't work on
  # non-consuming input, hence we have to process the input string a
  # bit
  name = _OPID_RE.sub(r"\1,\2", name)
  elems = name.split(",")
  return "_".join(n.upper() for n in elems)

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

def RequireFileStorage():
  """Checks that file storage is enabled.

  While it doesn't really fit into this module, L{utils} was deemed too large
  of a dependency to be imported for just one or two functions.

  @raise errors.OpPrereqError: when file storage is disabled

  """
  if not constants.ENABLE_FILE_STORAGE:
    raise errors.OpPrereqError("File storage disabled at configure time",
                               errors.ECODE_INVAL)


175
176
177
178
179
180
181
182
183
184
185
186
187
188
def RequireSharedFileStorage():
  """Checks that shared file storage is enabled.

  While it doesn't really fit into this module, L{utils} was deemed too large
  of a dependency to be imported for just one or two functions.

  @raise errors.OpPrereqError: when shared file storage is disabled

  """
  if not constants.ENABLE_SHARED_FILE_STORAGE:
    raise errors.OpPrereqError("Shared file storage disabled at"
                               " configure time", errors.ECODE_INVAL)


189
190
191
@ht.WithDesc("CheckFileStorage")
def _CheckFileStorage(value):
  """Ensures file storage is enabled if used.
192
193

  """
194
  if value == constants.DT_FILE:
195
    RequireFileStorage()
196
197
  elif value == constants.DT_SHARED_FILE:
    RequireSharedFileStorage()
198
199
200
  return True


201
202
203
204
_CheckDiskTemplate = ht.TAnd(ht.TElemOf(constants.DISK_TEMPLATES),
                             _CheckFileStorage)


205
206
207
208
209
210
211
212
213
214
215
216
217
def _CheckStorageType(storage_type):
  """Ensure a given storage type is valid.

  """
  if storage_type not in constants.VALID_STORAGE_TYPES:
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
                               errors.ECODE_INVAL)
  if storage_type == constants.ST_FILE:
    RequireFileStorage()
  return True


#: Storage type parameter
218
219
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
                 "Storage type")
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237


class _AutoOpParamSlots(type):
  """Meta class for opcode definitions.

  """
  def __new__(mcs, name, bases, attrs):
    """Called when a class should be created.

    @param mcs: The meta class
    @param name: Name of created class
    @param bases: Base classes
    @type attrs: dict
    @param attrs: Class attributes

    """
    assert "__slots__" not in attrs, \
      "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
238
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
239

240
    attrs["OP_ID"] = _NameToId(name)
241
242
243
244
245

    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
    params = attrs.setdefault("OP_PARAMS", [])

    # Use parameter names as slots
246
    slots = [pname for (pname, _, _, _) in params]
247
248
249
250
251
252
253
254

    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name

    attrs["__slots__"] = slots

    return type.__new__(mcs, name, bases, attrs)

255

Iustin Pop's avatar
Iustin Pop committed
256
class BaseOpCode(object):
257
258
  """A simple serializable object.

Iustin Pop's avatar
Iustin Pop committed
259
260
261
  This object serves as a parent class for OpCode without any custom
  field handling.

262
  """
263
264
  # pylint: disable-msg=E1101
  # as OP_ID is dynamically defined
265
266
  __metaclass__ = _AutoOpParamSlots

Iustin Pop's avatar
Iustin Pop committed
267
  def __init__(self, **kwargs):
Iustin Pop's avatar
Iustin Pop committed
268
269
270
271
272
273
274
275
    """Constructor for BaseOpCode.

    The constructor takes only keyword arguments and will set
    attributes on this object based on the passed arguments. As such,
    it means that you should not pass arguments which are not in the
    __slots__ attribute for this class.

    """
276
    slots = self._all_slots()
Iustin Pop's avatar
Iustin Pop committed
277
    for key in kwargs:
278
      if key not in slots:
279
        raise TypeError("Object %s doesn't support the parameter '%s'" %
280
                        (self.__class__.__name__, key))
Iustin Pop's avatar
Iustin Pop committed
281
282
      setattr(self, key, kwargs[key])

283
  def __getstate__(self):
Iustin Pop's avatar
Iustin Pop committed
284
285
286
287
288
289
290
291
292
    """Generic serializer.

    This method just returns the contents of the instance as a
    dictionary.

    @rtype:  C{dict}
    @return: the instance attributes and their values

    """
293
    state = {}
294
    for name in self._all_slots():
295
296
297
298
299
      if hasattr(self, name):
        state[name] = getattr(self, name)
    return state

  def __setstate__(self, state):
Iustin Pop's avatar
Iustin Pop committed
300
301
302
303
304
305
306
307
308
    """Generic unserializer.

    This method just restores from the serialized state the attributes
    of the current instance.

    @param state: the serialized opcode data
    @type state:  C{dict}

    """
309
310
311
312
    if not isinstance(state, dict):
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
                       type(state))

313
    for name in self._all_slots():
Iustin Pop's avatar
Iustin Pop committed
314
      if name not in state and hasattr(self, name):
315
316
317
318
319
        delattr(self, name)

    for name in state:
      setattr(self, name, state[name])

320
321
322
323
324
325
326
327
328
329
  @classmethod
  def _all_slots(cls):
    """Compute the list of all declared slots for a class.

    """
    slots = []
    for parent in cls.__mro__:
      slots.extend(getattr(parent, "__slots__", []))
    return slots

330
331
332
333
334
335
336
337
338
339
  @classmethod
  def GetAllParams(cls):
    """Compute list of all parameters for an opcode.

    """
    slots = []
    for parent in cls.__mro__:
      slots.extend(getattr(parent, "OP_PARAMS", []))
    return slots

340
341
342
343
344
345
346
347
348
  def Validate(self, set_defaults):
    """Validate opcode parameters, optionally setting default values.

    @type set_defaults: bool
    @param set_defaults: Whether to set default values
    @raise errors.OpPrereqError: When a parameter value doesn't match
                                 requirements

    """
349
    for (attr_name, default, test, _) in self.GetAllParams():
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
      assert test == ht.NoType or callable(test)

      if not hasattr(self, attr_name):
        if default == ht.NoDefault:
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
                                     (self.OP_ID, attr_name),
                                     errors.ECODE_INVAL)
        elif set_defaults:
          if callable(default):
            dval = default()
          else:
            dval = default
          setattr(self, attr_name, dval)

      if test == ht.NoType:
        # no tests here
        continue

      if set_defaults or hasattr(self, attr_name):
        attr_val = getattr(self, attr_name)
        if not test(attr_val):
          logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
                        self.OP_ID, attr_name, type(attr_val), attr_val)
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
                                     (self.OP_ID, attr_name),
                                     errors.ECODE_INVAL)

377

Iustin Pop's avatar
Iustin Pop committed
378
class OpCode(BaseOpCode):
Iustin Pop's avatar
Iustin Pop committed
379
380
381
382
383
384
  """Abstract OpCode.

  This is the root of the actual OpCode hierarchy. All clases derived
  from this class should override OP_ID.

  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
385
               children of this class.
386
387
388
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
                      string returned by Summary(); see the docstring of that
                      method for details).
389
390
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
                   get if not already defined, and types they must match.
391
392
  @cvar WITH_LU: Boolean that specifies whether this should be included in
      mcpu's dispatch table
393
394
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
                 the check steps
395
  @ivar priority: Opcode priority for queue
Iustin Pop's avatar
Iustin Pop committed
396
397

  """
398
399
  # pylint: disable-msg=E1101
  # as OP_ID is dynamically defined
400
  WITH_LU = True
401
  OP_PARAMS = [
402
403
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
404
    ("priority", constants.OP_PRIO_DEFAULT,
405
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
406
    ]
407
408
409
410

  def __getstate__(self):
    """Specialized getstate for opcodes.

Iustin Pop's avatar
Iustin Pop committed
411
412
413
414
415
416
417
    This method adds to the state dictionary the OP_ID of the class,
    so that on unload we can identify the correct class for
    instantiating the opcode.

    @rtype:   C{dict}
    @return:  the state as a dictionary

418
    """
Iustin Pop's avatar
Iustin Pop committed
419
    data = BaseOpCode.__getstate__(self)
420
421
422
423
    data["OP_ID"] = self.OP_ID
    return data

  @classmethod
424
  def LoadOpCode(cls, data):
425
426
    """Generic load opcode method.

Iustin Pop's avatar
Iustin Pop committed
427
428
429
430
431
432
433
    The method identifies the correct opcode class from the dict-form
    by looking for a OP_ID key, if this is not found, or its value is
    not available in this module as a child of this class, we fail.

    @type data:  C{dict}
    @param data: the serialized opcode

434
435
436
437
438
439
440
    """
    if not isinstance(data, dict):
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
    if "OP_ID" not in data:
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
    op_id = data["OP_ID"]
    op_class = None
Iustin Pop's avatar
Iustin Pop committed
441
442
443
    if op_id in OP_MAPPING:
      op_class = OP_MAPPING[op_id]
    else:
444
445
446
447
448
449
450
451
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
                       op_id)
    op = op_class()
    new_data = data.copy()
    del new_data["OP_ID"]
    op.__setstate__(new_data)
    return op

452
453
454
  def Summary(self):
    """Generates a summary description of this opcode.

455
456
457
458
459
    The summary is the value of the OP_ID attribute (without the "OP_"
    prefix), plus the value of the OP_DSC_FIELD attribute, if one was
    defined; this field should allow to easily identify the operation
    (for an instance creation job, e.g., it would be the instance
    name).
460

461
    """
462
    assert self.OP_ID is not None and len(self.OP_ID) > 3
463
464
465
466
467
    # all OP_ID start with OP_, we remove that
    txt = self.OP_ID[3:]
    field_name = getattr(self, "OP_DSC_FIELD", None)
    if field_name:
      field_value = getattr(self, field_name, None)
468
469
      if isinstance(field_value, (list, tuple)):
        field_value = ",".join(str(i) for i in field_value)
470
471
472
      txt = "%s(%s)" % (txt, field_value)
    return txt

473
474
475
476
477
478
479
480
481
482
483
484
485
486
  def TinySummary(self):
    """Generates a compact summary description of the opcode.

    """
    assert self.OP_ID.startswith("OP_")

    text = self.OP_ID[3:]

    for (prefix, supplement) in _SUMMARY_PREFIX.items():
      if text.startswith(prefix):
        return supplement + text[len(prefix):]

    return text

Iustin Pop's avatar
Iustin Pop committed
487

488
489
# cluster opcodes

490
class OpClusterPostInit(OpCode):
491
492
493
494
495
496
497
498
  """Post cluster initialization.

  This opcode does not touch the cluster at all. Its purpose is to run hooks
  after the cluster has been initialized.

  """


499
class OpClusterDestroy(OpCode):
Iustin Pop's avatar
Iustin Pop committed
500
501
502
503
504
505
  """Destroy the cluster.

  This opcode has no other parameters. All the state is irreversibly
  lost after the execution of this opcode.

  """
Iustin Pop's avatar
Iustin Pop committed
506
507


508
class OpClusterQuery(OpCode):
Iustin Pop's avatar
Iustin Pop committed
509
  """Query cluster information."""
Iustin Pop's avatar
Iustin Pop committed
510
511


512
class OpClusterVerify(OpCode):
Iustin Pop's avatar
Iustin Pop committed
513
514
515
516
517
518
519
520
521
  """Verify the cluster state.

  @type skip_checks: C{list}
  @ivar skip_checks: steps to be skipped from the verify process; this
                     needs to be a subset of
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed

  """
522
523
  OP_PARAMS = [
    ("skip_checks", ht.EmptyList,
524
525
526
527
     ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)), None),
    ("verbose", False, ht.TBool, None),
    ("error_codes", False, ht.TBool, None),
    ("debug_simulate_errors", False, ht.TBool, None),
528
    ]
Iustin Pop's avatar
Iustin Pop committed
529
530


531
class OpClusterVerifyDisks(OpCode):
Iustin Pop's avatar
Iustin Pop committed
532
533
534
535
  """Verify the cluster disks.

  Parameters: none

536
  Result: a tuple of four elements:
Iustin Pop's avatar
Iustin Pop committed
537
    - list of node names with bad data returned (unreachable, etc.)
Iustin Pop's avatar
Iustin Pop committed
538
    - dict of node names with broken volume groups (values: error msg)
Iustin Pop's avatar
Iustin Pop committed
539
    - list of instances with degraded disks (that should be activated)
540
541
    - dict of instances with missing logical volumes (values: (node, vol)
      pairs with details about the missing volumes)
Iustin Pop's avatar
Iustin Pop committed
542

543
544
545
546
  In normal operation, all lists should be empty. A non-empty instance
  list (3rd element of the result) is still ok (errors were fixed) but
  non-empty node list means some node is down, and probably there are
  unfixable drbd errors.
Iustin Pop's avatar
Iustin Pop committed
547
548
549
550
551
552
553

  Note that only instances that are drbd-based are taken into
  consideration. This might need to be revisited in the future.

  """


554
class OpClusterRepairDiskSizes(OpCode):
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
  """Verify the disk sizes of the instances and fixes configuration
  mimatches.

  Parameters: optional instances list, in case we want to restrict the
  checks to only a subset of the instances.

  Result: a list of tuples, (instance, disk, new-size) for changed
  configurations.

  In normal operation, the list should be empty.

  @type instances: list
  @ivar instances: the list of instances to check, or empty for all instances

  """
570
  OP_PARAMS = [
571
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
572
    ]
573
574


575
class OpClusterConfigQuery(OpCode):
576
  """Query cluster configuration values."""
577
578
579
  OP_PARAMS = [
    _POutputFields
    ]
Iustin Pop's avatar
Iustin Pop committed
580
581


582
class OpClusterRename(OpCode):
Iustin Pop's avatar
Iustin Pop committed
583
584
585
586
587
588
589
590
  """Rename the cluster.

  @type name: C{str}
  @ivar name: The new name of the cluster. The name and/or the master IP
              address will be changed to match the new name and its IP
              address.

  """
591
  OP_DSC_FIELD = "name"
592
  OP_PARAMS = [
593
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
594
    ]
595
596


597
class OpClusterSetParams(OpCode):
Iustin Pop's avatar
Iustin Pop committed
598
599
600
601
602
603
  """Change the parameters of the cluster.

  @type vg_name: C{str} or C{None}
  @ivar vg_name: The new volume group name or None to disable LVM usage.

  """
604
  OP_PARAMS = [
605
    ("vg_name", None, ht.TMaybeString, "Volume group name"),
606
607
    ("enabled_hypervisors", None,
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
608
609
            ht.TNone),
     "List of enabled hypervisors"),
610
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
611
612
613
614
                              ht.TNone),
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
     "Cluster-wide backend parameter defaults"),
615
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
616
617
                            ht.TNone),
     "Cluster-wide per-OS hypervisor parameter defaults"),
618
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
619
620
                              ht.TNone),
     "Cluster-wide OS parameter defaults"),
621
    ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
622
623
624
625
626
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
     "Master candidate pool size"),
    ("uid_pool", None, ht.NoType,
     "Set UID pool, must be list of lists describing UID ranges (two items,"
     " start and end inclusive)"),
    ("add_uids", None, ht.NoType,
     "Extend UID pool, must be list of lists describing UID ranges (two"
     " items, start and end inclusive) to be added"),
    ("remove_uids", None, ht.NoType,
     "Shrink UID pool, must be list of lists describing UID ranges (two"
     " items, start and end inclusive) to be removed"),
    ("maintain_node_health", None, ht.TMaybeBool,
     "Whether to automatically maintain node health"),
    ("prealloc_wipe_disks", None, ht.TMaybeBool,
     "Whether to wipe disks before allocating them to instances"),
    ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
     "Default iallocator for cluster"),
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
     "Master network device"),
    ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone),
     "List of reserved LVs"),
    ("hidden_os", None, _TestClusterOsList,
     "Modify list of hidden operating systems. Each modification must have"
     " two items, the operation and the OS name. The operation can be"
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
    ("blacklisted_os", None, _TestClusterOsList,
     "Modify list of blacklisted operating systems. Each modification must have"
     " two items, the operation and the OS name. The operation can be"
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
653
    ]
654
655


656
class OpClusterRedistConf(OpCode):
657
658
659
660
  """Force a full push of the cluster configuration.

  """

Michael Hanselmann's avatar
Michael Hanselmann committed
661
662
663
664

class OpQuery(OpCode):
  """Query for resources/items.

665
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
Michael Hanselmann's avatar
Michael Hanselmann committed
666
667
668
669
  @ivar fields: List of fields to retrieve
  @ivar filter: Query filter

  """
670
  OP_PARAMS = [
671
    _PQueryWhat,
672
673
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
     "Requested fields"),
674
    ("filter", None, ht.TOr(ht.TNone, ht.TListOf),
675
     "Query filter"),
Michael Hanselmann's avatar
Michael Hanselmann committed
676
677
678
679
680
681
    ]


class OpQueryFields(OpCode):
  """Query for available resource/item fields.

682
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
Michael Hanselmann's avatar
Michael Hanselmann committed
683
684
685
  @ivar fields: List of fields to retrieve

  """
686
  OP_PARAMS = [
687
688
689
    _PQueryWhat,
    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
     "Requested fields; if not given, all are returned"),
Michael Hanselmann's avatar
Michael Hanselmann committed
690
691
692
    ]


693
class OpOobCommand(OpCode):
René Nussbaumer's avatar
René Nussbaumer committed
694
  """Interact with OOB."""
695
  OP_PARAMS = [
696
697
698
699
700
701
702
703
    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
     "List of nodes to run the OOB command against"),
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
     "OOB command to be run"),
    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
     "Timeout before the OOB helper will be terminated"),
    ("ignore_status", False, ht.TBool,
     "Ignores the node offline status for power off"),
704
705
    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
     "Time in seconds to wait between powering on nodes"),
René Nussbaumer's avatar
René Nussbaumer committed
706
707
708
    ]


709
710
# node opcodes

711
class OpNodeRemove(OpCode):
Iustin Pop's avatar
Iustin Pop committed
712
713
714
715
716
717
718
  """Remove a node.

  @type node_name: C{str}
  @ivar node_name: The name of the node to remove. If the node still has
                   instances on it, the operation will fail.

  """
719
  OP_DSC_FIELD = "node_name"
720
721
722
  OP_PARAMS = [
    _PNodeName,
    ]
Iustin Pop's avatar
Iustin Pop committed
723
724


Iustin Pop's avatar
Iustin Pop committed
725
class OpNodeAdd(OpCode):
Iustin Pop's avatar
Iustin Pop committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
  """Add a node to the cluster.

  @type node_name: C{str}
  @ivar node_name: The name of the node to add. This can be a short name,
                   but it will be expanded to the FQDN.
  @type primary_ip: IP address
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
                    opcode is submitted, but will be filled during the node
                    add (so it will be visible in the job query).
  @type secondary_ip: IP address
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
                      if the cluster has been initialized in 'dual-network'
                      mode, otherwise it must not be given.
  @type readd: C{bool}
  @ivar readd: Whether to re-add an existing node to the cluster. If
               this is not passed, then the operation will abort if the node
               name is already in the cluster; use this parameter to 'repair'
               a node that had its configuration broken, or was reinstalled
               without removal from the cluster.
745
746
  @type group: C{str}
  @ivar group: The node group to which this node will belong.
747
748
749
750
  @type vm_capable: C{bool}
  @ivar vm_capable: The vm_capable node attribute
  @type master_capable: C{bool}
  @ivar master_capable: The master_capable node attribute
Iustin Pop's avatar
Iustin Pop committed
751
752

  """
753
  OP_DSC_FIELD = "node_name"
754
755
  OP_PARAMS = [
    _PNodeName,
756
757
758
759
760
761
762
763
764
    ("primary_ip", None, ht.NoType, "Primary IP address"),
    ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
    ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
    ("group", None, ht.TMaybeString, "Initial node group"),
    ("master_capable", None, ht.TMaybeBool,
     "Whether node can become master or master candidate"),
    ("vm_capable", None, ht.TMaybeBool,
     "Whether node can host instances"),
    ("ndparams", None, ht.TMaybeDict, "Node parameters"),
765
    ]
Iustin Pop's avatar
Iustin Pop committed
766
767


768
class OpNodeQuery(OpCode):
Iustin Pop's avatar
Iustin Pop committed
769
  """Compute the list of nodes."""
770
771
  OP_PARAMS = [
    _POutputFields,
772
773
774
    _PUseLocking,
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
     "Empty list to query all nodes, node names otherwise"),
775
    ]
Iustin Pop's avatar
Iustin Pop committed
776
777


778
class OpNodeQueryvols(OpCode):
779
  """Get list of volumes on node."""
780
781
  OP_PARAMS = [
    _POutputFields,
782
783
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
     "Empty list to query all nodes, node names otherwise"),
784
    ]
785
786


787
class OpNodeQueryStorage(OpCode):
788
  """Get information on storage for node(s)."""
789
790
791
  OP_PARAMS = [
    _POutputFields,
    _PStorageType,
792
793
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
    ("name", None, ht.TMaybeString, "Storage name"),
794
795
796
    ]


797
class OpNodeModifyStorage(OpCode):
798
  """Modifies the properies of a storage unit"""
799
800
801
  OP_PARAMS = [
    _PNodeName,
    _PStorageType,
802
803
    _PStorageName,
    ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
804
805
806
    ]


807
808
809
class OpRepairNodeStorage(OpCode):
  """Repairs the volume group on a node."""
  OP_DSC_FIELD = "node_name"
810
811
812
  OP_PARAMS = [
    _PNodeName,
    _PStorageType,
813
814
    _PStorageName,
    _PIgnoreConsistency,
815
816
817
    ]


818
class OpNodeSetParams(OpCode):
Iustin Pop's avatar
Iustin Pop committed
819
820
  """Change the parameters of a node."""
  OP_DSC_FIELD = "node_name"
821
822
823
  OP_PARAMS = [
    _PNodeName,
    _PForce,
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
    ("master_candidate", None, ht.TMaybeBool,
     "Whether the node should become a master candidate"),
    ("offline", None, ht.TMaybeBool,
     "Whether the node should be marked as offline"),
    ("drained", None, ht.TMaybeBool,
     "Whether the node should be marked as drained"),
    ("auto_promote", False, ht.TBool,
     "Whether node(s) should be promoted to master candidate if necessary"),
    ("master_capable", None, ht.TMaybeBool,
     "Denote whether node can become master or master candidate"),
    ("vm_capable", None, ht.TMaybeBool,
     "Denote whether node can host instances"),
    ("secondary_ip", None, ht.TMaybeString,
     "Change node's secondary IP address"),
    ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
    ("powered", None, ht.TMaybeBool,
     "Whether the node should be marked as powered"),
Iustin Pop's avatar
Iustin Pop committed
841
842
    ]

Iustin Pop's avatar
Iustin Pop committed
843

844
class OpNodePowercycle(OpCode):
Iustin Pop's avatar
Iustin Pop committed
845
846
  """Tries to powercycle a node."""
  OP_DSC_FIELD = "node_name"
847
848
849
  OP_PARAMS = [
    _PNodeName,
    _PForce,
Iustin Pop's avatar
Iustin Pop committed
850
851
    ]

852

853
class OpNodeMigrate(OpCode):
854
855
  """Migrate all instances from a node."""
  OP_DSC_FIELD = "node_name"
856
857
858
859
  OP_PARAMS = [
    _PNodeName,
    _PMigrationMode,
    _PMigrationLive,
860
861
    ("iallocator", None, ht.TMaybeString,
     "Iallocator for deciding the target node for shared-storage instances"),
862
863
864
    ]


865
class OpNodeEvacStrategy(OpCode):
866
867
  """Compute the evacuation strategy for a list of nodes."""
  OP_DSC_FIELD = "nodes"
868
  OP_PARAMS = [
869
870
871
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None),
    ("remote_node", None, ht.TMaybeString, None),
    ("iallocator", None, ht.TMaybeString, None),
872
    ]
873
874


Iustin Pop's avatar
Iustin Pop committed
875
876
# instance opcodes

877
class OpInstanceCreate(OpCode):
878
879
880
881
882
883
884
  """Create an instance.

  @ivar instance_name: Instance name
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
  @ivar source_handshake: Signed handshake from source (remote import only)
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
  @ivar source_instance_name: Previous name of instance (remote import only)
885
886
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
    (remote import only)
887
888

  """
889
  OP_DSC_FIELD = "instance_name"
890
891
  OP_PARAMS = [
    _PInstanceName,
892
893
894
895
    _PForceVariant,
    _PWaitForSync,
    _PNameCheck,
    ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
896
897
898
899
900
901
902
903
904
905
906
    ("disks", ht.NoDefault,
     # TODO: Generate check from constants.IDISK_PARAMS_TYPES
     ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
                           ht.TOr(ht.TNonEmptyString, ht.TInt))),
     "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
     " each disk definition must contain a ``%s`` value and"
     " can contain an optional ``%s`` value denoting the disk access mode"
     " (%s)" %
     (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
      constants.IDISK_MODE,
      " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
    ("disk_template", ht.NoDefault, _CheckDiskTemplate, "Disk template"),
    ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
     "Driver for file-backed disks"),
    ("file_storage_dir", None, ht.TMaybeString,
     "Directory for storing file-backed disks"),
    ("hvparams", ht.EmptyDict, ht.TDict,
     "Hypervisor parameters for instance, hypervisor-dependent"),
    ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
    ("iallocator", None, ht.TMaybeString,
     "Iallocator for deciding which node(s) to use"),
    ("identify_defaults", False, ht.TBool,
     "Reset instance parameters to default if equal"),
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
     "Instance creation mode"),
922
923
924
925
926
927
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
     "List of NIC (network interface) definitions, for example"
     " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
     " contain the optional values %s" %
     (constants.INIC_IP,
      ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
928
929
930
931
932
933
934
935
936
937
    ("no_install", None, ht.TMaybeBool,
     "Do not install the OS (will disable automatic start)"),
    ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
    ("os_type", None, ht.TMaybeString, "Operating system"),
    ("pnode", None, ht.TMaybeString, "Primary node"),
    ("snode", None, ht.TMaybeString, "Secondary node"),
    ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
     "Signed handshake from source (remote import only)"),
    ("source_instance_name", None, ht.TMaybeString,
     "Source instance name (remote import only)"),
938
    ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
939
940
     ht.TPositiveInt,
     "How long source instance was given to shut down (remote import only)"),
941
942
943
944
945
    ("source_x509_ca", None, ht.TMaybeString,
     "Source X509 CA in PEM format (remote import only)"),
    ("src_node", None, ht.TMaybeString, "Source node for import"),
    ("src_path", None, ht.TMaybeString, "Source directory for import"),
    ("start", True, ht.TBool, "Whether to start instance after creation"),
946
    ]
Iustin Pop's avatar
Iustin Pop committed
947
948


949
class OpInstanceReinstall(OpCode):
Iustin Pop's avatar
Iustin Pop committed
950
  """Reinstall an instance's OS."""
951
  OP_DSC_FIELD = "instance_name"
952
953
  OP_PARAMS = [
    _PInstanceName,
954
955
956
    _PForceVariant,
    ("os_type", None, ht.TMaybeString, "Instance operating system"),
    ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
957
    ]
958
959


960
class OpInstanceRemove(OpCode):
Iustin Pop's avatar
Iustin Pop committed
961
  """Remove an instance."""
962
  OP_DSC_FIELD = "instance_name"
963
964
965
  OP_PARAMS = [
    _PInstanceName,
    _PShutdownTimeout,
966
967
    ("ignore_failures", False, ht.TBool,
     "Whether to ignore failures during removal"),
968
    ]
Iustin Pop's avatar
Iustin Pop committed
969
970


971
class OpInstanceRename(OpCode):
972
  """Rename an instance."""
973
974
  OP_PARAMS = [
    _PInstanceName,
975
976
977
    _PNameCheck,
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
    ("ip_check", False, ht.TBool, _PIpCheckDoc),
978
    ]
979
980


981
class OpInstanceStartup(OpCode):
Iustin Pop's avatar
Iustin Pop committed
982
  """Startup an instance."""
983
  OP_DSC_FIELD = "instance_name"
984
985
986
987
  OP_PARAMS = [
    _PInstanceName,
    _PForce,
    _PIgnoreOfflineNodes,
988
989
990
    ("hvparams", ht.EmptyDict, ht.TDict,
     "Temporary hypervisor parameters, hypervisor-dependent"),
    ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
991
    ]
Iustin Pop's avatar
Iustin Pop committed
992
993


994
class OpInstanceShutdown(OpCode):
Iustin Pop's avatar
Iustin Pop committed
995
  """Shutdown an instance."""
996
  OP_DSC_FIELD = "instance_name"
997
998
999
  OP_PARAMS = [
    _PInstanceName,
    _PIgnoreOfflineNodes,
1000
1001
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
     "How long to wait for instance to shut down"),
1002
    ]
Iustin Pop's avatar
Iustin Pop committed
1003
1004


1005
class OpInstanceReboot(OpCode):
1006
  """Reboot an instance."""
1007
  OP_DSC_FIELD = "instance_name"
1008
1009
1010
  OP_PARAMS = [
    _PInstanceName,
    _PShutdownTimeout,
1011
1012
1013
1014
    ("ignore_secondaries", False, ht.TBool,
     "Whether to start the instance even if secondary disks are failing"),
    ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
     "How to reboot instance"),
1015
    ]
1016
1017


1018
class OpInstanceReplaceDisks(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1019
  """Replace the disks of an instance."""
1020
  OP_DSC_FIELD = "instance_name"
1021
1022
  OP_PARAMS = [
    _PInstanceName,
1023
1024
1025
1026
1027
1028
1029
1030
1031
    ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
     "Replacement mode"),
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
     "Disk indexes"),
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
    ("iallocator", None, ht.TMaybeString,
     "Iallocator for deciding new secondary node"),
    ("early_release", False, ht.TBool,
     "Whether to release locks as soon as possible"),
1032
    ]
Iustin Pop's avatar
Iustin Pop committed
1033
1034


1035
class OpInstanceFailover(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1036
  """Failover an instance."""
1037
  OP_DSC_FIELD = "instance_name"
1038
1039
1040
  OP_PARAMS = [
    _PInstanceName,
    _PShutdownTimeout,
1041
    _PIgnoreConsistency,
1042
1043
1044
1045
    ("iallocator", None, ht.TMaybeString,
     "Iallocator for deciding the target node for shared-storage instances"),
    ("target_node", None, ht.TMaybeString,
     "Target node for shared-storage instances"),
1046
    ]
Iustin Pop's avatar
Iustin Pop committed
1047
1048


1049
class OpInstanceMigrate(OpCode):
1050
1051
1052
1053
1054
  """Migrate an instance.

  This migrates (without shutting down an instance) to its secondary
  node.

Iustin Pop's avatar
Iustin Pop committed
1055
  @ivar instance_name: the name of the instance
1056
  @ivar mode: the migration mode (live, non-live or None for auto)
1057
1058

  """
Iustin Pop's avatar
Iustin Pop committed
1059
  OP_DSC_FIELD = "instance_name"
1060
1061
1062
1063
  OP_PARAMS = [
    _PInstanceName,
    _PMigrationMode,
    _PMigrationLive,
1064
1065
    ("cleanup", False, ht.TBool,
     "Whether a previously failed migration should be cleaned up"),
1066
1067
1068
1069
    ("iallocator", None, ht.TMaybeString,
     "Iallocator for deciding the target node for shared-storage instances"),
    ("target_node", None, ht.TMaybeString,
     "Target node for shared-storage instances"),
1070
1071
    ("allow_failover", False, ht.TBool,
     "Whether we can fallback to failover if migration is not possible"),
1072
    ]
1073
1074


1075
class OpInstanceMove(OpCode):
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
  """Move an instance.

  This move (with shutting down an instance and data copying) to an
  arbitrary node.

  @ivar instance_name: the name of the instance
  @ivar target_node: the destination node

  """
  OP_DSC_FIELD = "instance_name"
1086
1087
1088
  OP_PARAMS = [
    _PInstanceName,
    _PShutdownTimeout,
1089
    ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
Balazs Lecz's avatar
Balazs Lecz committed
1090
    ]
1091
1092


1093
class OpInstanceConsole(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1094
  """Connect to an instance's console."""
1095
  OP_DSC_FIELD = "instance_name"
1096
1097
1098
  OP_PARAMS = [
    _PInstanceName
    ]
Iustin Pop's avatar
Iustin Pop committed
1099
1100


1101
class OpInstanceActivateDisks(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1102
  """Activate an instance's disks."""
1103
  OP_DSC_FIELD = "instance_name"
1104
1105
  OP_PARAMS = [
    _PInstanceName,
1106
    ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1107
    ]
Iustin Pop's avatar
Iustin Pop committed
1108
1109


1110
class OpInstanceDeactivateDisks(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1111
  """Deactivate an instance's disks."""
1112
  OP_DSC_FIELD = "instance_name"
1113
  OP_PARAMS = [
1114
1115
    _PInstanceName,
    _PForce,
1116
    ]
Iustin Pop's avatar
Iustin Pop committed
1117
1118


1119
class OpInstanceRecreateDisks(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1120
1121
  """Deactivate an instance's disks."""
  OP_DSC_FIELD = "instance_name"
1122
1123
  OP_PARAMS = [
    _PInstanceName,
1124
1125
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
     "List of disk indexes"),
Guido Trotter's avatar
Guido Trotter committed
1126
1127
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
     "New instance nodes, if relocation is desired"),
1128
    ]
Iustin Pop's avatar
Iustin Pop committed
1129
1130


1131
class OpInstanceQuery(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1132
  """Compute the list of instances."""
1133
1134
  OP_PARAMS = [
    _POutputFields,
1135
1136
1137
    _PUseLocking,
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
     "Empty list to query all instances, instance names otherwise"),
1138
    ]
Iustin Pop's avatar
Iustin Pop committed
1139
1140


1141
class OpInstanceQueryData(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1142
  """Compute the run-time status of instances."""
1143
  OP_PARAMS = [
Michael Hanselmann's avatar
Michael Hanselmann committed
1144
1145
1146
1147
1148
1149
    _PUseLocking,
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
     "Instance names"),
    ("static", False, ht.TBool,
     "Whether to only return configuration data without querying"
     " nodes"),
1150
    ]
Iustin Pop's avatar
Iustin Pop committed
1151
1152


1153
class OpInstanceSetParams(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1154
  """Change the parameters of an instance."""
1155
  OP_DSC_FIELD = "instance_name"
1156
1157
1158
  OP_PARAMS = [
    _PInstanceName,
    _PForce,
1159
    _PForceVariant,
1160
    # TODO: Use _TestNicDef
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
    ("nics", ht.EmptyList, ht.TList,
     "List of NIC changes. Each item is of the form ``(op, settings)``."
     " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
     " ``%s`` to remove the last NIC or a number to modify the settings"
     " of the NIC with that index." %
     (constants.DDM_ADD, constants.DDM_REMOVE)),
    ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
    ("hvparams", ht.EmptyDict, ht.TDict,
     "Per-instance hypervisor parameters, hypervisor-dependent"),
    ("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate),
     "Disk template for instance"),
    ("remote_node", None, ht.TMaybeString,
     "Secondary node (used when changing disk template)"),
    ("os_name", None, ht.TMaybeString,
     "Change instance's OS name. Does not reinstall the instance."),
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
Guido Trotter's avatar
Guido Trotter committed
1178
1179
    ("wait_for_sync", True, ht.TBool,
     "Whether to wait for the disk to synchronize, when changing template"),
1180
    ]
Iustin Pop's avatar
Iustin Pop committed
1181
1182


Iustin Pop's avatar
Iustin Pop committed
1183
class OpInstanceGrowDisk(OpCode):
Iustin Pop's avatar
Iustin Pop committed
1184
  """Grow a disk of an instance."""
1185
  OP_DSC_FIELD = "instance_name"
1186
1187
  OP_PARAMS = [
    _PInstanceName,
1188
1189
1190
1191
    _PWaitForSync,
    ("disk", ht.NoDefault, ht.TInt, "Disk index"),
    ("amount", ht.NoDefault, ht.TInt,
     "Amount of disk space to add (megabytes)"),
1192
    ]
Iustin Pop's avatar
Iustin Pop committed
1193
1194