1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 """OpCodes module
32
33 Note that this file is autogenerated using @src/hs2py@ with a header
34 from @lib/opcodes.py.in_before@ and a footer from @lib/opcodes.py.in_after@.
35
36 This module implements part of the data structures which define the
37 cluster operations - the so-called opcodes.
38
39 Every operation which modifies the cluster state is expressed via
40 opcodes.
41
42 """
43
44
45
46
47
48
49 from ganeti import constants
50 from ganeti import ht
51
52 from ganeti import opcodes_base
53
54
55 -class OpCode(opcodes_base.BaseOpCode):
56 """Abstract OpCode.
57
58 This is the root of the actual OpCode hierarchy. All clases derived
59 from this class should override OP_ID.
60
61 @cvar OP_ID: The ID of this opcode. This should be unique amongst all
62 children of this class.
63 @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
64 string returned by Summary(); see the docstring of that
65 method for details).
66 @cvar OP_DSC_FORMATTER: A callable that should format the OP_DSC_FIELD; if
67 not present, then the field will be simply converted
68 to string
69 @cvar OP_PARAMS: List of opcode attributes, the default values they should
70 get if not already defined, and types they must match.
71 @cvar OP_RESULT: Callable to verify opcode result
72 @cvar WITH_LU: Boolean that specifies whether this should be included in
73 mcpu's dispatch table
74 @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
75 the check steps
76 @ivar priority: Opcode priority for queue
77
78 """
79
80
81 WITH_LU = True
82 OP_PARAMS = [
83 ("dry_run", None, ht.TMaybe(ht.TBool), "Run checks only, don't execute"),
84 ("debug_level", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "Debug level"),
85 ("priority", constants.OP_PRIO_DEFAULT,
86 ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
87 (opcodes_base.DEPEND_ATTR, None, opcodes_base.BuildJobDepCheck(True),
88 "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
89 " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
90 " for details"),
91 (opcodes_base.COMMENT_ATTR, None, ht.TMaybe(ht.TString),
92 "Comment describing the purpose of the opcode"),
93 (constants.OPCODE_REASON, [], ht.TMaybe(ht.TListOf(ht.TAny)),
94 "The reason trail, describing why the OpCode is executed"),
95 ]
96 OP_RESULT = None
97
99 """Specialized getstate for opcodes.
100
101 This method adds to the state dictionary the OP_ID of the class,
102 so that on unload we can identify the correct class for
103 instantiating the opcode.
104
105 @rtype: C{dict}
106 @return: the state as a dictionary
107
108 """
109 data = opcodes_base.BaseOpCode.__getstate__(self)
110 data["OP_ID"] = self.OP_ID
111 return data
112
113 @classmethod
115 """Generic load opcode method.
116
117 The method identifies the correct opcode class from the dict-form
118 by looking for a OP_ID key, if this is not found, or its value is
119 not available in this module as a child of this class, we fail.
120
121 @type data: C{dict}
122 @param data: the serialized opcode
123
124 """
125 if not isinstance(data, dict):
126 raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
127 if "OP_ID" not in data:
128 raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
129 op_id = data["OP_ID"]
130 op_class = None
131 if op_id in OP_MAPPING:
132 op_class = OP_MAPPING[op_id]
133 else:
134 raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
135 op_id)
136 op = op_class()
137 new_data = data.copy()
138 del new_data["OP_ID"]
139 op.__setstate__(new_data)
140 return op
141
143 """Generates a summary description of this opcode.
144
145 The summary is the value of the OP_ID attribute (without the "OP_"
146 prefix), plus the value of the OP_DSC_FIELD attribute, if one was
147 defined; this field should allow to easily identify the operation
148 (for an instance creation job, e.g., it would be the instance
149 name).
150
151 """
152 assert self.OP_ID is not None and len(self.OP_ID) > 3
153
154 txt = self.OP_ID[3:]
155 field_name = getattr(self, "OP_DSC_FIELD", None)
156 if field_name:
157 field_value = getattr(self, field_name, None)
158 field_formatter = getattr(self, "OP_DSC_FORMATTER", None)
159 if callable(field_formatter):
160 field_value = field_formatter(field_value)
161 elif isinstance(field_value, (list, tuple)):
162 field_value = ",".join(str(i) for i in field_value)
163 txt = "%s(%s)" % (txt, field_value)
164 return txt
165
167 """Generates a compact summary description of the opcode.
168
169 """
170 assert self.OP_ID.startswith("OP_")
171
172 text = self.OP_ID[3:]
173
174 for (prefix, supplement) in opcodes_base.SUMMARY_PREFIX.items():
175 if text.startswith(prefix):
176 return supplement + text[len(prefix):]
177
178 return text
179
182 """Allocates multiple instances.
183
184 """
194
196 """Generic unserializer.
197
198 This method just restores from the serialized state the attributes
199 of the current instance.
200
201 @param state: the serialized opcode data
202 @type state: C{dict}
203
204 """
205 if not isinstance(state, dict):
206 raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
207 type(state))
208
209 if "instances" in state:
210 state["instances"] = map(OpCode.LoadOpCode, state["instances"])
211
212 return OpCode.__setstate__(self, state)
213
215 """Validates this opcode.
216
217 We do this recursively.
218
219 @type set_defaults: bool
220 @param set_defaults: whether to set default values
221
222 @rtype: NoneType
223 @return: L{None}, if the validation succeeds
224
225 @raise errors.OpPrereqError: when a parameter value doesn't match
226 requirements
227
228 """
229 OpCode.Validate(self, set_defaults)
230
231 for inst in self.instances:
232 inst.Validate(set_defaults)
233 -class OpClusterPostInit(OpCode):
234 """Post cluster initialization.
235
236 This opcode does not touch the cluster at all. Its purpose is to run hooks
237 after the cluster has been initialized.
238
239 """
240 OP_PARAMS = [
241 ]
242 OP_RESULT = ht.TBool
243
245 """Destroy the cluster.
246
247 This opcode has no other parameters. All the state is irreversibly
248 lost after the execution of this opcode.
249
250 """
251 OP_PARAMS = [
252 ]
253 OP_RESULT = ht.TNonEmptyString
254
260
262 """Submits all jobs necessary to verify the cluster."""
263 OP_PARAMS = [
264 ("debug_simulate_errors", False, ht.TBool, "Whether to simulate errors (useful for debugging)"),
265 ("error_codes", False, ht.TBool, "Error codes"),
266 ("skip_checks", [], ht.TSetOf(ht.TVerifyOptionalChecks), "Which checks to skip"),
267 ("ignore_errors", [], ht.TSetOf(ht.TCVErrorCode), "List of error codes that should be treated as warnings"),
268 ("verbose", False, ht.TBool, "Verbose mode"),
269 ("group_name", None, ht.TMaybe(ht.TNonEmptyString), "Optional group name")
270 ]
271 OP_RESULT = ht.TJobIdListOnly
272
274 """Verify the cluster config."""
275 OP_PARAMS = [
276 ("debug_simulate_errors", False, ht.TBool, "Whether to simulate errors (useful for debugging)"),
277 ("error_codes", False, ht.TBool, "Error codes"),
278 ("ignore_errors", [], ht.TSetOf(ht.TCVErrorCode), "List of error codes that should be treated as warnings"),
279 ("verbose", False, ht.TBool, "Verbose mode")
280 ]
281 OP_RESULT = ht.TBool
282
284 """Run verify on a node group from the cluster.
285
286 @type skip_checks: C{list}
287 @ivar skip_checks: steps to be skipped from the verify process; this
288 needs to be a subset of
289 L{constants.VERIFY_OPTIONAL_CHECKS}; currently
290 only L{constants.VERIFY_NPLUSONE_MEM} can be passed
291
292 """
293 OP_DSC_FIELD = "group_name"
294 OP_PARAMS = [
295 ("group_name", None, ht.TNonEmptyString, "Group name"),
296 ("debug_simulate_errors", False, ht.TBool, "Whether to simulate errors (useful for debugging)"),
297 ("error_codes", False, ht.TBool, "Error codes"),
298 ("skip_checks", [], ht.TSetOf(ht.TVerifyOptionalChecks), "Which checks to skip"),
299 ("ignore_errors", [], ht.TSetOf(ht.TCVErrorCode), "List of error codes that should be treated as warnings"),
300 ("verbose", False, ht.TBool, "Verbose mode")
301 ]
302 OP_RESULT = ht.TBool
303
309
311 """Verifies the status of all disks in a node group.
312
313 Result: a tuple of three elements:
314 - dict of node names with issues (values: error msg)
315 - list of instances with degraded disks (that should be activated)
316 - dict of instances with missing logical volumes (values: (node, vol)
317 pairs with details about the missing volumes)
318
319 In normal operation, all lists should be empty. A non-empty instance
320 list (3rd element of the result) is still ok (errors were fixed) but
321 non-empty node list means some node is down, and probably there are
322 unfixable drbd errors.
323
324 Note that only instances that are drbd-based are taken into
325 consideration. This might need to be revisited in the future.
326
327 """
328 OP_DSC_FIELD = "group_name"
329 OP_PARAMS = [
330 ("group_name", None, ht.TNonEmptyString, "Group name")
331 ]
332 OP_RESULT = ht.TTupleOf(ht.TDictOf(ht.TString, ht.TString), ht.TListOf(ht.TString), ht.TDictOf(ht.TString, ht.TListOf(ht.TListOf(ht.TString))))
333
335 """Verify the disk sizes of the instances and fixes configuration
336 mismatches.
337
338 Parameters: optional instances list, in case we want to restrict the
339 checks to only a subset of the instances.
340
341 Result: a list of tuples, (instance, disk, parameter, new-size) for
342 changed configurations.
343
344 In normal operation, the list should be empty.
345
346 @type instances: list
347 @ivar instances: the list of instances to check, or empty for all instances
348
349 """
350 OP_PARAMS = [
351 ("instances", [], ht.TListOf(ht.TNonEmptyString), "List of instances")
352 ]
353 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TNonNegative(ht.TInt), ht.TNonEmptyString, ht.TNonNegative(ht.TInt)))
354
361
363 """Rename the cluster.
364
365 @type name: C{str}
366 @ivar name: The new name of the cluster. The name and/or the master IP
367 address will be changed to match the new name and its IP
368 address.
369
370 """
371 OP_DSC_FIELD = "name"
372 OP_PARAMS = [
373 ("name", None, ht.TNonEmptyString, "A generic name")
374 ]
375 OP_RESULT = ht.TNonEmptyString
376
378 """Change the parameters of the cluster.
379
380 @type vg_name: C{str} or C{None}
381 @ivar vg_name: The new volume group name or None to disable LVM usage.
382
383 """
384 OP_PARAMS = [
385 ("force", False, ht.TBool, "Whether to force the operation"),
386 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
387 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
388 ("vg_name", None, ht.TMaybe(ht.TString), "Volume group name"),
389 ("enabled_hypervisors", None, ht.TMaybe(ht.TListOf(ht.THypervisor)), "List of enabled hypervisors"),
390 ("hvparams", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TAny))), "Cluster-wide hypervisor parameters, hypervisor-dependent"),
391 ("beparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Cluster-wide backend parameter defaults"),
392 ("os_hvp", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TAny))), "Cluster-wide per-OS hypervisor parameter defaults"),
393 ("osparams", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TAny))), "Cluster-wide OS parameter defaults"),
394 ("osparams_private_cluster", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TPrivate(ht.TAny)))), "Cluster-wide private OS parameter defaults"),
395 ("diskparams", None, ht.TMaybe(ht.TDictOf(ht.TDiskTemplate, ht.TObject(ht.TAny))), "Disk templates' parameter defaults"),
396 ("candidate_pool_size", None, ht.TMaybe(ht.TPositive(ht.TInt)), "Master candidate pool size"),
397 ("max_running_jobs", None, ht.TMaybe(ht.TPositive(ht.TInt)), "Maximal number of jobs to run simultaneously"),
398 ("max_tracked_jobs", None, ht.TMaybe(ht.TPositive(ht.TInt)), "Maximal number of jobs tracked in the job queue"),
399 ("uid_pool", None, ht.TMaybe(ht.TListOf(ht.TTupleOf(ht.TInt, ht.TInt))), "Set UID pool, must be list of lists describing UID ranges (two items, start and end inclusive)"),
400 ("add_uids", None, ht.TMaybe(ht.TListOf(ht.TTupleOf(ht.TInt, ht.TInt))), "Extend UID pool, must be list of lists describing UID ranges (two items, start and end inclusive)"),
401 ("remove_uids", None, ht.TMaybe(ht.TListOf(ht.TTupleOf(ht.TInt, ht.TInt))), "Shrink UID pool, must be list of lists describing UID ranges (two items, start and end inclusive) to be removed"),
402 ("maintain_node_health", None, ht.TMaybe(ht.TBool), "Whether to automatically maintain node health"),
403 ("prealloc_wipe_disks", None, ht.TMaybe(ht.TBool), "Whether to wipe disks before allocating them to instances"),
404 ("nicparams", None, ht.TMaybe(ht.TINicParams), "Cluster-wide NIC parameter defaults"),
405 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Cluster-wide node parameter defaults"),
406 ("ipolicy", None, ht.TMaybe(ht.TObject(ht.TAny)), "Cluster-wide ipolicy specs"),
407 ("drbd_helper", None, ht.TMaybe(ht.TString), "DRBD helper program"),
408 ("default_iallocator", None, ht.TMaybe(ht.TString), "Default iallocator for cluster"),
409 ("default_iallocator_params", None, ht.TMaybe(ht.TObject(ht.TAny)), "Default iallocator parameters for cluster"),
410 ("mac_prefix", None, ht.TMaybe(ht.TNonEmptyString), "Network specific mac prefix (that overrides the cluster one)"),
411 ("master_netdev", None, ht.TMaybe(ht.TString), "Master network device"),
412 ("master_netmask", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "Netmask of the master IP"),
413 ("reserved_lvs", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of reserved LVs"),
414 ("hidden_os", None, ht.TMaybe(ht.TListOf(ht.TTupleOf(ht.TDdmSimple, ht.TNonEmptyString))), "Modify list of hidden operating systems: each modification must have two items, the operation and the OS name; the operation can be add or remove"),
415 ("blacklisted_os", None, ht.TMaybe(ht.TListOf(ht.TTupleOf(ht.TDdmSimple, ht.TNonEmptyString))), "Modify list of blacklisted operating systems: each modification must have two items, the operation and the OS name; the operation can be add or remove"),
416 ("use_external_mip_script", None, ht.TMaybe(ht.TBool), "Whether to use an external master IP address setup script"),
417 ("enabled_disk_templates", None, ht.TMaybe(ht.TListOf(ht.TDiskTemplate)), "List of enabled disk templates"),
418 ("modify_etc_hosts", None, ht.TMaybe(ht.TBool), ""),
419 ("file_storage_dir", None, ht.TMaybe(ht.TString), ""),
420 ("shared_file_storage_dir", None, ht.TMaybe(ht.TString), ""),
421 ("gluster_storage_dir", None, ht.TMaybe(ht.TString), ""),
422 ("install_image", None, ht.TMaybe(ht.TString), "OS image for running OS scripts in a safe environment"),
423 ("instance_communication_network", None, ht.TMaybe(ht.TString), ""),
424 ("zeroing_image", None, ht.TMaybe(ht.TString), ""),
425 ("compression_tools", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of enabled compression tools"),
426 ("enabled_user_shutdown", None, ht.TMaybe(ht.TBool), "Whether user shutdown is enabled cluster wide")
427 ]
428 OP_RESULT = ht.TOr(ht.TNone, ht.TJobIdListOnly)
429
435
441
447
449 """Renews the cluster node's SSL client certificates."""
450 OP_PARAMS = [
451 ("verbose", False, ht.TBool, "Verbose mode"),
452 ("debug", False, ht.TBool, "Debug mode")
453 ]
454 OP_RESULT = ht.TNone
455
457 """Query for resources/items.
458
459 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
460 @ivar fields: List of fields to retrieve
461 @ivar qfilter: Query filter
462
463 """
464 OP_DSC_FIELD = "what"
465 OP_PARAMS = [
466 ("what", None, ht.TQueryTypeOp, "Resource(s) to query for"),
467 ("use_locking", False, ht.TBool, "Whether to use synchronization"),
468 ("fields", None, ht.TListOf(ht.TNonEmptyString), "Requested fields"),
469 ("qfilter", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Query filter")
470 ]
471 OP_RESULT = ht.TQueryResponse
472
486
488 """Interact with OOB."""
489 OP_PARAMS = [
490 ("node_names", [], ht.TListOf(ht.TNonEmptyString), "List of node names to run the OOB command against"),
491 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of node UUIDs to run the OOB command against"),
492 ("command", None, ht.TOobCommand, "OOB command to run"),
493 ("timeout", 60, ht.TInt, "Timeout before the OOB helper will be terminated"),
494 ("ignore_status", False, ht.TBool, "Ignores the node offline status for power off"),
495 ("power_delay", 2.0, ht.TDouble, "Time in seconds to wait between powering on nodes")
496 ]
497 OP_RESULT = ht.TListOf(ht.TListOf(ht.TTupleOf(ht.TQueryResultCode, ht.TAny)))
498
500 """Runs a restricted command on node(s)."""
501 OP_PARAMS = [
502 ("use_locking", False, ht.TBool, "Whether to use synchronization"),
503 ("nodes", None, ht.TListOf(ht.TNonEmptyString), "Nodes on which the command should be run (at least one)"),
504 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Node UUIDs on which the command should be run (at least one)"),
505 ("command", None, ht.TNonEmptyString, "Restricted command name")
506 ]
507 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TBool, ht.TString))
508
510 """Remove a node.
511
512 @type node_name: C{str}
513 @ivar node_name: The name of the node to remove. If the node still has
514 instances on it, the operation will fail.
515
516 """
517 OP_DSC_FIELD = "node_name"
518 OP_PARAMS = [
519 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
520 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)")
521 ]
522 OP_RESULT = ht.TNone
523
525 """Add a node to the cluster.
526
527 @type node_name: C{str}
528 @ivar node_name: The name of the node to add. This can be a short name,
529 but it will be expanded to the FQDN.
530 @type primary_ip: IP address
531 @ivar primary_ip: The primary IP of the node. This will be ignored when
532 the opcode is submitted, but will be filled during the
533 node add (so it will be visible in the job query).
534 @type secondary_ip: IP address
535 @ivar secondary_ip: The secondary IP of the node. This needs to be passed
536 if the cluster has been initialized in 'dual-network'
537 mode, otherwise it must not be given.
538 @type readd: C{bool}
539 @ivar readd: Whether to re-add an existing node to the cluster. If
540 this is not passed, then the operation will abort if the node
541 name is already in the cluster; use this parameter to
542 'repair' a node that had its configuration broken, or was
543 reinstalled without removal from the cluster.
544 @type group: C{str}
545 @ivar group: The node group to which this node will belong.
546 @type vm_capable: C{bool}
547 @ivar vm_capable: The vm_capable node attribute
548 @type master_capable: C{bool}
549 @ivar master_capable: The master_capable node attribute
550
551 """
552 OP_DSC_FIELD = "node_name"
553 OP_PARAMS = [
554 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
555 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
556 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
557 ("primary_ip", None, ht.TMaybe(ht.TNonEmptyString), "Primary IP address"),
558 ("secondary_ip", None, ht.TMaybe(ht.TNonEmptyString), "Secondary IP address"),
559 ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
560 ("group", None, ht.TMaybe(ht.TNonEmptyString), "Initial node group"),
561 ("master_capable", None, ht.TMaybe(ht.TBool), "Whether node can become master or master candidate"),
562 ("vm_capable", None, ht.TMaybe(ht.TBool), "Whether node can host instances"),
563 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Node parameters")
564 ]
565 OP_RESULT = ht.TNone
566
574
576 """Get information on storage for node(s)."""
577 OP_PARAMS = [
578 ("output_fields", None, ht.TListOf(ht.TNonEmptyString), "Selected output fields"),
579 ("storage_type", None, ht.TMaybe(ht.TStorageType), "Storage type"),
580 ("nodes", [], ht.TListOf(ht.TNonEmptyString), "Empty list to query all, list of names to query otherwise"),
581 ("name", None, ht.TMaybe(ht.TNonEmptyString), "Storage name")
582 ]
583 OP_RESULT = ht.TListOf(ht.TListOf(ht.TAny))
584
586 """Modifies the properies of a storage unit"""
587 OP_DSC_FIELD = "node_name"
588 OP_PARAMS = [
589 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
590 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)"),
591 ("storage_type", None, ht.TStorageType, "Storage type"),
592 ("name", None, ht.TMaybe(ht.TNonEmptyString), "Storage name"),
593 ("changes", None, ht.TObject(ht.TAny), "Requested storage changes")
594 ]
595 OP_RESULT = ht.TNone
596
598 """Repairs the volume group on a node."""
599 OP_DSC_FIELD = "node_name"
600 OP_PARAMS = [
601 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
602 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)"),
603 ("storage_type", None, ht.TStorageType, "Storage type"),
604 ("name", None, ht.TMaybe(ht.TNonEmptyString), "Storage name"),
605 ("ignore_consistency", False, ht.TBool, "Whether to ignore disk consistency")
606 ]
607 OP_RESULT = ht.TNone
608
610 """Change the parameters of a node."""
611 OP_DSC_FIELD = "node_name"
612 OP_PARAMS = [
613 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
614 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)"),
615 ("force", False, ht.TBool, "Whether to force the operation"),
616 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
617 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
618 ("master_candidate", None, ht.TMaybe(ht.TBool), "Whether the node should become a master candidate"),
619 ("offline", None, ht.TMaybe(ht.TBool), "Whether to mark the node offline"),
620 ("drained", None, ht.TMaybe(ht.TBool), "Whether to mark the node as drained"),
621 ("auto_promote", False, ht.TBool, "Whether node(s) should be promoted to master candidate if necessary"),
622 ("master_capable", None, ht.TMaybe(ht.TBool), "Whether node can become master or master candidate"),
623 ("vm_capable", None, ht.TMaybe(ht.TBool), "Whether node can host instances"),
624 ("secondary_ip", None, ht.TMaybe(ht.TNonEmptyString), "Secondary IP address"),
625 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Node parameters"),
626 ("powered", None, ht.TMaybe(ht.TBool), "Whether the node should be marked as powered")
627 ]
628 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TAny))
629
631 """Tries to powercycle a node."""
632 OP_DSC_FIELD = "node_name"
633 OP_PARAMS = [
634 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
635 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)"),
636 ("force", False, ht.TBool, "Whether to force the operation")
637 ]
638 OP_RESULT = ht.TMaybe(ht.TNonEmptyString)
639
641 """Migrate all instances from a node."""
642 OP_DSC_FIELD = "node_name"
643 OP_PARAMS = [
644 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
645 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)"),
646 ("mode", None, ht.TMaybe(ht.TMigrationMode), "Migration type (live/non-live)"),
647 ("live", None, ht.TMaybe(ht.TBool), "Obsolete 'live' migration mode (do not use)"),
648 ("target_node", None, ht.TMaybe(ht.TNonEmptyString), "Target node for instance migration/failover"),
649 ("target_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Target node UUID for instance migration/failover"),
650 ("allow_runtime_changes", True, ht.TBool, "Whether to allow runtime changes while migrating"),
651 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
652 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances")
653 ]
654 OP_RESULT = ht.TJobIdListOnly
655
657 """Evacuate instances off a number of nodes."""
658 OP_DSC_FIELD = "node_name"
659 OP_PARAMS = [
660 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
661 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
662 ("node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "A node UUID (for single-node LUs)"),
663 ("remote_node", None, ht.TMaybe(ht.TNonEmptyString), "New secondary node"),
664 ("remote_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "New secondary node UUID"),
665 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
666 ("mode", None, ht.TEvacMode, "Node evacuation mode")
667 ]
668 OP_RESULT = ht.TJobIdListOnly
669
671 """Create an instance.
672
673 @ivar instance_name: Instance name
674 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
675 @ivar source_handshake: Signed handshake from source (remote import only)
676 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
677 @ivar source_instance_name: Previous name of instance (remote import only)
678 @ivar source_shutdown_timeout: Shutdown timeout used for source instance
679 (remote import only)
680
681 """
682 OP_DSC_FIELD = "instance_name"
683 OP_PARAMS = [
684 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
685 ("force_variant", False, ht.TBool, "Whether to force an unknown OS variant"),
686 ("wait_for_sync", True, ht.TBool, "Whether to wait for the disk to synchronize"),
687 ("name_check", True, ht.TBool, "Whether to check name"),
688 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
689 ("opportunistic_locking", False, ht.TBool, "Whether to employ opportunistic locking for nodes, meaning nodes already locked by another opcode won't be considered for instance allocation (only when an iallocator is used)"),
690 ("beparams", {}, ht.TObject(ht.TAny), "Backend parameters for instance"),
691 ("disks", None, ht.TListOf(ht.TIDiskParams), "List of instance disks"),
692 ("disk_template", None, ht.TMaybe(ht.TDiskTemplate), "Instance disk template"),
693 ("file_driver", None, ht.TMaybe(ht.TFileDriver), "Driver for file-backed disks"),
694 ("file_storage_dir", None, ht.TMaybe(ht.TNonEmptyString), "Directory for storing file-backed disks"),
695 ("hvparams", {}, ht.TObject(ht.TAny), "Hypervisor parameters for instance, hypervisor-dependent"),
696 ("hypervisor", None, ht.TMaybe(ht.THypervisor), "Selected hypervisor for an instance"),
697 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
698 ("identify_defaults", False, ht.TBool, "Reset instance parameters to default if equal"),
699 ("ip_check", True, ht.TBool, "Whether to ensure instance's IP address is inactive"),
700 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses"),
701 ("mode", None, ht.TInstCreateMode, "Instance creation mode"),
702 ("nics", None, ht.TListOf(ht.TINicParams), "List of NIC (network interface) definitions"),
703 ("no_install", None, ht.TMaybe(ht.TBool), "Do not install the OS (will disable automatic start)"),
704 ("osparams", {}, ht.TObject(ht.TAny), "OS parameters for instance"),
705 ("osparams_private", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Private OS parameters for instance"),
706 ("osparams_secret", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Secret OS parameters for instance"),
707 ("os_type", None, ht.TMaybe(ht.TNonEmptyString), "OS type for instance installation"),
708 ("pnode", None, ht.TMaybe(ht.TNonEmptyString), "Primary node for an instance"),
709 ("pnode_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Primary node UUID for an instance"),
710 ("snode", None, ht.TMaybe(ht.TNonEmptyString), "Secondary node for an instance"),
711 ("snode_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Secondary node UUID for an instance"),
712 ("source_handshake", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Signed handshake from source (remote import only)"),
713 ("source_instance_name", None, ht.TMaybe(ht.TNonEmptyString), "Source instance name (remote import only)"),
714 ("source_shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long source instance was given to shut down (remote import only)"),
715 ("source_x509_ca", None, ht.TMaybe(ht.TNonEmptyString), "Source X509 CA in PEM format (remote import only)"),
716 ("src_node", None, ht.TMaybe(ht.TNonEmptyString), "Source node for import"),
717 ("src_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Source node UUID for import"),
718 ("src_path", None, ht.TMaybe(ht.TNonEmptyString), "Source directory for import"),
719 ("compress", "none", ht.TString, "Compression mode to use for moves during backups/imports"),
720 ("start", True, ht.TBool, "Whether to start instance after creation"),
721 ("tags", [], ht.TListOf(ht.TNonEmptyString), "Instance tags"),
722 ("instance_communication", False, ht.TBool, "Enable or disable the communication mechanism for an instance"),
723 ("helper_startup_timeout", None, ht.TMaybe(ht.TInt), "Startup timeout for the helper VM"),
724 ("helper_shutdown_timeout", None, ht.TMaybe(ht.TInt), "Shutdown timeout for the helper VM")
725 ]
726 OP_RESULT = ht.TListOf(ht.TNonEmptyString)
727
729 """Allocates multiple instances."""
730 OP_PARAMS = [
731 ("opportunistic_locking", False, ht.TBool, "Whether to employ opportunistic locking for nodes, meaning nodes already locked by another opcode won't be considered for instance allocation (only when an iallocator is used)"),
732 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
733 ("instances", [], ht.TListOf(ht.TAny), "List of instance create opcodes describing the instances to allocate")
734 ]
735 OP_RESULT = ht.TInstanceMultiAllocResponse
736
738 """Reinstall an instance's OS."""
739 OP_DSC_FIELD = "instance_name"
740 OP_PARAMS = [
741 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
742 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
743 ("force_variant", False, ht.TBool, "Whether to force an unknown OS variant"),
744 ("os_type", None, ht.TMaybe(ht.TNonEmptyString), "OS type for instance installation"),
745 ("osparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Temporary OS parameters (currently only in reinstall, might be added to install as well)"),
746 ("osparams_private", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Private OS parameters for instance reinstalls"),
747 ("osparams_secret", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Secret OS parameters for instance reinstalls")
748 ]
749 OP_RESULT = ht.TNone
750
752 """Remove an instance."""
753 OP_DSC_FIELD = "instance_name"
754 OP_PARAMS = [
755 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
756 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
757 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
758 ("ignore_failures", False, ht.TBool, "Whether to ignore failures during removal")
759 ]
760 OP_RESULT = ht.TNone
761
763 """Rename an instance."""
764 OP_PARAMS = [
765 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
766 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
767 ("new_name", None, ht.TNonEmptyString, "New instance name"),
768 ("name_check", True, ht.TBool, "Whether to check name"),
769 ("ip_check", True, ht.TBool, "Whether to ensure instance's IP address is inactive")
770 ]
771 OP_RESULT = ht.TNonEmptyString
772
774 """Startup an instance."""
775 OP_DSC_FIELD = "instance_name"
776 OP_PARAMS = [
777 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
778 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
779 ("force", False, ht.TBool, "Whether to force the operation"),
780 ("ignore_offline_nodes", False, ht.TBool, "Whether to ignore offline nodes"),
781 ("hvparams", {}, ht.TObject(ht.TAny), "Temporary hypervisor parameters, hypervisor-dependent"),
782 ("beparams", {}, ht.TObject(ht.TAny), "Temporary backend parameters"),
783 ("no_remember", False, ht.TBool, "Do not remember instance state changes"),
784 ("startup_paused", False, ht.TBool, "Pause instance at startup"),
785 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down")
786 ]
787 OP_RESULT = ht.TNone
788
790 """Shutdown an instance."""
791 OP_DSC_FIELD = "instance_name"
792 OP_PARAMS = [
793 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
794 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
795 ("force", False, ht.TBool, "Whether to force the operation"),
796 ("ignore_offline_nodes", False, ht.TBool, "Whether to ignore offline nodes"),
797 ("timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
798 ("no_remember", False, ht.TBool, "Do not remember instance state changes"),
799 ("admin_state_source", None, ht.TMaybe(ht.TAdminStateSource), "Who last changed the instance admin state")
800 ]
801 OP_RESULT = ht.TNone
802
804 """Reboot an instance."""
805 OP_DSC_FIELD = "instance_name"
806 OP_PARAMS = [
807 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
808 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
809 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
810 ("ignore_secondaries", False, ht.TBool, "Whether to start the instance even if secondary disks are failing"),
811 ("reboot_type", None, ht.TRebootType, "How to reboot the instance")
812 ]
813 OP_RESULT = ht.TNone
814
816 """Replace the disks of an instance."""
817 OP_DSC_FIELD = "instance_name"
818 OP_PARAMS = [
819 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
820 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
821 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
822 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
823 ("mode", None, ht.TReplaceDisksMode, "Replacement mode"),
824 ("disks", [], ht.TListOf(ht.TDiskIndex), "List of disk indices"),
825 ("remote_node", None, ht.TMaybe(ht.TNonEmptyString), "New secondary node"),
826 ("remote_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "New secondary node UUID"),
827 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances")
828 ]
829 OP_RESULT = ht.TNone
830
832 """Failover an instance."""
833 OP_DSC_FIELD = "instance_name"
834 OP_PARAMS = [
835 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
836 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
837 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
838 ("ignore_consistency", False, ht.TBool, "Whether to ignore disk consistency"),
839 ("target_node", None, ht.TMaybe(ht.TNonEmptyString), "Target node for instance migration/failover"),
840 ("target_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Target node UUID for instance migration/failover"),
841 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
842 ("cleanup", False, ht.TBool, "Whether a previously failed migration should be cleaned up"),
843 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances")
844 ]
845 OP_RESULT = ht.TNone
846
848 """Migrate an instance.
849
850 This migrates (without shutting down an instance) to its secondary
851 node.
852
853 @ivar instance_name: the name of the instance
854 @ivar mode: the migration mode (live, non-live or None for auto)
855
856 """
857 OP_DSC_FIELD = "instance_name"
858 OP_PARAMS = [
859 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
860 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
861 ("mode", None, ht.TMaybe(ht.TMigrationMode), "Migration type (live/non-live)"),
862 ("live", None, ht.TMaybe(ht.TBool), "Obsolete 'live' migration mode (do not use)"),
863 ("target_node", None, ht.TMaybe(ht.TNonEmptyString), "Target node for instance migration/failover"),
864 ("target_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Target node UUID for instance migration/failover"),
865 ("allow_runtime_changes", True, ht.TBool, "Whether to allow runtime changes while migrating"),
866 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
867 ("cleanup", False, ht.TBool, "Whether a previously failed migration should be cleaned up"),
868 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
869 ("allow_failover", False, ht.TBool, "Whether we can fallback to failover if migration is not possible")
870 ]
871 OP_RESULT = ht.TNone
872
874 """Move an instance.
875
876 This move (with shutting down an instance and data copying) to an
877 arbitrary node.
878
879 @ivar instance_name: the name of the instance
880 @ivar target_node: the destination node
881
882 """
883 OP_DSC_FIELD = "instance_name"
884 OP_PARAMS = [
885 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
886 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
887 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
888 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
889 ("target_node", None, ht.TNonEmptyString, "Target node for instance move"),
890 ("target_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Target node UUID for instance move"),
891 ("compress", "none", ht.TString, "Compression mode to use during instance moves"),
892 ("ignore_consistency", False, ht.TBool, "Whether to ignore disk consistency")
893 ]
894 OP_RESULT = ht.TNone
895
904
906 """Activate an instance's disks."""
907 OP_DSC_FIELD = "instance_name"
908 OP_PARAMS = [
909 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
910 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
911 ("ignore_size", False, ht.TBool, "Whether to ignore recorded disk size"),
912 ("wait_for_sync", False, ht.TBool, "Whether to wait for the disk to synchronize (defaults to false)")
913 ]
914 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TNonEmptyString, ht.TNonEmptyString))
915
917 """Deactivate an instance's disks."""
918 OP_DSC_FIELD = "instance_name"
919 OP_PARAMS = [
920 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
921 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
922 ("force", False, ht.TBool, "Whether to force the operation")
923 ]
924 OP_RESULT = ht.TNone
925
927 """Recreate an instance's disks."""
928 OP_DSC_FIELD = "instance_name"
929 OP_PARAMS = [
930 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
931 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
932 ("disks", [], ht.TRecreateDisksInfo, "Disk list for recreate disks"),
933 ("nodes", [], ht.TListOf(ht.TNonEmptyString), "New instance nodes, if relocation is desired"),
934 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "New instance node UUIDs, if relocation is desired"),
935 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances")
936 ]
937 OP_RESULT = ht.TNone
938
940 """Compute the run-time status of instances."""
941 OP_PARAMS = [
942 ("use_locking", False, ht.TBool, "Whether to use synchronization"),
943 ("instances", [], ht.TListOf(ht.TNonEmptyString), "List of instances"),
944 ("static", False, ht.TBool, "Whether to only return configuration data without querying nodes")
945 ]
946 OP_RESULT = ht.TObject(ht.TObject(ht.TAny))
947
949 """Change the parameters of an instance."""
950 OP_DSC_FIELD = "instance_name"
951 OP_PARAMS = [
952 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
953 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
954 ("force", False, ht.TBool, "Whether to force the operation"),
955 ("force_variant", False, ht.TBool, "Whether to force an unknown OS variant"),
956 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
957 ("nics", [], ht.TSetParamsMods(ht.TINicParams), "List of NIC changes"),
958 ("disks", [], ht.TSetParamsMods(ht.TIDiskParams), "List of disk changes"),
959 ("beparams", {}, ht.TObject(ht.TAny), "Backend parameters for instance"),
960 ("runtime_mem", None, ht.TMaybe(ht.TPositive(ht.TInt)), "New runtime memory"),
961 ("hvparams", {}, ht.TObject(ht.TAny), "Hypervisor parameters for instance, hypervisor-dependent"),
962 ("disk_template", None, ht.TMaybe(ht.TDiskTemplate), "Instance disk template"),
963 ("pnode", None, ht.TMaybe(ht.TNonEmptyString), "Primary node for an instance"),
964 ("pnode_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Primary node UUID for an instance"),
965 ("remote_node", None, ht.TMaybe(ht.TNonEmptyString), "Secondary node (used when changing disk template)"),
966 ("remote_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Secondary node UUID (used when changing disk template)"),
967 ("os_name", None, ht.TMaybe(ht.TNonEmptyString), "Change the instance's OS without reinstalling the instance"),
968 ("osparams", {}, ht.TObject(ht.TAny), "OS parameters for instance"),
969 ("osparams_private", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Private OS parameters for instance"),
970 ("wait_for_sync", True, ht.TBool, "Whether to wait for the disk to synchronize"),
971 ("offline", None, ht.TMaybe(ht.TBool), "Whether to mark the instance as offline"),
972 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses"),
973 ("hotplug", False, ht.TBool, ""),
974 ("hotplug_if_possible", False, ht.TBool, ""),
975 ("instance_communication", None, ht.TMaybe(ht.TBool), "Enable or disable the communication mechanism for an instance")
976 ]
977 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TAny))
978
980 """Grow a disk of an instance."""
981 OP_DSC_FIELD = "instance_name"
982 OP_PARAMS = [
983 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
984 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
985 ("wait_for_sync", True, ht.TBool, "Whether to wait for the disk to synchronize"),
986 ("disk", None, ht.TDiskIndex, "Disk index for e.g. grow disk"),
987 ("amount", None, ht.TNonNegative(ht.TInt), "Disk amount to add or grow to"),
988 ("absolute", False, ht.TBool, "Whether the amount parameter is an absolute target or a relative one"),
989 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations")
990 ]
991 OP_RESULT = ht.TNone
992
994 """Moves an instance to another node group."""
995 OP_DSC_FIELD = "instance_name"
996 OP_PARAMS = [
997 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
998 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
999 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
1000 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
1001 ("target_groups", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Destination group names or UUIDs (defaults to \"all but current group\")")
1002 ]
1003 OP_RESULT = ht.TJobIdListOnly
1004
1006 """Add a node group to the cluster."""
1007 OP_DSC_FIELD = "group_name"
1008 OP_PARAMS = [
1009 ("group_name", None, ht.TNonEmptyString, "Group name"),
1010 ("alloc_policy", None, ht.TMaybe(ht.TAllocPolicy), "Instance allocation policy"),
1011 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Default node parameters for group"),
1012 ("diskparams", None, ht.TMaybe(ht.TDictOf(ht.TDiskTemplate, ht.TObject(ht.TAny))), "Disk templates' parameter defaults"),
1013 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
1014 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
1015 ("ipolicy", None, ht.TMaybe(ht.TObject(ht.TAny)), "Group-wide ipolicy specs")
1016 ]
1017 OP_RESULT = ht.TOr(ht.TNone, ht.TJobIdListOnly)
1018
1020 """Assign nodes to a node group."""
1021 OP_DSC_FIELD = "group_name"
1022 OP_PARAMS = [
1023 ("group_name", None, ht.TNonEmptyString, "Group name"),
1024 ("force", False, ht.TBool, "Whether to force the operation"),
1025 ("nodes", None, ht.TListOf(ht.TNonEmptyString), "List of nodes to assign"),
1026 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of node UUIDs to assign")
1027 ]
1028 OP_RESULT = ht.TNone
1029
1031 """Change the parameters of a node group."""
1032 OP_DSC_FIELD = "group_name"
1033 OP_PARAMS = [
1034 ("group_name", None, ht.TNonEmptyString, "Group name"),
1035 ("alloc_policy", None, ht.TMaybe(ht.TAllocPolicy), "Instance allocation policy"),
1036 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Default node parameters for group"),
1037 ("diskparams", None, ht.TMaybe(ht.TDictOf(ht.TDiskTemplate, ht.TObject(ht.TAny))), "Disk templates' parameter defaults"),
1038 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
1039 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
1040 ("ipolicy", None, ht.TMaybe(ht.TObject(ht.TAny)), "Group-wide ipolicy specs")
1041 ]
1042 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TAny))
1043
1051
1059
1061 """Evacuate a node group in the cluster."""
1062 OP_DSC_FIELD = "group_name"
1063 OP_PARAMS = [
1064 ("group_name", None, ht.TNonEmptyString, "Group name"),
1065 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
1066 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
1067 ("target_groups", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Destination group names or UUIDs (defaults to \"all but current group\")"),
1068 ("sequential", False, ht.TBool, "Sequential job execution"),
1069 ("force_failover", False, ht.TBool, "Disallow migration moves and always use failovers")
1070 ]
1071 OP_RESULT = ht.TJobIdListOnly
1072
1080
1088
1090 """Prepares an instance export.
1091
1092 @ivar instance_name: Instance name
1093 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1094
1095 """
1096 OP_DSC_FIELD = "instance_name"
1097 OP_PARAMS = [
1098 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1099 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
1100 ("mode", None, ht.TExportMode, "Export mode")
1101 ]
1102 OP_RESULT = ht.TMaybe(ht.TObject(ht.TAny))
1103
1105 """Export an instance.
1106
1107 For local exports, the export destination is the node name. For
1108 remote exports, the export destination is a list of tuples, each
1109 consisting of hostname/IP address, port, magic, HMAC and HMAC
1110 salt. The HMAC is calculated using the cluster domain secret over
1111 the value "${index}:${hostname}:${port}". The destination X509 CA
1112 must be a signed certificate.
1113
1114 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1115 @ivar target_node: Export destination
1116 @ivar x509_key_name: X509 key to use (remote export only)
1117 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote
1118 export only)
1119
1120 """
1121 OP_DSC_FIELD = "instance_name"
1122 OP_PARAMS = [
1123 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1124 ("instance_uuid", None, ht.TMaybe(ht.TNonEmptyString), "An instance UUID (for single-instance LUs)"),
1125 ("compress", "none", ht.TString, "Compression mode to use for moves during backups/imports"),
1126 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
1127 ("target_node", None, ht.TExportTarget, "Target node (depends on export mode)"),
1128 ("target_node_uuid", None, ht.TMaybe(ht.TNonEmptyString), "Target node UUID (if local export)"),
1129 ("shutdown", True, ht.TBool, "Whether to shutdown the instance before export"),
1130 ("remove_instance", False, ht.TBool, "Whether to remove instance after export"),
1131 ("ignore_remove_failures", False, ht.TBool, "Whether to ignore failures while removing instances"),
1132 ("mode", "local", ht.TExportMode, "Export mode"),
1133 ("x509_key_name", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Name of X509 key (remote export only)"),
1134 ("destination_x509_ca", None, ht.TMaybe(ht.TNonEmptyString), "Destination X509 CA (remote export only)"),
1135 ("zero_free_space", False, ht.TBool, "Whether to zero the free space on the disks of the instance"),
1136 ("zeroing_timeout_fixed", None, ht.TMaybe(ht.TInt), "The fixed part of time to wait before declaring the zeroing operation to have failed"),
1137 ("zeroing_timeout_per_mib", None, ht.TMaybe(ht.TDouble), "The variable part of time to wait before declaring the zeroing operation to have failed, dependent on total size of disks")
1138 ]
1139 OP_RESULT = ht.TTupleOf(ht.TBool, ht.TListOf(ht.TBool))
1140
1149
1159
1167
1176
1185
1187 """Sleeps for a configured amount of time.
1188
1189 This is used just for debugging and testing.
1190
1191 Parameters:
1192 - duration: the time to sleep, in seconds
1193 - on_master: if true, sleep on the master
1194 - on_nodes: list of nodes in which to sleep
1195
1196 If the on_master parameter is true, it will execute a sleep on the
1197 master (before any node sleep).
1198
1199 If the on_nodes list is not empty, it will sleep on those nodes
1200 (after the sleep on the master, if that is enabled).
1201
1202 As an additional feature, the case of duration < 0 will be reported
1203 as an execution error, so this opcode can be used as a failure
1204 generator. The case of duration == 0 will not be treated specially.
1205
1206 """
1207 OP_DSC_FIELD = "duration"
1208 OP_PARAMS = [
1209 ("duration", None, ht.TDouble, "Duration parameter for 'OpTestDelay'"),
1210 ("on_master", True, ht.TBool, "on_master field for 'OpTestDelay'"),
1211 ("on_nodes", [], ht.TListOf(ht.TNonEmptyString), "on_nodes field for 'OpTestDelay'"),
1212 ("on_node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "on_node_uuids field for 'OpTestDelay'"),
1213 ("repeat", 0, ht.TNonNegative(ht.TInt), "Repeat parameter for OpTestDelay"),
1214 ("interruptible", False, ht.TBool, "Allows socket-based interruption of a running OpTestDelay"),
1215 ("no_locks", True, ht.TBool, "Don't take locks during the delay")
1216 ]
1217 OP_RESULT = ht.TNone
1218
1220 """Allocator framework testing.
1221
1222 This opcode has two modes:
1223 - gather and return allocator input for a given mode (allocate new
1224 or replace secondary) and a given instance definition (direction
1225 'in')
1226 - run a selected allocator for a given operation (as above) and
1227 return the allocator output (direction 'out')
1228
1229 """
1230 OP_DSC_FIELD = "iallocator"
1231 OP_PARAMS = [
1232 ("direction", None, ht.TIAllocatorTestDir, "IAllocator test direction"),
1233 ("mode", None, ht.TIAllocatorMode, "IAllocator test mode"),
1234 ("name", None, ht.TNonEmptyString, "IAllocator target name (new instance, node to evac, etc.)"),
1235 ("nics", None, ht.TMaybe(ht.TListOf(ht.TINicParams)), "Custom OpTestIAllocator nics"),
1236 ("disks", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Custom OpTestAllocator disks"),
1237 ("hypervisor", None, ht.TMaybe(ht.THypervisor), "Selected hypervisor for an instance"),
1238 ("iallocator", None, ht.TMaybe(ht.TNonEmptyString), "Iallocator for deciding the target node for shared-storage instances"),
1239 ("tags", [], ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1240 ("memory", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "IAllocator memory field"),
1241 ("vcpus", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "IAllocator vcpus field"),
1242 ("os", None, ht.TMaybe(ht.TNonEmptyString), "IAllocator os field"),
1243 ("disk_template", None, ht.TDiskTemplate, "Disk template"),
1244 ("instances", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "IAllocator instances field"),
1245 ("evac_mode", None, ht.TMaybe(ht.TEvacMode), "IAllocator evac mode"),
1246 ("target_groups", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Destination group names or UUIDs (defaults to \"all but current group\")"),
1247 ("spindle_use", 1, ht.TNonNegative(ht.TInt), "IAllocator spindle use"),
1248 ("count", 1, ht.TNonNegative(ht.TInt), "IAllocator count field")
1249 ]
1250 OP_RESULT = ht.TString
1251
1253 """Utility opcode to test some aspects of the job queue."""
1254 OP_PARAMS = [
1255 ("notify_waitlock", False, ht.TBool, "'OpTestJqueue' notify_waitlock"),
1256 ("notify_exec", False, ht.TBool, "'OpTestJQueue' notify_exec"),
1257 ("log_messages", [], ht.TListOf(ht.TString), "'OpTestJQueue' log_messages"),
1258 ("fail", False, ht.TBool, "'OpTestJQueue' fail attribute")
1259 ]
1260 OP_RESULT = ht.TBool
1261
1263 """Utility opcode used by unittests."""
1264 OP_PARAMS = [
1265 ("result", None, ht.TAny, "'OpTestDummy' result field"),
1266 ("messages", None, ht.TAny, "'OpTestDummy' messages field"),
1267 ("fail", None, ht.TAny, "'OpTestDummy' fail field"),
1268 ("submit_jobs", None, ht.TAny, "'OpTestDummy' submit_jobs field")
1269 ]
1270 OP_RESULT = ht.TNone
1271 WITH_LU = False
1272
1274 """Add an IP network to the cluster."""
1275 OP_DSC_FIELD = "network_name"
1276 OP_PARAMS = [
1277 ("network_name", None, ht.TNonEmptyString, "Network name"),
1278 ("network", None, ht.TIPv4Network, "Network address (IPv4 subnet)"),
1279 ("gateway", None, ht.TMaybe(ht.TIPv4Address), "Network gateway (IPv4 address)"),
1280 ("network6", None, ht.TMaybe(ht.TIPv6Network), "Network address (IPv6 subnet)"),
1281 ("gateway6", None, ht.TMaybe(ht.TIPv6Address), "Network gateway (IPv6 address)"),
1282 ("mac_prefix", None, ht.TMaybe(ht.TNonEmptyString), "Network specific mac prefix (that overrides the cluster one)"),
1283 ("add_reserved_ips", None, ht.TMaybe(ht.TListOf(ht.TIPv4Address)), "Which IP addresses to reserve"),
1284 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses"),
1285 ("tags", [], ht.TListOf(ht.TNonEmptyString), "Network tags")
1286 ]
1287 OP_RESULT = ht.TNone
1288
1290 """Remove an existing network from the cluster.
1291 Must not be connected to any nodegroup.
1292
1293 """
1294 OP_DSC_FIELD = "network_name"
1295 OP_PARAMS = [
1296 ("network_name", None, ht.TNonEmptyString, "Network name"),
1297 ("force", False, ht.TBool, "Whether to force the operation")
1298 ]
1299 OP_RESULT = ht.TNone
1300
1302 """Modify Network's parameters except for IPv4 subnet"""
1303 OP_DSC_FIELD = "network_name"
1304 OP_PARAMS = [
1305 ("network_name", None, ht.TNonEmptyString, "Network name"),
1306 ("gateway", None, ht.TMaybe(ht.TIPv4Address), "Network gateway (IPv4 address)"),
1307 ("network6", None, ht.TMaybe(ht.TIPv6Network), "Network address (IPv6 subnet)"),
1308 ("gateway6", None, ht.TMaybe(ht.TIPv6Address), "Network gateway (IPv6 address)"),
1309 ("mac_prefix", None, ht.TMaybe(ht.TNonEmptyString), "Network specific mac prefix (that overrides the cluster one)"),
1310 ("add_reserved_ips", None, ht.TMaybe(ht.TListOf(ht.TIPv4Address)), "Which external IP addresses to reserve"),
1311 ("remove_reserved_ips", None, ht.TMaybe(ht.TListOf(ht.TIPv4Address)), "Which external IP addresses to release")
1312 ]
1313 OP_RESULT = ht.TNone
1314
1316 """Connect a Network to a specific Nodegroup with the defined netparams
1317 (mode, link). Nics in this Network will inherit those params.
1318 Produce errors if a NIC (that its not already assigned to a network)
1319 has an IP that is contained in the Network this will produce error unless
1320 --no-conflicts-check is passed.
1321
1322 """
1323 OP_DSC_FIELD = "network_name"
1324 OP_PARAMS = [
1325 ("group_name", None, ht.TNonEmptyString, "Group name"),
1326 ("network_name", None, ht.TNonEmptyString, "Network name"),
1327 ("network_mode", None, ht.TNICMode, "Network mode when connecting to a group"),
1328 ("network_link", None, ht.TNonEmptyString, "Network link when connecting to a group"),
1329 ("network_vlan", "", ht.TString, "Network vlan when connecting to a group"),
1330 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses")
1331 ]
1332 OP_RESULT = ht.TNone
1333
1335 """Disconnect a Network from a Nodegroup. Produce errors if NICs are
1336 present in the Network unless --no-conficts-check option is passed.
1337
1338 """
1339 OP_DSC_FIELD = "network_name"
1340 OP_PARAMS = [
1341 ("group_name", None, ht.TNonEmptyString, "Group name"),
1342 ("network_name", None, ht.TNonEmptyString, "Network name")
1343 ]
1344 OP_RESULT = ht.TNone
1345
1350 """Returns list of all defined opcodes.
1351
1352 Does not eliminate duplicates by C{OP_ID}.
1353
1354 """
1355 return [v for v in globals().values()
1356 if (isinstance(v, type) and issubclass(v, OpCode) and
1357 hasattr(v, "OP_ID") and v is not OpCode and
1358 v.OP_ID != 'OP_INSTANCE_MULTI_ALLOC_BASE')]
1359
1360
1361 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())
1362