Newer
Older
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""OpCodes module
This module implements the data structures which define the cluster
operations - the so-called opcodes.
Every operation which modifies the cluster state is expressed via
opcodes.
"""
# this are practically structures, so disable the message about too
# few public methods:
# pylint: disable-msg=R0903
import logging
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from ganeti import constants
from ganeti import errors
from ganeti import ht
# Common opcode attributes
#: output fields for a query operation
_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString))
#: the shutdown timeout
_PShutdownTimeout = ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
ht.TPositiveInt)
#: the force parameter
_PForce = ("force", False, ht.TBool)
#: a required instance name (for single-instance LUs)
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString)
#: Whether to ignore offline nodes
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool)
#: a required node name (for single-node LUs)
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString)
#: a required node group name (for single-group LUs)
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString)
#: Migration type (live/non-live)
_PMigrationMode = ("mode", None,
ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)))
#: Obsolete 'live' migration mode (boolean)
_PMigrationLive = ("live", None, ht.TMaybeBool)
#: Tag type
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES))
#: List of tag strings
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString))
def RequireFileStorage():
"""Checks that file storage is enabled.
While it doesn't really fit into this module, L{utils} was deemed too large
of a dependency to be imported for just one or two functions.
@raise errors.OpPrereqError: when file storage is disabled
"""
if not constants.ENABLE_FILE_STORAGE:
raise errors.OpPrereqError("File storage disabled at configure time",
errors.ECODE_INVAL)
def _CheckDiskTemplate(template):
"""Ensure a given disk template is valid.
"""
if template not in constants.DISK_TEMPLATES:
# Using str.join directly to avoid importing utils for CommaJoin
msg = ("Invalid disk template name '%s', valid templates are: %s" %
(template, ", ".join(constants.DISK_TEMPLATES)))
raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
if template == constants.DT_FILE:
RequireFileStorage()
return True
def _CheckStorageType(storage_type):
"""Ensure a given storage type is valid.
"""
if storage_type not in constants.VALID_STORAGE_TYPES:
raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
errors.ECODE_INVAL)
if storage_type == constants.ST_FILE:
RequireFileStorage()
return True
#: Storage type parameter
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType)
class _AutoOpParamSlots(type):
"""Meta class for opcode definitions.
"""
def __new__(mcs, name, bases, attrs):
"""Called when a class should be created.
@param mcs: The meta class
@param name: Name of created class
@param bases: Base classes
@type attrs: dict
@param attrs: Class attributes
"""
assert "__slots__" not in attrs, \
"Class '%s' defines __slots__ when it should use OP_PARAMS" % name
assert "OP_ID" in attrs, "Class '%s' is missing OP_ID attribute" % name
# Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
params = attrs.setdefault("OP_PARAMS", [])
# Use parameter names as slots
slots = [pname for (pname, _, _) in params]
assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
"Class '%s' uses unknown field in OP_DSC_FIELD" % name
attrs["__slots__"] = slots
return type.__new__(mcs, name, bases, attrs)
"""A simple serializable object.
This object serves as a parent class for OpCode without any custom
field handling.
__metaclass__ = _AutoOpParamSlots
OP_ID = None
"""Constructor for BaseOpCode.
The constructor takes only keyword arguments and will set
attributes on this object based on the passed arguments. As such,
it means that you should not pass arguments which are not in the
__slots__ attribute for this class.
"""
raise TypeError("Object %s doesn't support the parameter '%s'" %
(self.__class__.__name__, key))
"""Generic serializer.
This method just returns the contents of the instance as a
dictionary.
@rtype: C{dict}
@return: the instance attributes and their values
"""
if hasattr(self, name):
state[name] = getattr(self, name)
return state
def __setstate__(self, state):
"""Generic unserializer.
This method just restores from the serialized state the attributes
of the current instance.
@param state: the serialized opcode data
@type state: C{dict}
"""
if not isinstance(state, dict):
raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
type(state))
if name not in state and hasattr(self, name):
delattr(self, name)
for name in state:
setattr(self, name, state[name])
@classmethod
def _all_slots(cls):
"""Compute the list of all declared slots for a class.
"""
slots = []
for parent in cls.__mro__:
slots.extend(getattr(parent, "__slots__", []))
return slots
@classmethod
def GetAllParams(cls):
"""Compute list of all parameters for an opcode.
"""
slots = []
for parent in cls.__mro__:
slots.extend(getattr(parent, "OP_PARAMS", []))
return slots
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
def Validate(self, set_defaults):
"""Validate opcode parameters, optionally setting default values.
@type set_defaults: bool
@param set_defaults: Whether to set default values
@raise errors.OpPrereqError: When a parameter value doesn't match
requirements
"""
for (attr_name, default, test) in self.GetAllParams():
assert test == ht.NoType or callable(test)
if not hasattr(self, attr_name):
if default == ht.NoDefault:
raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
(self.OP_ID, attr_name),
errors.ECODE_INVAL)
elif set_defaults:
if callable(default):
dval = default()
else:
dval = default
setattr(self, attr_name, dval)
if test == ht.NoType:
# no tests here
continue
if set_defaults or hasattr(self, attr_name):
attr_val = getattr(self, attr_name)
if not test(attr_val):
logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
self.OP_ID, attr_name, type(attr_val), attr_val)
raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
(self.OP_ID, attr_name),
errors.ECODE_INVAL)
"""Abstract OpCode.
This is the root of the actual OpCode hierarchy. All clases derived
from this class should override OP_ID.
@cvar OP_ID: The ID of this opcode. This should be unique amongst all
@cvar OP_DSC_FIELD: The name of a field whose value will be included in the
string returned by Summary(); see the docstring of that
method for details).
@cvar OP_PARAMS: List of opcode attributes, the default values they should
get if not already defined, and types they must match.
@cvar WITH_LU: Boolean that specifies whether this should be included in
mcpu's dispatch table
@ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
the check steps
@ivar priority: Opcode priority for queue
OP_PARAMS = [
("dry_run", None, ht.TMaybeBool),
("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt)),
("priority", constants.OP_PRIO_DEFAULT,
ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID)),
]
def __getstate__(self):
"""Specialized getstate for opcodes.
This method adds to the state dictionary the OP_ID of the class,
so that on unload we can identify the correct class for
instantiating the opcode.
@rtype: C{dict}
@return: the state as a dictionary
data["OP_ID"] = self.OP_ID
return data
@classmethod
def LoadOpCode(cls, data):
"""Generic load opcode method.
The method identifies the correct opcode class from the dict-form
by looking for a OP_ID key, if this is not found, or its value is
not available in this module as a child of this class, we fail.
@type data: C{dict}
@param data: the serialized opcode
"""
if not isinstance(data, dict):
raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
if "OP_ID" not in data:
raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
op_id = data["OP_ID"]
op_class = None
if op_id in OP_MAPPING:
op_class = OP_MAPPING[op_id]
else:
raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
op_id)
op = op_class()
new_data = data.copy()
del new_data["OP_ID"]
op.__setstate__(new_data)
return op
def Summary(self):
"""Generates a summary description of this opcode.
The summary is the value of the OP_ID attribute (without the "OP_" prefix),
plus the value of the OP_DSC_FIELD attribute, if one was defined; this field
should allow to easily identify the operation (for an instance creation job,
e.g., it would be the instance name).
"""
# all OP_ID start with OP_, we remove that
txt = self.OP_ID[3:]
field_name = getattr(self, "OP_DSC_FIELD", None)
if field_name:
field_value = getattr(self, field_name, None)
if isinstance(field_value, (list, tuple)):
field_value = ",".join(str(i) for i in field_value)
txt = "%s(%s)" % (txt, field_value)
return txt
class OpClusterPostInit(OpCode):
"""Post cluster initialization.
This opcode does not touch the cluster at all. Its purpose is to run hooks
after the cluster has been initialized.
"""
OP_ID = "OP_CLUSTER_POST_INIT"
class OpClusterDestroy(OpCode):
"""Destroy the cluster.
This opcode has no other parameters. All the state is irreversibly
lost after the execution of this opcode.
"""
class OpClusterQuery(OpCode):
"""Verify the cluster state.
@type skip_checks: C{list}
@ivar skip_checks: steps to be skipped from the verify process; this
needs to be a subset of
L{constants.VERIFY_OPTIONAL_CHECKS}; currently
only L{constants.VERIFY_NPLUSONE_MEM} can be passed
"""
OP_PARAMS = [
("skip_checks", ht.EmptyList,
ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS))),
("verbose", False, ht.TBool),
("error_codes", False, ht.TBool),
("debug_simulate_errors", False, ht.TBool),
]
"""Verify the cluster disks.
Parameters: none
Result: a tuple of four elements:
- list of node names with bad data returned (unreachable, etc.)
- dict of node names with broken volume groups (values: error msg)
- list of instances with degraded disks (that should be activated)
- dict of instances with missing logical volumes (values: (node, vol)
pairs with details about the missing volumes)
In normal operation, all lists should be empty. A non-empty instance
list (3rd element of the result) is still ok (errors were fixed) but
non-empty node list means some node is down, and probably there are
unfixable drbd errors.
Note that only instances that are drbd-based are taken into
consideration. This might need to be revisited in the future.
"""
OP_ID = "OP_CLUSTER_VERIFY_DISKS"
class OpClusterRepairDiskSizes(OpCode):
"""Verify the disk sizes of the instances and fixes configuration
mimatches.
Parameters: optional instances list, in case we want to restrict the
checks to only a subset of the instances.
Result: a list of tuples, (instance, disk, new-size) for changed
configurations.
In normal operation, the list should be empty.
@type instances: list
@ivar instances: the list of instances to check, or empty for all instances
"""
OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
OP_PARAMS = [
("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
]
class OpClusterConfigQuery(OpCode):
"""Query cluster configuration values."""
OP_ID = "OP_CLUSTER_CONFIG_QUERY"
OP_PARAMS = [
_POutputFields
]
"""Rename the cluster.
@type name: C{str}
@ivar name: The new name of the cluster. The name and/or the master IP
address will be changed to match the new name and its IP
address.
"""
OP_PARAMS = [
("name", ht.NoDefault, ht.TNonEmptyString),
]
class OpClusterSetParams(OpCode):
"""Change the parameters of the cluster.
@type vg_name: C{str} or C{None}
@ivar vg_name: The new volume group name or None to disable LVM usage.
"""
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
OP_PARAMS = [
("vg_name", None, ht.TMaybeString),
("enabled_hypervisors", None,
ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
ht.TNone)),
("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
ht.TNone)),
("beparams", None, ht.TOr(ht.TDict, ht.TNone)),
("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
ht.TNone)),
("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
ht.TNone)),
("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone)),
("uid_pool", None, ht.NoType),
("add_uids", None, ht.NoType),
("remove_uids", None, ht.NoType),
("maintain_node_health", None, ht.TMaybeBool),
("prealloc_wipe_disks", None, ht.TMaybeBool),
("nicparams", None, ht.TOr(ht.TDict, ht.TNone)),
("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
("drbd_helper", None, ht.TOr(ht.TString, ht.TNone)),
("default_iallocator", None, ht.TOr(ht.TString, ht.TNone)),
("master_netdev", None, ht.TOr(ht.TString, ht.TNone)),
("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone)),
("hidden_os", None, ht.TOr(ht.TListOf(
ht.TAnd(ht.TList,
ht.TIsLength(2),
ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))),
ht.TNone)),
("blacklisted_os", None, ht.TOr(ht.TListOf(
ht.TAnd(ht.TList,
ht.TIsLength(2),
ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))),
ht.TNone)),
class OpClusterRedistConf(OpCode):
"""Force a full push of the cluster configuration.
"""
OP_ID = "OP_CLUSTER_REDIST_CONF"
class OpQuery(OpCode):
"""Query for resources/items.
@ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
@ivar fields: List of fields to retrieve
@ivar filter: Query filter
"""
OP_ID = "OP_QUERY"
OP_PARAMS = [
("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
("filter", None, ht.TOr(ht.TNone,
ht.TListOf(ht.TOr(ht.TNonEmptyString, ht.TList)))),
]
class OpQueryFields(OpCode):
"""Query for available resource/item fields.
@ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
@ivar fields: List of fields to retrieve
"""
OP_ID = "OP_QUERY_FIELDS"
OP_PARAMS = [
("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))),
class OpOobCommand(OpCode):
OP_PARAMS = [
_PNodeName,
("command", None, ht.TElemOf(constants.OOB_COMMANDS)),
("timeout", constants.OOB_TIMEOUT, ht.TInt),
"""Remove a node.
@type node_name: C{str}
@ivar node_name: The name of the node to remove. If the node still has
instances on it, the operation will fail.
"""
OP_PARAMS = [
_PNodeName,
]
"""Add a node to the cluster.
@type node_name: C{str}
@ivar node_name: The name of the node to add. This can be a short name,
but it will be expanded to the FQDN.
@type primary_ip: IP address
@ivar primary_ip: The primary IP of the node. This will be ignored when the
opcode is submitted, but will be filled during the node
add (so it will be visible in the job query).
@type secondary_ip: IP address
@ivar secondary_ip: The secondary IP of the node. This needs to be passed
if the cluster has been initialized in 'dual-network'
mode, otherwise it must not be given.
@type readd: C{bool}
@ivar readd: Whether to re-add an existing node to the cluster. If
this is not passed, then the operation will abort if the node
name is already in the cluster; use this parameter to 'repair'
a node that had its configuration broken, or was reinstalled
without removal from the cluster.
@type group: C{str}
@ivar group: The node group to which this node will belong.
@type vm_capable: C{bool}
@ivar vm_capable: The vm_capable node attribute
@type master_capable: C{bool}
@ivar master_capable: The master_capable node attribute
OP_PARAMS = [
_PNodeName,
("primary_ip", None, ht.NoType),
("secondary_ip", None, ht.TMaybeString),
("readd", False, ht.TBool),
("group", None, ht.TMaybeString),
("master_capable", None, ht.TMaybeBool),
("vm_capable", None, ht.TMaybeBool),
("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
]
class OpQueryNodes(OpCode):
"""Compute the list of nodes."""
OP_ID = "OP_NODE_QUERY"
OP_PARAMS = [
_POutputFields,
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("use_locking", False, ht.TBool),
]
class OpQueryNodeVolumes(OpCode):
"""Get list of volumes on node."""
OP_ID = "OP_NODE_QUERYVOLS"
OP_PARAMS = [
_POutputFields,
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
]
class OpQueryNodeStorage(OpCode):
"""Get information on storage for node(s)."""
OP_ID = "OP_NODE_QUERY_STORAGE"
OP_PARAMS = [
_POutputFields,
_PStorageType,
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("name", None, ht.TMaybeString),
class OpModifyNodeStorage(OpCode):
"""Modifies the properies of a storage unit"""
OP_ID = "OP_NODE_MODIFY_STORAGE"
OP_PARAMS = [
_PNodeName,
_PStorageType,
("name", ht.NoDefault, ht.TNonEmptyString),
("changes", ht.NoDefault, ht.TDict),
class OpRepairNodeStorage(OpCode):
"""Repairs the volume group on a node."""
OP_ID = "OP_REPAIR_NODE_STORAGE"
OP_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PStorageType,
("name", ht.NoDefault, ht.TNonEmptyString),
("ignore_consistency", False, ht.TBool),
class OpSetNodeParams(OpCode):
"""Change the parameters of a node."""
OP_ID = "OP_NODE_SET_PARAMS"
OP_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PForce,
("master_candidate", None, ht.TMaybeBool),
("offline", None, ht.TMaybeBool),
("drained", None, ht.TMaybeBool),
("auto_promote", False, ht.TBool),
("master_capable", None, ht.TMaybeBool),
("vm_capable", None, ht.TMaybeBool),
("secondary_ip", None, ht.TMaybeString),
("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
("powered", None, ht.TMaybeBool),
class OpPowercycleNode(OpCode):
"""Tries to powercycle a node."""
OP_ID = "OP_NODE_POWERCYCLE"
OP_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PForce,
class OpMigrateNode(OpCode):
"""Migrate all instances from a node."""
OP_ID = "OP_NODE_MIGRATE"
OP_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PMigrationMode,
_PMigrationLive,
class OpNodeEvacuationStrategy(OpCode):
"""Compute the evacuation strategy for a list of nodes."""
OP_ID = "OP_NODE_EVAC_STRATEGY"
OP_DSC_FIELD = "nodes"
OP_PARAMS = [
("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
("remote_node", None, ht.TMaybeString),
("iallocator", None, ht.TMaybeString),
]
class OpInstanceCreate(OpCode):
"""Create an instance.
@ivar instance_name: Instance name
@ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
@ivar source_handshake: Signed handshake from source (remote import only)
@ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
@ivar source_instance_name: Previous name of instance (remote import only)
@ivar source_shutdown_timeout: Shutdown timeout used for source instance
(remote import only)
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
OP_PARAMS = [
_PInstanceName,
("beparams", ht.EmptyDict, ht.TDict),
("disks", ht.NoDefault, ht.TListOf(ht.TDict)),
("disk_template", ht.NoDefault, _CheckDiskTemplate),
("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER))),
("file_storage_dir", None, ht.TMaybeString),
("force_variant", False, ht.TBool),
("hvparams", ht.EmptyDict, ht.TDict),
("hypervisor", None, ht.TMaybeString),
("iallocator", None, ht.TMaybeString),
("identify_defaults", False, ht.TBool),
("ip_check", True, ht.TBool),
("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES)),
("name_check", True, ht.TBool),
("nics", ht.NoDefault, ht.TListOf(ht.TDict)),
("no_install", None, ht.TMaybeBool),
("osparams", ht.EmptyDict, ht.TDict),
("os_type", None, ht.TMaybeString),
("pnode", None, ht.TMaybeString),
("snode", None, ht.TMaybeString),
("source_handshake", None, ht.TOr(ht.TList, ht.TNone)),
("source_instance_name", None, ht.TMaybeString),
("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
ht.TPositiveInt),
("source_x509_ca", None, ht.TMaybeString),
("src_node", None, ht.TMaybeString),
("src_path", None, ht.TMaybeString),
("start", True, ht.TBool),
("wait_for_sync", True, ht.TBool),
OP_PARAMS = [
_PInstanceName,
("os_type", None, ht.TMaybeString),
("force_variant", False, ht.TBool),
("osparams", None, ht.TOr(ht.TDict, ht.TNone)),
]
class OpRemoveInstance(OpCode):
"""Remove an instance."""
OP_ID = "OP_INSTANCE_REMOVE"
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("ignore_failures", False, ht.TBool),
class OpRenameInstance(OpCode):
"""Rename an instance."""
OP_ID = "OP_INSTANCE_RENAME"
OP_PARAMS = [
_PInstanceName,
("new_name", ht.NoDefault, ht.TNonEmptyString),
("ip_check", False, ht.TBool),
("name_check", True, ht.TBool),
OP_PARAMS = [
_PInstanceName,
_PForce,
_PIgnoreOfflineNodes,
("hvparams", ht.EmptyDict, ht.TDict),
("beparams", ht.EmptyDict, ht.TDict),
OP_PARAMS = [
_PInstanceName,
_PIgnoreOfflineNodes,
("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt),
class OpRebootInstance(OpCode):
"""Reboot an instance."""
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("ignore_secondaries", False, ht.TBool),
("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES)),
OP_PARAMS = [
_PInstanceName,
("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES)),
("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
("remote_node", None, ht.TMaybeString),
("iallocator", None, ht.TMaybeString),
("early_release", False, ht.TBool),
class OpInstanceFailover(OpCode):
"""Failover an instance."""
OP_ID = "OP_INSTANCE_FAILOVER"
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("ignore_consistency", False, ht.TBool),
class OpInstanceMigrate(OpCode):
"""Migrate an instance.
This migrates (without shutting down an instance) to its secondary
node.
@ivar instance_name: the name of the instance
@ivar mode: the migration mode (live, non-live or None for auto)
"""
OP_ID = "OP_INSTANCE_MIGRATE"
OP_PARAMS = [
_PInstanceName,
_PMigrationMode,
_PMigrationLive,
("cleanup", False, ht.TBool),
]
"""Move an instance.
This move (with shutting down an instance and data copying) to an
arbitrary node.
@ivar instance_name: the name of the instance
@ivar target_node: the destination node
"""
OP_ID = "OP_INSTANCE_MOVE"
OP_DSC_FIELD = "instance_name"
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("target_node", ht.NoDefault, ht.TNonEmptyString),
class OpInstanceConsole(OpCode):
OP_PARAMS = [
_PInstanceName
]
class OpInstanceActivateDisks(OpCode):
OP_PARAMS = [
_PInstanceName,
("ignore_size", False, ht.TBool),
]
class OpInstanceDeactivateDisks(OpCode):
OP_PARAMS = [
_PInstanceName
]
class OpRecreateInstanceDisks(OpCode):
"""Deactivate an instance's disks."""
OP_ID = "OP_INSTANCE_RECREATE_DISKS"
OP_DSC_FIELD = "instance_name"
OP_PARAMS = [
_PInstanceName,
("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
]
class OpQueryInstances(OpCode):
"""Compute the list of instances."""
OP_ID = "OP_INSTANCE_QUERY"
OP_PARAMS = [
_POutputFields,
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("use_locking", False, ht.TBool),
]
class OpQueryInstanceData(OpCode):
"""Compute the run-time status of instances."""
OP_ID = "OP_INSTANCE_QUERY_DATA"
OP_PARAMS = [
("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("static", False, ht.TBool),
]
OP_PARAMS = [
_PInstanceName,
_PForce,
("nics", ht.EmptyList, ht.TList),
("disks", ht.EmptyList, ht.TList),
("beparams", ht.EmptyDict, ht.TDict),
("hvparams", ht.EmptyDict, ht.TDict),
("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate)),
("remote_node", None, ht.TMaybeString),
("os_name", None, ht.TMaybeString),
("force_variant", False, ht.TBool),
("osparams", None, ht.TOr(ht.TDict, ht.TNone)),