Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ bc8bbda1

History | View | Annotate | Download (21 kB)

1
#
2
#
3

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

    
21

    
22
"""OpCodes module
23

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

27
Every operation which modifies the cluster state is expressed via
28
opcodes.
29

30
"""
31

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

    
36

    
37
class BaseOpCode(object):
38
  """A simple serializable object.
39

40
  This object serves as a parent class for OpCode without any custom
41
  field handling.
42

43
  """
44
  __slots__ = []
45

    
46
  def __init__(self, **kwargs):
47
    """Constructor for BaseOpCode.
48

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

54
    """
55
    slots = self._all_slots()
56
    for key in kwargs:
57
      if key not in slots:
58
        raise TypeError("Object %s doesn't support the parameter '%s'" %
59
                        (self.__class__.__name__, key))
60
      setattr(self, key, kwargs[key])
61

    
62
  def __getstate__(self):
63
    """Generic serializer.
64

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

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

71
    """
72
    state = {}
73
    for name in self._all_slots():
74
      if hasattr(self, name):
75
        state[name] = getattr(self, name)
76
    return state
77

    
78
  def __setstate__(self, state):
79
    """Generic unserializer.
80

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

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

87
    """
88
    if not isinstance(state, dict):
89
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
90
                       type(state))
91

    
92
    for name in self._all_slots():
93
      if name not in state and hasattr(self, name):
94
        delattr(self, name)
95

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

    
99
  @classmethod
100
  def _all_slots(cls):
101
    """Compute the list of all declared slots for a class.
102

103
    """
104
    slots = []
105
    for parent in cls.__mro__:
106
      slots.extend(getattr(parent, "__slots__", []))
107
    return slots
108

    
109

    
110
class OpCode(BaseOpCode):
111
  """Abstract OpCode.
112

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

116
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
117
               children of this class.
118
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
119
                 the check steps
120

121
  """
122
  OP_ID = "OP_ABSTRACT"
123
  __slots__ = ["dry_run", "debug_level"]
124

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

128
    This method adds to the state dictionary the OP_ID of the class,
129
    so that on unload we can identify the correct class for
130
    instantiating the opcode.
131

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

135
    """
136
    data = BaseOpCode.__getstate__(self)
137
    data["OP_ID"] = self.OP_ID
138
    return data
139

    
140
  @classmethod
141
  def LoadOpCode(cls, data):
142
    """Generic load opcode method.
143

144
    The method identifies the correct opcode class from the dict-form
145
    by looking for a OP_ID key, if this is not found, or its value is
146
    not available in this module as a child of this class, we fail.
147

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

151
    """
152
    if not isinstance(data, dict):
153
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
154
    if "OP_ID" not in data:
155
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
156
    op_id = data["OP_ID"]
157
    op_class = None
158
    if op_id in OP_MAPPING:
159
      op_class = OP_MAPPING[op_id]
160
    else:
161
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
162
                       op_id)
163
    op = op_class()
164
    new_data = data.copy()
165
    del new_data["OP_ID"]
166
    op.__setstate__(new_data)
167
    return op
168

    
169
  def Summary(self):
170
    """Generates a summary description of this opcode.
171

172
    """
173
    # all OP_ID start with OP_, we remove that
174
    txt = self.OP_ID[3:]
175
    field_name = getattr(self, "OP_DSC_FIELD", None)
176
    if field_name:
177
      field_value = getattr(self, field_name, None)
178
      if isinstance(field_value, (list, tuple)):
179
        field_value = ",".join(str(i) for i in field_value)
180
      txt = "%s(%s)" % (txt, field_value)
181
    return txt
182

    
183

    
184
# cluster opcodes
185

    
186
class OpPostInitCluster(OpCode):
187
  """Post cluster initialization.
188

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

192
  """
193
  OP_ID = "OP_CLUSTER_POST_INIT"
194
  __slots__ = []
195

    
196

    
197
class OpDestroyCluster(OpCode):
198
  """Destroy the cluster.
199

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

203
  """
204
  OP_ID = "OP_CLUSTER_DESTROY"
205
  __slots__ = []
206

    
207

    
208
class OpQueryClusterInfo(OpCode):
209
  """Query cluster information."""
210
  OP_ID = "OP_CLUSTER_QUERY"
211
  __slots__ = []
212

    
213

    
214
class OpVerifyCluster(OpCode):
215
  """Verify the cluster state.
216

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

223
  """
224
  OP_ID = "OP_CLUSTER_VERIFY"
225
  __slots__ = ["skip_checks", "verbose", "error_codes",
226
               "debug_simulate_errors"]
227

    
228

    
229
class OpVerifyDisks(OpCode):
230
  """Verify the cluster disks.
231

232
  Parameters: none
233

234
  Result: a tuple of four elements:
235
    - list of node names with bad data returned (unreachable, etc.)
236
    - dict of node names with broken volume groups (values: error msg)
237
    - list of instances with degraded disks (that should be activated)
238
    - dict of instances with missing logical volumes (values: (node, vol)
239
      pairs with details about the missing volumes)
240

241
  In normal operation, all lists should be empty. A non-empty instance
242
  list (3rd element of the result) is still ok (errors were fixed) but
243
  non-empty node list means some node is down, and probably there are
244
  unfixable drbd errors.
245

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

249
  """
250
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
251
  __slots__ = []
252

    
253

    
254
class OpRepairDiskSizes(OpCode):
255
  """Verify the disk sizes of the instances and fixes configuration
256
  mimatches.
257

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

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

264
  In normal operation, the list should be empty.
265

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

269
  """
270
  OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
271
  __slots__ = ["instances"]
272

    
273

    
274
class OpQueryConfigValues(OpCode):
275
  """Query cluster configuration values."""
276
  OP_ID = "OP_CLUSTER_CONFIG_QUERY"
277
  __slots__ = ["output_fields"]
278

    
279

    
280
class OpRenameCluster(OpCode):
281
  """Rename the cluster.
282

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

288
  """
289
  OP_ID = "OP_CLUSTER_RENAME"
290
  OP_DSC_FIELD = "name"
291
  __slots__ = ["name"]
292

    
293

    
294
class OpSetClusterParams(OpCode):
295
  """Change the parameters of the cluster.
296

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

300
  """
301
  OP_ID = "OP_CLUSTER_SET_PARAMS"
302
  __slots__ = [
303
    "vg_name",
304
    "drbd_helper",
305
    "enabled_hypervisors",
306
    "hvparams",
307
    "os_hvp",
308
    "beparams",
309
    "osparams",
310
    "nicparams",
311
    "candidate_pool_size",
312
    "maintain_node_health",
313
    "uid_pool",
314
    "add_uids",
315
    "remove_uids",
316
    "default_iallocator",
317
    "reserved_lvs",
318
    ]
319

    
320

    
321
class OpRedistributeConfig(OpCode):
322
  """Force a full push of the cluster configuration.
323

324
  """
325
  OP_ID = "OP_CLUSTER_REDIST_CONF"
326
  __slots__ = []
327

    
328
# node opcodes
329

    
330
class OpRemoveNode(OpCode):
331
  """Remove a node.
332

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

337
  """
338
  OP_ID = "OP_NODE_REMOVE"
339
  OP_DSC_FIELD = "node_name"
340
  __slots__ = ["node_name"]
341

    
342

    
343
class OpAddNode(OpCode):
344
  """Add a node to the cluster.
345

346
  @type node_name: C{str}
347
  @ivar node_name: The name of the node to add. This can be a short name,
348
                   but it will be expanded to the FQDN.
349
  @type primary_ip: IP address
350
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
351
                    opcode is submitted, but will be filled during the node
352
                    add (so it will be visible in the job query).
353
  @type secondary_ip: IP address
354
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
355
                      if the cluster has been initialized in 'dual-network'
356
                      mode, otherwise it must not be given.
357
  @type readd: C{bool}
358
  @ivar readd: Whether to re-add an existing node to the cluster. If
359
               this is not passed, then the operation will abort if the node
360
               name is already in the cluster; use this parameter to 'repair'
361
               a node that had its configuration broken, or was reinstalled
362
               without removal from the cluster.
363

364
  """
365
  OP_ID = "OP_NODE_ADD"
366
  OP_DSC_FIELD = "node_name"
367
  __slots__ = ["node_name", "primary_ip", "secondary_ip", "readd"]
368

    
369

    
370
class OpQueryNodes(OpCode):
371
  """Compute the list of nodes."""
372
  OP_ID = "OP_NODE_QUERY"
373
  __slots__ = ["output_fields", "names", "use_locking"]
374

    
375

    
376
class OpQueryNodeVolumes(OpCode):
377
  """Get list of volumes on node."""
378
  OP_ID = "OP_NODE_QUERYVOLS"
379
  __slots__ = ["nodes", "output_fields"]
380

    
381

    
382
class OpQueryNodeStorage(OpCode):
383
  """Get information on storage for node(s)."""
384
  OP_ID = "OP_NODE_QUERY_STORAGE"
385
  __slots__ = [
386
    "nodes",
387
    "storage_type",
388
    "name",
389
    "output_fields",
390
    ]
391

    
392

    
393
class OpModifyNodeStorage(OpCode):
394
  """Modifies the properies of a storage unit"""
395
  OP_ID = "OP_NODE_MODIFY_STORAGE"
396
  __slots__ = [
397
    "node_name",
398
    "storage_type",
399
    "name",
400
    "changes",
401
    ]
402

    
403

    
404
class OpRepairNodeStorage(OpCode):
405
  """Repairs the volume group on a node."""
406
  OP_ID = "OP_REPAIR_NODE_STORAGE"
407
  OP_DSC_FIELD = "node_name"
408
  __slots__ = [
409
    "node_name",
410
    "storage_type",
411
    "name",
412
    "ignore_consistency",
413
    ]
414

    
415

    
416
class OpSetNodeParams(OpCode):
417
  """Change the parameters of a node."""
418
  OP_ID = "OP_NODE_SET_PARAMS"
419
  OP_DSC_FIELD = "node_name"
420
  __slots__ = [
421
    "node_name",
422
    "force",
423
    "master_candidate",
424
    "offline",
425
    "drained",
426
    "auto_promote",
427
    ]
428

    
429

    
430
class OpPowercycleNode(OpCode):
431
  """Tries to powercycle a node."""
432
  OP_ID = "OP_NODE_POWERCYCLE"
433
  OP_DSC_FIELD = "node_name"
434
  __slots__ = [
435
    "node_name",
436
    "force",
437
    ]
438

    
439

    
440
class OpMigrateNode(OpCode):
441
  """Migrate all instances from a node."""
442
  OP_ID = "OP_NODE_MIGRATE"
443
  OP_DSC_FIELD = "node_name"
444
  __slots__ = [
445
    "node_name",
446
    "mode",
447
    "live",
448
    ]
449

    
450

    
451
class OpNodeEvacuationStrategy(OpCode):
452
  """Compute the evacuation strategy for a list of nodes."""
453
  OP_ID = "OP_NODE_EVAC_STRATEGY"
454
  OP_DSC_FIELD = "nodes"
455
  __slots__ = ["nodes", "iallocator", "remote_node"]
456

    
457

    
458
# instance opcodes
459

    
460
class OpCreateInstance(OpCode):
461
  """Create an instance.
462

463
  @ivar instance_name: Instance name
464
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
465
  @ivar source_handshake: Signed handshake from source (remote import only)
466
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
467
  @ivar source_instance_name: Previous name of instance (remote import only)
468

469
  """
470
  OP_ID = "OP_INSTANCE_CREATE"
471
  OP_DSC_FIELD = "instance_name"
472
  __slots__ = [
473
    "instance_name",
474
    "os_type", "force_variant", "no_install",
475
    "pnode", "disk_template", "snode", "mode",
476
    "disks", "nics",
477
    "src_node", "src_path", "start", "identify_defaults",
478
    "wait_for_sync", "ip_check", "name_check",
479
    "file_storage_dir", "file_driver",
480
    "iallocator",
481
    "hypervisor", "hvparams", "beparams", "osparams",
482
    "source_handshake",
483
    "source_x509_ca",
484
    "source_instance_name",
485
    ]
486

    
487

    
488
class OpReinstallInstance(OpCode):
489
  """Reinstall an instance's OS."""
490
  OP_ID = "OP_INSTANCE_REINSTALL"
491
  OP_DSC_FIELD = "instance_name"
492
  __slots__ = ["instance_name", "os_type", "force_variant"]
493

    
494

    
495
class OpRemoveInstance(OpCode):
496
  """Remove an instance."""
497
  OP_ID = "OP_INSTANCE_REMOVE"
498
  OP_DSC_FIELD = "instance_name"
499
  __slots__ = [
500
    "instance_name",
501
    "ignore_failures",
502
    "shutdown_timeout",
503
    ]
504

    
505

    
506
class OpRenameInstance(OpCode):
507
  """Rename an instance."""
508
  OP_ID = "OP_INSTANCE_RENAME"
509
  __slots__ = [
510
    "instance_name", "ip_check", "new_name", "name_check",
511
    ]
512

    
513

    
514
class OpStartupInstance(OpCode):
515
  """Startup an instance."""
516
  OP_ID = "OP_INSTANCE_STARTUP"
517
  OP_DSC_FIELD = "instance_name"
518
  __slots__ = [
519
    "instance_name", "force", "hvparams", "beparams",
520
    ]
521

    
522

    
523
class OpShutdownInstance(OpCode):
524
  """Shutdown an instance."""
525
  OP_ID = "OP_INSTANCE_SHUTDOWN"
526
  OP_DSC_FIELD = "instance_name"
527
  __slots__ = ["instance_name", "timeout"]
528

    
529

    
530
class OpRebootInstance(OpCode):
531
  """Reboot an instance."""
532
  OP_ID = "OP_INSTANCE_REBOOT"
533
  OP_DSC_FIELD = "instance_name"
534
  __slots__ = [
535
    "instance_name", "reboot_type", "ignore_secondaries", "shutdown_timeout",
536
    ]
537

    
538

    
539
class OpReplaceDisks(OpCode):
540
  """Replace the disks of an instance."""
541
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
542
  OP_DSC_FIELD = "instance_name"
543
  __slots__ = [
544
    "instance_name", "remote_node", "mode", "disks", "iallocator",
545
    "early_release",
546
    ]
547

    
548

    
549
class OpFailoverInstance(OpCode):
550
  """Failover an instance."""
551
  OP_ID = "OP_INSTANCE_FAILOVER"
552
  OP_DSC_FIELD = "instance_name"
553
  __slots__ = [
554
    "instance_name", "ignore_consistency", "shutdown_timeout",
555
    ]
556

    
557

    
558
class OpMigrateInstance(OpCode):
559
  """Migrate an instance.
560

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

564
  @ivar instance_name: the name of the instance
565
  @ivar mode: the migration mode (live, non-live or None for auto)
566

567
  """
568
  OP_ID = "OP_INSTANCE_MIGRATE"
569
  OP_DSC_FIELD = "instance_name"
570
  __slots__ = ["instance_name", "mode", "cleanup", "live"]
571

    
572

    
573
class OpMoveInstance(OpCode):
574
  """Move an instance.
575

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

579
  @ivar instance_name: the name of the instance
580
  @ivar target_node: the destination node
581

582
  """
583
  OP_ID = "OP_INSTANCE_MOVE"
584
  OP_DSC_FIELD = "instance_name"
585
  __slots__ = [
586
    "instance_name", "target_node", "shutdown_timeout",
587
    ]
588

    
589

    
590
class OpConnectConsole(OpCode):
591
  """Connect to an instance's console."""
592
  OP_ID = "OP_INSTANCE_CONSOLE"
593
  OP_DSC_FIELD = "instance_name"
594
  __slots__ = ["instance_name"]
595

    
596

    
597
class OpActivateInstanceDisks(OpCode):
598
  """Activate an instance's disks."""
599
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
600
  OP_DSC_FIELD = "instance_name"
601
  __slots__ = ["instance_name", "ignore_size"]
602

    
603

    
604
class OpDeactivateInstanceDisks(OpCode):
605
  """Deactivate an instance's disks."""
606
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
607
  OP_DSC_FIELD = "instance_name"
608
  __slots__ = ["instance_name"]
609

    
610

    
611
class OpRecreateInstanceDisks(OpCode):
612
  """Deactivate an instance's disks."""
613
  OP_ID = "OP_INSTANCE_RECREATE_DISKS"
614
  OP_DSC_FIELD = "instance_name"
615
  __slots__ = ["instance_name", "disks"]
616

    
617

    
618
class OpQueryInstances(OpCode):
619
  """Compute the list of instances."""
620
  OP_ID = "OP_INSTANCE_QUERY"
621
  __slots__ = ["output_fields", "names", "use_locking"]
622

    
623

    
624
class OpQueryInstanceData(OpCode):
625
  """Compute the run-time status of instances."""
626
  OP_ID = "OP_INSTANCE_QUERY_DATA"
627
  __slots__ = ["instances", "static"]
628

    
629

    
630
class OpSetInstanceParams(OpCode):
631
  """Change the parameters of an instance."""
632
  OP_ID = "OP_INSTANCE_SET_PARAMS"
633
  OP_DSC_FIELD = "instance_name"
634
  __slots__ = [
635
    "instance_name",
636
    "hvparams", "beparams", "osparams", "force",
637
    "nics", "disks", "disk_template",
638
    "remote_node", "os_name", "force_variant",
639
    ]
640

    
641

    
642
class OpGrowDisk(OpCode):
643
  """Grow a disk of an instance."""
644
  OP_ID = "OP_INSTANCE_GROW_DISK"
645
  OP_DSC_FIELD = "instance_name"
646
  __slots__ = [
647
    "instance_name", "disk", "amount", "wait_for_sync",
648
    ]
649

    
650

    
651
# OS opcodes
652
class OpDiagnoseOS(OpCode):
653
  """Compute the list of guest operating systems."""
654
  OP_ID = "OP_OS_DIAGNOSE"
655
  __slots__ = ["output_fields", "names"]
656

    
657

    
658
# Exports opcodes
659
class OpQueryExports(OpCode):
660
  """Compute the list of exported images."""
661
  OP_ID = "OP_BACKUP_QUERY"
662
  __slots__ = ["nodes", "use_locking"]
663

    
664

    
665
class OpPrepareExport(OpCode):
666
  """Prepares an instance export.
667

668
  @ivar instance_name: Instance name
669
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
670

671
  """
672
  OP_ID = "OP_BACKUP_PREPARE"
673
  OP_DSC_FIELD = "instance_name"
674
  __slots__ = [
675
    "instance_name", "mode",
676
    ]
677

    
678

    
679
class OpExportInstance(OpCode):
680
  """Export an instance.
681

682
  For local exports, the export destination is the node name. For remote
683
  exports, the export destination is a list of tuples, each consisting of
684
  hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
685
  the cluster domain secret over the value "${index}:${hostname}:${port}". The
686
  destination X509 CA must be a signed certificate.
687

688
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
689
  @ivar target_node: Export destination
690
  @ivar x509_key_name: X509 key to use (remote export only)
691
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
692
                             only)
693

694
  """
695
  OP_ID = "OP_BACKUP_EXPORT"
696
  OP_DSC_FIELD = "instance_name"
697
  __slots__ = [
698
    # TODO: Rename target_node as it changes meaning for different export modes
699
    # (e.g. "destination")
700
    "instance_name", "target_node", "shutdown", "shutdown_timeout",
701
    "remove_instance",
702
    "ignore_remove_failures",
703
    "mode",
704
    "x509_key_name",
705
    "destination_x509_ca",
706
    ]
707

    
708

    
709
class OpRemoveExport(OpCode):
710
  """Remove an instance's export."""
711
  OP_ID = "OP_BACKUP_REMOVE"
712
  OP_DSC_FIELD = "instance_name"
713
  __slots__ = ["instance_name"]
714

    
715

    
716
# Tags opcodes
717
class OpGetTags(OpCode):
718
  """Returns the tags of the given object."""
719
  OP_ID = "OP_TAGS_GET"
720
  OP_DSC_FIELD = "name"
721
  __slots__ = ["kind", "name"]
722

    
723

    
724
class OpSearchTags(OpCode):
725
  """Searches the tags in the cluster for a given pattern."""
726
  OP_ID = "OP_TAGS_SEARCH"
727
  OP_DSC_FIELD = "pattern"
728
  __slots__ = ["pattern"]
729

    
730

    
731
class OpAddTags(OpCode):
732
  """Add a list of tags on a given object."""
733
  OP_ID = "OP_TAGS_SET"
734
  __slots__ = ["kind", "name", "tags"]
735

    
736

    
737
class OpDelTags(OpCode):
738
  """Remove a list of tags from a given object."""
739
  OP_ID = "OP_TAGS_DEL"
740
  __slots__ = ["kind", "name", "tags"]
741

    
742

    
743
# Test opcodes
744
class OpTestDelay(OpCode):
745
  """Sleeps for a configured amount of time.
746

747
  This is used just for debugging and testing.
748

749
  Parameters:
750
    - duration: the time to sleep
751
    - on_master: if true, sleep on the master
752
    - on_nodes: list of nodes in which to sleep
753

754
  If the on_master parameter is true, it will execute a sleep on the
755
  master (before any node sleep).
756

757
  If the on_nodes list is not empty, it will sleep on those nodes
758
  (after the sleep on the master, if that is enabled).
759

760
  As an additional feature, the case of duration < 0 will be reported
761
  as an execution error, so this opcode can be used as a failure
762
  generator. The case of duration == 0 will not be treated specially.
763

764
  """
765
  OP_ID = "OP_TEST_DELAY"
766
  OP_DSC_FIELD = "duration"
767
  __slots__ = ["duration", "on_master", "on_nodes", "repeat"]
768

    
769

    
770
class OpTestAllocator(OpCode):
771
  """Allocator framework testing.
772

773
  This opcode has two modes:
774
    - gather and return allocator input for a given mode (allocate new
775
      or replace secondary) and a given instance definition (direction
776
      'in')
777
    - run a selected allocator for a given operation (as above) and
778
      return the allocator output (direction 'out')
779

780
  """
781
  OP_ID = "OP_TEST_ALLOCATOR"
782
  OP_DSC_FIELD = "allocator"
783
  __slots__ = [
784
    "direction", "mode", "allocator", "name",
785
    "mem_size", "disks", "disk_template",
786
    "os", "tags", "nics", "vcpus", "hypervisor",
787
    "evac_nodes",
788
    ]
789

    
790

    
791
class OpTestJobqueue(OpCode):
792
  """Utility opcode to test some aspects of the job queue.
793

794
  """
795
  OP_ID = "OP_TEST_JQUEUE"
796
  __slots__ = [
797
    "notify_waitlock",
798
    "notify_exec",
799
    "log_messages",
800
    "fail",
801
    ]
802

    
803

    
804
OP_MAPPING = dict([(v.OP_ID, v) for v in globals().values()
805
                   if (isinstance(v, type) and issubclass(v, OpCode) and
806
                       hasattr(v, "OP_ID"))])