Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 68a856ef

History | View | Annotate | Download (52.4 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 687c10d9 Iustin Pop
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 a8083063 Iustin Pop
"""OpCodes module
23 a8083063 Iustin Pop

24 a8083063 Iustin Pop
This module implements the data structures which define the cluster
25 a8083063 Iustin Pop
operations - the so-called opcodes.
26 a8083063 Iustin Pop

27 0e46916d Iustin Pop
Every operation which modifies the cluster state is expressed via
28 0e46916d Iustin Pop
opcodes.
29 a8083063 Iustin Pop

30 a8083063 Iustin Pop
"""
31 a8083063 Iustin Pop
32 a8083063 Iustin Pop
# this are practically structures, so disable the message about too
33 a8083063 Iustin Pop
# few public methods:
34 b459a848 Andrea Spadaccini
# pylint: disable=R0903
35 a8083063 Iustin Pop
36 1cbef6d8 Michael Hanselmann
import logging
37 ff0d18e6 Iustin Pop
import re
38 1cbef6d8 Michael Hanselmann
39 eb62069e Iustin Pop
from ganeti import compat
40 65e183af Michael Hanselmann
from ganeti import constants
41 65e183af Michael Hanselmann
from ganeti import errors
42 65e183af Michael Hanselmann
from ganeti import ht
43 65e183af Michael Hanselmann
44 65e183af Michael Hanselmann
45 65e183af Michael Hanselmann
# Common opcode attributes
46 65e183af Michael Hanselmann
47 65e183af Michael Hanselmann
#: output fields for a query operation
48 197b323b Michael Hanselmann
_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
49 45d4c81c Michael Hanselmann
                  "Selected output fields")
50 65e183af Michael Hanselmann
51 65e183af Michael Hanselmann
#: the shutdown timeout
52 45d4c81c Michael Hanselmann
_PShutdownTimeout = \
53 45d4c81c Michael Hanselmann
  ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
54 45d4c81c Michael Hanselmann
   "How long to wait for instance to shut down")
55 65e183af Michael Hanselmann
56 65e183af Michael Hanselmann
#: the force parameter
57 45d4c81c Michael Hanselmann
_PForce = ("force", False, ht.TBool, "Whether to force the operation")
58 65e183af Michael Hanselmann
59 65e183af Michael Hanselmann
#: a required instance name (for single-instance LUs)
60 45d4c81c Michael Hanselmann
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
61 45d4c81c Michael Hanselmann
                  "Instance name")
62 65e183af Michael Hanselmann
63 65e183af Michael Hanselmann
#: Whether to ignore offline nodes
64 45d4c81c Michael Hanselmann
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
65 45d4c81c Michael Hanselmann
                        "Whether to ignore offline nodes")
66 65e183af Michael Hanselmann
67 65e183af Michael Hanselmann
#: a required node name (for single-node LUs)
68 45d4c81c Michael Hanselmann
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
69 65e183af Michael Hanselmann
70 65e183af Michael Hanselmann
#: a required node group name (for single-group LUs)
71 45d4c81c Michael Hanselmann
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
72 65e183af Michael Hanselmann
73 65e183af Michael Hanselmann
#: Migration type (live/non-live)
74 65e183af Michael Hanselmann
_PMigrationMode = ("mode", None,
75 197b323b Michael Hanselmann
                   ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
76 45d4c81c Michael Hanselmann
                   "Migration mode")
77 65e183af Michael Hanselmann
78 65e183af Michael Hanselmann
#: Obsolete 'live' migration mode (boolean)
79 45d4c81c Michael Hanselmann
_PMigrationLive = ("live", None, ht.TMaybeBool,
80 45d4c81c Michael Hanselmann
                   "Legacy setting for live migration, do not use")
81 65e183af Michael Hanselmann
82 65e183af Michael Hanselmann
#: Tag type
83 197b323b Michael Hanselmann
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None)
84 65e183af Michael Hanselmann
85 65e183af Michael Hanselmann
#: List of tag strings
86 197b323b Michael Hanselmann
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None)
87 65e183af Michael Hanselmann
88 45d4c81c Michael Hanselmann
_PForceVariant = ("force_variant", False, ht.TBool,
89 45d4c81c Michael Hanselmann
                  "Whether to force an unknown OS variant")
90 45d4c81c Michael Hanselmann
91 45d4c81c Michael Hanselmann
_PWaitForSync = ("wait_for_sync", True, ht.TBool,
92 45d4c81c Michael Hanselmann
                 "Whether to wait for the disk to synchronize")
93 45d4c81c Michael Hanselmann
94 45d4c81c Michael Hanselmann
_PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
95 45d4c81c Michael Hanselmann
                       "Whether to ignore disk consistency")
96 45d4c81c Michael Hanselmann
97 45d4c81c Michael Hanselmann
_PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")
98 45d4c81c Michael Hanselmann
99 45d4c81c Michael Hanselmann
_PUseLocking = ("use_locking", False, ht.TBool,
100 45d4c81c Michael Hanselmann
                "Whether to use synchronization")
101 45d4c81c Michael Hanselmann
102 45d4c81c Michael Hanselmann
_PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")
103 45d4c81c Michael Hanselmann
104 45d4c81c Michael Hanselmann
_PNodeGroupAllocPolicy = \
105 45d4c81c Michael Hanselmann
  ("alloc_policy", None,
106 45d4c81c Michael Hanselmann
   ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
107 45d4c81c Michael Hanselmann
   "Instance allocation policy")
108 45d4c81c Michael Hanselmann
109 45d4c81c Michael Hanselmann
_PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
110 45d4c81c Michael Hanselmann
                     "Default node parameters for group")
111 45d4c81c Michael Hanselmann
112 abd66bf8 Michael Hanselmann
_PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
113 8e7078e0 Michael Hanselmann
               "Resource(s) to query for")
114 8e7078e0 Michael Hanselmann
115 e1f23243 Michael Hanselmann
_PEarlyRelease = ("early_release", False, ht.TBool,
116 e1f23243 Michael Hanselmann
                  "Whether to release locks as soon as possible")
117 e1f23243 Michael Hanselmann
118 45d4c81c Michael Hanselmann
_PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
119 45d4c81c Michael Hanselmann
120 9b64e486 Iustin Pop
#: Do not remember instance state changes
121 6aac5aef Iustin Pop
_PNoRemember = ("no_remember", False, ht.TBool,
122 6aac5aef Iustin Pop
                "Do not remember the state change")
123 9b64e486 Iustin Pop
124 f8fa4175 Michael Hanselmann
#: Target node for instance migration/failover
125 f8fa4175 Michael Hanselmann
_PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
126 f8fa4175 Michael Hanselmann
                         "Target node for shared-storage instances")
127 f8fa4175 Michael Hanselmann
128 323f9095 Stephen Shirley
_PStartupPaused = ("startup_paused", False, ht.TBool,
129 323f9095 Stephen Shirley
                   "Pause instance at startup")
130 323f9095 Stephen Shirley
131 57106b74 Michael Hanselmann
_PVerbose = ("verbose", False, ht.TBool, "Verbose mode")
132 57106b74 Michael Hanselmann
133 57106b74 Michael Hanselmann
# Parameters for cluster verification
134 57106b74 Michael Hanselmann
_PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool,
135 57106b74 Michael Hanselmann
                         "Whether to simulate errors (useful for debugging)")
136 57106b74 Michael Hanselmann
_PErrorCodes = ("error_codes", False, ht.TBool, "Error codes")
137 57106b74 Michael Hanselmann
_PSkipChecks = ("skip_checks", ht.EmptyList,
138 57106b74 Michael Hanselmann
                ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)),
139 57106b74 Michael Hanselmann
                "Which checks to skip")
140 93f2399e Andrea Spadaccini
_PIgnoreErrors = ("ignore_errors", ht.EmptyList,
141 93f2399e Andrea Spadaccini
                  ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
142 93f2399e Andrea Spadaccini
                  "List of error codes that should be treated as warnings")
143 323f9095 Stephen Shirley
144 bc5d0215 Andrea Spadaccini
# Disk parameters
145 bc5d0215 Andrea Spadaccini
_PDiskParams = ("diskparams", None,
146 bc5d0215 Andrea Spadaccini
                ht.TOr(
147 bc5d0215 Andrea Spadaccini
                  ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict),
148 bc5d0215 Andrea Spadaccini
                  ht.TNone),
149 bc5d0215 Andrea Spadaccini
                "Disk templates' parameter defaults")
150 bc5d0215 Andrea Spadaccini
151 0ec2ce46 Renรฉ Nussbaumer
# Parameters for node resource model
152 0ec2ce46 Renรฉ Nussbaumer
_PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states")
153 0ec2ce46 Renรฉ Nussbaumer
_PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states")
154 0ec2ce46 Renรฉ Nussbaumer
155 ff0d18e6 Iustin Pop
#: OP_ID conversion regular expression
156 ff0d18e6 Iustin Pop
_OPID_RE = re.compile("([a-z])([A-Z])")
157 ff0d18e6 Iustin Pop
158 8c9ee749 Michael Hanselmann
#: Utility function for L{OpClusterSetParams}
159 8c9ee749 Michael Hanselmann
_TestClusterOsList = ht.TOr(ht.TNone,
160 8c9ee749 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
161 eb62069e Iustin Pop
    ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
162 8c9ee749 Michael Hanselmann
            ht.TElemOf(constants.DDMS_VALUES)))))
163 8c9ee749 Michael Hanselmann
164 ff0d18e6 Iustin Pop
165 526a662a Michael Hanselmann
# TODO: Generate check from constants.INIC_PARAMS_TYPES
166 526a662a Michael Hanselmann
#: Utility function for testing NIC definitions
167 526a662a Michael Hanselmann
_TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
168 526a662a Michael Hanselmann
                         ht.TOr(ht.TNone, ht.TNonEmptyString))
169 526a662a Michael Hanselmann
170 1456df62 Michael Hanselmann
_TSetParamsResultItemItems = [
171 1456df62 Michael Hanselmann
  ht.Comment("name of changed parameter")(ht.TNonEmptyString),
172 b3d2ee31 Michael Hanselmann
  ht.Comment("new value")(ht.TAny),
173 1456df62 Michael Hanselmann
  ]
174 1456df62 Michael Hanselmann
175 1456df62 Michael Hanselmann
_TSetParamsResult = \
176 1456df62 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
177 1456df62 Michael Hanselmann
                     ht.TItems(_TSetParamsResultItemItems)))
178 1456df62 Michael Hanselmann
179 3ce9a5e7 Michael Hanselmann
_SUMMARY_PREFIX = {
180 3ce9a5e7 Michael Hanselmann
  "CLUSTER_": "C_",
181 3ce9a5e7 Michael Hanselmann
  "GROUP_": "G_",
182 3ce9a5e7 Michael Hanselmann
  "NODE_": "N_",
183 3ce9a5e7 Michael Hanselmann
  "INSTANCE_": "I_",
184 3ce9a5e7 Michael Hanselmann
  }
185 3ce9a5e7 Michael Hanselmann
186 b95479a5 Michael Hanselmann
#: Attribute name for dependencies
187 b95479a5 Michael Hanselmann
DEPEND_ATTR = "depends"
188 b95479a5 Michael Hanselmann
189 018ae30b Michael Hanselmann
#: Attribute name for comment
190 018ae30b Michael Hanselmann
COMMENT_ATTR = "comment"
191 018ae30b Michael Hanselmann
192 526a662a Michael Hanselmann
193 ff0d18e6 Iustin Pop
def _NameToId(name):
194 ff0d18e6 Iustin Pop
  """Convert an opcode class name to an OP_ID.
195 ff0d18e6 Iustin Pop

196 ff0d18e6 Iustin Pop
  @type name: string
197 ff0d18e6 Iustin Pop
  @param name: the class name, as OpXxxYyy
198 ff0d18e6 Iustin Pop
  @rtype: string
199 ff0d18e6 Iustin Pop
  @return: the name in the OP_XXXX_YYYY format
200 ff0d18e6 Iustin Pop

201 ff0d18e6 Iustin Pop
  """
202 ff0d18e6 Iustin Pop
  if not name.startswith("Op"):
203 ff0d18e6 Iustin Pop
    return None
204 ff0d18e6 Iustin Pop
  # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
205 ff0d18e6 Iustin Pop
  # consume any input, and hence we would just have all the elements
206 ff0d18e6 Iustin Pop
  # in the list, one by one; but it seems that split doesn't work on
207 ff0d18e6 Iustin Pop
  # non-consuming input, hence we have to process the input string a
208 ff0d18e6 Iustin Pop
  # bit
209 ff0d18e6 Iustin Pop
  name = _OPID_RE.sub(r"\1,\2", name)
210 ff0d18e6 Iustin Pop
  elems = name.split(",")
211 ff0d18e6 Iustin Pop
  return "_".join(n.upper() for n in elems)
212 ff0d18e6 Iustin Pop
213 65e183af Michael Hanselmann
214 65e183af Michael Hanselmann
def RequireFileStorage():
215 65e183af Michael Hanselmann
  """Checks that file storage is enabled.
216 65e183af Michael Hanselmann

217 65e183af Michael Hanselmann
  While it doesn't really fit into this module, L{utils} was deemed too large
218 65e183af Michael Hanselmann
  of a dependency to be imported for just one or two functions.
219 65e183af Michael Hanselmann

220 65e183af Michael Hanselmann
  @raise errors.OpPrereqError: when file storage is disabled
221 65e183af Michael Hanselmann

222 65e183af Michael Hanselmann
  """
223 65e183af Michael Hanselmann
  if not constants.ENABLE_FILE_STORAGE:
224 65e183af Michael Hanselmann
    raise errors.OpPrereqError("File storage disabled at configure time",
225 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
226 65e183af Michael Hanselmann
227 65e183af Michael Hanselmann
228 4b97f902 Apollon Oikonomopoulos
def RequireSharedFileStorage():
229 4b97f902 Apollon Oikonomopoulos
  """Checks that shared file storage is enabled.
230 4b97f902 Apollon Oikonomopoulos

231 4b97f902 Apollon Oikonomopoulos
  While it doesn't really fit into this module, L{utils} was deemed too large
232 4b97f902 Apollon Oikonomopoulos
  of a dependency to be imported for just one or two functions.
233 4b97f902 Apollon Oikonomopoulos

234 4b97f902 Apollon Oikonomopoulos
  @raise errors.OpPrereqError: when shared file storage is disabled
235 4b97f902 Apollon Oikonomopoulos

236 4b97f902 Apollon Oikonomopoulos
  """
237 4b97f902 Apollon Oikonomopoulos
  if not constants.ENABLE_SHARED_FILE_STORAGE:
238 4b97f902 Apollon Oikonomopoulos
    raise errors.OpPrereqError("Shared file storage disabled at"
239 4b97f902 Apollon Oikonomopoulos
                               " configure time", errors.ECODE_INVAL)
240 4b97f902 Apollon Oikonomopoulos
241 4b97f902 Apollon Oikonomopoulos
242 8c9ee749 Michael Hanselmann
@ht.WithDesc("CheckFileStorage")
243 8c9ee749 Michael Hanselmann
def _CheckFileStorage(value):
244 8c9ee749 Michael Hanselmann
  """Ensures file storage is enabled if used.
245 65e183af Michael Hanselmann

246 65e183af Michael Hanselmann
  """
247 8c9ee749 Michael Hanselmann
  if value == constants.DT_FILE:
248 65e183af Michael Hanselmann
    RequireFileStorage()
249 4b97f902 Apollon Oikonomopoulos
  elif value == constants.DT_SHARED_FILE:
250 4b97f902 Apollon Oikonomopoulos
    RequireSharedFileStorage()
251 65e183af Michael Hanselmann
  return True
252 65e183af Michael Hanselmann
253 65e183af Michael Hanselmann
254 45fe090b Michael Hanselmann
def _BuildDiskTemplateCheck(accept_none):
255 45fe090b Michael Hanselmann
  """Builds check for disk template.
256 45fe090b Michael Hanselmann

257 45fe090b Michael Hanselmann
  @type accept_none: bool
258 45fe090b Michael Hanselmann
  @param accept_none: whether to accept None as a correct value
259 45fe090b Michael Hanselmann
  @rtype: callable
260 45fe090b Michael Hanselmann

261 45fe090b Michael Hanselmann
  """
262 45fe090b Michael Hanselmann
  template_check = ht.TElemOf(constants.DISK_TEMPLATES)
263 45fe090b Michael Hanselmann
264 45fe090b Michael Hanselmann
  if accept_none:
265 45fe090b Michael Hanselmann
    template_check = ht.TOr(template_check, ht.TNone)
266 45fe090b Michael Hanselmann
267 45fe090b Michael Hanselmann
  return ht.TAnd(template_check, _CheckFileStorage)
268 8c9ee749 Michael Hanselmann
269 8c9ee749 Michael Hanselmann
270 65e183af Michael Hanselmann
def _CheckStorageType(storage_type):
271 65e183af Michael Hanselmann
  """Ensure a given storage type is valid.
272 65e183af Michael Hanselmann

273 65e183af Michael Hanselmann
  """
274 65e183af Michael Hanselmann
  if storage_type not in constants.VALID_STORAGE_TYPES:
275 65e183af Michael Hanselmann
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
276 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
277 65e183af Michael Hanselmann
  if storage_type == constants.ST_FILE:
278 65e183af Michael Hanselmann
    RequireFileStorage()
279 65e183af Michael Hanselmann
  return True
280 65e183af Michael Hanselmann
281 65e183af Michael Hanselmann
282 65e183af Michael Hanselmann
#: Storage type parameter
283 45d4c81c Michael Hanselmann
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
284 45d4c81c Michael Hanselmann
                 "Storage type")
285 65e183af Michael Hanselmann
286 65e183af Michael Hanselmann
287 65e183af Michael Hanselmann
class _AutoOpParamSlots(type):
288 65e183af Michael Hanselmann
  """Meta class for opcode definitions.
289 65e183af Michael Hanselmann

290 65e183af Michael Hanselmann
  """
291 65e183af Michael Hanselmann
  def __new__(mcs, name, bases, attrs):
292 65e183af Michael Hanselmann
    """Called when a class should be created.
293 65e183af Michael Hanselmann

294 65e183af Michael Hanselmann
    @param mcs: The meta class
295 65e183af Michael Hanselmann
    @param name: Name of created class
296 65e183af Michael Hanselmann
    @param bases: Base classes
297 65e183af Michael Hanselmann
    @type attrs: dict
298 65e183af Michael Hanselmann
    @param attrs: Class attributes
299 65e183af Michael Hanselmann

300 65e183af Michael Hanselmann
    """
301 65e183af Michael Hanselmann
    assert "__slots__" not in attrs, \
302 65e183af Michael Hanselmann
      "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
303 e89a9021 Iustin Pop
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
304 ff0d18e6 Iustin Pop
305 e89a9021 Iustin Pop
    attrs["OP_ID"] = _NameToId(name)
306 65e183af Michael Hanselmann
307 65e183af Michael Hanselmann
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
308 65e183af Michael Hanselmann
    params = attrs.setdefault("OP_PARAMS", [])
309 65e183af Michael Hanselmann
310 65e183af Michael Hanselmann
    # Use parameter names as slots
311 197b323b Michael Hanselmann
    slots = [pname for (pname, _, _, _) in params]
312 65e183af Michael Hanselmann
313 65e183af Michael Hanselmann
    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
314 65e183af Michael Hanselmann
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name
315 65e183af Michael Hanselmann
316 65e183af Michael Hanselmann
    attrs["__slots__"] = slots
317 65e183af Michael Hanselmann
318 65e183af Michael Hanselmann
    return type.__new__(mcs, name, bases, attrs)
319 65e183af Michael Hanselmann
320 df458e0b Iustin Pop
321 0e46916d Iustin Pop
class BaseOpCode(object):
322 df458e0b Iustin Pop
  """A simple serializable object.
323 df458e0b Iustin Pop

324 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
325 0e46916d Iustin Pop
  field handling.
326 0e46916d Iustin Pop

327 df458e0b Iustin Pop
  """
328 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
329 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
330 65e183af Michael Hanselmann
  __metaclass__ = _AutoOpParamSlots
331 65e183af Michael Hanselmann
332 a8083063 Iustin Pop
  def __init__(self, **kwargs):
333 a7399f66 Iustin Pop
    """Constructor for BaseOpCode.
334 a7399f66 Iustin Pop

335 a7399f66 Iustin Pop
    The constructor takes only keyword arguments and will set
336 a7399f66 Iustin Pop
    attributes on this object based on the passed arguments. As such,
337 a7399f66 Iustin Pop
    it means that you should not pass arguments which are not in the
338 a7399f66 Iustin Pop
    __slots__ attribute for this class.
339 a7399f66 Iustin Pop

340 a7399f66 Iustin Pop
    """
341 adf385c7 Iustin Pop
    slots = self._all_slots()
342 a8083063 Iustin Pop
    for key in kwargs:
343 adf385c7 Iustin Pop
      if key not in slots:
344 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
345 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
346 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
347 a8083063 Iustin Pop
348 df458e0b Iustin Pop
  def __getstate__(self):
349 a7399f66 Iustin Pop
    """Generic serializer.
350 a7399f66 Iustin Pop

351 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
352 a7399f66 Iustin Pop
    dictionary.
353 a7399f66 Iustin Pop

354 a7399f66 Iustin Pop
    @rtype:  C{dict}
355 a7399f66 Iustin Pop
    @return: the instance attributes and their values
356 a7399f66 Iustin Pop

357 a7399f66 Iustin Pop
    """
358 df458e0b Iustin Pop
    state = {}
359 adf385c7 Iustin Pop
    for name in self._all_slots():
360 df458e0b Iustin Pop
      if hasattr(self, name):
361 df458e0b Iustin Pop
        state[name] = getattr(self, name)
362 df458e0b Iustin Pop
    return state
363 df458e0b Iustin Pop
364 df458e0b Iustin Pop
  def __setstate__(self, state):
365 a7399f66 Iustin Pop
    """Generic unserializer.
366 a7399f66 Iustin Pop

367 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
368 a7399f66 Iustin Pop
    of the current instance.
369 a7399f66 Iustin Pop

370 a7399f66 Iustin Pop
    @param state: the serialized opcode data
371 a7399f66 Iustin Pop
    @type state:  C{dict}
372 a7399f66 Iustin Pop

373 a7399f66 Iustin Pop
    """
374 df458e0b Iustin Pop
    if not isinstance(state, dict):
375 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
376 df458e0b Iustin Pop
                       type(state))
377 df458e0b Iustin Pop
378 adf385c7 Iustin Pop
    for name in self._all_slots():
379 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
380 df458e0b Iustin Pop
        delattr(self, name)
381 df458e0b Iustin Pop
382 df458e0b Iustin Pop
    for name in state:
383 df458e0b Iustin Pop
      setattr(self, name, state[name])
384 df458e0b Iustin Pop
385 adf385c7 Iustin Pop
  @classmethod
386 adf385c7 Iustin Pop
  def _all_slots(cls):
387 adf385c7 Iustin Pop
    """Compute the list of all declared slots for a class.
388 adf385c7 Iustin Pop

389 adf385c7 Iustin Pop
    """
390 adf385c7 Iustin Pop
    slots = []
391 adf385c7 Iustin Pop
    for parent in cls.__mro__:
392 adf385c7 Iustin Pop
      slots.extend(getattr(parent, "__slots__", []))
393 adf385c7 Iustin Pop
    return slots
394 adf385c7 Iustin Pop
395 65e183af Michael Hanselmann
  @classmethod
396 65e183af Michael Hanselmann
  def GetAllParams(cls):
397 65e183af Michael Hanselmann
    """Compute list of all parameters for an opcode.
398 65e183af Michael Hanselmann

399 65e183af Michael Hanselmann
    """
400 65e183af Michael Hanselmann
    slots = []
401 65e183af Michael Hanselmann
    for parent in cls.__mro__:
402 65e183af Michael Hanselmann
      slots.extend(getattr(parent, "OP_PARAMS", []))
403 65e183af Michael Hanselmann
    return slots
404 65e183af Michael Hanselmann
405 1cbef6d8 Michael Hanselmann
  def Validate(self, set_defaults):
406 1cbef6d8 Michael Hanselmann
    """Validate opcode parameters, optionally setting default values.
407 1cbef6d8 Michael Hanselmann

408 1cbef6d8 Michael Hanselmann
    @type set_defaults: bool
409 1cbef6d8 Michael Hanselmann
    @param set_defaults: Whether to set default values
410 1cbef6d8 Michael Hanselmann
    @raise errors.OpPrereqError: When a parameter value doesn't match
411 1cbef6d8 Michael Hanselmann
                                 requirements
412 1cbef6d8 Michael Hanselmann

413 1cbef6d8 Michael Hanselmann
    """
414 197b323b Michael Hanselmann
    for (attr_name, default, test, _) in self.GetAllParams():
415 1cbef6d8 Michael Hanselmann
      assert test == ht.NoType or callable(test)
416 1cbef6d8 Michael Hanselmann
417 1cbef6d8 Michael Hanselmann
      if not hasattr(self, attr_name):
418 1cbef6d8 Michael Hanselmann
        if default == ht.NoDefault:
419 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
420 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
421 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
422 1cbef6d8 Michael Hanselmann
        elif set_defaults:
423 1cbef6d8 Michael Hanselmann
          if callable(default):
424 1cbef6d8 Michael Hanselmann
            dval = default()
425 1cbef6d8 Michael Hanselmann
          else:
426 1cbef6d8 Michael Hanselmann
            dval = default
427 1cbef6d8 Michael Hanselmann
          setattr(self, attr_name, dval)
428 1cbef6d8 Michael Hanselmann
429 1cbef6d8 Michael Hanselmann
      if test == ht.NoType:
430 1cbef6d8 Michael Hanselmann
        # no tests here
431 1cbef6d8 Michael Hanselmann
        continue
432 1cbef6d8 Michael Hanselmann
433 1cbef6d8 Michael Hanselmann
      if set_defaults or hasattr(self, attr_name):
434 1cbef6d8 Michael Hanselmann
        attr_val = getattr(self, attr_name)
435 1cbef6d8 Michael Hanselmann
        if not test(attr_val):
436 1cbef6d8 Michael Hanselmann
          logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
437 1cbef6d8 Michael Hanselmann
                        self.OP_ID, attr_name, type(attr_val), attr_val)
438 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
439 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
440 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
441 1cbef6d8 Michael Hanselmann
442 df458e0b Iustin Pop
443 b247c6fc Michael Hanselmann
def _BuildJobDepCheck(relative):
444 b247c6fc Michael Hanselmann
  """Builds check for job dependencies (L{DEPEND_ATTR}).
445 b247c6fc Michael Hanselmann

446 b247c6fc Michael Hanselmann
  @type relative: bool
447 b247c6fc Michael Hanselmann
  @param relative: Whether to accept relative job IDs (negative)
448 b247c6fc Michael Hanselmann
  @rtype: callable
449 b247c6fc Michael Hanselmann

450 b247c6fc Michael Hanselmann
  """
451 b247c6fc Michael Hanselmann
  if relative:
452 b247c6fc Michael Hanselmann
    job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
453 b247c6fc Michael Hanselmann
  else:
454 b247c6fc Michael Hanselmann
    job_id = ht.TJobId
455 b247c6fc Michael Hanselmann
456 b247c6fc Michael Hanselmann
  job_dep = \
457 b247c6fc Michael Hanselmann
    ht.TAnd(ht.TIsLength(2),
458 b247c6fc Michael Hanselmann
            ht.TItems([job_id,
459 b247c6fc Michael Hanselmann
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
460 b247c6fc Michael Hanselmann
461 b247c6fc Michael Hanselmann
  return ht.TOr(ht.TNone, ht.TListOf(job_dep))
462 b247c6fc Michael Hanselmann
463 b247c6fc Michael Hanselmann
464 b247c6fc Michael Hanselmann
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
465 b247c6fc Michael Hanselmann
466 1ce03fb1 Michael Hanselmann
#: List of submission status and job ID as returned by C{SubmitManyJobs}
467 1456df62 Michael Hanselmann
_TJobIdListItem = \
468 1456df62 Michael Hanselmann
  ht.TAnd(ht.TIsLength(2),
469 1456df62 Michael Hanselmann
          ht.TItems([ht.Comment("success")(ht.TBool),
470 1456df62 Michael Hanselmann
                     ht.Comment("Job ID if successful, error message"
471 1456df62 Michael Hanselmann
                                " otherwise")(ht.TOr(ht.TString,
472 1456df62 Michael Hanselmann
                                                     ht.TJobId))]))
473 1456df62 Michael Hanselmann
TJobIdList = ht.TListOf(_TJobIdListItem)
474 1ce03fb1 Michael Hanselmann
475 f7686867 Michael Hanselmann
#: Result containing only list of submitted jobs
476 f7686867 Michael Hanselmann
TJobIdListOnly = ht.TStrictDict(True, True, {
477 1456df62 Michael Hanselmann
  constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
478 f7686867 Michael Hanselmann
  })
479 f7686867 Michael Hanselmann
480 b247c6fc Michael Hanselmann
481 0e46916d Iustin Pop
class OpCode(BaseOpCode):
482 a7399f66 Iustin Pop
  """Abstract OpCode.
483 a7399f66 Iustin Pop

484 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
485 a7399f66 Iustin Pop
  from this class should override OP_ID.
486 a7399f66 Iustin Pop

487 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
488 20777413 Iustin Pop
               children of this class.
489 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
490 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
491 bde8f481 Adeodato Simo
                      method for details).
492 65e183af Michael Hanselmann
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
493 65e183af Michael Hanselmann
                   get if not already defined, and types they must match.
494 1ce03fb1 Michael Hanselmann
  @cvar OP_RESULT: Callable to verify opcode result
495 687c10d9 Iustin Pop
  @cvar WITH_LU: Boolean that specifies whether this should be included in
496 687c10d9 Iustin Pop
      mcpu's dispatch table
497 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
498 20777413 Iustin Pop
                 the check steps
499 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
500 a7399f66 Iustin Pop

501 a7399f66 Iustin Pop
  """
502 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
503 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
504 687c10d9 Iustin Pop
  WITH_LU = True
505 65e183af Michael Hanselmann
  OP_PARAMS = [
506 45d4c81c Michael Hanselmann
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
507 45d4c81c Michael Hanselmann
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
508 65e183af Michael Hanselmann
    ("priority", constants.OP_PRIO_DEFAULT,
509 45d4c81c Michael Hanselmann
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
510 b247c6fc Michael Hanselmann
    (DEPEND_ATTR, None, _BuildJobDepCheck(True),
511 b247c6fc Michael Hanselmann
     "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
512 822a50c4 Michael Hanselmann
     " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
513 822a50c4 Michael Hanselmann
     " for details"),
514 018ae30b Michael Hanselmann
    (COMMENT_ATTR, None, ht.TMaybeString,
515 018ae30b Michael Hanselmann
     "Comment describing the purpose of the opcode"),
516 65e183af Michael Hanselmann
    ]
517 1ce03fb1 Michael Hanselmann
  OP_RESULT = None
518 df458e0b Iustin Pop
519 df458e0b Iustin Pop
  def __getstate__(self):
520 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
521 df458e0b Iustin Pop

522 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
523 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
524 a7399f66 Iustin Pop
    instantiating the opcode.
525 a7399f66 Iustin Pop

526 a7399f66 Iustin Pop
    @rtype:   C{dict}
527 a7399f66 Iustin Pop
    @return:  the state as a dictionary
528 a7399f66 Iustin Pop

529 df458e0b Iustin Pop
    """
530 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
531 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
532 df458e0b Iustin Pop
    return data
533 df458e0b Iustin Pop
534 df458e0b Iustin Pop
  @classmethod
535 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
536 df458e0b Iustin Pop
    """Generic load opcode method.
537 df458e0b Iustin Pop

538 a7399f66 Iustin Pop
    The method identifies the correct opcode class from the dict-form
539 a7399f66 Iustin Pop
    by looking for a OP_ID key, if this is not found, or its value is
540 a7399f66 Iustin Pop
    not available in this module as a child of this class, we fail.
541 a7399f66 Iustin Pop

542 a7399f66 Iustin Pop
    @type data:  C{dict}
543 a7399f66 Iustin Pop
    @param data: the serialized opcode
544 a7399f66 Iustin Pop

545 df458e0b Iustin Pop
    """
546 df458e0b Iustin Pop
    if not isinstance(data, dict):
547 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
548 df458e0b Iustin Pop
    if "OP_ID" not in data:
549 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
550 df458e0b Iustin Pop
    op_id = data["OP_ID"]
551 df458e0b Iustin Pop
    op_class = None
552 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
553 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
554 363acb1e Iustin Pop
    else:
555 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
556 df458e0b Iustin Pop
                       op_id)
557 df458e0b Iustin Pop
    op = op_class()
558 df458e0b Iustin Pop
    new_data = data.copy()
559 df458e0b Iustin Pop
    del new_data["OP_ID"]
560 df458e0b Iustin Pop
    op.__setstate__(new_data)
561 df458e0b Iustin Pop
    return op
562 df458e0b Iustin Pop
563 60dd1473 Iustin Pop
  def Summary(self):
564 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
565 60dd1473 Iustin Pop

566 ff0d18e6 Iustin Pop
    The summary is the value of the OP_ID attribute (without the "OP_"
567 ff0d18e6 Iustin Pop
    prefix), plus the value of the OP_DSC_FIELD attribute, if one was
568 ff0d18e6 Iustin Pop
    defined; this field should allow to easily identify the operation
569 ff0d18e6 Iustin Pop
    (for an instance creation job, e.g., it would be the instance
570 ff0d18e6 Iustin Pop
    name).
571 bde8f481 Adeodato Simo

572 60dd1473 Iustin Pop
    """
573 ff0d18e6 Iustin Pop
    assert self.OP_ID is not None and len(self.OP_ID) > 3
574 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
575 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
576 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
577 60dd1473 Iustin Pop
    if field_name:
578 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
579 bc8bbda1 Iustin Pop
      if isinstance(field_value, (list, tuple)):
580 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
581 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
582 60dd1473 Iustin Pop
    return txt
583 60dd1473 Iustin Pop
584 3ce9a5e7 Michael Hanselmann
  def TinySummary(self):
585 3ce9a5e7 Michael Hanselmann
    """Generates a compact summary description of the opcode.
586 3ce9a5e7 Michael Hanselmann

587 3ce9a5e7 Michael Hanselmann
    """
588 3ce9a5e7 Michael Hanselmann
    assert self.OP_ID.startswith("OP_")
589 3ce9a5e7 Michael Hanselmann
590 3ce9a5e7 Michael Hanselmann
    text = self.OP_ID[3:]
591 3ce9a5e7 Michael Hanselmann
592 3ce9a5e7 Michael Hanselmann
    for (prefix, supplement) in _SUMMARY_PREFIX.items():
593 3ce9a5e7 Michael Hanselmann
      if text.startswith(prefix):
594 3ce9a5e7 Michael Hanselmann
        return supplement + text[len(prefix):]
595 3ce9a5e7 Michael Hanselmann
596 3ce9a5e7 Michael Hanselmann
    return text
597 3ce9a5e7 Michael Hanselmann
598 a8083063 Iustin Pop
599 afee0879 Iustin Pop
# cluster opcodes
600 afee0879 Iustin Pop
601 bc84ffa7 Iustin Pop
class OpClusterPostInit(OpCode):
602 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
603 b5f5fae9 Luca Bigliardi

604 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
605 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
606 b5f5fae9 Luca Bigliardi

607 b5f5fae9 Luca Bigliardi
  """
608 b5f5fae9 Luca Bigliardi
609 b5f5fae9 Luca Bigliardi
610 c6d43e9e Iustin Pop
class OpClusterDestroy(OpCode):
611 a7399f66 Iustin Pop
  """Destroy the cluster.
612 a7399f66 Iustin Pop

613 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
614 a7399f66 Iustin Pop
  lost after the execution of this opcode.
615 a7399f66 Iustin Pop

616 a7399f66 Iustin Pop
  """
617 a8083063 Iustin Pop
618 a8083063 Iustin Pop
619 a2f7ab92 Iustin Pop
class OpClusterQuery(OpCode):
620 fdc267f4 Iustin Pop
  """Query cluster information."""
621 a8083063 Iustin Pop
622 a8083063 Iustin Pop
623 fcad7225 Michael Hanselmann
class OpClusterVerify(OpCode):
624 fcad7225 Michael Hanselmann
  """Submits all jobs necessary to verify the cluster.
625 fcad7225 Michael Hanselmann

626 fcad7225 Michael Hanselmann
  """
627 fcad7225 Michael Hanselmann
  OP_PARAMS = [
628 fcad7225 Michael Hanselmann
    _PDebugSimulateErrors,
629 fcad7225 Michael Hanselmann
    _PErrorCodes,
630 fcad7225 Michael Hanselmann
    _PSkipChecks,
631 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
632 fcad7225 Michael Hanselmann
    _PVerbose,
633 fcad7225 Michael Hanselmann
    ("group_name", None, ht.TMaybeString, "Group to verify")
634 fcad7225 Michael Hanselmann
    ]
635 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
636 fcad7225 Michael Hanselmann
637 fcad7225 Michael Hanselmann
638 bf93ae69 Adeodato Simo
class OpClusterVerifyConfig(OpCode):
639 bf93ae69 Adeodato Simo
  """Verify the cluster config.
640 bf93ae69 Adeodato Simo

641 bf93ae69 Adeodato Simo
  """
642 bf93ae69 Adeodato Simo
  OP_PARAMS = [
643 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
644 57106b74 Michael Hanselmann
    _PErrorCodes,
645 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
646 57106b74 Michael Hanselmann
    _PVerbose,
647 bf93ae69 Adeodato Simo
    ]
648 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
649 bf93ae69 Adeodato Simo
650 bf93ae69 Adeodato Simo
651 bf93ae69 Adeodato Simo
class OpClusterVerifyGroup(OpCode):
652 bf93ae69 Adeodato Simo
  """Run verify on a node group from the cluster.
653 a7399f66 Iustin Pop

654 a7399f66 Iustin Pop
  @type skip_checks: C{list}
655 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
656 a7399f66 Iustin Pop
                     needs to be a subset of
657 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
658 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
659 a7399f66 Iustin Pop

660 a7399f66 Iustin Pop
  """
661 bf93ae69 Adeodato Simo
  OP_DSC_FIELD = "group_name"
662 65e183af Michael Hanselmann
  OP_PARAMS = [
663 57106b74 Michael Hanselmann
    _PGroupName,
664 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
665 57106b74 Michael Hanselmann
    _PErrorCodes,
666 57106b74 Michael Hanselmann
    _PSkipChecks,
667 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
668 57106b74 Michael Hanselmann
    _PVerbose,
669 65e183af Michael Hanselmann
    ]
670 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
671 a8083063 Iustin Pop
672 a8083063 Iustin Pop
673 bd8210a7 Iustin Pop
class OpClusterVerifyDisks(OpCode):
674 150e978f Iustin Pop
  """Verify the cluster disks.
675 150e978f Iustin Pop

676 ae1a845c Michael Hanselmann
  """
677 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
678 ae1a845c Michael Hanselmann
679 ae1a845c Michael Hanselmann
680 ae1a845c Michael Hanselmann
class OpGroupVerifyDisks(OpCode):
681 ae1a845c Michael Hanselmann
  """Verifies the status of all disks in a node group.
682 150e978f Iustin Pop

683 ae1a845c Michael Hanselmann
  Result: a tuple of three elements:
684 ae1a845c Michael Hanselmann
    - dict of node names with issues (values: error msg)
685 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
686 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
687 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
688 150e978f Iustin Pop

689 b63ed789 Iustin Pop
  In normal operation, all lists should be empty. A non-empty instance
690 b63ed789 Iustin Pop
  list (3rd element of the result) is still ok (errors were fixed) but
691 b63ed789 Iustin Pop
  non-empty node list means some node is down, and probably there are
692 b63ed789 Iustin Pop
  unfixable drbd errors.
693 150e978f Iustin Pop

694 150e978f Iustin Pop
  Note that only instances that are drbd-based are taken into
695 150e978f Iustin Pop
  consideration. This might need to be revisited in the future.
696 150e978f Iustin Pop

697 150e978f Iustin Pop
  """
698 ae1a845c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
699 ae1a845c Michael Hanselmann
  OP_PARAMS = [
700 ae1a845c Michael Hanselmann
    _PGroupName,
701 ae1a845c Michael Hanselmann
    ]
702 1ce03fb1 Michael Hanselmann
  OP_RESULT = \
703 1ce03fb1 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3),
704 1ce03fb1 Michael Hanselmann
            ht.TItems([ht.TDictOf(ht.TString, ht.TString),
705 1ce03fb1 Michael Hanselmann
                       ht.TListOf(ht.TString),
706 6973587f Michael Hanselmann
                       ht.TDictOf(ht.TString,
707 6973587f Michael Hanselmann
                                  ht.TListOf(ht.TListOf(ht.TString)))]))
708 150e978f Iustin Pop
709 150e978f Iustin Pop
710 5d01aca3 Iustin Pop
class OpClusterRepairDiskSizes(OpCode):
711 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
712 60975797 Iustin Pop
  mimatches.
713 60975797 Iustin Pop

714 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
715 60975797 Iustin Pop
  checks to only a subset of the instances.
716 60975797 Iustin Pop

717 60975797 Iustin Pop
  Result: a list of tuples, (instance, disk, new-size) for changed
718 60975797 Iustin Pop
  configurations.
719 60975797 Iustin Pop

720 60975797 Iustin Pop
  In normal operation, the list should be empty.
721 60975797 Iustin Pop

722 60975797 Iustin Pop
  @type instances: list
723 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
724 60975797 Iustin Pop

725 60975797 Iustin Pop
  """
726 65e183af Michael Hanselmann
  OP_PARAMS = [
727 197b323b Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
728 65e183af Michael Hanselmann
    ]
729 60975797 Iustin Pop
730 60975797 Iustin Pop
731 2f093ea0 Iustin Pop
class OpClusterConfigQuery(OpCode):
732 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
733 65e183af Michael Hanselmann
  OP_PARAMS = [
734 65e183af Michael Hanselmann
    _POutputFields
735 65e183af Michael Hanselmann
    ]
736 a8083063 Iustin Pop
737 a8083063 Iustin Pop
738 e126df25 Iustin Pop
class OpClusterRename(OpCode):
739 a7399f66 Iustin Pop
  """Rename the cluster.
740 a7399f66 Iustin Pop

741 a7399f66 Iustin Pop
  @type name: C{str}
742 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
743 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
744 a7399f66 Iustin Pop
              address.
745 a7399f66 Iustin Pop

746 a7399f66 Iustin Pop
  """
747 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
748 65e183af Michael Hanselmann
  OP_PARAMS = [
749 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
750 65e183af Michael Hanselmann
    ]
751 07bd8a51 Iustin Pop
752 07bd8a51 Iustin Pop
753 a6682fdc Iustin Pop
class OpClusterSetParams(OpCode):
754 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
755 a7399f66 Iustin Pop

756 a7399f66 Iustin Pop
  @type vg_name: C{str} or C{None}
757 a7399f66 Iustin Pop
  @ivar vg_name: The new volume group name or None to disable LVM usage.
758 a7399f66 Iustin Pop

759 a7399f66 Iustin Pop
  """
760 65e183af Michael Hanselmann
  OP_PARAMS = [
761 2da9f556 Renรฉ Nussbaumer
    _PHvState,
762 2da9f556 Renรฉ Nussbaumer
    _PDiskState,
763 45d4c81c Michael Hanselmann
    ("vg_name", None, ht.TMaybeString, "Volume group name"),
764 65e183af Michael Hanselmann
    ("enabled_hypervisors", None,
765 65e183af Michael Hanselmann
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
766 45d4c81c Michael Hanselmann
            ht.TNone),
767 45d4c81c Michael Hanselmann
     "List of enabled hypervisors"),
768 65e183af Michael Hanselmann
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
769 45d4c81c Michael Hanselmann
                              ht.TNone),
770 45d4c81c Michael Hanselmann
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
771 45d4c81c Michael Hanselmann
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
772 45d4c81c Michael Hanselmann
     "Cluster-wide backend parameter defaults"),
773 65e183af Michael Hanselmann
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
774 45d4c81c Michael Hanselmann
                            ht.TNone),
775 45d4c81c Michael Hanselmann
     "Cluster-wide per-OS hypervisor parameter defaults"),
776 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
777 45d4c81c Michael Hanselmann
                              ht.TNone),
778 45d4c81c Michael Hanselmann
     "Cluster-wide OS parameter defaults"),
779 bc5d0215 Andrea Spadaccini
    _PDiskParams,
780 197b323b Michael Hanselmann
    ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
781 45d4c81c Michael Hanselmann
     "Master candidate pool size"),
782 45d4c81c Michael Hanselmann
    ("uid_pool", None, ht.NoType,
783 45d4c81c Michael Hanselmann
     "Set UID pool, must be list of lists describing UID ranges (two items,"
784 45d4c81c Michael Hanselmann
     " start and end inclusive)"),
785 45d4c81c Michael Hanselmann
    ("add_uids", None, ht.NoType,
786 45d4c81c Michael Hanselmann
     "Extend UID pool, must be list of lists describing UID ranges (two"
787 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be added"),
788 45d4c81c Michael Hanselmann
    ("remove_uids", None, ht.NoType,
789 45d4c81c Michael Hanselmann
     "Shrink UID pool, must be list of lists describing UID ranges (two"
790 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be removed"),
791 45d4c81c Michael Hanselmann
    ("maintain_node_health", None, ht.TMaybeBool,
792 45d4c81c Michael Hanselmann
     "Whether to automatically maintain node health"),
793 45d4c81c Michael Hanselmann
    ("prealloc_wipe_disks", None, ht.TMaybeBool,
794 45d4c81c Michael Hanselmann
     "Whether to wipe disks before allocating them to instances"),
795 45d4c81c Michael Hanselmann
    ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
796 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
797 e1a6850f Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Cluster-wide instance policy specs"),
798 45d4c81c Michael Hanselmann
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
799 45d4c81c Michael Hanselmann
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
800 45d4c81c Michael Hanselmann
     "Default iallocator for cluster"),
801 45d4c81c Michael Hanselmann
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
802 45d4c81c Michael Hanselmann
     "Master network device"),
803 5a8648eb Andrea Spadaccini
    ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
804 5a8648eb Andrea Spadaccini
     "Netmask of the master IP"),
805 45d4c81c Michael Hanselmann
    ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone),
806 45d4c81c Michael Hanselmann
     "List of reserved LVs"),
807 45d4c81c Michael Hanselmann
    ("hidden_os", None, _TestClusterOsList,
808 45d4c81c Michael Hanselmann
     "Modify list of hidden operating systems. Each modification must have"
809 45d4c81c Michael Hanselmann
     " two items, the operation and the OS name. The operation can be"
810 45d4c81c Michael Hanselmann
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
811 45d4c81c Michael Hanselmann
    ("blacklisted_os", None, _TestClusterOsList,
812 45d4c81c Michael Hanselmann
     "Modify list of blacklisted operating systems. Each modification must have"
813 45d4c81c Michael Hanselmann
     " two items, the operation and the OS name. The operation can be"
814 45d4c81c Michael Hanselmann
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
815 bf689b7a Andrea Spadaccini
    ("use_external_mip_script", None, ht.TMaybeBool,
816 bf689b7a Andrea Spadaccini
     "Whether to use an external master IP address setup script"),
817 4b7735f9 Iustin Pop
    ]
818 12515db7 Manuel Franceschini
819 12515db7 Manuel Franceschini
820 d1240007 Iustin Pop
class OpClusterRedistConf(OpCode):
821 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
822 afee0879 Iustin Pop

823 afee0879 Iustin Pop
  """
824 afee0879 Iustin Pop
825 83f72637 Michael Hanselmann
826 fb926117 Andrea Spadaccini
class OpClusterActivateMasterIp(OpCode):
827 fb926117 Andrea Spadaccini
  """Activate the master IP on the master node.
828 fb926117 Andrea Spadaccini

829 fb926117 Andrea Spadaccini
  """
830 fb926117 Andrea Spadaccini
831 fb926117 Andrea Spadaccini
832 fb926117 Andrea Spadaccini
class OpClusterDeactivateMasterIp(OpCode):
833 fb926117 Andrea Spadaccini
  """Deactivate the master IP on the master node.
834 fb926117 Andrea Spadaccini

835 fb926117 Andrea Spadaccini
  """
836 fb926117 Andrea Spadaccini
837 fb926117 Andrea Spadaccini
838 83f72637 Michael Hanselmann
class OpQuery(OpCode):
839 83f72637 Michael Hanselmann
  """Query for resources/items.
840 83f72637 Michael Hanselmann

841 abd66bf8 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
842 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
843 2e5c33db Iustin Pop
  @ivar qfilter: Query filter
844 83f72637 Michael Hanselmann

845 83f72637 Michael Hanselmann
  """
846 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
847 65e183af Michael Hanselmann
  OP_PARAMS = [
848 8e7078e0 Michael Hanselmann
    _PQueryWhat,
849 ee13764f Michael Hanselmann
    _PUseLocking,
850 45d4c81c Michael Hanselmann
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
851 45d4c81c Michael Hanselmann
     "Requested fields"),
852 2e5c33db Iustin Pop
    ("qfilter", None, ht.TOr(ht.TNone, ht.TListOf),
853 45d4c81c Michael Hanselmann
     "Query filter"),
854 83f72637 Michael Hanselmann
    ]
855 83f72637 Michael Hanselmann
856 83f72637 Michael Hanselmann
857 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
858 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
859 83f72637 Michael Hanselmann

860 abd66bf8 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
861 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
862 83f72637 Michael Hanselmann

863 83f72637 Michael Hanselmann
  """
864 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
865 65e183af Michael Hanselmann
  OP_PARAMS = [
866 8e7078e0 Michael Hanselmann
    _PQueryWhat,
867 8e7078e0 Michael Hanselmann
    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
868 8e7078e0 Michael Hanselmann
     "Requested fields; if not given, all are returned"),
869 83f72637 Michael Hanselmann
    ]
870 83f72637 Michael Hanselmann
871 83f72637 Michael Hanselmann
872 792af3ad Renรฉ Nussbaumer
class OpOobCommand(OpCode):
873 eb64da59 Renรฉ Nussbaumer
  """Interact with OOB."""
874 65e183af Michael Hanselmann
  OP_PARAMS = [
875 c4ec0755 Renรฉ Nussbaumer
    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
876 c4ec0755 Renรฉ Nussbaumer
     "List of nodes to run the OOB command against"),
877 c4ec0755 Renรฉ Nussbaumer
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
878 c4ec0755 Renรฉ Nussbaumer
     "OOB command to be run"),
879 c4ec0755 Renรฉ Nussbaumer
    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
880 c4ec0755 Renรฉ Nussbaumer
     "Timeout before the OOB helper will be terminated"),
881 c4ec0755 Renรฉ Nussbaumer
    ("ignore_status", False, ht.TBool,
882 c4ec0755 Renรฉ Nussbaumer
     "Ignores the node offline status for power off"),
883 beff3779 Renรฉ Nussbaumer
    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
884 beff3779 Renรฉ Nussbaumer
     "Time in seconds to wait between powering on nodes"),
885 eb64da59 Renรฉ Nussbaumer
    ]
886 eb64da59 Renรฉ Nussbaumer
887 eb64da59 Renรฉ Nussbaumer
888 07bd8a51 Iustin Pop
# node opcodes
889 07bd8a51 Iustin Pop
890 73d565a3 Iustin Pop
class OpNodeRemove(OpCode):
891 a7399f66 Iustin Pop
  """Remove a node.
892 a7399f66 Iustin Pop

893 a7399f66 Iustin Pop
  @type node_name: C{str}
894 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
895 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
896 a7399f66 Iustin Pop

897 a7399f66 Iustin Pop
  """
898 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
899 65e183af Michael Hanselmann
  OP_PARAMS = [
900 65e183af Michael Hanselmann
    _PNodeName,
901 65e183af Michael Hanselmann
    ]
902 a8083063 Iustin Pop
903 a8083063 Iustin Pop
904 d817d49f Iustin Pop
class OpNodeAdd(OpCode):
905 a7399f66 Iustin Pop
  """Add a node to the cluster.
906 a7399f66 Iustin Pop

907 a7399f66 Iustin Pop
  @type node_name: C{str}
908 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
909 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
910 a7399f66 Iustin Pop
  @type primary_ip: IP address
911 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
912 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
913 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
914 a7399f66 Iustin Pop
  @type secondary_ip: IP address
915 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
916 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
917 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
918 a7399f66 Iustin Pop
  @type readd: C{bool}
919 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
920 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
921 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
922 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
923 a7399f66 Iustin Pop
               without removal from the cluster.
924 f936c153 Iustin Pop
  @type group: C{str}
925 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
926 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
927 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
928 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
929 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
930 a7399f66 Iustin Pop

931 a7399f66 Iustin Pop
  """
932 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
933 65e183af Michael Hanselmann
  OP_PARAMS = [
934 65e183af Michael Hanselmann
    _PNodeName,
935 085e0d9f Renรฉ Nussbaumer
    _PHvState,
936 085e0d9f Renรฉ Nussbaumer
    _PDiskState,
937 45d4c81c Michael Hanselmann
    ("primary_ip", None, ht.NoType, "Primary IP address"),
938 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
939 45d4c81c Michael Hanselmann
    ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
940 45d4c81c Michael Hanselmann
    ("group", None, ht.TMaybeString, "Initial node group"),
941 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
942 45d4c81c Michael Hanselmann
     "Whether node can become master or master candidate"),
943 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
944 45d4c81c Michael Hanselmann
     "Whether node can host instances"),
945 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Node parameters"),
946 65e183af Michael Hanselmann
    ]
947 a8083063 Iustin Pop
948 a8083063 Iustin Pop
949 2237687b Iustin Pop
class OpNodeQuery(OpCode):
950 a8083063 Iustin Pop
  """Compute the list of nodes."""
951 65e183af Michael Hanselmann
  OP_PARAMS = [
952 65e183af Michael Hanselmann
    _POutputFields,
953 45d4c81c Michael Hanselmann
    _PUseLocking,
954 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
955 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
956 65e183af Michael Hanselmann
    ]
957 a8083063 Iustin Pop
958 a8083063 Iustin Pop
959 8ed55bfd Iustin Pop
class OpNodeQueryvols(OpCode):
960 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
961 65e183af Michael Hanselmann
  OP_PARAMS = [
962 65e183af Michael Hanselmann
    _POutputFields,
963 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
964 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
965 65e183af Michael Hanselmann
    ]
966 dcb93971 Michael Hanselmann
967 dcb93971 Michael Hanselmann
968 ad8d0595 Iustin Pop
class OpNodeQueryStorage(OpCode):
969 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
970 65e183af Michael Hanselmann
  OP_PARAMS = [
971 65e183af Michael Hanselmann
    _POutputFields,
972 65e183af Michael Hanselmann
    _PStorageType,
973 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
974 45d4c81c Michael Hanselmann
    ("name", None, ht.TMaybeString, "Storage name"),
975 9e5442ce Michael Hanselmann
    ]
976 9e5442ce Michael Hanselmann
977 9e5442ce Michael Hanselmann
978 2cee4077 Iustin Pop
class OpNodeModifyStorage(OpCode):
979 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
980 65e183af Michael Hanselmann
  OP_PARAMS = [
981 65e183af Michael Hanselmann
    _PNodeName,
982 65e183af Michael Hanselmann
    _PStorageType,
983 45d4c81c Michael Hanselmann
    _PStorageName,
984 45d4c81c Michael Hanselmann
    ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
985 efb8da02 Michael Hanselmann
    ]
986 efb8da02 Michael Hanselmann
987 efb8da02 Michael Hanselmann
988 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
989 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
990 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
991 65e183af Michael Hanselmann
  OP_PARAMS = [
992 65e183af Michael Hanselmann
    _PNodeName,
993 65e183af Michael Hanselmann
    _PStorageType,
994 45d4c81c Michael Hanselmann
    _PStorageName,
995 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
996 76aef8fc Michael Hanselmann
    ]
997 76aef8fc Michael Hanselmann
998 76aef8fc Michael Hanselmann
999 f13973c4 Iustin Pop
class OpNodeSetParams(OpCode):
1000 b31c8676 Iustin Pop
  """Change the parameters of a node."""
1001 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
1002 65e183af Michael Hanselmann
  OP_PARAMS = [
1003 65e183af Michael Hanselmann
    _PNodeName,
1004 65e183af Michael Hanselmann
    _PForce,
1005 0ec2ce46 Renรฉ Nussbaumer
    _PHvState,
1006 0ec2ce46 Renรฉ Nussbaumer
    _PDiskState,
1007 45d4c81c Michael Hanselmann
    ("master_candidate", None, ht.TMaybeBool,
1008 45d4c81c Michael Hanselmann
     "Whether the node should become a master candidate"),
1009 45d4c81c Michael Hanselmann
    ("offline", None, ht.TMaybeBool,
1010 45d4c81c Michael Hanselmann
     "Whether the node should be marked as offline"),
1011 45d4c81c Michael Hanselmann
    ("drained", None, ht.TMaybeBool,
1012 45d4c81c Michael Hanselmann
     "Whether the node should be marked as drained"),
1013 45d4c81c Michael Hanselmann
    ("auto_promote", False, ht.TBool,
1014 45d4c81c Michael Hanselmann
     "Whether node(s) should be promoted to master candidate if necessary"),
1015 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
1016 45d4c81c Michael Hanselmann
     "Denote whether node can become master or master candidate"),
1017 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
1018 45d4c81c Michael Hanselmann
     "Denote whether node can host instances"),
1019 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString,
1020 45d4c81c Michael Hanselmann
     "Change node's secondary IP address"),
1021 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
1022 45d4c81c Michael Hanselmann
    ("powered", None, ht.TMaybeBool,
1023 45d4c81c Michael Hanselmann
     "Whether the node should be marked as powered"),
1024 b31c8676 Iustin Pop
    ]
1025 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1026 b31c8676 Iustin Pop
1027 f5118ade Iustin Pop
1028 e0d4735f Iustin Pop
class OpNodePowercycle(OpCode):
1029 f5118ade Iustin Pop
  """Tries to powercycle a node."""
1030 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
1031 65e183af Michael Hanselmann
  OP_PARAMS = [
1032 65e183af Michael Hanselmann
    _PNodeName,
1033 65e183af Michael Hanselmann
    _PForce,
1034 f5118ade Iustin Pop
    ]
1035 f5118ade Iustin Pop
1036 7ffc5a86 Michael Hanselmann
1037 5b14a488 Iustin Pop
class OpNodeMigrate(OpCode):
1038 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
1039 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1040 65e183af Michael Hanselmann
  OP_PARAMS = [
1041 65e183af Michael Hanselmann
    _PNodeName,
1042 65e183af Michael Hanselmann
    _PMigrationMode,
1043 65e183af Michael Hanselmann
    _PMigrationLive,
1044 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1045 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1046 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1047 80cb875c Michael Hanselmann
    ]
1048 65c9591c Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1049 80cb875c Michael Hanselmann
1050 80cb875c Michael Hanselmann
1051 e1f23243 Michael Hanselmann
class OpNodeEvacuate(OpCode):
1052 e1f23243 Michael Hanselmann
  """Evacuate instances off a number of nodes."""
1053 e1f23243 Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1054 e1f23243 Michael Hanselmann
  OP_PARAMS = [
1055 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1056 e1f23243 Michael Hanselmann
    _PNodeName,
1057 e1f23243 Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1058 e1f23243 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1059 cb92e7a1 Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1060 e1f23243 Michael Hanselmann
     "Node evacuation mode"),
1061 e1f23243 Michael Hanselmann
    ]
1062 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1063 e1f23243 Michael Hanselmann
1064 e1f23243 Michael Hanselmann
1065 a8083063 Iustin Pop
# instance opcodes
1066 a8083063 Iustin Pop
1067 e1530b10 Iustin Pop
class OpInstanceCreate(OpCode):
1068 9bf56d77 Michael Hanselmann
  """Create an instance.
1069 9bf56d77 Michael Hanselmann

1070 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
1071 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1072 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
1073 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1074 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
1075 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1076 dae91d02 Michael Hanselmann
    (remote import only)
1077 9bf56d77 Michael Hanselmann

1078 9bf56d77 Michael Hanselmann
  """
1079 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1080 65e183af Michael Hanselmann
  OP_PARAMS = [
1081 65e183af Michael Hanselmann
    _PInstanceName,
1082 45d4c81c Michael Hanselmann
    _PForceVariant,
1083 45d4c81c Michael Hanselmann
    _PWaitForSync,
1084 45d4c81c Michael Hanselmann
    _PNameCheck,
1085 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1086 526a662a Michael Hanselmann
    ("disks", ht.NoDefault,
1087 526a662a Michael Hanselmann
     # TODO: Generate check from constants.IDISK_PARAMS_TYPES
1088 526a662a Michael Hanselmann
     ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
1089 526a662a Michael Hanselmann
                           ht.TOr(ht.TNonEmptyString, ht.TInt))),
1090 526a662a Michael Hanselmann
     "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1091 526a662a Michael Hanselmann
     " each disk definition must contain a ``%s`` value and"
1092 526a662a Michael Hanselmann
     " can contain an optional ``%s`` value denoting the disk access mode"
1093 526a662a Michael Hanselmann
     " (%s)" %
1094 526a662a Michael Hanselmann
     (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1095 526a662a Michael Hanselmann
      constants.IDISK_MODE,
1096 526a662a Michael Hanselmann
      " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1097 45fe090b Michael Hanselmann
    ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1098 45fe090b Michael Hanselmann
     "Disk template"),
1099 45d4c81c Michael Hanselmann
    ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1100 45d4c81c Michael Hanselmann
     "Driver for file-backed disks"),
1101 45d4c81c Michael Hanselmann
    ("file_storage_dir", None, ht.TMaybeString,
1102 45d4c81c Michael Hanselmann
     "Directory for storing file-backed disks"),
1103 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1104 45d4c81c Michael Hanselmann
     "Hypervisor parameters for instance, hypervisor-dependent"),
1105 45d4c81c Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1106 45d4c81c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString,
1107 45d4c81c Michael Hanselmann
     "Iallocator for deciding which node(s) to use"),
1108 45d4c81c Michael Hanselmann
    ("identify_defaults", False, ht.TBool,
1109 45d4c81c Michael Hanselmann
     "Reset instance parameters to default if equal"),
1110 45d4c81c Michael Hanselmann
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
1111 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1112 45d4c81c Michael Hanselmann
     "Instance creation mode"),
1113 526a662a Michael Hanselmann
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1114 526a662a Michael Hanselmann
     "List of NIC (network interface) definitions, for example"
1115 526a662a Michael Hanselmann
     " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1116 526a662a Michael Hanselmann
     " contain the optional values %s" %
1117 526a662a Michael Hanselmann
     (constants.INIC_IP,
1118 526a662a Michael Hanselmann
      ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1119 45d4c81c Michael Hanselmann
    ("no_install", None, ht.TMaybeBool,
1120 45d4c81c Michael Hanselmann
     "Do not install the OS (will disable automatic start)"),
1121 45d4c81c Michael Hanselmann
    ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1122 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Operating system"),
1123 45d4c81c Michael Hanselmann
    ("pnode", None, ht.TMaybeString, "Primary node"),
1124 45d4c81c Michael Hanselmann
    ("snode", None, ht.TMaybeString, "Secondary node"),
1125 45d4c81c Michael Hanselmann
    ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1126 45d4c81c Michael Hanselmann
     "Signed handshake from source (remote import only)"),
1127 45d4c81c Michael Hanselmann
    ("source_instance_name", None, ht.TMaybeString,
1128 45d4c81c Michael Hanselmann
     "Source instance name (remote import only)"),
1129 65e183af Michael Hanselmann
    ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1130 526a662a Michael Hanselmann
     ht.TPositiveInt,
1131 526a662a Michael Hanselmann
     "How long source instance was given to shut down (remote import only)"),
1132 45d4c81c Michael Hanselmann
    ("source_x509_ca", None, ht.TMaybeString,
1133 45d4c81c Michael Hanselmann
     "Source X509 CA in PEM format (remote import only)"),
1134 45d4c81c Michael Hanselmann
    ("src_node", None, ht.TMaybeString, "Source node for import"),
1135 45d4c81c Michael Hanselmann
    ("src_path", None, ht.TMaybeString, "Source directory for import"),
1136 45d4c81c Michael Hanselmann
    ("start", True, ht.TBool, "Whether to start instance after creation"),
1137 720f56c8 Apollon Oikonomopoulos
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1138 3b6d8c9b Iustin Pop
    ]
1139 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1140 a8083063 Iustin Pop
1141 a8083063 Iustin Pop
1142 5073fd8f Iustin Pop
class OpInstanceReinstall(OpCode):
1143 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
1144 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1145 65e183af Michael Hanselmann
  OP_PARAMS = [
1146 65e183af Michael Hanselmann
    _PInstanceName,
1147 45d4c81c Michael Hanselmann
    _PForceVariant,
1148 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Instance operating system"),
1149 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1150 65e183af Michael Hanselmann
    ]
1151 fe7b0351 Michael Hanselmann
1152 fe7b0351 Michael Hanselmann
1153 3cd2d4b1 Iustin Pop
class OpInstanceRemove(OpCode):
1154 a8083063 Iustin Pop
  """Remove an instance."""
1155 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1156 65e183af Michael Hanselmann
  OP_PARAMS = [
1157 65e183af Michael Hanselmann
    _PInstanceName,
1158 65e183af Michael Hanselmann
    _PShutdownTimeout,
1159 45d4c81c Michael Hanselmann
    ("ignore_failures", False, ht.TBool,
1160 45d4c81c Michael Hanselmann
     "Whether to ignore failures during removal"),
1161 fc1baca9 Michael Hanselmann
    ]
1162 a8083063 Iustin Pop
1163 a8083063 Iustin Pop
1164 5659e2e2 Iustin Pop
class OpInstanceRename(OpCode):
1165 decd5f45 Iustin Pop
  """Rename an instance."""
1166 65e183af Michael Hanselmann
  OP_PARAMS = [
1167 65e183af Michael Hanselmann
    _PInstanceName,
1168 45d4c81c Michael Hanselmann
    _PNameCheck,
1169 45d4c81c Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1170 45d4c81c Michael Hanselmann
    ("ip_check", False, ht.TBool, _PIpCheckDoc),
1171 4f05fd3b Iustin Pop
    ]
1172 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1173 decd5f45 Iustin Pop
1174 decd5f45 Iustin Pop
1175 c873d91c Iustin Pop
class OpInstanceStartup(OpCode):
1176 fdc267f4 Iustin Pop
  """Startup an instance."""
1177 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1178 65e183af Michael Hanselmann
  OP_PARAMS = [
1179 65e183af Michael Hanselmann
    _PInstanceName,
1180 65e183af Michael Hanselmann
    _PForce,
1181 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1182 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1183 45d4c81c Michael Hanselmann
     "Temporary hypervisor parameters, hypervisor-dependent"),
1184 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1185 9b64e486 Iustin Pop
    _PNoRemember,
1186 323f9095 Stephen Shirley
    _PStartupPaused,
1187 4f05fd3b Iustin Pop
    ]
1188 a8083063 Iustin Pop
1189 a8083063 Iustin Pop
1190 ee3e37a7 Iustin Pop
class OpInstanceShutdown(OpCode):
1191 fdc267f4 Iustin Pop
  """Shutdown an instance."""
1192 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1193 65e183af Michael Hanselmann
  OP_PARAMS = [
1194 65e183af Michael Hanselmann
    _PInstanceName,
1195 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1196 45d4c81c Michael Hanselmann
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1197 45d4c81c Michael Hanselmann
     "How long to wait for instance to shut down"),
1198 9b64e486 Iustin Pop
    _PNoRemember,
1199 b44bd844 Michael Hanselmann
    ]
1200 a8083063 Iustin Pop
1201 a8083063 Iustin Pop
1202 90ab1a95 Iustin Pop
class OpInstanceReboot(OpCode):
1203 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
1204 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1205 65e183af Michael Hanselmann
  OP_PARAMS = [
1206 65e183af Michael Hanselmann
    _PInstanceName,
1207 65e183af Michael Hanselmann
    _PShutdownTimeout,
1208 45d4c81c Michael Hanselmann
    ("ignore_secondaries", False, ht.TBool,
1209 45d4c81c Michael Hanselmann
     "Whether to start the instance even if secondary disks are failing"),
1210 45d4c81c Michael Hanselmann
    ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1211 45d4c81c Michael Hanselmann
     "How to reboot instance"),
1212 4f05fd3b Iustin Pop
    ]
1213 bf6929a2 Alexander Schreiber
1214 bf6929a2 Alexander Schreiber
1215 668f755d Iustin Pop
class OpInstanceReplaceDisks(OpCode):
1216 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
1217 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1218 65e183af Michael Hanselmann
  OP_PARAMS = [
1219 65e183af Michael Hanselmann
    _PInstanceName,
1220 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1221 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1222 45d4c81c Michael Hanselmann
     "Replacement mode"),
1223 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1224 45d4c81c Michael Hanselmann
     "Disk indexes"),
1225 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1226 45d4c81c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString,
1227 45d4c81c Michael Hanselmann
     "Iallocator for deciding new secondary node"),
1228 4f05fd3b Iustin Pop
    ]
1229 a8083063 Iustin Pop
1230 a8083063 Iustin Pop
1231 019dbee1 Iustin Pop
class OpInstanceFailover(OpCode):
1232 a8083063 Iustin Pop
  """Failover an instance."""
1233 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1234 65e183af Michael Hanselmann
  OP_PARAMS = [
1235 65e183af Michael Hanselmann
    _PInstanceName,
1236 65e183af Michael Hanselmann
    _PShutdownTimeout,
1237 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1238 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1239 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1240 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1241 17c3f802 Guido Trotter
    ]
1242 a8083063 Iustin Pop
1243 a8083063 Iustin Pop
1244 75c866c2 Iustin Pop
class OpInstanceMigrate(OpCode):
1245 53c776b5 Iustin Pop
  """Migrate an instance.
1246 53c776b5 Iustin Pop

1247 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
1248 53c776b5 Iustin Pop
  node.
1249 53c776b5 Iustin Pop

1250 2f907a8c Iustin Pop
  @ivar instance_name: the name of the instance
1251 8c35561f Iustin Pop
  @ivar mode: the migration mode (live, non-live or None for auto)
1252 53c776b5 Iustin Pop

1253 53c776b5 Iustin Pop
  """
1254 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
1255 65e183af Michael Hanselmann
  OP_PARAMS = [
1256 65e183af Michael Hanselmann
    _PInstanceName,
1257 65e183af Michael Hanselmann
    _PMigrationMode,
1258 65e183af Michael Hanselmann
    _PMigrationLive,
1259 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1260 45d4c81c Michael Hanselmann
    ("cleanup", False, ht.TBool,
1261 45d4c81c Michael Hanselmann
     "Whether a previously failed migration should be cleaned up"),
1262 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1263 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1264 d5cafd31 Renรฉ Nussbaumer
    ("allow_failover", False, ht.TBool,
1265 d5cafd31 Renรฉ Nussbaumer
     "Whether we can fallback to failover if migration is not possible"),
1266 65e183af Michael Hanselmann
    ]
1267 53c776b5 Iustin Pop
1268 53c776b5 Iustin Pop
1269 0091b480 Iustin Pop
class OpInstanceMove(OpCode):
1270 313bcead Iustin Pop
  """Move an instance.
1271 313bcead Iustin Pop

1272 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
1273 313bcead Iustin Pop
  arbitrary node.
1274 313bcead Iustin Pop

1275 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
1276 313bcead Iustin Pop
  @ivar target_node: the destination node
1277 313bcead Iustin Pop

1278 313bcead Iustin Pop
  """
1279 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
1280 65e183af Michael Hanselmann
  OP_PARAMS = [
1281 65e183af Michael Hanselmann
    _PInstanceName,
1282 65e183af Michael Hanselmann
    _PShutdownTimeout,
1283 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1284 bb851c63 Iustin Pop
    _PIgnoreConsistency,
1285 154b9580 Balazs Lecz
    ]
1286 313bcead Iustin Pop
1287 313bcead Iustin Pop
1288 cc0dec7b Iustin Pop
class OpInstanceConsole(OpCode):
1289 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
1290 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1291 65e183af Michael Hanselmann
  OP_PARAMS = [
1292 65e183af Michael Hanselmann
    _PInstanceName
1293 65e183af Michael Hanselmann
    ]
1294 a8083063 Iustin Pop
1295 a8083063 Iustin Pop
1296 83f5d475 Iustin Pop
class OpInstanceActivateDisks(OpCode):
1297 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
1298 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1299 65e183af Michael Hanselmann
  OP_PARAMS = [
1300 65e183af Michael Hanselmann
    _PInstanceName,
1301 45d4c81c Michael Hanselmann
    ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1302 65e183af Michael Hanselmann
    ]
1303 a8083063 Iustin Pop
1304 a8083063 Iustin Pop
1305 e176281f Iustin Pop
class OpInstanceDeactivateDisks(OpCode):
1306 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
1307 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1308 65e183af Michael Hanselmann
  OP_PARAMS = [
1309 c9c41373 Iustin Pop
    _PInstanceName,
1310 c9c41373 Iustin Pop
    _PForce,
1311 65e183af Michael Hanselmann
    ]
1312 a8083063 Iustin Pop
1313 a8083063 Iustin Pop
1314 6b273e78 Iustin Pop
class OpInstanceRecreateDisks(OpCode):
1315 a52978c7 Michael Hanselmann
  """Recreate an instance's disks."""
1316 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
1317 65e183af Michael Hanselmann
  OP_PARAMS = [
1318 65e183af Michael Hanselmann
    _PInstanceName,
1319 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1320 45d4c81c Michael Hanselmann
     "List of disk indexes"),
1321 93384b8c Guido Trotter
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1322 93384b8c Guido Trotter
     "New instance nodes, if relocation is desired"),
1323 65e183af Michael Hanselmann
    ]
1324 bd315bfa Iustin Pop
1325 bd315bfa Iustin Pop
1326 f2af0bec Iustin Pop
class OpInstanceQuery(OpCode):
1327 a8083063 Iustin Pop
  """Compute the list of instances."""
1328 65e183af Michael Hanselmann
  OP_PARAMS = [
1329 65e183af Michael Hanselmann
    _POutputFields,
1330 45d4c81c Michael Hanselmann
    _PUseLocking,
1331 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1332 45d4c81c Michael Hanselmann
     "Empty list to query all instances, instance names otherwise"),
1333 65e183af Michael Hanselmann
    ]
1334 a8083063 Iustin Pop
1335 a8083063 Iustin Pop
1336 dc28c4e4 Iustin Pop
class OpInstanceQueryData(OpCode):
1337 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
1338 65e183af Michael Hanselmann
  OP_PARAMS = [
1339 af7b6689 Michael Hanselmann
    _PUseLocking,
1340 af7b6689 Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1341 af7b6689 Michael Hanselmann
     "Instance names"),
1342 af7b6689 Michael Hanselmann
    ("static", False, ht.TBool,
1343 af7b6689 Michael Hanselmann
     "Whether to only return configuration data without querying"
1344 af7b6689 Michael Hanselmann
     " nodes"),
1345 65e183af Michael Hanselmann
    ]
1346 a8083063 Iustin Pop
1347 a8083063 Iustin Pop
1348 9a3cc7ae Iustin Pop
class OpInstanceSetParams(OpCode):
1349 a8083063 Iustin Pop
  """Change the parameters of an instance."""
1350 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1351 65e183af Michael Hanselmann
  OP_PARAMS = [
1352 65e183af Michael Hanselmann
    _PInstanceName,
1353 65e183af Michael Hanselmann
    _PForce,
1354 45d4c81c Michael Hanselmann
    _PForceVariant,
1355 526a662a Michael Hanselmann
    # TODO: Use _TestNicDef
1356 45d4c81c Michael Hanselmann
    ("nics", ht.EmptyList, ht.TList,
1357 45d4c81c Michael Hanselmann
     "List of NIC changes. Each item is of the form ``(op, settings)``."
1358 45d4c81c Michael Hanselmann
     " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
1359 45d4c81c Michael Hanselmann
     " ``%s`` to remove the last NIC or a number to modify the settings"
1360 45d4c81c Michael Hanselmann
     " of the NIC with that index." %
1361 45d4c81c Michael Hanselmann
     (constants.DDM_ADD, constants.DDM_REMOVE)),
1362 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
1363 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1364 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1365 45d4c81c Michael Hanselmann
     "Per-instance hypervisor parameters, hypervisor-dependent"),
1366 45fe090b Michael Hanselmann
    ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1367 45d4c81c Michael Hanselmann
     "Disk template for instance"),
1368 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString,
1369 45d4c81c Michael Hanselmann
     "Secondary node (used when changing disk template)"),
1370 45d4c81c Michael Hanselmann
    ("os_name", None, ht.TMaybeString,
1371 45d4c81c Michael Hanselmann
     "Change instance's OS name. Does not reinstall the instance."),
1372 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1373 93384b8c Guido Trotter
    ("wait_for_sync", True, ht.TBool,
1374 93384b8c Guido Trotter
     "Whether to wait for the disk to synchronize, when changing template"),
1375 57de31c0 Agata Murawska
    ("offline_inst", False, ht.TBool,
1376 57de31c0 Agata Murawska
     "Whether to turn off the down instance completely"),
1377 57de31c0 Agata Murawska
    ("online_inst", False, ht.TBool,
1378 57de31c0 Agata Murawska
     "Whether to enable the offline instance"),
1379 973d7867 Iustin Pop
    ]
1380 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1381 a8083063 Iustin Pop
1382 a8083063 Iustin Pop
1383 60472d29 Iustin Pop
class OpInstanceGrowDisk(OpCode):
1384 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
1385 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1386 65e183af Michael Hanselmann
  OP_PARAMS = [
1387 65e183af Michael Hanselmann
    _PInstanceName,
1388 45d4c81c Michael Hanselmann
    _PWaitForSync,
1389 45d4c81c Michael Hanselmann
    ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1390 45d4c81c Michael Hanselmann
    ("amount", ht.NoDefault, ht.TInt,
1391 45d4c81c Michael Hanselmann
     "Amount of disk space to add (megabytes)"),
1392 4f05fd3b Iustin Pop
    ]
1393 8729e0d7 Iustin Pop
1394 8729e0d7 Iustin Pop
1395 1aef3df8 Michael Hanselmann
class OpInstanceChangeGroup(OpCode):
1396 1aef3df8 Michael Hanselmann
  """Moves an instance to another node group."""
1397 1aef3df8 Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1398 1aef3df8 Michael Hanselmann
  OP_PARAMS = [
1399 1aef3df8 Michael Hanselmann
    _PInstanceName,
1400 1aef3df8 Michael Hanselmann
    _PEarlyRelease,
1401 1aef3df8 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1402 1aef3df8 Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1403 1aef3df8 Michael Hanselmann
     "Destination group names or UUIDs (defaults to \"all but current group\""),
1404 1aef3df8 Michael Hanselmann
    ]
1405 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1406 1aef3df8 Michael Hanselmann
1407 1aef3df8 Michael Hanselmann
1408 70a6a926 Adeodato Simo
# Node group opcodes
1409 70a6a926 Adeodato Simo
1410 fabf1731 Iustin Pop
class OpGroupAdd(OpCode):
1411 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
1412 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1413 65e183af Michael Hanselmann
  OP_PARAMS = [
1414 65e183af Michael Hanselmann
    _PGroupName,
1415 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1416 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1417 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1418 e4c03256 Renรฉ Nussbaumer
    _PHvState,
1419 e4c03256 Renรฉ Nussbaumer
    _PDiskState,
1420 1f5d9bf8 Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1421 483be60d Adeodato Simo
    ]
1422 b1ee5610 Adeodato Simo
1423 b1ee5610 Adeodato Simo
1424 934704ae Iustin Pop
class OpGroupAssignNodes(OpCode):
1425 96276ae7 Adeodato Simo
  """Assign nodes to a node group."""
1426 96276ae7 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1427 96276ae7 Adeodato Simo
  OP_PARAMS = [
1428 96276ae7 Adeodato Simo
    _PGroupName,
1429 96276ae7 Adeodato Simo
    _PForce,
1430 45d4c81c Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1431 45d4c81c Michael Hanselmann
     "List of nodes to assign"),
1432 96276ae7 Adeodato Simo
    ]
1433 96276ae7 Adeodato Simo
1434 96276ae7 Adeodato Simo
1435 d4d654bd Iustin Pop
class OpGroupQuery(OpCode):
1436 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
1437 65e183af Michael Hanselmann
  OP_PARAMS = [
1438 65e183af Michael Hanselmann
    _POutputFields,
1439 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1440 45d4c81c Michael Hanselmann
     "Empty list to query all groups, group names otherwise"),
1441 65e183af Michael Hanselmann
    ]
1442 70a6a926 Adeodato Simo
1443 70a6a926 Adeodato Simo
1444 7cbf74f0 Iustin Pop
class OpGroupSetParams(OpCode):
1445 4da7909a Adeodato Simo
  """Change the parameters of a node group."""
1446 4da7909a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1447 65e183af Michael Hanselmann
  OP_PARAMS = [
1448 65e183af Michael Hanselmann
    _PGroupName,
1449 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1450 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1451 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1452 a8282327 Renรฉ Nussbaumer
    _PHvState,
1453 a8282327 Renรฉ Nussbaumer
    _PDiskState,
1454 fb644e77 Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1455 4da7909a Adeodato Simo
    ]
1456 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1457 4da7909a Adeodato Simo
1458 4da7909a Adeodato Simo
1459 4d1baa51 Iustin Pop
class OpGroupRemove(OpCode):
1460 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
1461 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1462 65e183af Michael Hanselmann
  OP_PARAMS = [
1463 65e183af Michael Hanselmann
    _PGroupName,
1464 65e183af Michael Hanselmann
    ]
1465 94bd652a Adeodato Simo
1466 94bd652a Adeodato Simo
1467 a8173e82 Iustin Pop
class OpGroupRename(OpCode):
1468 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
1469 65e183af Michael Hanselmann
  OP_PARAMS = [
1470 12da663a Michael Hanselmann
    _PGroupName,
1471 12da663a Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1472 65e183af Michael Hanselmann
    ]
1473 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1474 4fe5cf90 Adeodato Simo
1475 4fe5cf90 Adeodato Simo
1476 08f8c82c Michael Hanselmann
class OpGroupEvacuate(OpCode):
1477 08f8c82c Michael Hanselmann
  """Evacuate a node group in the cluster."""
1478 08f8c82c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
1479 08f8c82c Michael Hanselmann
  OP_PARAMS = [
1480 08f8c82c Michael Hanselmann
    _PGroupName,
1481 08f8c82c Michael Hanselmann
    _PEarlyRelease,
1482 08f8c82c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1483 08f8c82c Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1484 08f8c82c Michael Hanselmann
     "Destination group names or UUIDs"),
1485 08f8c82c Michael Hanselmann
    ]
1486 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1487 08f8c82c Michael Hanselmann
1488 08f8c82c Michael Hanselmann
1489 a8083063 Iustin Pop
# OS opcodes
1490 da2d02e7 Iustin Pop
class OpOsDiagnose(OpCode):
1491 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
1492 65e183af Michael Hanselmann
  OP_PARAMS = [
1493 65e183af Michael Hanselmann
    _POutputFields,
1494 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1495 45d4c81c Michael Hanselmann
     "Which operating systems to diagnose"),
1496 65e183af Michael Hanselmann
    ]
1497 a8083063 Iustin Pop
1498 7c0d6283 Michael Hanselmann
1499 a8083063 Iustin Pop
# Exports opcodes
1500 7ca2d4d8 Iustin Pop
class OpBackupQuery(OpCode):
1501 a8083063 Iustin Pop
  """Compute the list of exported images."""
1502 65e183af Michael Hanselmann
  OP_PARAMS = [
1503 45d4c81c Michael Hanselmann
    _PUseLocking,
1504 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1505 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1506 65e183af Michael Hanselmann
    ]
1507 a8083063 Iustin Pop
1508 7c0d6283 Michael Hanselmann
1509 71910715 Iustin Pop
class OpBackupPrepare(OpCode):
1510 1410fa8d Michael Hanselmann
  """Prepares an instance export.
1511 1410fa8d Michael Hanselmann

1512 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
1513 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1514 1410fa8d Michael Hanselmann

1515 1410fa8d Michael Hanselmann
  """
1516 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1517 65e183af Michael Hanselmann
  OP_PARAMS = [
1518 65e183af Michael Hanselmann
    _PInstanceName,
1519 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1520 45d4c81c Michael Hanselmann
     "Export mode"),
1521 1410fa8d Michael Hanselmann
    ]
1522 1410fa8d Michael Hanselmann
1523 1410fa8d Michael Hanselmann
1524 4ff922a2 Iustin Pop
class OpBackupExport(OpCode):
1525 4a96f1d1 Michael Hanselmann
  """Export an instance.
1526 4a96f1d1 Michael Hanselmann

1527 4a96f1d1 Michael Hanselmann
  For local exports, the export destination is the node name. For remote
1528 4a96f1d1 Michael Hanselmann
  exports, the export destination is a list of tuples, each consisting of
1529 4a96f1d1 Michael Hanselmann
  hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
1530 4a96f1d1 Michael Hanselmann
  the cluster domain secret over the value "${index}:${hostname}:${port}". The
1531 4a96f1d1 Michael Hanselmann
  destination X509 CA must be a signed certificate.
1532 4a96f1d1 Michael Hanselmann

1533 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1534 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
1535 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
1536 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1537 4a96f1d1 Michael Hanselmann
                             only)
1538 4a96f1d1 Michael Hanselmann

1539 4a96f1d1 Michael Hanselmann
  """
1540 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1541 65e183af Michael Hanselmann
  OP_PARAMS = [
1542 65e183af Michael Hanselmann
    _PInstanceName,
1543 65e183af Michael Hanselmann
    _PShutdownTimeout,
1544 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
1545 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
1546 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1547 45d4c81c Michael Hanselmann
     "Destination information, depends on export mode"),
1548 45d4c81c Michael Hanselmann
    ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1549 45d4c81c Michael Hanselmann
    ("remove_instance", False, ht.TBool,
1550 45d4c81c Michael Hanselmann
     "Whether to remove instance after export"),
1551 45d4c81c Michael Hanselmann
    ("ignore_remove_failures", False, ht.TBool,
1552 45d4c81c Michael Hanselmann
     "Whether to ignore failures while removing instances"),
1553 45d4c81c Michael Hanselmann
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1554 45d4c81c Michael Hanselmann
     "Export mode"),
1555 45d4c81c Michael Hanselmann
    ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1556 45d4c81c Michael Hanselmann
     "Name of X509 key (remote export only)"),
1557 45d4c81c Michael Hanselmann
    ("destination_x509_ca", None, ht.TMaybeString,
1558 45d4c81c Michael Hanselmann
     "Destination X509 CA (remote export only)"),
1559 17c3f802 Guido Trotter
    ]
1560 5c947f38 Iustin Pop
1561 0a7bed64 Michael Hanselmann
1562 ca5890ad Iustin Pop
class OpBackupRemove(OpCode):
1563 9ac99fda Guido Trotter
  """Remove an instance's export."""
1564 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1565 65e183af Michael Hanselmann
  OP_PARAMS = [
1566 65e183af Michael Hanselmann
    _PInstanceName,
1567 65e183af Michael Hanselmann
    ]
1568 5c947f38 Iustin Pop
1569 0a7bed64 Michael Hanselmann
1570 5c947f38 Iustin Pop
# Tags opcodes
1571 c6afb1ca Iustin Pop
class OpTagsGet(OpCode):
1572 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
1573 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
1574 65e183af Michael Hanselmann
  OP_PARAMS = [
1575 65e183af Michael Hanselmann
    _PTagKind,
1576 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1577 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1578 65e183af Michael Hanselmann
    ]
1579 5c947f38 Iustin Pop
1580 5c947f38 Iustin Pop
1581 715462e7 Iustin Pop
class OpTagsSearch(OpCode):
1582 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
1583 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
1584 65e183af Michael Hanselmann
  OP_PARAMS = [
1585 197b323b Michael Hanselmann
    ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
1586 65e183af Michael Hanselmann
    ]
1587 73415719 Iustin Pop
1588 73415719 Iustin Pop
1589 d1602edc Iustin Pop
class OpTagsSet(OpCode):
1590 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
1591 65e183af Michael Hanselmann
  OP_PARAMS = [
1592 65e183af Michael Hanselmann
    _PTagKind,
1593 65e183af Michael Hanselmann
    _PTags,
1594 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1595 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1596 65e183af Michael Hanselmann
    ]
1597 5c947f38 Iustin Pop
1598 5c947f38 Iustin Pop
1599 3f0ab95f Iustin Pop
class OpTagsDel(OpCode):
1600 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
1601 65e183af Michael Hanselmann
  OP_PARAMS = [
1602 65e183af Michael Hanselmann
    _PTagKind,
1603 65e183af Michael Hanselmann
    _PTags,
1604 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1605 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1606 65e183af Michael Hanselmann
    ]
1607 06009e27 Iustin Pop
1608 e687ec01 Michael Hanselmann
1609 06009e27 Iustin Pop
# Test opcodes
1610 06009e27 Iustin Pop
class OpTestDelay(OpCode):
1611 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
1612 06009e27 Iustin Pop

1613 06009e27 Iustin Pop
  This is used just for debugging and testing.
1614 06009e27 Iustin Pop

1615 06009e27 Iustin Pop
  Parameters:
1616 06009e27 Iustin Pop
    - duration: the time to sleep
1617 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
1618 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
1619 06009e27 Iustin Pop

1620 06009e27 Iustin Pop
  If the on_master parameter is true, it will execute a sleep on the
1621 06009e27 Iustin Pop
  master (before any node sleep).
1622 06009e27 Iustin Pop

1623 06009e27 Iustin Pop
  If the on_nodes list is not empty, it will sleep on those nodes
1624 06009e27 Iustin Pop
  (after the sleep on the master, if that is enabled).
1625 06009e27 Iustin Pop

1626 06009e27 Iustin Pop
  As an additional feature, the case of duration < 0 will be reported
1627 06009e27 Iustin Pop
  as an execution error, so this opcode can be used as a failure
1628 06009e27 Iustin Pop
  generator. The case of duration == 0 will not be treated specially.
1629 06009e27 Iustin Pop

1630 06009e27 Iustin Pop
  """
1631 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
1632 65e183af Michael Hanselmann
  OP_PARAMS = [
1633 b795a775 Michael Hanselmann
    ("duration", ht.NoDefault, ht.TNumber, None),
1634 197b323b Michael Hanselmann
    ("on_master", True, ht.TBool, None),
1635 197b323b Michael Hanselmann
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1636 197b323b Michael Hanselmann
    ("repeat", 0, ht.TPositiveInt, None),
1637 65e183af Michael Hanselmann
    ]
1638 d61df03e Iustin Pop
1639 d61df03e Iustin Pop
1640 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
1641 d61df03e Iustin Pop
  """Allocator framework testing.
1642 d61df03e Iustin Pop

1643 d61df03e Iustin Pop
  This opcode has two modes:
1644 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
1645 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
1646 d61df03e Iustin Pop
      'in')
1647 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
1648 d61df03e Iustin Pop
      return the allocator output (direction 'out')
1649 d61df03e Iustin Pop

1650 d61df03e Iustin Pop
  """
1651 60dd1473 Iustin Pop
  OP_DSC_FIELD = "allocator"
1652 65e183af Michael Hanselmann
  OP_PARAMS = [
1653 65e183af Michael Hanselmann
    ("direction", ht.NoDefault,
1654 197b323b Michael Hanselmann
     ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1655 197b323b Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1656 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
1657 65e183af Michael Hanselmann
    ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
1658 fdbe29ee Michael Hanselmann
     ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
1659 45d4c81c Michael Hanselmann
                ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
1660 197b323b Michael Hanselmann
    ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1661 197b323b Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, None),
1662 197b323b Michael Hanselmann
    ("allocator", None, ht.TMaybeString, None),
1663 197b323b Michael Hanselmann
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1664 dd47a0f0 Iustin Pop
    ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1665 197b323b Michael Hanselmann
    ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1666 197b323b Michael Hanselmann
    ("os", None, ht.TMaybeString, None),
1667 197b323b Michael Hanselmann
    ("disk_template", None, ht.TMaybeString, None),
1668 bee581e2 Michael Hanselmann
    ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1669 bee581e2 Michael Hanselmann
     None),
1670 60152bbe Michael Hanselmann
    ("evac_mode", None,
1671 60152bbe Michael Hanselmann
     ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1672 bee581e2 Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1673 bee581e2 Michael Hanselmann
     None),
1674 d61df03e Iustin Pop
    ]
1675 363acb1e Iustin Pop
1676 76aef8fc Michael Hanselmann
1677 b469eb4d Iustin Pop
class OpTestJqueue(OpCode):
1678 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
1679 e58f87a9 Michael Hanselmann

1680 e58f87a9 Michael Hanselmann
  """
1681 65e183af Michael Hanselmann
  OP_PARAMS = [
1682 197b323b Michael Hanselmann
    ("notify_waitlock", False, ht.TBool, None),
1683 197b323b Michael Hanselmann
    ("notify_exec", False, ht.TBool, None),
1684 197b323b Michael Hanselmann
    ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1685 197b323b Michael Hanselmann
    ("fail", False, ht.TBool, None),
1686 e58f87a9 Michael Hanselmann
    ]
1687 e58f87a9 Michael Hanselmann
1688 e58f87a9 Michael Hanselmann
1689 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
1690 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
1691 be760ba8 Michael Hanselmann

1692 be760ba8 Michael Hanselmann
  """
1693 65e183af Michael Hanselmann
  OP_PARAMS = [
1694 197b323b Michael Hanselmann
    ("result", ht.NoDefault, ht.NoType, None),
1695 197b323b Michael Hanselmann
    ("messages", ht.NoDefault, ht.NoType, None),
1696 197b323b Michael Hanselmann
    ("fail", ht.NoDefault, ht.NoType, None),
1697 6a373640 Michael Hanselmann
    ("submit_jobs", None, ht.NoType, None),
1698 be760ba8 Michael Hanselmann
    ]
1699 687c10d9 Iustin Pop
  WITH_LU = False
1700 be760ba8 Michael Hanselmann
1701 be760ba8 Michael Hanselmann
1702 dbc96028 Michael Hanselmann
def _GetOpList():
1703 dbc96028 Michael Hanselmann
  """Returns list of all defined opcodes.
1704 dbc96028 Michael Hanselmann

1705 dbc96028 Michael Hanselmann
  Does not eliminate duplicates by C{OP_ID}.
1706 dbc96028 Michael Hanselmann

1707 dbc96028 Michael Hanselmann
  """
1708 dbc96028 Michael Hanselmann
  return [v for v in globals().values()
1709 dbc96028 Michael Hanselmann
          if (isinstance(v, type) and issubclass(v, OpCode) and
1710 687c10d9 Iustin Pop
              hasattr(v, "OP_ID") and v is not OpCode)]
1711 dbc96028 Michael Hanselmann
1712 dbc96028 Michael Hanselmann
1713 dbc96028 Michael Hanselmann
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())