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
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
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))
#: OP_ID conversion regular expression
_OPID_RE = re.compile("([a-z])([A-Z])")
def _NameToId(name):
"""Convert an opcode class name to an OP_ID.
@type name: string
@param name: the class name, as OpXxxYyy
@rtype: string
@return: the name in the OP_XXXX_YYYY format
"""
if not name.startswith("Op"):
return None
# Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
# consume any input, and hence we would just have all the elements
# in the list, one by one; but it seems that split doesn't work on
# non-consuming input, hence we have to process the input string a
# bit
name = _OPID_RE.sub(r"\1,\2", name)
elems = name.split(",")
return "_".join(n.upper() for n in elems)
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 RequireSharedFileStorage():
"""Checks that shared 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 shared file storage is disabled
"""
if not constants.ENABLE_SHARED_FILE_STORAGE:
raise errors.OpPrereqError("Shared 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()
elif template == constants.DT_SHARED_FILE:
RequireSharedFileStorage()
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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" not in attrs, "Class '%s' defining OP_ID" % 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.
# pylint: disable-msg=E1101
# as OP_ID is dynamically defined
__metaclass__ = _AutoOpParamSlots
"""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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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
# pylint: disable-msg=E1101
# as OP_ID is dynamically defined
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).
assert self.OP_ID is not None and len(self.OP_ID) > 3
# 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.
"""
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.
"""
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_PARAMS = [
("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
]
class OpClusterConfigQuery(OpCode):
"""Query cluster configuration values."""
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.
"""
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.TMaybeDict),
("ndparams", None, ht.TMaybeDict),
("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.
"""
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_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_PARAMS = [
("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))),
class OpOobCommand(OpCode):
("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("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),
OP_PARAMS = [
_POutputFields,
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("use_locking", False, ht.TBool),
]
class OpNodeQueryvols(OpCode):
OP_PARAMS = [
_POutputFields,
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
]
class OpNodeQueryStorage(OpCode):
"""Get information on storage for node(s)."""
OP_PARAMS = [
_POutputFields,
_PStorageType,
("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("name", None, ht.TMaybeString),
class OpNodeModifyStorage(OpCode):
"""Modifies the properies of a storage unit"""
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_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PStorageType,
("name", ht.NoDefault, ht.TNonEmptyString),
("ignore_consistency", False, ht.TBool),
"""Change the parameters of a node."""
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),
("powered", None, ht.TMaybeBool),
class OpNodePowercycle(OpCode):
"""Tries to powercycle a node."""
OP_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PForce,
"""Migrate all instances from a node."""
OP_DSC_FIELD = "node_name"
OP_PARAMS = [
_PNodeName,
_PMigrationMode,
_PMigrationLive,
("iallocator", None, ht.TMaybeString),
class OpNodeEvacStrategy(OpCode):
"""Compute the evacuation strategy for a list of nodes."""
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)
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
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),
class OpInstanceReinstall(OpCode):
OP_PARAMS = [
_PInstanceName,
("os_type", None, ht.TMaybeString),
("force_variant", False, ht.TBool),
class OpInstanceRemove(OpCode):
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("ignore_failures", False, ht.TBool),
class OpInstanceRename(OpCode):
OP_PARAMS = [
_PInstanceName,
("new_name", ht.NoDefault, ht.TNonEmptyString),
("ip_check", False, ht.TBool),
("name_check", True, ht.TBool),
class OpInstanceStartup(OpCode):
OP_PARAMS = [
_PInstanceName,
_PForce,
_PIgnoreOfflineNodes,
("hvparams", ht.EmptyDict, ht.TDict),
("beparams", ht.EmptyDict, ht.TDict),
class OpInstanceShutdown(OpCode):
OP_PARAMS = [
_PInstanceName,
_PIgnoreOfflineNodes,
("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt),
class OpInstanceReboot(OpCode):
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("ignore_secondaries", False, ht.TBool),
("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES)),
class OpInstanceReplaceDisks(OpCode):
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):
OP_PARAMS = [
_PInstanceName,
_PShutdownTimeout,
("ignore_consistency", False, ht.TBool),
("iallocator", None, ht.TMaybeString),
("target_node", None, ht.TMaybeString),
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_PARAMS = [
_PInstanceName,
_PMigrationMode,
_PMigrationLive,
("cleanup", False, ht.TBool),
("iallocator", None, ht.TMaybeString),
("target_node", None, ht.TMaybeString),
"""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_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):
_PInstanceName,
_PForce,
class OpInstanceRecreateDisks(OpCode):
"""Deactivate an instance's disks."""
OP_DSC_FIELD = "instance_name"
OP_PARAMS = [
_PInstanceName,
("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
]
class OpInstanceQuery(OpCode):
OP_PARAMS = [
_POutputFields,
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("use_locking", False, ht.TBool),
]
class OpInstanceQueryData(OpCode):
OP_PARAMS = [
("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
("static", False, ht.TBool),
]
class OpInstanceSetParams(OpCode):
OP_PARAMS = [
_PInstanceName,