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.TMaybeString, "Optional group name"),
270 ("verify_clutter", False, ht.TBool, "Whether to check for clutter in the 'authorized_keys' file.")
271 ]
272 OP_RESULT = ht.TJobIdListOnly
273
275 """Verify the cluster config."""
276 OP_PARAMS = [
277 ("debug_simulate_errors", False, ht.TBool, "Whether to simulate errors (useful for debugging)"),
278 ("error_codes", False, ht.TBool, "Error codes"),
279 ("ignore_errors", [], ht.TSetOf(ht.TCVErrorCode), "List of error codes that should be treated as warnings"),
280 ("verbose", False, ht.TBool, "Verbose mode")
281 ]
282 OP_RESULT = ht.TBool
283
285 """Run verify on a node group from the cluster.
286
287 @type skip_checks: C{list}
288 @ivar skip_checks: steps to be skipped from the verify process; this
289 needs to be a subset of
290 L{constants.VERIFY_OPTIONAL_CHECKS}; currently
291 only L{constants.VERIFY_NPLUSONE_MEM} can be passed
292
293 """
294 OP_DSC_FIELD = "group_name"
295 OP_PARAMS = [
296 ("group_name", None, ht.TNonEmptyString, "Group name"),
297 ("debug_simulate_errors", False, ht.TBool, "Whether to simulate errors (useful for debugging)"),
298 ("error_codes", False, ht.TBool, "Error codes"),
299 ("skip_checks", [], ht.TSetOf(ht.TVerifyOptionalChecks), "Which checks to skip"),
300 ("ignore_errors", [], ht.TSetOf(ht.TCVErrorCode), "List of error codes that should be treated as warnings"),
301 ("verbose", False, ht.TBool, "Verbose mode"),
302 ("verify_clutter", False, ht.TBool, "Whether to check for clutter in the 'authorized_keys' file.")
303 ]
304 OP_RESULT = ht.TBool
305
312
314 """Verifies the status of all disks in a node group.
315
316 Result: a tuple of three elements:
317 - dict of node names with issues (values: error msg)
318 - list of instances with degraded disks (that should be activated)
319 - dict of instances with missing logical volumes (values: (node, vol)
320 pairs with details about the missing volumes)
321
322 In normal operation, all lists should be empty. A non-empty instance
323 list (3rd element of the result) is still ok (errors were fixed) but
324 non-empty node list means some node is down, and probably there are
325 unfixable drbd errors.
326
327 Note that only instances that are drbd-based are taken into
328 consideration. This might need to be revisited in the future.
329
330 """
331 OP_DSC_FIELD = "group_name"
332 OP_PARAMS = [
333 ("group_name", None, ht.TNonEmptyString, "Group name")
334 ]
335 OP_RESULT = ht.TTupleOf(ht.TDictOf(ht.TString, ht.TString), ht.TListOf(ht.TString), ht.TDictOf(ht.TString, ht.TListOf(ht.TListOf(ht.TString))))
336
338 """Verify the disk sizes of the instances and fixes configuration
339 mismatches.
340
341 Parameters: optional instances list, in case we want to restrict the
342 checks to only a subset of the instances.
343
344 Result: a list of tuples, (instance, disk, parameter, new-size) for
345 changed configurations.
346
347 In normal operation, the list should be empty.
348
349 @type instances: list
350 @ivar instances: the list of instances to check, or empty for all instances
351
352 """
353 OP_PARAMS = [
354 ("instances", [], ht.TListOf(ht.TNonEmptyString), "List of instances")
355 ]
356 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TNonNegative(ht.TInt), ht.TNonEmptyString, ht.TNonNegative(ht.TInt)))
357
364
366 """Rename the cluster.
367
368 @type name: C{str}
369 @ivar name: The new name of the cluster. The name and/or the master IP
370 address will be changed to match the new name and its IP
371 address.
372
373 """
374 OP_DSC_FIELD = "name"
375 OP_PARAMS = [
376 ("name", None, ht.TNonEmptyString, "A generic name")
377 ]
378 OP_RESULT = ht.TNonEmptyString
379
381 """Change the parameters of the cluster.
382
383 @type vg_name: C{str} or C{None}
384 @ivar vg_name: The new volume group name or None to disable LVM usage.
385
386 """
387 OP_PARAMS = [
388 ("force", False, ht.TBool, "Whether to force the operation"),
389 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
390 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
391 ("vg_name", None, ht.TMaybe(ht.TString), "Volume group name"),
392 ("enabled_hypervisors", None, ht.TMaybe(ht.TListOf(ht.THypervisor)), "List of enabled hypervisors"),
393 ("hvparams", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TAny))), "Cluster-wide hypervisor parameters, hypervisor-dependent"),
394 ("beparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Cluster-wide backend parameter defaults"),
395 ("os_hvp", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TAny))), "Cluster-wide per-OS hypervisor parameter defaults"),
396 ("osparams", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TAny))), "Cluster-wide OS parameter defaults"),
397 ("osparams_private_cluster", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TObject(ht.TPrivate(ht.TAny)))), "Cluster-wide private OS parameter defaults"),
398 ("diskparams", None, ht.TMaybe(ht.TDictOf(ht.TDiskTemplate, ht.TObject(ht.TAny))), "Disk templates' parameter defaults"),
399 ("candidate_pool_size", None, ht.TMaybe(ht.TPositive(ht.TInt)), "Master candidate pool size"),
400 ("max_running_jobs", None, ht.TMaybe(ht.TPositive(ht.TInt)), "Maximal number of jobs to run simultaneously"),
401 ("max_tracked_jobs", None, ht.TMaybe(ht.TPositive(ht.TInt)), "Maximal number of jobs tracked in the job queue"),
402 ("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)"),
403 ("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)"),
404 ("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"),
405 ("maintain_node_health", None, ht.TMaybeBool, "Whether to automatically maintain node health"),
406 ("prealloc_wipe_disks", None, ht.TMaybeBool, "Whether to wipe disks before allocating them to instances"),
407 ("nicparams", None, ht.TMaybe(ht.TINicParams), "Cluster-wide NIC parameter defaults"),
408 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Cluster-wide node parameter defaults"),
409 ("ipolicy", None, ht.TMaybe(ht.TObject(ht.TAny)), "Cluster-wide ipolicy specs"),
410 ("drbd_helper", None, ht.TMaybe(ht.TString), "DRBD helper program"),
411 ("default_iallocator", None, ht.TMaybe(ht.TString), "Default iallocator for cluster"),
412 ("default_iallocator_params", None, ht.TMaybe(ht.TObject(ht.TAny)), "Default iallocator parameters for cluster"),
413 ("mac_prefix", None, ht.TMaybeString, "Network specific mac prefix (that overrides the cluster one)"),
414 ("master_netdev", None, ht.TMaybe(ht.TString), "Master network device"),
415 ("master_netmask", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "Netmask of the master IP"),
416 ("reserved_lvs", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of reserved LVs"),
417 ("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"),
418 ("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"),
419 ("use_external_mip_script", None, ht.TMaybeBool, "Whether to use an external master IP address setup script"),
420 ("enabled_disk_templates", None, ht.TMaybe(ht.TListOf(ht.TDiskTemplate)), "List of enabled disk templates"),
421 ("modify_etc_hosts", None, ht.TMaybeBool, ""),
422 ("file_storage_dir", None, ht.TMaybe(ht.TString), ""),
423 ("shared_file_storage_dir", None, ht.TMaybe(ht.TString), ""),
424 ("gluster_storage_dir", None, ht.TMaybe(ht.TString), ""),
425 ("install_image", None, ht.TMaybe(ht.TString), "OS image for running OS scripts in a safe environment"),
426 ("instance_communication_network", None, ht.TMaybe(ht.TString), ""),
427 ("zeroing_image", None, ht.TMaybe(ht.TString), ""),
428 ("compression_tools", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of enabled compression tools"),
429 ("enabled_user_shutdown", None, ht.TMaybeBool, "Whether user shutdown is enabled cluster wide"),
430 ("enabled_data_collectors", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TBool)), "Set the active data collectors"),
431 ("data_collector_interval", None, ht.TMaybe(ht.TDictOf(ht.TString, ht.TInt)), "Sets the interval in that data collectors are run")
432 ]
433 OP_RESULT = ht.TOr(ht.TNone, ht.TJobIdListOnly)
434
440
446
452
454 """Renews the cluster node's SSL client certificates."""
455 OP_PARAMS = [
456 ("node_certificates", False, ht.TBool, "Whether to renew node SSL certificates"),
457 ("renew_ssh_keys", False, ht.TBool, "Whether to renew SSH keys"),
458 ("ssh_key_type", None, ht.TMaybe(ht.TSshKeyType), "The type of the SSH key Ganeti uses"),
459 ("ssh_key_bits", None, ht.TMaybe(ht.TPositive(ht.TInt)), "The number of bits of the SSH key Ganeti uses"),
460 ("verbose", False, ht.TBool, "Verbose mode"),
461 ("debug", False, ht.TBool, "Debug mode")
462 ]
463 OP_RESULT = ht.TNone
464
466 """Query for resources/items.
467
468 @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
469 @ivar fields: List of fields to retrieve
470 @ivar qfilter: Query filter
471
472 """
473 OP_DSC_FIELD = "what"
474 OP_PARAMS = [
475 ("what", None, ht.TQueryTypeOp, "Resource(s) to query for"),
476 ("use_locking", False, ht.TBool, "Whether to use synchronization"),
477 ("fields", None, ht.TListOf(ht.TNonEmptyString), "Requested fields"),
478 ("qfilter", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Query filter")
479 ]
480 OP_RESULT = ht.TQueryResponse
481
495
497 """Interact with OOB."""
498 OP_PARAMS = [
499 ("node_names", [], ht.TListOf(ht.TNonEmptyString), "List of node names to run the OOB command against"),
500 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of node UUIDs to run the OOB command against"),
501 ("command", None, ht.TOobCommand, "OOB command to run"),
502 ("timeout", 60, ht.TInt, "Timeout before the OOB helper will be terminated"),
503 ("ignore_status", False, ht.TBool, "Ignores the node offline status for power off"),
504 ("power_delay", 2.0, ht.TDouble, "Time in seconds to wait between powering on nodes")
505 ]
506 OP_RESULT = ht.TListOf(ht.TListOf(ht.TTupleOf(ht.TQueryResultCode, ht.TAny)))
507
509 """Runs a restricted command on node(s)."""
510 OP_PARAMS = [
511 ("use_locking", False, ht.TBool, "Whether to use synchronization"),
512 ("nodes", None, ht.TListOf(ht.TNonEmptyString), "Nodes on which the command should be run (at least one)"),
513 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Node UUIDs on which the command should be run (at least one)"),
514 ("command", None, ht.TNonEmptyString, "Restricted command name")
515 ]
516 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TBool, ht.TString))
517
519 """Remove a node.
520
521 @type node_name: C{str}
522 @ivar node_name: The name of the node to remove. If the node still has
523 instances on it, the operation will fail.
524
525 """
526 OP_DSC_FIELD = "node_name"
527 OP_PARAMS = [
528 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
529 ("node_uuid", None, ht.TMaybeString, "A node UUID (for single-node LUs)")
530 ]
531 OP_RESULT = ht.TNone
532
534 """Add a node to the cluster.
535
536 @type node_name: C{str}
537 @ivar node_name: The name of the node to add. This can be a short name,
538 but it will be expanded to the FQDN.
539 @type primary_ip: IP address
540 @ivar primary_ip: The primary IP of the node. This will be ignored when
541 the opcode is submitted, but will be filled during the
542 node add (so it will be visible in the job query).
543 @type secondary_ip: IP address
544 @ivar secondary_ip: The secondary IP of the node. This needs to be passed
545 if the cluster has been initialized in 'dual-network'
546 mode, otherwise it must not be given.
547 @type readd: C{bool}
548 @ivar readd: Whether to re-add an existing node to the cluster. If
549 this is not passed, then the operation will abort if the node
550 name is already in the cluster; use this parameter to
551 'repair' a node that had its configuration broken, or was
552 reinstalled without removal from the cluster.
553 @type group: C{str}
554 @ivar group: The node group to which this node will belong.
555 @type vm_capable: C{bool}
556 @ivar vm_capable: The vm_capable node attribute
557 @type master_capable: C{bool}
558 @ivar master_capable: The master_capable node attribute
559
560 """
561 OP_DSC_FIELD = "node_name"
562 OP_PARAMS = [
563 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
564 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
565 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
566 ("primary_ip", None, ht.TMaybeString, "Primary IP address"),
567 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
568 ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
569 ("group", None, ht.TMaybeString, "Initial node group"),
570 ("master_capable", None, ht.TMaybeBool, "Whether node can become master or master candidate"),
571 ("vm_capable", None, ht.TMaybeBool, "Whether node can host instances"),
572 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Node parameters"),
573 ("node_setup", False, ht.TBool, "Whether to perform a SSH setup on the new node")
574 ]
575 OP_RESULT = ht.TNone
576
584
586 """Get information on storage for node(s)."""
587 OP_PARAMS = [
588 ("output_fields", None, ht.TListOf(ht.TNonEmptyString), "Selected output fields"),
589 ("storage_type", None, ht.TMaybe(ht.TStorageType), "Storage type"),
590 ("nodes", [], ht.TListOf(ht.TNonEmptyString), "Empty list to query all, list of names to query otherwise"),
591 ("name", None, ht.TMaybeString, "Storage name")
592 ]
593 OP_RESULT = ht.TListOf(ht.TListOf(ht.TAny))
594
596 """Modifies the properies of a storage unit"""
597 OP_DSC_FIELD = "node_name"
598 OP_PARAMS = [
599 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
600 ("node_uuid", None, ht.TMaybeString, "A node UUID (for single-node LUs)"),
601 ("storage_type", None, ht.TStorageType, "Storage type"),
602 ("name", None, ht.TMaybeString, "Storage name"),
603 ("changes", None, ht.TObject(ht.TAny), "Requested storage changes")
604 ]
605 OP_RESULT = ht.TNone
606
608 """Repairs the volume group on a node."""
609 OP_DSC_FIELD = "node_name"
610 OP_PARAMS = [
611 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
612 ("node_uuid", None, ht.TMaybeString, "A node UUID (for single-node LUs)"),
613 ("storage_type", None, ht.TStorageType, "Storage type"),
614 ("name", None, ht.TMaybeString, "Storage name"),
615 ("ignore_consistency", False, ht.TBool, "Whether to ignore disk consistency")
616 ]
617 OP_RESULT = ht.TNone
618
620 """Change the parameters of a node."""
621 OP_DSC_FIELD = "node_name"
622 OP_PARAMS = [
623 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
624 ("node_uuid", None, ht.TMaybeString, "A node UUID (for single-node LUs)"),
625 ("force", False, ht.TBool, "Whether to force the operation"),
626 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
627 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
628 ("master_candidate", None, ht.TMaybeBool, "Whether the node should become a master candidate"),
629 ("offline", None, ht.TMaybeBool, "Whether to mark the node offline"),
630 ("drained", None, ht.TMaybeBool, "Whether to mark the node as drained"),
631 ("auto_promote", False, ht.TBool, "Whether node(s) should be promoted to master candidate if necessary"),
632 ("master_capable", None, ht.TMaybeBool, "Whether node can become master or master candidate"),
633 ("vm_capable", None, ht.TMaybeBool, "Whether node can host instances"),
634 ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
635 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Node parameters"),
636 ("powered", None, ht.TMaybeBool, "Whether the node should be marked as powered")
637 ]
638 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TAny))
639
641 """Tries to powercycle 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.TMaybeString, "A node UUID (for single-node LUs)"),
646 ("force", False, ht.TBool, "Whether to force the operation")
647 ]
648 OP_RESULT = ht.TMaybe(ht.TNonEmptyString)
649
651 """Migrate all instances from a node."""
652 OP_DSC_FIELD = "node_name"
653 OP_PARAMS = [
654 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
655 ("node_uuid", None, ht.TMaybeString, "A node UUID (for single-node LUs)"),
656 ("mode", None, ht.TMaybe(ht.TMigrationMode), "Migration type (live/non-live)"),
657 ("live", None, ht.TMaybeBool, "Obsolete 'live' migration mode (do not use)"),
658 ("target_node", None, ht.TMaybeString, "Target node for instance migration/failover"),
659 ("target_node_uuid", None, ht.TMaybeString, "Target node UUID for instance migration/failover"),
660 ("allow_runtime_changes", True, ht.TBool, "Whether to allow runtime changes while migrating"),
661 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
662 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances")
663 ]
664 OP_RESULT = ht.TJobIdListOnly
665
667 """Evacuate instances off a number of nodes."""
668 OP_DSC_FIELD = "node_name"
669 OP_PARAMS = [
670 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
671 ("node_name", None, ht.TNonEmptyString, "A required node name (for single-node LUs)"),
672 ("node_uuid", None, ht.TMaybeString, "A node UUID (for single-node LUs)"),
673 ("remote_node", None, ht.TMaybeString, "New secondary node"),
674 ("remote_node_uuid", None, ht.TMaybeString, "New secondary node UUID"),
675 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
676 ("mode", None, ht.TEvacMode, "Node evacuation mode"),
677 ("ignore_soft_errors", None, ht.TMaybeBool, "Ignore soft htools errors")
678 ]
679 OP_RESULT = ht.TJobIdListOnly
680
682 """Create an instance.
683
684 @ivar instance_name: Instance name
685 @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
686 @ivar source_handshake: Signed handshake from source (remote import only)
687 @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
688 @ivar source_instance_name: Previous name of instance (remote import only)
689 @ivar source_shutdown_timeout: Shutdown timeout used for source instance
690 (remote import only)
691
692 """
693 OP_DSC_FIELD = "instance_name"
694 OP_PARAMS = [
695 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
696 ("force_variant", False, ht.TBool, "Whether to force an unknown OS variant"),
697 ("wait_for_sync", True, ht.TBool, "Whether to wait for the disk to synchronize"),
698 ("name_check", True, ht.TBool, "Whether to check name"),
699 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
700 ("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)"),
701 ("beparams", {}, ht.TObject(ht.TAny), "Backend parameters for instance"),
702 ("disks", None, ht.TListOf(ht.TIDiskParams), "List of instance disks"),
703 ("disk_template", None, ht.TMaybe(ht.TDiskTemplate), "Instance disk template"),
704 ("group_name", None, ht.TMaybeString, "Optional group name"),
705 ("file_driver", None, ht.TMaybe(ht.TFileDriver), "Driver for file-backed disks"),
706 ("file_storage_dir", None, ht.TMaybeString, "Directory for storing file-backed disks"),
707 ("hvparams", {}, ht.TObject(ht.TAny), "Hypervisor parameters for instance, hypervisor-dependent"),
708 ("hypervisor", None, ht.TMaybe(ht.THypervisor), "Selected hypervisor for an instance"),
709 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
710 ("identify_defaults", False, ht.TBool, "Reset instance parameters to default if equal"),
711 ("ip_check", True, ht.TBool, "Whether to ensure instance's IP address is inactive"),
712 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses"),
713 ("mode", None, ht.TInstCreateMode, "Instance creation mode"),
714 ("nics", None, ht.TListOf(ht.TINicParams), "List of NIC (network interface) definitions"),
715 ("no_install", None, ht.TMaybeBool, "Do not install the OS (will disable automatic start)"),
716 ("osparams", {}, ht.TObject(ht.TAny), "OS parameters for instance"),
717 ("osparams_private", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Private OS parameters for instance"),
718 ("osparams_secret", None, ht.TMaybe(ht.TObject(ht.TSecret(ht.TAny))), "Secret OS parameters for instance"),
719 ("os_type", None, ht.TMaybeString, "OS type for instance installation"),
720 ("pnode", None, ht.TMaybeString, "Primary node for an instance"),
721 ("pnode_uuid", None, ht.TMaybeString, "Primary node UUID for an instance"),
722 ("snode", None, ht.TMaybeString, "Secondary node for an instance"),
723 ("snode_uuid", None, ht.TMaybeString, "Secondary node UUID for an instance"),
724 ("source_handshake", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Signed handshake from source (remote import only)"),
725 ("source_instance_name", None, ht.TMaybeString, "Source instance name (remote import only)"),
726 ("source_shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long source instance was given to shut down (remote import only)"),
727 ("source_x509_ca", None, ht.TMaybeString, "Source X509 CA in PEM format (remote import only)"),
728 ("src_node", None, ht.TMaybeString, "Source node for import"),
729 ("src_node_uuid", None, ht.TMaybeString, "Source node UUID for import"),
730 ("src_path", None, ht.TMaybeString, "Source directory for import"),
731 ("compress", "none", ht.TString, "Compression mode to use for moves during backups/imports"),
732 ("start", True, ht.TBool, "Whether to start instance after creation"),
733 ("forthcoming", False, ht.TBool, "Whether to only reserve resources"),
734 ("commit", False, ht.TBool, "Commit the already reserved instance"),
735 ("tags", [], ht.TListOf(ht.TNonEmptyString), "Instance tags"),
736 ("instance_communication", False, ht.TBool, "Enable or disable the communication mechanism for an instance"),
737 ("helper_startup_timeout", None, ht.TMaybe(ht.TInt), "Startup timeout for the helper VM"),
738 ("helper_shutdown_timeout", None, ht.TMaybe(ht.TInt), "Shutdown timeout for the helper VM")
739 ]
740 OP_RESULT = ht.TListOf(ht.TNonEmptyString)
741
743 """Allocates multiple instances."""
744 OP_PARAMS = [
745 ("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)"),
746 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
747 ("instances", [], ht.TListOf(ht.TAny), "List of instance create opcodes describing the instances to allocate")
748 ]
749 OP_RESULT = ht.TInstanceMultiAllocResponse
750
752 """Reinstall an instance's OS."""
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.TMaybeString, "An instance UUID (for single-instance LUs)"),
757 ("force_variant", False, ht.TBool, "Whether to force an unknown OS variant"),
758 ("os_type", None, ht.TMaybeString, "OS type for instance installation"),
759 ("osparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Temporary OS parameters (currently only in reinstall, might be added to install as well)"),
760 ("osparams_private", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Private OS parameters for instance reinstalls"),
761 ("osparams_secret", None, ht.TMaybe(ht.TObject(ht.TSecret(ht.TAny))), "Secret OS parameters for instance reinstalls")
762 ]
763 OP_RESULT = ht.TNone
764
766 """Remove an instance."""
767 OP_DSC_FIELD = "instance_name"
768 OP_PARAMS = [
769 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
770 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
771 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
772 ("ignore_failures", False, ht.TBool, "Whether to ignore failures during removal")
773 ]
774 OP_RESULT = ht.TNone
775
777 """Rename an instance."""
778 OP_PARAMS = [
779 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
780 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
781 ("new_name", None, ht.TNonEmptyString, "New instance name"),
782 ("name_check", True, ht.TBool, "Whether to check name"),
783 ("ip_check", True, ht.TBool, "Whether to ensure instance's IP address is inactive")
784 ]
785 OP_RESULT = ht.TNonEmptyString
786
788 """Startup an instance."""
789 OP_DSC_FIELD = "instance_name"
790 OP_PARAMS = [
791 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
792 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
793 ("force", False, ht.TBool, "Whether to force the operation"),
794 ("ignore_offline_nodes", False, ht.TBool, "Whether to ignore offline nodes"),
795 ("hvparams", {}, ht.TObject(ht.TAny), "Temporary hypervisor parameters, hypervisor-dependent"),
796 ("beparams", {}, ht.TObject(ht.TAny), "Temporary backend parameters"),
797 ("no_remember", False, ht.TBool, "Do not remember instance state changes"),
798 ("startup_paused", False, ht.TBool, "Pause instance at startup"),
799 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down")
800 ]
801 OP_RESULT = ht.TNone
802
804 """Shutdown 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.TMaybeString, "An instance UUID (for single-instance LUs)"),
809 ("force", False, ht.TBool, "Whether to force the operation"),
810 ("ignore_offline_nodes", False, ht.TBool, "Whether to ignore offline nodes"),
811 ("timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
812 ("no_remember", False, ht.TBool, "Do not remember instance state changes"),
813 ("admin_state_source", None, ht.TMaybe(ht.TAdminStateSource), "Who last changed the instance admin state")
814 ]
815 OP_RESULT = ht.TNone
816
818 """Reboot an instance."""
819 OP_DSC_FIELD = "instance_name"
820 OP_PARAMS = [
821 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
822 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
823 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
824 ("ignore_secondaries", False, ht.TBool, "Whether to start the instance even if secondary disks are failing"),
825 ("reboot_type", None, ht.TRebootType, "How to reboot the instance")
826 ]
827 OP_RESULT = ht.TNone
828
830 """Replace the disks of an instance."""
831 OP_DSC_FIELD = "instance_name"
832 OP_PARAMS = [
833 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
834 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
835 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
836 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
837 ("mode", None, ht.TReplaceDisksMode, "Replacement mode"),
838 ("disks", [], ht.TListOf(ht.TDiskIndex), "List of disk indices"),
839 ("remote_node", None, ht.TMaybeString, "New secondary node"),
840 ("remote_node_uuid", None, ht.TMaybeString, "New secondary node UUID"),
841 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances")
842 ]
843 OP_RESULT = ht.TNone
844
846 """Failover an instance."""
847 OP_DSC_FIELD = "instance_name"
848 OP_PARAMS = [
849 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
850 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
851 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
852 ("ignore_consistency", False, ht.TBool, "Whether to ignore disk consistency"),
853 ("target_node", None, ht.TMaybeString, "Target node for instance migration/failover"),
854 ("target_node_uuid", None, ht.TMaybeString, "Target node UUID for instance migration/failover"),
855 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
856 ("cleanup", False, ht.TBool, "Whether a previously failed migration should be cleaned up"),
857 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances")
858 ]
859 OP_RESULT = ht.TNone
860
862 """Migrate an instance.
863
864 This migrates (without shutting down an instance) to its secondary
865 node.
866
867 @ivar instance_name: the name of the instance
868 @ivar mode: the migration mode (live, non-live or None for auto)
869
870 """
871 OP_DSC_FIELD = "instance_name"
872 OP_PARAMS = [
873 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
874 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
875 ("mode", None, ht.TMaybe(ht.TMigrationMode), "Migration type (live/non-live)"),
876 ("live", None, ht.TMaybeBool, "Obsolete 'live' migration mode (do not use)"),
877 ("target_node", None, ht.TMaybeString, "Target node for instance migration/failover"),
878 ("target_node_uuid", None, ht.TMaybeString, "Target node UUID for instance migration/failover"),
879 ("allow_runtime_changes", True, ht.TBool, "Whether to allow runtime changes while migrating"),
880 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
881 ("cleanup", False, ht.TBool, "Whether a previously failed migration should be cleaned up"),
882 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
883 ("allow_failover", False, ht.TBool, "Whether we can fallback to failover if migration is not possible"),
884 ("ignore_hvversions", False, ht.TBool, "Whether to ignore incompatible Hypervisor versions")
885 ]
886 OP_RESULT = ht.TNone
887
889 """Move an instance.
890
891 This move (with shutting down an instance and data copying) to an
892 arbitrary node.
893
894 @ivar instance_name: the name of the instance
895 @ivar target_node: the destination node
896
897 """
898 OP_DSC_FIELD = "instance_name"
899 OP_PARAMS = [
900 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
901 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
902 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
903 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
904 ("target_node", None, ht.TNonEmptyString, "Target node for instance move"),
905 ("target_node_uuid", None, ht.TMaybeString, "Target node UUID for instance move"),
906 ("compress", "none", ht.TString, "Compression mode to use during instance moves"),
907 ("ignore_consistency", False, ht.TBool, "Whether to ignore disk consistency")
908 ]
909 OP_RESULT = ht.TNone
910
919
921 """Activate an instance's disks."""
922 OP_DSC_FIELD = "instance_name"
923 OP_PARAMS = [
924 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
925 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
926 ("ignore_size", False, ht.TBool, "Whether to ignore recorded disk size"),
927 ("wait_for_sync", False, ht.TBool, "Whether to wait for the disk to synchronize (defaults to false)")
928 ]
929 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TNonEmptyString, ht.TMaybe(ht.TNonEmptyString)))
930
932 """Deactivate an instance's disks."""
933 OP_DSC_FIELD = "instance_name"
934 OP_PARAMS = [
935 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
936 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
937 ("force", False, ht.TBool, "Whether to force the operation")
938 ]
939 OP_RESULT = ht.TNone
940
942 """Recreate an instance's disks."""
943 OP_DSC_FIELD = "instance_name"
944 OP_PARAMS = [
945 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
946 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
947 ("disks", [], ht.TRecreateDisksInfo, "Disk list for recreate disks"),
948 ("nodes", [], ht.TListOf(ht.TNonEmptyString), "New instance nodes, if relocation is desired"),
949 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "New instance node UUIDs, if relocation is desired"),
950 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances")
951 ]
952 OP_RESULT = ht.TNone
953
955 """Compute the run-time status of instances."""
956 OP_PARAMS = [
957 ("use_locking", False, ht.TBool, "Whether to use synchronization"),
958 ("instances", [], ht.TListOf(ht.TNonEmptyString), "List of instances"),
959 ("static", False, ht.TBool, "Whether to only return configuration data without querying nodes")
960 ]
961 OP_RESULT = ht.TObject(ht.TObject(ht.TAny))
962
964 """Change the parameters of an instance."""
965 OP_DSC_FIELD = "instance_name"
966 OP_PARAMS = [
967 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
968 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
969 ("force", False, ht.TBool, "Whether to force the operation"),
970 ("force_variant", False, ht.TBool, "Whether to force an unknown OS variant"),
971 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations"),
972 ("nics", [], ht.TSetParamsMods(ht.TINicParams), "List of NIC changes"),
973 ("disks", [], ht.TSetParamsMods(ht.TIDiskParams), "List of disk changes"),
974 ("beparams", {}, ht.TObject(ht.TAny), "Backend parameters for instance"),
975 ("runtime_mem", None, ht.TMaybe(ht.TPositive(ht.TInt)), "New runtime memory"),
976 ("hvparams", {}, ht.TObject(ht.TAny), "Hypervisor parameters for instance, hypervisor-dependent"),
977 ("disk_template", None, ht.TMaybe(ht.TDiskTemplate), "Instance disk template"),
978 ("ext_params", {}, ht.TObject(ht.TAny), "List of ExtStorage parameters"),
979 ("file_driver", None, ht.TMaybe(ht.TFileDriver), "Driver for file-backed disks"),
980 ("file_storage_dir", None, ht.TMaybeString, "Directory for storing file-backed disks"),
981 ("pnode", None, ht.TMaybeString, "Primary node for an instance"),
982 ("pnode_uuid", None, ht.TMaybeString, "Primary node UUID for an instance"),
983 ("remote_node", None, ht.TMaybeString, "Secondary node (used when changing disk template)"),
984 ("remote_node_uuid", None, ht.TMaybeString, "Secondary node UUID (used when changing disk template)"),
985 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
986 ("os_name", None, ht.TMaybeString, "Change the instance's OS without reinstalling the instance"),
987 ("osparams", {}, ht.TObject(ht.TAny), "OS parameters for instance"),
988 ("osparams_private", None, ht.TMaybe(ht.TObject(ht.TPrivate(ht.TAny))), "Private OS parameters for instance"),
989 ("wait_for_sync", True, ht.TBool, "Whether to wait for the disk to synchronize"),
990 ("offline", None, ht.TMaybeBool, "Whether to mark the instance as offline"),
991 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses"),
992 ("hotplug", False, ht.TBool, ""),
993 ("hotplug_if_possible", False, ht.TBool, ""),
994 ("instance_communication", None, ht.TMaybeBool, "Enable or disable the communication mechanism for an instance")
995 ]
996 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TAny))
997
999 """Grow a disk of an instance."""
1000 OP_DSC_FIELD = "instance_name"
1001 OP_PARAMS = [
1002 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1003 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
1004 ("wait_for_sync", True, ht.TBool, "Whether to wait for the disk to synchronize"),
1005 ("disk", None, ht.TDiskIndex, "Disk index for e.g. grow disk"),
1006 ("amount", None, ht.TNonNegative(ht.TInt), "Disk amount to add or grow to"),
1007 ("absolute", False, ht.TBool, "Whether the amount parameter is an absolute target or a relative one"),
1008 ("ignore_ipolicy", False, ht.TBool, "Whether to ignore ipolicy violations")
1009 ]
1010 OP_RESULT = ht.TNone
1011
1013 """Moves an instance to another node group."""
1014 OP_DSC_FIELD = "instance_name"
1015 OP_PARAMS = [
1016 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1017 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
1018 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
1019 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
1020 ("target_groups", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Destination group names or UUIDs (defaults to \"all but current group\")")
1021 ]
1022 OP_RESULT = ht.TJobIdListOnly
1023
1025 """Add a node group to the cluster."""
1026 OP_DSC_FIELD = "group_name"
1027 OP_PARAMS = [
1028 ("group_name", None, ht.TNonEmptyString, "Group name"),
1029 ("alloc_policy", None, ht.TMaybe(ht.TAllocPolicy), "Instance allocation policy"),
1030 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Default node parameters for group"),
1031 ("diskparams", None, ht.TMaybe(ht.TDictOf(ht.TDiskTemplate, ht.TObject(ht.TAny))), "Disk templates' parameter defaults"),
1032 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
1033 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
1034 ("ipolicy", None, ht.TMaybe(ht.TObject(ht.TAny)), "Group-wide ipolicy specs")
1035 ]
1036 OP_RESULT = ht.TOr(ht.TNone, ht.TJobIdListOnly)
1037
1039 """Assign nodes to a node group."""
1040 OP_DSC_FIELD = "group_name"
1041 OP_PARAMS = [
1042 ("group_name", None, ht.TNonEmptyString, "Group name"),
1043 ("force", False, ht.TBool, "Whether to force the operation"),
1044 ("nodes", None, ht.TListOf(ht.TNonEmptyString), "List of nodes to assign"),
1045 ("node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "List of node UUIDs to assign")
1046 ]
1047 OP_RESULT = ht.TNone
1048
1050 """Change the parameters of a node group."""
1051 OP_DSC_FIELD = "group_name"
1052 OP_PARAMS = [
1053 ("group_name", None, ht.TNonEmptyString, "Group name"),
1054 ("alloc_policy", None, ht.TMaybe(ht.TAllocPolicy), "Instance allocation policy"),
1055 ("ndparams", None, ht.TMaybe(ht.TObject(ht.TAny)), "Default node parameters for group"),
1056 ("diskparams", None, ht.TMaybe(ht.TDictOf(ht.TDiskTemplate, ht.TObject(ht.TAny))), "Disk templates' parameter defaults"),
1057 ("hv_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set hypervisor states"),
1058 ("disk_state", None, ht.TMaybe(ht.TObject(ht.TAny)), "Set disk states"),
1059 ("ipolicy", None, ht.TMaybe(ht.TObject(ht.TAny)), "Group-wide ipolicy specs")
1060 ]
1061 OP_RESULT = ht.TListOf(ht.TTupleOf(ht.TNonEmptyString, ht.TAny))
1062
1070
1078
1080 """Evacuate a node group in the cluster."""
1081 OP_DSC_FIELD = "group_name"
1082 OP_PARAMS = [
1083 ("group_name", None, ht.TNonEmptyString, "Group name"),
1084 ("early_release", False, ht.TBool, "Whether to release locks as soon as possible"),
1085 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
1086 ("target_groups", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Destination group names or UUIDs (defaults to \"all but current group\")"),
1087 ("sequential", False, ht.TBool, "Sequential job execution"),
1088 ("force_failover", False, ht.TBool, "Disallow migration moves and always use failovers")
1089 ]
1090 OP_RESULT = ht.TJobIdListOnly
1091
1099
1107
1109 """Prepares an instance export.
1110
1111 @ivar instance_name: Instance name
1112 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1113
1114 """
1115 OP_DSC_FIELD = "instance_name"
1116 OP_PARAMS = [
1117 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1118 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
1119 ("mode", None, ht.TExportMode, "Export mode")
1120 ]
1121 OP_RESULT = ht.TMaybe(ht.TObject(ht.TAny))
1122
1124 """Export an instance.
1125
1126 For local exports, the export destination is the node name. For
1127 remote exports, the export destination is a list of tuples, each
1128 consisting of hostname/IP address, port, magic, HMAC and HMAC
1129 salt. The HMAC is calculated using the cluster domain secret over
1130 the value "${index}:${hostname}:${port}". The destination X509 CA
1131 must be a signed certificate.
1132
1133 @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1134 @ivar target_node: Export destination
1135 @ivar x509_key_name: X509 key to use (remote export only)
1136 @ivar destination_x509_ca: Destination X509 CA in PEM format (remote
1137 export only)
1138
1139 """
1140 OP_DSC_FIELD = "instance_name"
1141 OP_PARAMS = [
1142 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1143 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)"),
1144 ("compress", "none", ht.TString, "Compression mode to use for moves during backups/imports"),
1145 ("shutdown_timeout", 120, ht.TNonNegative(ht.TInt), "How long to wait for instance to shut down"),
1146 ("target_node", None, ht.TExportTarget, "Target node (depends on export mode)"),
1147 ("target_node_uuid", None, ht.TMaybeString, "Target node UUID (if local export)"),
1148 ("shutdown", True, ht.TBool, "Whether to shutdown the instance before export"),
1149 ("remove_instance", False, ht.TBool, "Whether to remove instance after export"),
1150 ("ignore_remove_failures", False, ht.TBool, "Whether to ignore failures while removing instances"),
1151 ("mode", "local", ht.TExportMode, "Export mode"),
1152 ("x509_key_name", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Name of X509 key (remote export only)"),
1153 ("destination_x509_ca", None, ht.TMaybeString, "Destination X509 CA (remote export only)"),
1154 ("zero_free_space", False, ht.TBool, "Whether to zero the free space on the disks of the instance"),
1155 ("zeroing_timeout_fixed", None, ht.TMaybe(ht.TInt), "The fixed part of time to wait before declaring the zeroing operation to have failed"),
1156 ("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"),
1157 ("long_sleep", False, ht.TBool, "Whether to allow long instance shutdowns during exports")
1158 ]
1159 OP_RESULT = ht.TTupleOf(ht.TBool, ht.TListOf(ht.TBool))
1160
1162 """Remove an instance's export."""
1163 OP_DSC_FIELD = "instance_name"
1164 OP_PARAMS = [
1165 ("instance_name", None, ht.TString, "A required instance name (for single-instance LUs)"),
1166 ("instance_uuid", None, ht.TMaybeString, "An instance UUID (for single-instance LUs)")
1167 ]
1168 OP_RESULT = ht.TNone
1169
1179
1187
1196
1205
1207 """Sleeps for a configured amount of time.
1208
1209 This is used just for debugging and testing.
1210
1211 Parameters:
1212 - duration: the time to sleep, in seconds
1213 - on_master: if true, sleep on the master
1214 - on_nodes: list of nodes in which to sleep
1215
1216 If the on_master parameter is true, it will execute a sleep on the
1217 master (before any node sleep).
1218
1219 If the on_nodes list is not empty, it will sleep on those nodes
1220 (after the sleep on the master, if that is enabled).
1221
1222 As an additional feature, the case of duration < 0 will be reported
1223 as an execution error, so this opcode can be used as a failure
1224 generator. The case of duration == 0 will not be treated specially.
1225
1226 """
1227 OP_DSC_FIELD = "duration"
1228 OP_PARAMS = [
1229 ("duration", None, ht.TDouble, "Duration parameter for 'OpTestDelay'"),
1230 ("on_master", True, ht.TBool, "on_master field for 'OpTestDelay'"),
1231 ("on_nodes", [], ht.TListOf(ht.TNonEmptyString), "on_nodes field for 'OpTestDelay'"),
1232 ("on_node_uuids", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "on_node_uuids field for 'OpTestDelay'"),
1233 ("repeat", 0, ht.TNonNegative(ht.TInt), "Repeat parameter for OpTestDelay"),
1234 ("interruptible", False, ht.TBool, "Allows socket-based interruption of a running OpTestDelay"),
1235 ("no_locks", True, ht.TBool, "Don't take locks during the delay")
1236 ]
1237 OP_RESULT = ht.TNone
1238
1240 """Allocator framework testing.
1241
1242 This opcode has two modes:
1243 - gather and return allocator input for a given mode (allocate new
1244 or replace secondary) and a given instance definition (direction
1245 'in')
1246 - run a selected allocator for a given operation (as above) and
1247 return the allocator output (direction 'out')
1248
1249 """
1250 OP_DSC_FIELD = "iallocator"
1251 OP_PARAMS = [
1252 ("direction", None, ht.TIAllocatorTestDir, "IAllocator test direction"),
1253 ("mode", None, ht.TIAllocatorMode, "IAllocator test mode"),
1254 ("name", None, ht.TNonEmptyString, "IAllocator target name (new instance, node to evac, etc.)"),
1255 ("nics", None, ht.TMaybe(ht.TListOf(ht.TINicParams)), "Custom OpTestIAllocator nics"),
1256 ("disks", None, ht.TMaybe(ht.TListOf(ht.TAny)), "Custom OpTestAllocator disks"),
1257 ("hypervisor", None, ht.TMaybe(ht.THypervisor), "Selected hypervisor for an instance"),
1258 ("iallocator", None, ht.TMaybeString, "Iallocator for deciding the target node for shared-storage instances"),
1259 ("tags", [], ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1260 ("memory", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "IAllocator memory field"),
1261 ("vcpus", None, ht.TMaybe(ht.TNonNegative(ht.TInt)), "IAllocator vcpus field"),
1262 ("os", None, ht.TMaybeString, "IAllocator os field"),
1263 ("disk_template", None, ht.TMaybe(ht.TDiskTemplate), "Instance disk template"),
1264 ("instances", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "IAllocator instances field"),
1265 ("evac_mode", None, ht.TMaybe(ht.TEvacMode), "IAllocator evac mode"),
1266 ("target_groups", None, ht.TMaybe(ht.TListOf(ht.TNonEmptyString)), "Destination group names or UUIDs (defaults to \"all but current group\")"),
1267 ("spindle_use", 1, ht.TNonNegative(ht.TInt), "IAllocator spindle use"),
1268 ("count", 1, ht.TNonNegative(ht.TInt), "IAllocator count field"),
1269 ("group_name", None, ht.TMaybeString, "Optional group name")
1270 ]
1271 OP_RESULT = ht.TString
1272
1274 """Utility opcode to test some aspects of the job queue."""
1275 OP_PARAMS = [
1276 ("notify_waitlock", False, ht.TBool, "'OpTestJqueue' notify_waitlock"),
1277 ("notify_exec", False, ht.TBool, "'OpTestJQueue' notify_exec"),
1278 ("log_messages", [], ht.TListOf(ht.TString), "'OpTestJQueue' log_messages"),
1279 ("fail", False, ht.TBool, "'OpTestJQueue' fail attribute")
1280 ]
1281 OP_RESULT = ht.TBool
1282
1289
1291 """Utility opcode used by unittests."""
1292 OP_PARAMS = [
1293 ("result", None, ht.TAny, "'OpTestDummy' result field"),
1294 ("messages", None, ht.TAny, "'OpTestDummy' messages field"),
1295 ("fail", None, ht.TAny, "'OpTestDummy' fail field"),
1296 ("submit_jobs", None, ht.TAny, "'OpTestDummy' submit_jobs field")
1297 ]
1298 OP_RESULT = ht.TNone
1299 WITH_LU = False
1300
1302 """Add an IP network to the cluster."""
1303 OP_DSC_FIELD = "network_name"
1304 OP_PARAMS = [
1305 ("network_name", None, ht.TNonEmptyString, "Network name"),
1306 ("network", None, ht.TIPv4Network, "Network address (IPv4 subnet)"),
1307 ("gateway", None, ht.TMaybe(ht.TIPv4Address), "Network gateway (IPv4 address)"),
1308 ("network6", None, ht.TMaybe(ht.TIPv6Network), "Network address (IPv6 subnet)"),
1309 ("gateway6", None, ht.TMaybe(ht.TIPv6Address), "Network gateway (IPv6 address)"),
1310 ("mac_prefix", None, ht.TMaybeString, "Network specific mac prefix (that overrides the cluster one)"),
1311 ("add_reserved_ips", None, ht.TMaybe(ht.TListOf(ht.TIPv4Address)), "Which IP addresses to reserve"),
1312 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses"),
1313 ("tags", [], ht.TListOf(ht.TNonEmptyString), "Network tags")
1314 ]
1315 OP_RESULT = ht.TNone
1316
1318 """Remove an existing network from the cluster.
1319 Must not be connected to any nodegroup.
1320
1321 """
1322 OP_DSC_FIELD = "network_name"
1323 OP_PARAMS = [
1324 ("network_name", None, ht.TNonEmptyString, "Network name"),
1325 ("force", False, ht.TBool, "Whether to force the operation")
1326 ]
1327 OP_RESULT = ht.TNone
1328
1330 """Modify Network's parameters except for IPv4 subnet"""
1331 OP_DSC_FIELD = "network_name"
1332 OP_PARAMS = [
1333 ("network_name", None, ht.TNonEmptyString, "Network name"),
1334 ("gateway", None, ht.TMaybe(ht.TIPv4Address), "Network gateway (IPv4 address)"),
1335 ("network6", None, ht.TMaybe(ht.TIPv6Network), "Network address (IPv6 subnet)"),
1336 ("gateway6", None, ht.TMaybe(ht.TIPv6Address), "Network gateway (IPv6 address)"),
1337 ("mac_prefix", None, ht.TMaybeString, "Network specific mac prefix (that overrides the cluster one)"),
1338 ("add_reserved_ips", None, ht.TMaybe(ht.TListOf(ht.TIPv4Address)), "Which external IP addresses to reserve"),
1339 ("remove_reserved_ips", None, ht.TMaybe(ht.TListOf(ht.TIPv4Address)), "Which external IP addresses to release")
1340 ]
1341 OP_RESULT = ht.TNone
1342
1344 """Connect a Network to a specific Nodegroup with the defined netparams
1345 (mode, link). Nics in this Network will inherit those params.
1346 Produce errors if a NIC (that its not already assigned to a network)
1347 has an IP that is contained in the Network this will produce error unless
1348 --no-conflicts-check is passed.
1349
1350 """
1351 OP_DSC_FIELD = "network_name"
1352 OP_PARAMS = [
1353 ("group_name", None, ht.TNonEmptyString, "Group name"),
1354 ("network_name", None, ht.TNonEmptyString, "Network name"),
1355 ("network_mode", None, ht.TNICMode, "Network mode when connecting to a group"),
1356 ("network_link", None, ht.TNonEmptyString, "Network link when connecting to a group"),
1357 ("network_vlan", "", ht.TString, "Network vlan when connecting to a group"),
1358 ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IP addresses")
1359 ]
1360 OP_RESULT = ht.TNone
1361
1363 """Disconnect a Network from a Nodegroup. Produce errors if NICs are
1364 present in the Network unless --no-conficts-check option is passed.
1365
1366 """
1367 OP_DSC_FIELD = "network_name"
1368 OP_PARAMS = [
1369 ("group_name", None, ht.TNonEmptyString, "Group name"),
1370 ("network_name", None, ht.TNonEmptyString, "Network name")
1371 ]
1372 OP_RESULT = ht.TNone
1373
1378 """Returns list of all defined opcodes.
1379
1380 Does not eliminate duplicates by C{OP_ID}.
1381
1382 """
1383 return [v for v in globals().values()
1384 if (isinstance(v, type) and issubclass(v, OpCode) and
1385 hasattr(v, "OP_ID") and v is not OpCode and
1386 v.OP_ID != 'OP_INSTANCE_MULTI_ALLOC_BASE')]
1387
1388
1389 OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())
1390