Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 5fbbd028

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
  @ivar priority: Opcode priority for queue
121

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

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

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

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

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

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

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

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

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

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

173
    """
174
    # all OP_ID start with OP_, we remove that
175
    txt = self.OP_ID[3:]
176
    field_name = getattr(self, "OP_DSC_FIELD", None)
177
    if field_name:
178
      field_value = getattr(self, field_name, None)
179
      txt = "%s(%s)" % (txt, field_value)
180
    return txt
181

    
182

    
183
# cluster opcodes
184

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

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

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

    
195

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

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

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

    
206

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

    
212

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

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

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

    
227

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

231
  Parameters: none
232

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

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

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

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

    
252

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

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

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

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

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

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

    
272

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

    
278

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

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

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

    
292

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

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

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

    
319

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

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

    
327
# node opcodes
328

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

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

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

    
341

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

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

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

    
368

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

    
374

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

    
380

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

    
391

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

    
402

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

    
414

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

    
428

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

    
438

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

    
449

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

    
456

    
457
# instance opcodes
458

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

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

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

    
486

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

    
493

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

    
504

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

    
512

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

    
521

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

    
528

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

    
537

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

    
547

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

    
556

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

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

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

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

    
571

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

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

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

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

    
588

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

    
595

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

    
602

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

    
609

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

    
616

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

    
622

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

    
628

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

    
640

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

    
649

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

    
656

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

    
663

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

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

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

    
677

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

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

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

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

    
707

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

    
714

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

    
722

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

    
729

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

    
735

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

    
741

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

746
  This is used just for debugging and testing.
747

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

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

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

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

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

    
768

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

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

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

    
789

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

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

    
802

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