Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 0ad1ea40

History | View | Annotate | Download (50.6 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 323f9095 Stephen Shirley
141 ff0d18e6 Iustin Pop
#: OP_ID conversion regular expression
142 ff0d18e6 Iustin Pop
_OPID_RE = re.compile("([a-z])([A-Z])")
143 ff0d18e6 Iustin Pop
144 8c9ee749 Michael Hanselmann
#: Utility function for L{OpClusterSetParams}
145 8c9ee749 Michael Hanselmann
_TestClusterOsList = ht.TOr(ht.TNone,
146 8c9ee749 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
147 eb62069e Iustin Pop
    ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
148 8c9ee749 Michael Hanselmann
            ht.TElemOf(constants.DDMS_VALUES)))))
149 8c9ee749 Michael Hanselmann
150 ff0d18e6 Iustin Pop
151 526a662a Michael Hanselmann
# TODO: Generate check from constants.INIC_PARAMS_TYPES
152 526a662a Michael Hanselmann
#: Utility function for testing NIC definitions
153 526a662a Michael Hanselmann
_TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
154 526a662a Michael Hanselmann
                         ht.TOr(ht.TNone, ht.TNonEmptyString))
155 526a662a Michael Hanselmann
156 1456df62 Michael Hanselmann
_TSetParamsResultItemItems = [
157 1456df62 Michael Hanselmann
  ht.Comment("name of changed parameter")(ht.TNonEmptyString),
158 b3d2ee31 Michael Hanselmann
  ht.Comment("new value")(ht.TAny),
159 1456df62 Michael Hanselmann
  ]
160 1456df62 Michael Hanselmann
161 1456df62 Michael Hanselmann
_TSetParamsResult = \
162 1456df62 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
163 1456df62 Michael Hanselmann
                     ht.TItems(_TSetParamsResultItemItems)))
164 1456df62 Michael Hanselmann
165 3ce9a5e7 Michael Hanselmann
_SUMMARY_PREFIX = {
166 3ce9a5e7 Michael Hanselmann
  "CLUSTER_": "C_",
167 3ce9a5e7 Michael Hanselmann
  "GROUP_": "G_",
168 3ce9a5e7 Michael Hanselmann
  "NODE_": "N_",
169 3ce9a5e7 Michael Hanselmann
  "INSTANCE_": "I_",
170 3ce9a5e7 Michael Hanselmann
  }
171 3ce9a5e7 Michael Hanselmann
172 b95479a5 Michael Hanselmann
#: Attribute name for dependencies
173 b95479a5 Michael Hanselmann
DEPEND_ATTR = "depends"
174 b95479a5 Michael Hanselmann
175 018ae30b Michael Hanselmann
#: Attribute name for comment
176 018ae30b Michael Hanselmann
COMMENT_ATTR = "comment"
177 018ae30b Michael Hanselmann
178 526a662a Michael Hanselmann
179 ff0d18e6 Iustin Pop
def _NameToId(name):
180 ff0d18e6 Iustin Pop
  """Convert an opcode class name to an OP_ID.
181 ff0d18e6 Iustin Pop

182 ff0d18e6 Iustin Pop
  @type name: string
183 ff0d18e6 Iustin Pop
  @param name: the class name, as OpXxxYyy
184 ff0d18e6 Iustin Pop
  @rtype: string
185 ff0d18e6 Iustin Pop
  @return: the name in the OP_XXXX_YYYY format
186 ff0d18e6 Iustin Pop

187 ff0d18e6 Iustin Pop
  """
188 ff0d18e6 Iustin Pop
  if not name.startswith("Op"):
189 ff0d18e6 Iustin Pop
    return None
190 ff0d18e6 Iustin Pop
  # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
191 ff0d18e6 Iustin Pop
  # consume any input, and hence we would just have all the elements
192 ff0d18e6 Iustin Pop
  # in the list, one by one; but it seems that split doesn't work on
193 ff0d18e6 Iustin Pop
  # non-consuming input, hence we have to process the input string a
194 ff0d18e6 Iustin Pop
  # bit
195 ff0d18e6 Iustin Pop
  name = _OPID_RE.sub(r"\1,\2", name)
196 ff0d18e6 Iustin Pop
  elems = name.split(",")
197 ff0d18e6 Iustin Pop
  return "_".join(n.upper() for n in elems)
198 ff0d18e6 Iustin Pop
199 65e183af Michael Hanselmann
200 65e183af Michael Hanselmann
def RequireFileStorage():
201 65e183af Michael Hanselmann
  """Checks that file storage is enabled.
202 65e183af Michael Hanselmann

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

206 65e183af Michael Hanselmann
  @raise errors.OpPrereqError: when file storage is disabled
207 65e183af Michael Hanselmann

208 65e183af Michael Hanselmann
  """
209 65e183af Michael Hanselmann
  if not constants.ENABLE_FILE_STORAGE:
210 65e183af Michael Hanselmann
    raise errors.OpPrereqError("File storage disabled at configure time",
211 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
212 65e183af Michael Hanselmann
213 65e183af Michael Hanselmann
214 4b97f902 Apollon Oikonomopoulos
def RequireSharedFileStorage():
215 4b97f902 Apollon Oikonomopoulos
  """Checks that shared file storage is enabled.
216 4b97f902 Apollon Oikonomopoulos

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

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

222 4b97f902 Apollon Oikonomopoulos
  """
223 4b97f902 Apollon Oikonomopoulos
  if not constants.ENABLE_SHARED_FILE_STORAGE:
224 4b97f902 Apollon Oikonomopoulos
    raise errors.OpPrereqError("Shared file storage disabled at"
225 4b97f902 Apollon Oikonomopoulos
                               " configure time", errors.ECODE_INVAL)
226 4b97f902 Apollon Oikonomopoulos
227 4b97f902 Apollon Oikonomopoulos
228 8c9ee749 Michael Hanselmann
@ht.WithDesc("CheckFileStorage")
229 8c9ee749 Michael Hanselmann
def _CheckFileStorage(value):
230 8c9ee749 Michael Hanselmann
  """Ensures file storage is enabled if used.
231 65e183af Michael Hanselmann

232 65e183af Michael Hanselmann
  """
233 8c9ee749 Michael Hanselmann
  if value == constants.DT_FILE:
234 65e183af Michael Hanselmann
    RequireFileStorage()
235 4b97f902 Apollon Oikonomopoulos
  elif value == constants.DT_SHARED_FILE:
236 4b97f902 Apollon Oikonomopoulos
    RequireSharedFileStorage()
237 65e183af Michael Hanselmann
  return True
238 65e183af Michael Hanselmann
239 65e183af Michael Hanselmann
240 8c9ee749 Michael Hanselmann
_CheckDiskTemplate = ht.TAnd(ht.TElemOf(constants.DISK_TEMPLATES),
241 8c9ee749 Michael Hanselmann
                             _CheckFileStorage)
242 8c9ee749 Michael Hanselmann
243 8c9ee749 Michael Hanselmann
244 65e183af Michael Hanselmann
def _CheckStorageType(storage_type):
245 65e183af Michael Hanselmann
  """Ensure a given storage type is valid.
246 65e183af Michael Hanselmann

247 65e183af Michael Hanselmann
  """
248 65e183af Michael Hanselmann
  if storage_type not in constants.VALID_STORAGE_TYPES:
249 65e183af Michael Hanselmann
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
250 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
251 65e183af Michael Hanselmann
  if storage_type == constants.ST_FILE:
252 65e183af Michael Hanselmann
    RequireFileStorage()
253 65e183af Michael Hanselmann
  return True
254 65e183af Michael Hanselmann
255 65e183af Michael Hanselmann
256 65e183af Michael Hanselmann
#: Storage type parameter
257 45d4c81c Michael Hanselmann
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
258 45d4c81c Michael Hanselmann
                 "Storage type")
259 65e183af Michael Hanselmann
260 65e183af Michael Hanselmann
261 65e183af Michael Hanselmann
class _AutoOpParamSlots(type):
262 65e183af Michael Hanselmann
  """Meta class for opcode definitions.
263 65e183af Michael Hanselmann

264 65e183af Michael Hanselmann
  """
265 65e183af Michael Hanselmann
  def __new__(mcs, name, bases, attrs):
266 65e183af Michael Hanselmann
    """Called when a class should be created.
267 65e183af Michael Hanselmann

268 65e183af Michael Hanselmann
    @param mcs: The meta class
269 65e183af Michael Hanselmann
    @param name: Name of created class
270 65e183af Michael Hanselmann
    @param bases: Base classes
271 65e183af Michael Hanselmann
    @type attrs: dict
272 65e183af Michael Hanselmann
    @param attrs: Class attributes
273 65e183af Michael Hanselmann

274 65e183af Michael Hanselmann
    """
275 65e183af Michael Hanselmann
    assert "__slots__" not in attrs, \
276 65e183af Michael Hanselmann
      "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
277 e89a9021 Iustin Pop
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
278 ff0d18e6 Iustin Pop
279 e89a9021 Iustin Pop
    attrs["OP_ID"] = _NameToId(name)
280 65e183af Michael Hanselmann
281 65e183af Michael Hanselmann
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
282 65e183af Michael Hanselmann
    params = attrs.setdefault("OP_PARAMS", [])
283 65e183af Michael Hanselmann
284 65e183af Michael Hanselmann
    # Use parameter names as slots
285 197b323b Michael Hanselmann
    slots = [pname for (pname, _, _, _) in params]
286 65e183af Michael Hanselmann
287 65e183af Michael Hanselmann
    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
288 65e183af Michael Hanselmann
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name
289 65e183af Michael Hanselmann
290 65e183af Michael Hanselmann
    attrs["__slots__"] = slots
291 65e183af Michael Hanselmann
292 65e183af Michael Hanselmann
    return type.__new__(mcs, name, bases, attrs)
293 65e183af Michael Hanselmann
294 df458e0b Iustin Pop
295 0e46916d Iustin Pop
class BaseOpCode(object):
296 df458e0b Iustin Pop
  """A simple serializable object.
297 df458e0b Iustin Pop

298 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
299 0e46916d Iustin Pop
  field handling.
300 0e46916d Iustin Pop

301 df458e0b Iustin Pop
  """
302 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
303 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
304 65e183af Michael Hanselmann
  __metaclass__ = _AutoOpParamSlots
305 65e183af Michael Hanselmann
306 a8083063 Iustin Pop
  def __init__(self, **kwargs):
307 a7399f66 Iustin Pop
    """Constructor for BaseOpCode.
308 a7399f66 Iustin Pop

309 a7399f66 Iustin Pop
    The constructor takes only keyword arguments and will set
310 a7399f66 Iustin Pop
    attributes on this object based on the passed arguments. As such,
311 a7399f66 Iustin Pop
    it means that you should not pass arguments which are not in the
312 a7399f66 Iustin Pop
    __slots__ attribute for this class.
313 a7399f66 Iustin Pop

314 a7399f66 Iustin Pop
    """
315 adf385c7 Iustin Pop
    slots = self._all_slots()
316 a8083063 Iustin Pop
    for key in kwargs:
317 adf385c7 Iustin Pop
      if key not in slots:
318 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
319 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
320 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
321 a8083063 Iustin Pop
322 df458e0b Iustin Pop
  def __getstate__(self):
323 a7399f66 Iustin Pop
    """Generic serializer.
324 a7399f66 Iustin Pop

325 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
326 a7399f66 Iustin Pop
    dictionary.
327 a7399f66 Iustin Pop

328 a7399f66 Iustin Pop
    @rtype:  C{dict}
329 a7399f66 Iustin Pop
    @return: the instance attributes and their values
330 a7399f66 Iustin Pop

331 a7399f66 Iustin Pop
    """
332 df458e0b Iustin Pop
    state = {}
333 adf385c7 Iustin Pop
    for name in self._all_slots():
334 df458e0b Iustin Pop
      if hasattr(self, name):
335 df458e0b Iustin Pop
        state[name] = getattr(self, name)
336 df458e0b Iustin Pop
    return state
337 df458e0b Iustin Pop
338 df458e0b Iustin Pop
  def __setstate__(self, state):
339 a7399f66 Iustin Pop
    """Generic unserializer.
340 a7399f66 Iustin Pop

341 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
342 a7399f66 Iustin Pop
    of the current instance.
343 a7399f66 Iustin Pop

344 a7399f66 Iustin Pop
    @param state: the serialized opcode data
345 a7399f66 Iustin Pop
    @type state:  C{dict}
346 a7399f66 Iustin Pop

347 a7399f66 Iustin Pop
    """
348 df458e0b Iustin Pop
    if not isinstance(state, dict):
349 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
350 df458e0b Iustin Pop
                       type(state))
351 df458e0b Iustin Pop
352 adf385c7 Iustin Pop
    for name in self._all_slots():
353 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
354 df458e0b Iustin Pop
        delattr(self, name)
355 df458e0b Iustin Pop
356 df458e0b Iustin Pop
    for name in state:
357 df458e0b Iustin Pop
      setattr(self, name, state[name])
358 df458e0b Iustin Pop
359 adf385c7 Iustin Pop
  @classmethod
360 adf385c7 Iustin Pop
  def _all_slots(cls):
361 adf385c7 Iustin Pop
    """Compute the list of all declared slots for a class.
362 adf385c7 Iustin Pop

363 adf385c7 Iustin Pop
    """
364 adf385c7 Iustin Pop
    slots = []
365 adf385c7 Iustin Pop
    for parent in cls.__mro__:
366 adf385c7 Iustin Pop
      slots.extend(getattr(parent, "__slots__", []))
367 adf385c7 Iustin Pop
    return slots
368 adf385c7 Iustin Pop
369 65e183af Michael Hanselmann
  @classmethod
370 65e183af Michael Hanselmann
  def GetAllParams(cls):
371 65e183af Michael Hanselmann
    """Compute list of all parameters for an opcode.
372 65e183af Michael Hanselmann

373 65e183af Michael Hanselmann
    """
374 65e183af Michael Hanselmann
    slots = []
375 65e183af Michael Hanselmann
    for parent in cls.__mro__:
376 65e183af Michael Hanselmann
      slots.extend(getattr(parent, "OP_PARAMS", []))
377 65e183af Michael Hanselmann
    return slots
378 65e183af Michael Hanselmann
379 1cbef6d8 Michael Hanselmann
  def Validate(self, set_defaults):
380 1cbef6d8 Michael Hanselmann
    """Validate opcode parameters, optionally setting default values.
381 1cbef6d8 Michael Hanselmann

382 1cbef6d8 Michael Hanselmann
    @type set_defaults: bool
383 1cbef6d8 Michael Hanselmann
    @param set_defaults: Whether to set default values
384 1cbef6d8 Michael Hanselmann
    @raise errors.OpPrereqError: When a parameter value doesn't match
385 1cbef6d8 Michael Hanselmann
                                 requirements
386 1cbef6d8 Michael Hanselmann

387 1cbef6d8 Michael Hanselmann
    """
388 197b323b Michael Hanselmann
    for (attr_name, default, test, _) in self.GetAllParams():
389 1cbef6d8 Michael Hanselmann
      assert test == ht.NoType or callable(test)
390 1cbef6d8 Michael Hanselmann
391 1cbef6d8 Michael Hanselmann
      if not hasattr(self, attr_name):
392 1cbef6d8 Michael Hanselmann
        if default == ht.NoDefault:
393 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
394 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
395 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
396 1cbef6d8 Michael Hanselmann
        elif set_defaults:
397 1cbef6d8 Michael Hanselmann
          if callable(default):
398 1cbef6d8 Michael Hanselmann
            dval = default()
399 1cbef6d8 Michael Hanselmann
          else:
400 1cbef6d8 Michael Hanselmann
            dval = default
401 1cbef6d8 Michael Hanselmann
          setattr(self, attr_name, dval)
402 1cbef6d8 Michael Hanselmann
403 1cbef6d8 Michael Hanselmann
      if test == ht.NoType:
404 1cbef6d8 Michael Hanselmann
        # no tests here
405 1cbef6d8 Michael Hanselmann
        continue
406 1cbef6d8 Michael Hanselmann
407 1cbef6d8 Michael Hanselmann
      if set_defaults or hasattr(self, attr_name):
408 1cbef6d8 Michael Hanselmann
        attr_val = getattr(self, attr_name)
409 1cbef6d8 Michael Hanselmann
        if not test(attr_val):
410 1cbef6d8 Michael Hanselmann
          logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
411 1cbef6d8 Michael Hanselmann
                        self.OP_ID, attr_name, type(attr_val), attr_val)
412 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
413 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
414 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
415 1cbef6d8 Michael Hanselmann
416 df458e0b Iustin Pop
417 b247c6fc Michael Hanselmann
def _BuildJobDepCheck(relative):
418 b247c6fc Michael Hanselmann
  """Builds check for job dependencies (L{DEPEND_ATTR}).
419 b247c6fc Michael Hanselmann

420 b247c6fc Michael Hanselmann
  @type relative: bool
421 b247c6fc Michael Hanselmann
  @param relative: Whether to accept relative job IDs (negative)
422 b247c6fc Michael Hanselmann
  @rtype: callable
423 b247c6fc Michael Hanselmann

424 b247c6fc Michael Hanselmann
  """
425 b247c6fc Michael Hanselmann
  if relative:
426 b247c6fc Michael Hanselmann
    job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
427 b247c6fc Michael Hanselmann
  else:
428 b247c6fc Michael Hanselmann
    job_id = ht.TJobId
429 b247c6fc Michael Hanselmann
430 b247c6fc Michael Hanselmann
  job_dep = \
431 b247c6fc Michael Hanselmann
    ht.TAnd(ht.TIsLength(2),
432 b247c6fc Michael Hanselmann
            ht.TItems([job_id,
433 b247c6fc Michael Hanselmann
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
434 b247c6fc Michael Hanselmann
435 b247c6fc Michael Hanselmann
  return ht.TOr(ht.TNone, ht.TListOf(job_dep))
436 b247c6fc Michael Hanselmann
437 b247c6fc Michael Hanselmann
438 b247c6fc Michael Hanselmann
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
439 b247c6fc Michael Hanselmann
440 1ce03fb1 Michael Hanselmann
#: List of submission status and job ID as returned by C{SubmitManyJobs}
441 1456df62 Michael Hanselmann
_TJobIdListItem = \
442 1456df62 Michael Hanselmann
  ht.TAnd(ht.TIsLength(2),
443 1456df62 Michael Hanselmann
          ht.TItems([ht.Comment("success")(ht.TBool),
444 1456df62 Michael Hanselmann
                     ht.Comment("Job ID if successful, error message"
445 1456df62 Michael Hanselmann
                                " otherwise")(ht.TOr(ht.TString,
446 1456df62 Michael Hanselmann
                                                     ht.TJobId))]))
447 1456df62 Michael Hanselmann
TJobIdList = ht.TListOf(_TJobIdListItem)
448 1ce03fb1 Michael Hanselmann
449 f7686867 Michael Hanselmann
#: Result containing only list of submitted jobs
450 f7686867 Michael Hanselmann
TJobIdListOnly = ht.TStrictDict(True, True, {
451 1456df62 Michael Hanselmann
  constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
452 f7686867 Michael Hanselmann
  })
453 f7686867 Michael Hanselmann
454 b247c6fc Michael Hanselmann
455 0e46916d Iustin Pop
class OpCode(BaseOpCode):
456 a7399f66 Iustin Pop
  """Abstract OpCode.
457 a7399f66 Iustin Pop

458 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
459 a7399f66 Iustin Pop
  from this class should override OP_ID.
460 a7399f66 Iustin Pop

461 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
462 20777413 Iustin Pop
               children of this class.
463 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
464 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
465 bde8f481 Adeodato Simo
                      method for details).
466 65e183af Michael Hanselmann
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
467 65e183af Michael Hanselmann
                   get if not already defined, and types they must match.
468 1ce03fb1 Michael Hanselmann
  @cvar OP_RESULT: Callable to verify opcode result
469 687c10d9 Iustin Pop
  @cvar WITH_LU: Boolean that specifies whether this should be included in
470 687c10d9 Iustin Pop
      mcpu's dispatch table
471 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
472 20777413 Iustin Pop
                 the check steps
473 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
474 a7399f66 Iustin Pop

475 a7399f66 Iustin Pop
  """
476 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
477 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
478 687c10d9 Iustin Pop
  WITH_LU = True
479 65e183af Michael Hanselmann
  OP_PARAMS = [
480 45d4c81c Michael Hanselmann
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
481 45d4c81c Michael Hanselmann
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
482 65e183af Michael Hanselmann
    ("priority", constants.OP_PRIO_DEFAULT,
483 45d4c81c Michael Hanselmann
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
484 b247c6fc Michael Hanselmann
    (DEPEND_ATTR, None, _BuildJobDepCheck(True),
485 b247c6fc Michael Hanselmann
     "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
486 b247c6fc Michael Hanselmann
     " job IDs can be used"),
487 018ae30b Michael Hanselmann
    (COMMENT_ATTR, None, ht.TMaybeString,
488 018ae30b Michael Hanselmann
     "Comment describing the purpose of the opcode"),
489 65e183af Michael Hanselmann
    ]
490 1ce03fb1 Michael Hanselmann
  OP_RESULT = None
491 df458e0b Iustin Pop
492 df458e0b Iustin Pop
  def __getstate__(self):
493 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
494 df458e0b Iustin Pop

495 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
496 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
497 a7399f66 Iustin Pop
    instantiating the opcode.
498 a7399f66 Iustin Pop

499 a7399f66 Iustin Pop
    @rtype:   C{dict}
500 a7399f66 Iustin Pop
    @return:  the state as a dictionary
501 a7399f66 Iustin Pop

502 df458e0b Iustin Pop
    """
503 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
504 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
505 df458e0b Iustin Pop
    return data
506 df458e0b Iustin Pop
507 df458e0b Iustin Pop
  @classmethod
508 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
509 df458e0b Iustin Pop
    """Generic load opcode method.
510 df458e0b Iustin Pop

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

515 a7399f66 Iustin Pop
    @type data:  C{dict}
516 a7399f66 Iustin Pop
    @param data: the serialized opcode
517 a7399f66 Iustin Pop

518 df458e0b Iustin Pop
    """
519 df458e0b Iustin Pop
    if not isinstance(data, dict):
520 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
521 df458e0b Iustin Pop
    if "OP_ID" not in data:
522 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
523 df458e0b Iustin Pop
    op_id = data["OP_ID"]
524 df458e0b Iustin Pop
    op_class = None
525 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
526 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
527 363acb1e Iustin Pop
    else:
528 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
529 df458e0b Iustin Pop
                       op_id)
530 df458e0b Iustin Pop
    op = op_class()
531 df458e0b Iustin Pop
    new_data = data.copy()
532 df458e0b Iustin Pop
    del new_data["OP_ID"]
533 df458e0b Iustin Pop
    op.__setstate__(new_data)
534 df458e0b Iustin Pop
    return op
535 df458e0b Iustin Pop
536 60dd1473 Iustin Pop
  def Summary(self):
537 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
538 60dd1473 Iustin Pop

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

545 60dd1473 Iustin Pop
    """
546 ff0d18e6 Iustin Pop
    assert self.OP_ID is not None and len(self.OP_ID) > 3
547 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
548 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
549 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
550 60dd1473 Iustin Pop
    if field_name:
551 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
552 bc8bbda1 Iustin Pop
      if isinstance(field_value, (list, tuple)):
553 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
554 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
555 60dd1473 Iustin Pop
    return txt
556 60dd1473 Iustin Pop
557 3ce9a5e7 Michael Hanselmann
  def TinySummary(self):
558 3ce9a5e7 Michael Hanselmann
    """Generates a compact summary description of the opcode.
559 3ce9a5e7 Michael Hanselmann

560 3ce9a5e7 Michael Hanselmann
    """
561 3ce9a5e7 Michael Hanselmann
    assert self.OP_ID.startswith("OP_")
562 3ce9a5e7 Michael Hanselmann
563 3ce9a5e7 Michael Hanselmann
    text = self.OP_ID[3:]
564 3ce9a5e7 Michael Hanselmann
565 3ce9a5e7 Michael Hanselmann
    for (prefix, supplement) in _SUMMARY_PREFIX.items():
566 3ce9a5e7 Michael Hanselmann
      if text.startswith(prefix):
567 3ce9a5e7 Michael Hanselmann
        return supplement + text[len(prefix):]
568 3ce9a5e7 Michael Hanselmann
569 3ce9a5e7 Michael Hanselmann
    return text
570 3ce9a5e7 Michael Hanselmann
571 a8083063 Iustin Pop
572 afee0879 Iustin Pop
# cluster opcodes
573 afee0879 Iustin Pop
574 bc84ffa7 Iustin Pop
class OpClusterPostInit(OpCode):
575 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
576 b5f5fae9 Luca Bigliardi

577 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
578 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
579 b5f5fae9 Luca Bigliardi

580 b5f5fae9 Luca Bigliardi
  """
581 b5f5fae9 Luca Bigliardi
582 b5f5fae9 Luca Bigliardi
583 c6d43e9e Iustin Pop
class OpClusterDestroy(OpCode):
584 a7399f66 Iustin Pop
  """Destroy the cluster.
585 a7399f66 Iustin Pop

586 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
587 a7399f66 Iustin Pop
  lost after the execution of this opcode.
588 a7399f66 Iustin Pop

589 a7399f66 Iustin Pop
  """
590 a8083063 Iustin Pop
591 a8083063 Iustin Pop
592 a2f7ab92 Iustin Pop
class OpClusterQuery(OpCode):
593 fdc267f4 Iustin Pop
  """Query cluster information."""
594 a8083063 Iustin Pop
595 a8083063 Iustin Pop
596 fcad7225 Michael Hanselmann
class OpClusterVerify(OpCode):
597 fcad7225 Michael Hanselmann
  """Submits all jobs necessary to verify the cluster.
598 fcad7225 Michael Hanselmann

599 fcad7225 Michael Hanselmann
  """
600 fcad7225 Michael Hanselmann
  OP_PARAMS = [
601 fcad7225 Michael Hanselmann
    _PDebugSimulateErrors,
602 fcad7225 Michael Hanselmann
    _PErrorCodes,
603 fcad7225 Michael Hanselmann
    _PSkipChecks,
604 fcad7225 Michael Hanselmann
    _PVerbose,
605 fcad7225 Michael Hanselmann
    ("group_name", None, ht.TMaybeString, "Group to verify")
606 fcad7225 Michael Hanselmann
    ]
607 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
608 fcad7225 Michael Hanselmann
609 fcad7225 Michael Hanselmann
610 bf93ae69 Adeodato Simo
class OpClusterVerifyConfig(OpCode):
611 bf93ae69 Adeodato Simo
  """Verify the cluster config.
612 bf93ae69 Adeodato Simo

613 bf93ae69 Adeodato Simo
  """
614 bf93ae69 Adeodato Simo
  OP_PARAMS = [
615 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
616 57106b74 Michael Hanselmann
    _PErrorCodes,
617 57106b74 Michael Hanselmann
    _PVerbose,
618 bf93ae69 Adeodato Simo
    ]
619 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
620 bf93ae69 Adeodato Simo
621 bf93ae69 Adeodato Simo
622 bf93ae69 Adeodato Simo
class OpClusterVerifyGroup(OpCode):
623 bf93ae69 Adeodato Simo
  """Run verify on a node group from the cluster.
624 a7399f66 Iustin Pop

625 a7399f66 Iustin Pop
  @type skip_checks: C{list}
626 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
627 a7399f66 Iustin Pop
                     needs to be a subset of
628 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
629 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
630 a7399f66 Iustin Pop

631 a7399f66 Iustin Pop
  """
632 bf93ae69 Adeodato Simo
  OP_DSC_FIELD = "group_name"
633 65e183af Michael Hanselmann
  OP_PARAMS = [
634 57106b74 Michael Hanselmann
    _PGroupName,
635 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
636 57106b74 Michael Hanselmann
    _PErrorCodes,
637 57106b74 Michael Hanselmann
    _PSkipChecks,
638 57106b74 Michael Hanselmann
    _PVerbose,
639 65e183af Michael Hanselmann
    ]
640 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
641 a8083063 Iustin Pop
642 a8083063 Iustin Pop
643 bd8210a7 Iustin Pop
class OpClusterVerifyDisks(OpCode):
644 150e978f Iustin Pop
  """Verify the cluster disks.
645 150e978f Iustin Pop

646 ae1a845c Michael Hanselmann
  """
647 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
648 ae1a845c Michael Hanselmann
649 ae1a845c Michael Hanselmann
650 ae1a845c Michael Hanselmann
class OpGroupVerifyDisks(OpCode):
651 ae1a845c Michael Hanselmann
  """Verifies the status of all disks in a node group.
652 150e978f Iustin Pop

653 ae1a845c Michael Hanselmann
  Result: a tuple of three elements:
654 ae1a845c Michael Hanselmann
    - dict of node names with issues (values: error msg)
655 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
656 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
657 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
658 150e978f Iustin Pop

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

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

667 150e978f Iustin Pop
  """
668 ae1a845c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
669 ae1a845c Michael Hanselmann
  OP_PARAMS = [
670 ae1a845c Michael Hanselmann
    _PGroupName,
671 ae1a845c Michael Hanselmann
    ]
672 1ce03fb1 Michael Hanselmann
  OP_RESULT = \
673 1ce03fb1 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3),
674 1ce03fb1 Michael Hanselmann
            ht.TItems([ht.TDictOf(ht.TString, ht.TString),
675 1ce03fb1 Michael Hanselmann
                       ht.TListOf(ht.TString),
676 1ce03fb1 Michael Hanselmann
                       ht.TDictOf(ht.TString, ht.TListOf(ht.TString))]))
677 150e978f Iustin Pop
678 150e978f Iustin Pop
679 5d01aca3 Iustin Pop
class OpClusterRepairDiskSizes(OpCode):
680 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
681 60975797 Iustin Pop
  mimatches.
682 60975797 Iustin Pop

683 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
684 60975797 Iustin Pop
  checks to only a subset of the instances.
685 60975797 Iustin Pop

686 60975797 Iustin Pop
  Result: a list of tuples, (instance, disk, new-size) for changed
687 60975797 Iustin Pop
  configurations.
688 60975797 Iustin Pop

689 60975797 Iustin Pop
  In normal operation, the list should be empty.
690 60975797 Iustin Pop

691 60975797 Iustin Pop
  @type instances: list
692 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
693 60975797 Iustin Pop

694 60975797 Iustin Pop
  """
695 65e183af Michael Hanselmann
  OP_PARAMS = [
696 197b323b Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
697 65e183af Michael Hanselmann
    ]
698 60975797 Iustin Pop
699 60975797 Iustin Pop
700 2f093ea0 Iustin Pop
class OpClusterConfigQuery(OpCode):
701 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
702 65e183af Michael Hanselmann
  OP_PARAMS = [
703 65e183af Michael Hanselmann
    _POutputFields
704 65e183af Michael Hanselmann
    ]
705 a8083063 Iustin Pop
706 a8083063 Iustin Pop
707 e126df25 Iustin Pop
class OpClusterRename(OpCode):
708 a7399f66 Iustin Pop
  """Rename the cluster.
709 a7399f66 Iustin Pop

710 a7399f66 Iustin Pop
  @type name: C{str}
711 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
712 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
713 a7399f66 Iustin Pop
              address.
714 a7399f66 Iustin Pop

715 a7399f66 Iustin Pop
  """
716 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
717 65e183af Michael Hanselmann
  OP_PARAMS = [
718 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
719 65e183af Michael Hanselmann
    ]
720 07bd8a51 Iustin Pop
721 07bd8a51 Iustin Pop
722 a6682fdc Iustin Pop
class OpClusterSetParams(OpCode):
723 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
724 a7399f66 Iustin Pop

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

728 a7399f66 Iustin Pop
  """
729 65e183af Michael Hanselmann
  OP_PARAMS = [
730 45d4c81c Michael Hanselmann
    ("vg_name", None, ht.TMaybeString, "Volume group name"),
731 65e183af Michael Hanselmann
    ("enabled_hypervisors", None,
732 65e183af Michael Hanselmann
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
733 45d4c81c Michael Hanselmann
            ht.TNone),
734 45d4c81c Michael Hanselmann
     "List of enabled hypervisors"),
735 65e183af Michael Hanselmann
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
736 45d4c81c Michael Hanselmann
                              ht.TNone),
737 45d4c81c Michael Hanselmann
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
738 45d4c81c Michael Hanselmann
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
739 45d4c81c Michael Hanselmann
     "Cluster-wide backend parameter defaults"),
740 65e183af Michael Hanselmann
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
741 45d4c81c Michael Hanselmann
                            ht.TNone),
742 45d4c81c Michael Hanselmann
     "Cluster-wide per-OS hypervisor parameter defaults"),
743 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
744 45d4c81c Michael Hanselmann
                              ht.TNone),
745 45d4c81c Michael Hanselmann
     "Cluster-wide OS parameter defaults"),
746 197b323b Michael Hanselmann
    ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
747 45d4c81c Michael Hanselmann
     "Master candidate pool size"),
748 45d4c81c Michael Hanselmann
    ("uid_pool", None, ht.NoType,
749 45d4c81c Michael Hanselmann
     "Set UID pool, must be list of lists describing UID ranges (two items,"
750 45d4c81c Michael Hanselmann
     " start and end inclusive)"),
751 45d4c81c Michael Hanselmann
    ("add_uids", None, ht.NoType,
752 45d4c81c Michael Hanselmann
     "Extend UID pool, must be list of lists describing UID ranges (two"
753 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be added"),
754 45d4c81c Michael Hanselmann
    ("remove_uids", None, ht.NoType,
755 45d4c81c Michael Hanselmann
     "Shrink UID pool, must be list of lists describing UID ranges (two"
756 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be removed"),
757 45d4c81c Michael Hanselmann
    ("maintain_node_health", None, ht.TMaybeBool,
758 45d4c81c Michael Hanselmann
     "Whether to automatically maintain node health"),
759 45d4c81c Michael Hanselmann
    ("prealloc_wipe_disks", None, ht.TMaybeBool,
760 45d4c81c Michael Hanselmann
     "Whether to wipe disks before allocating them to instances"),
761 45d4c81c Michael Hanselmann
    ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
762 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
763 45d4c81c Michael Hanselmann
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
764 45d4c81c Michael Hanselmann
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
765 45d4c81c Michael Hanselmann
     "Default iallocator for cluster"),
766 45d4c81c Michael Hanselmann
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
767 45d4c81c Michael Hanselmann
     "Master network device"),
768 45d4c81c Michael Hanselmann
    ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone),
769 45d4c81c Michael Hanselmann
     "List of reserved LVs"),
770 45d4c81c Michael Hanselmann
    ("hidden_os", None, _TestClusterOsList,
771 45d4c81c Michael Hanselmann
     "Modify list of hidden operating systems. Each modification must have"
772 45d4c81c Michael Hanselmann
     " two items, the operation and the OS name. The operation can be"
773 45d4c81c Michael Hanselmann
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
774 45d4c81c Michael Hanselmann
    ("blacklisted_os", None, _TestClusterOsList,
775 45d4c81c Michael Hanselmann
     "Modify list of blacklisted operating systems. Each modification must have"
776 45d4c81c Michael Hanselmann
     " two items, the operation and the OS name. The operation can be"
777 45d4c81c Michael Hanselmann
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
778 4b7735f9 Iustin Pop
    ]
779 12515db7 Manuel Franceschini
780 12515db7 Manuel Franceschini
781 d1240007 Iustin Pop
class OpClusterRedistConf(OpCode):
782 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
783 afee0879 Iustin Pop

784 afee0879 Iustin Pop
  """
785 afee0879 Iustin Pop
786 83f72637 Michael Hanselmann
787 fb44c6db Andrea Spadaccini
class OpClusterActivateMasterIp(OpCode):
788 fb44c6db Andrea Spadaccini
  """Activate the master IP on the master node.
789 fb44c6db Andrea Spadaccini

790 fb44c6db Andrea Spadaccini
  """
791 fb44c6db Andrea Spadaccini
792 fb44c6db Andrea Spadaccini
793 fb44c6db Andrea Spadaccini
class OpClusterDeactivateMasterIp(OpCode):
794 fb44c6db Andrea Spadaccini
  """Deactivate the master IP on the master node.
795 fb44c6db Andrea Spadaccini

796 fb44c6db Andrea Spadaccini
  """
797 fb44c6db Andrea Spadaccini
798 fb44c6db Andrea Spadaccini
799 83f72637 Michael Hanselmann
class OpQuery(OpCode):
800 83f72637 Michael Hanselmann
  """Query for resources/items.
801 83f72637 Michael Hanselmann

802 abd66bf8 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
803 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
804 83f72637 Michael Hanselmann
  @ivar filter: Query filter
805 83f72637 Michael Hanselmann

806 83f72637 Michael Hanselmann
  """
807 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
808 65e183af Michael Hanselmann
  OP_PARAMS = [
809 8e7078e0 Michael Hanselmann
    _PQueryWhat,
810 ee13764f Michael Hanselmann
    _PUseLocking,
811 45d4c81c Michael Hanselmann
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
812 45d4c81c Michael Hanselmann
     "Requested fields"),
813 b107fe05 Michael Hanselmann
    ("filter", None, ht.TOr(ht.TNone, ht.TListOf),
814 45d4c81c Michael Hanselmann
     "Query filter"),
815 83f72637 Michael Hanselmann
    ]
816 83f72637 Michael Hanselmann
817 83f72637 Michael Hanselmann
818 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
819 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
820 83f72637 Michael Hanselmann

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

824 83f72637 Michael Hanselmann
  """
825 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
826 65e183af Michael Hanselmann
  OP_PARAMS = [
827 8e7078e0 Michael Hanselmann
    _PQueryWhat,
828 8e7078e0 Michael Hanselmann
    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
829 8e7078e0 Michael Hanselmann
     "Requested fields; if not given, all are returned"),
830 83f72637 Michael Hanselmann
    ]
831 83f72637 Michael Hanselmann
832 83f72637 Michael Hanselmann
833 792af3ad René Nussbaumer
class OpOobCommand(OpCode):
834 eb64da59 René Nussbaumer
  """Interact with OOB."""
835 65e183af Michael Hanselmann
  OP_PARAMS = [
836 c4ec0755 René Nussbaumer
    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
837 c4ec0755 René Nussbaumer
     "List of nodes to run the OOB command against"),
838 c4ec0755 René Nussbaumer
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
839 c4ec0755 René Nussbaumer
     "OOB command to be run"),
840 c4ec0755 René Nussbaumer
    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
841 c4ec0755 René Nussbaumer
     "Timeout before the OOB helper will be terminated"),
842 c4ec0755 René Nussbaumer
    ("ignore_status", False, ht.TBool,
843 c4ec0755 René Nussbaumer
     "Ignores the node offline status for power off"),
844 beff3779 René Nussbaumer
    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
845 beff3779 René Nussbaumer
     "Time in seconds to wait between powering on nodes"),
846 eb64da59 René Nussbaumer
    ]
847 eb64da59 René Nussbaumer
848 eb64da59 René Nussbaumer
849 07bd8a51 Iustin Pop
# node opcodes
850 07bd8a51 Iustin Pop
851 73d565a3 Iustin Pop
class OpNodeRemove(OpCode):
852 a7399f66 Iustin Pop
  """Remove a node.
853 a7399f66 Iustin Pop

854 a7399f66 Iustin Pop
  @type node_name: C{str}
855 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
856 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
857 a7399f66 Iustin Pop

858 a7399f66 Iustin Pop
  """
859 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
860 65e183af Michael Hanselmann
  OP_PARAMS = [
861 65e183af Michael Hanselmann
    _PNodeName,
862 65e183af Michael Hanselmann
    ]
863 a8083063 Iustin Pop
864 a8083063 Iustin Pop
865 d817d49f Iustin Pop
class OpNodeAdd(OpCode):
866 a7399f66 Iustin Pop
  """Add a node to the cluster.
867 a7399f66 Iustin Pop

868 a7399f66 Iustin Pop
  @type node_name: C{str}
869 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
870 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
871 a7399f66 Iustin Pop
  @type primary_ip: IP address
872 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
873 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
874 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
875 a7399f66 Iustin Pop
  @type secondary_ip: IP address
876 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
877 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
878 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
879 a7399f66 Iustin Pop
  @type readd: C{bool}
880 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
881 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
882 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
883 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
884 a7399f66 Iustin Pop
               without removal from the cluster.
885 f936c153 Iustin Pop
  @type group: C{str}
886 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
887 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
888 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
889 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
890 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
891 a7399f66 Iustin Pop

892 a7399f66 Iustin Pop
  """
893 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
894 65e183af Michael Hanselmann
  OP_PARAMS = [
895 65e183af Michael Hanselmann
    _PNodeName,
896 45d4c81c Michael Hanselmann
    ("primary_ip", None, ht.NoType, "Primary IP address"),
897 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
898 45d4c81c Michael Hanselmann
    ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
899 45d4c81c Michael Hanselmann
    ("group", None, ht.TMaybeString, "Initial node group"),
900 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
901 45d4c81c Michael Hanselmann
     "Whether node can become master or master candidate"),
902 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
903 45d4c81c Michael Hanselmann
     "Whether node can host instances"),
904 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Node parameters"),
905 65e183af Michael Hanselmann
    ]
906 a8083063 Iustin Pop
907 a8083063 Iustin Pop
908 2237687b Iustin Pop
class OpNodeQuery(OpCode):
909 a8083063 Iustin Pop
  """Compute the list of nodes."""
910 65e183af Michael Hanselmann
  OP_PARAMS = [
911 65e183af Michael Hanselmann
    _POutputFields,
912 45d4c81c Michael Hanselmann
    _PUseLocking,
913 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
914 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
915 65e183af Michael Hanselmann
    ]
916 a8083063 Iustin Pop
917 a8083063 Iustin Pop
918 8ed55bfd Iustin Pop
class OpNodeQueryvols(OpCode):
919 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
920 65e183af Michael Hanselmann
  OP_PARAMS = [
921 65e183af Michael Hanselmann
    _POutputFields,
922 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
923 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
924 65e183af Michael Hanselmann
    ]
925 dcb93971 Michael Hanselmann
926 dcb93971 Michael Hanselmann
927 ad8d0595 Iustin Pop
class OpNodeQueryStorage(OpCode):
928 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
929 65e183af Michael Hanselmann
  OP_PARAMS = [
930 65e183af Michael Hanselmann
    _POutputFields,
931 65e183af Michael Hanselmann
    _PStorageType,
932 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
933 45d4c81c Michael Hanselmann
    ("name", None, ht.TMaybeString, "Storage name"),
934 9e5442ce Michael Hanselmann
    ]
935 9e5442ce Michael Hanselmann
936 9e5442ce Michael Hanselmann
937 2cee4077 Iustin Pop
class OpNodeModifyStorage(OpCode):
938 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
939 65e183af Michael Hanselmann
  OP_PARAMS = [
940 65e183af Michael Hanselmann
    _PNodeName,
941 65e183af Michael Hanselmann
    _PStorageType,
942 45d4c81c Michael Hanselmann
    _PStorageName,
943 45d4c81c Michael Hanselmann
    ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
944 efb8da02 Michael Hanselmann
    ]
945 efb8da02 Michael Hanselmann
946 efb8da02 Michael Hanselmann
947 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
948 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
949 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
950 65e183af Michael Hanselmann
  OP_PARAMS = [
951 65e183af Michael Hanselmann
    _PNodeName,
952 65e183af Michael Hanselmann
    _PStorageType,
953 45d4c81c Michael Hanselmann
    _PStorageName,
954 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
955 76aef8fc Michael Hanselmann
    ]
956 76aef8fc Michael Hanselmann
957 76aef8fc Michael Hanselmann
958 f13973c4 Iustin Pop
class OpNodeSetParams(OpCode):
959 b31c8676 Iustin Pop
  """Change the parameters of a node."""
960 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
961 65e183af Michael Hanselmann
  OP_PARAMS = [
962 65e183af Michael Hanselmann
    _PNodeName,
963 65e183af Michael Hanselmann
    _PForce,
964 45d4c81c Michael Hanselmann
    ("master_candidate", None, ht.TMaybeBool,
965 45d4c81c Michael Hanselmann
     "Whether the node should become a master candidate"),
966 45d4c81c Michael Hanselmann
    ("offline", None, ht.TMaybeBool,
967 45d4c81c Michael Hanselmann
     "Whether the node should be marked as offline"),
968 45d4c81c Michael Hanselmann
    ("drained", None, ht.TMaybeBool,
969 45d4c81c Michael Hanselmann
     "Whether the node should be marked as drained"),
970 45d4c81c Michael Hanselmann
    ("auto_promote", False, ht.TBool,
971 45d4c81c Michael Hanselmann
     "Whether node(s) should be promoted to master candidate if necessary"),
972 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
973 45d4c81c Michael Hanselmann
     "Denote whether node can become master or master candidate"),
974 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
975 45d4c81c Michael Hanselmann
     "Denote whether node can host instances"),
976 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString,
977 45d4c81c Michael Hanselmann
     "Change node's secondary IP address"),
978 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
979 45d4c81c Michael Hanselmann
    ("powered", None, ht.TMaybeBool,
980 45d4c81c Michael Hanselmann
     "Whether the node should be marked as powered"),
981 b31c8676 Iustin Pop
    ]
982 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
983 b31c8676 Iustin Pop
984 f5118ade Iustin Pop
985 e0d4735f Iustin Pop
class OpNodePowercycle(OpCode):
986 f5118ade Iustin Pop
  """Tries to powercycle a node."""
987 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
988 65e183af Michael Hanselmann
  OP_PARAMS = [
989 65e183af Michael Hanselmann
    _PNodeName,
990 65e183af Michael Hanselmann
    _PForce,
991 f5118ade Iustin Pop
    ]
992 f5118ade Iustin Pop
993 7ffc5a86 Michael Hanselmann
994 5b14a488 Iustin Pop
class OpNodeMigrate(OpCode):
995 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
996 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
997 65e183af Michael Hanselmann
  OP_PARAMS = [
998 65e183af Michael Hanselmann
    _PNodeName,
999 65e183af Michael Hanselmann
    _PMigrationMode,
1000 65e183af Michael Hanselmann
    _PMigrationLive,
1001 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1002 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1003 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1004 80cb875c Michael Hanselmann
    ]
1005 80cb875c Michael Hanselmann
1006 80cb875c Michael Hanselmann
1007 e1f23243 Michael Hanselmann
class OpNodeEvacuate(OpCode):
1008 e1f23243 Michael Hanselmann
  """Evacuate instances off a number of nodes."""
1009 e1f23243 Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1010 e1f23243 Michael Hanselmann
  OP_PARAMS = [
1011 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1012 e1f23243 Michael Hanselmann
    _PNodeName,
1013 e1f23243 Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1014 e1f23243 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1015 e1f23243 Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES),
1016 e1f23243 Michael Hanselmann
     "Node evacuation mode"),
1017 e1f23243 Michael Hanselmann
    ]
1018 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1019 e1f23243 Michael Hanselmann
1020 e1f23243 Michael Hanselmann
1021 a8083063 Iustin Pop
# instance opcodes
1022 a8083063 Iustin Pop
1023 e1530b10 Iustin Pop
class OpInstanceCreate(OpCode):
1024 9bf56d77 Michael Hanselmann
  """Create an instance.
1025 9bf56d77 Michael Hanselmann

1026 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
1027 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1028 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
1029 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1030 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
1031 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1032 dae91d02 Michael Hanselmann
    (remote import only)
1033 9bf56d77 Michael Hanselmann

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

1202 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
1203 53c776b5 Iustin Pop
  node.
1204 53c776b5 Iustin Pop

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

1208 53c776b5 Iustin Pop
  """
1209 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
1210 65e183af Michael Hanselmann
  OP_PARAMS = [
1211 65e183af Michael Hanselmann
    _PInstanceName,
1212 65e183af Michael Hanselmann
    _PMigrationMode,
1213 65e183af Michael Hanselmann
    _PMigrationLive,
1214 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1215 45d4c81c Michael Hanselmann
    ("cleanup", False, ht.TBool,
1216 45d4c81c Michael Hanselmann
     "Whether a previously failed migration should be cleaned up"),
1217 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1218 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1219 d5cafd31 René Nussbaumer
    ("allow_failover", False, ht.TBool,
1220 d5cafd31 René Nussbaumer
     "Whether we can fallback to failover if migration is not possible"),
1221 65e183af Michael Hanselmann
    ]
1222 53c776b5 Iustin Pop
1223 53c776b5 Iustin Pop
1224 0091b480 Iustin Pop
class OpInstanceMove(OpCode):
1225 313bcead Iustin Pop
  """Move an instance.
1226 313bcead Iustin Pop

1227 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
1228 313bcead Iustin Pop
  arbitrary node.
1229 313bcead Iustin Pop

1230 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
1231 313bcead Iustin Pop
  @ivar target_node: the destination node
1232 313bcead Iustin Pop

1233 313bcead Iustin Pop
  """
1234 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
1235 65e183af Michael Hanselmann
  OP_PARAMS = [
1236 65e183af Michael Hanselmann
    _PInstanceName,
1237 65e183af Michael Hanselmann
    _PShutdownTimeout,
1238 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1239 bb851c63 Iustin Pop
    _PIgnoreConsistency,
1240 154b9580 Balazs Lecz
    ]
1241 313bcead Iustin Pop
1242 313bcead Iustin Pop
1243 cc0dec7b Iustin Pop
class OpInstanceConsole(OpCode):
1244 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
1245 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1246 65e183af Michael Hanselmann
  OP_PARAMS = [
1247 65e183af Michael Hanselmann
    _PInstanceName
1248 65e183af Michael Hanselmann
    ]
1249 a8083063 Iustin Pop
1250 a8083063 Iustin Pop
1251 83f5d475 Iustin Pop
class OpInstanceActivateDisks(OpCode):
1252 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
1253 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1254 65e183af Michael Hanselmann
  OP_PARAMS = [
1255 65e183af Michael Hanselmann
    _PInstanceName,
1256 45d4c81c Michael Hanselmann
    ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1257 65e183af Michael Hanselmann
    ]
1258 a8083063 Iustin Pop
1259 a8083063 Iustin Pop
1260 e176281f Iustin Pop
class OpInstanceDeactivateDisks(OpCode):
1261 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
1262 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1263 65e183af Michael Hanselmann
  OP_PARAMS = [
1264 c9c41373 Iustin Pop
    _PInstanceName,
1265 c9c41373 Iustin Pop
    _PForce,
1266 65e183af Michael Hanselmann
    ]
1267 a8083063 Iustin Pop
1268 a8083063 Iustin Pop
1269 6b273e78 Iustin Pop
class OpInstanceRecreateDisks(OpCode):
1270 bd315bfa Iustin Pop
  """Deactivate an instance's disks."""
1271 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
1272 65e183af Michael Hanselmann
  OP_PARAMS = [
1273 65e183af Michael Hanselmann
    _PInstanceName,
1274 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1275 45d4c81c Michael Hanselmann
     "List of disk indexes"),
1276 93384b8c Guido Trotter
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1277 93384b8c Guido Trotter
     "New instance nodes, if relocation is desired"),
1278 65e183af Michael Hanselmann
    ]
1279 bd315bfa Iustin Pop
1280 bd315bfa Iustin Pop
1281 f2af0bec Iustin Pop
class OpInstanceQuery(OpCode):
1282 a8083063 Iustin Pop
  """Compute the list of instances."""
1283 65e183af Michael Hanselmann
  OP_PARAMS = [
1284 65e183af Michael Hanselmann
    _POutputFields,
1285 45d4c81c Michael Hanselmann
    _PUseLocking,
1286 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1287 45d4c81c Michael Hanselmann
     "Empty list to query all instances, instance names otherwise"),
1288 65e183af Michael Hanselmann
    ]
1289 a8083063 Iustin Pop
1290 a8083063 Iustin Pop
1291 dc28c4e4 Iustin Pop
class OpInstanceQueryData(OpCode):
1292 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
1293 65e183af Michael Hanselmann
  OP_PARAMS = [
1294 af7b6689 Michael Hanselmann
    _PUseLocking,
1295 af7b6689 Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1296 af7b6689 Michael Hanselmann
     "Instance names"),
1297 af7b6689 Michael Hanselmann
    ("static", False, ht.TBool,
1298 af7b6689 Michael Hanselmann
     "Whether to only return configuration data without querying"
1299 af7b6689 Michael Hanselmann
     " nodes"),
1300 65e183af Michael Hanselmann
    ]
1301 a8083063 Iustin Pop
1302 a8083063 Iustin Pop
1303 9a3cc7ae Iustin Pop
class OpInstanceSetParams(OpCode):
1304 a8083063 Iustin Pop
  """Change the parameters of an instance."""
1305 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1306 65e183af Michael Hanselmann
  OP_PARAMS = [
1307 65e183af Michael Hanselmann
    _PInstanceName,
1308 65e183af Michael Hanselmann
    _PForce,
1309 45d4c81c Michael Hanselmann
    _PForceVariant,
1310 526a662a Michael Hanselmann
    # TODO: Use _TestNicDef
1311 45d4c81c Michael Hanselmann
    ("nics", ht.EmptyList, ht.TList,
1312 45d4c81c Michael Hanselmann
     "List of NIC changes. Each item is of the form ``(op, settings)``."
1313 45d4c81c Michael Hanselmann
     " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
1314 45d4c81c Michael Hanselmann
     " ``%s`` to remove the last NIC or a number to modify the settings"
1315 45d4c81c Michael Hanselmann
     " of the NIC with that index." %
1316 45d4c81c Michael Hanselmann
     (constants.DDM_ADD, constants.DDM_REMOVE)),
1317 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
1318 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1319 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1320 45d4c81c Michael Hanselmann
     "Per-instance hypervisor parameters, hypervisor-dependent"),
1321 45d4c81c Michael Hanselmann
    ("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate),
1322 45d4c81c Michael Hanselmann
     "Disk template for instance"),
1323 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString,
1324 45d4c81c Michael Hanselmann
     "Secondary node (used when changing disk template)"),
1325 45d4c81c Michael Hanselmann
    ("os_name", None, ht.TMaybeString,
1326 45d4c81c Michael Hanselmann
     "Change instance's OS name. Does not reinstall the instance."),
1327 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1328 93384b8c Guido Trotter
    ("wait_for_sync", True, ht.TBool,
1329 93384b8c Guido Trotter
     "Whether to wait for the disk to synchronize, when changing template"),
1330 973d7867 Iustin Pop
    ]
1331 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1332 a8083063 Iustin Pop
1333 a8083063 Iustin Pop
1334 60472d29 Iustin Pop
class OpInstanceGrowDisk(OpCode):
1335 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
1336 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1337 65e183af Michael Hanselmann
  OP_PARAMS = [
1338 65e183af Michael Hanselmann
    _PInstanceName,
1339 45d4c81c Michael Hanselmann
    _PWaitForSync,
1340 45d4c81c Michael Hanselmann
    ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1341 45d4c81c Michael Hanselmann
    ("amount", ht.NoDefault, ht.TInt,
1342 45d4c81c Michael Hanselmann
     "Amount of disk space to add (megabytes)"),
1343 4f05fd3b Iustin Pop
    ]
1344 8729e0d7 Iustin Pop
1345 8729e0d7 Iustin Pop
1346 1aef3df8 Michael Hanselmann
class OpInstanceChangeGroup(OpCode):
1347 1aef3df8 Michael Hanselmann
  """Moves an instance to another node group."""
1348 1aef3df8 Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1349 1aef3df8 Michael Hanselmann
  OP_PARAMS = [
1350 1aef3df8 Michael Hanselmann
    _PInstanceName,
1351 1aef3df8 Michael Hanselmann
    _PEarlyRelease,
1352 1aef3df8 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1353 1aef3df8 Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1354 1aef3df8 Michael Hanselmann
     "Destination group names or UUIDs (defaults to \"all but current group\""),
1355 1aef3df8 Michael Hanselmann
    ]
1356 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1357 1aef3df8 Michael Hanselmann
1358 1aef3df8 Michael Hanselmann
1359 70a6a926 Adeodato Simo
# Node group opcodes
1360 70a6a926 Adeodato Simo
1361 fabf1731 Iustin Pop
class OpGroupAdd(OpCode):
1362 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
1363 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1364 65e183af Michael Hanselmann
  OP_PARAMS = [
1365 65e183af Michael Hanselmann
    _PGroupName,
1366 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1367 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1368 483be60d Adeodato Simo
    ]
1369 b1ee5610 Adeodato Simo
1370 b1ee5610 Adeodato Simo
1371 934704ae Iustin Pop
class OpGroupAssignNodes(OpCode):
1372 96276ae7 Adeodato Simo
  """Assign nodes to a node group."""
1373 96276ae7 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1374 96276ae7 Adeodato Simo
  OP_PARAMS = [
1375 96276ae7 Adeodato Simo
    _PGroupName,
1376 96276ae7 Adeodato Simo
    _PForce,
1377 45d4c81c Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1378 45d4c81c Michael Hanselmann
     "List of nodes to assign"),
1379 96276ae7 Adeodato Simo
    ]
1380 96276ae7 Adeodato Simo
1381 96276ae7 Adeodato Simo
1382 d4d654bd Iustin Pop
class OpGroupQuery(OpCode):
1383 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
1384 65e183af Michael Hanselmann
  OP_PARAMS = [
1385 65e183af Michael Hanselmann
    _POutputFields,
1386 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1387 45d4c81c Michael Hanselmann
     "Empty list to query all groups, group names otherwise"),
1388 65e183af Michael Hanselmann
    ]
1389 70a6a926 Adeodato Simo
1390 70a6a926 Adeodato Simo
1391 7cbf74f0 Iustin Pop
class OpGroupSetParams(OpCode):
1392 4da7909a Adeodato Simo
  """Change the parameters of a node group."""
1393 4da7909a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1394 65e183af Michael Hanselmann
  OP_PARAMS = [
1395 65e183af Michael Hanselmann
    _PGroupName,
1396 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1397 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1398 4da7909a Adeodato Simo
    ]
1399 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1400 4da7909a Adeodato Simo
1401 4da7909a Adeodato Simo
1402 4d1baa51 Iustin Pop
class OpGroupRemove(OpCode):
1403 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
1404 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1405 65e183af Michael Hanselmann
  OP_PARAMS = [
1406 65e183af Michael Hanselmann
    _PGroupName,
1407 65e183af Michael Hanselmann
    ]
1408 94bd652a Adeodato Simo
1409 94bd652a Adeodato Simo
1410 a8173e82 Iustin Pop
class OpGroupRename(OpCode):
1411 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
1412 65e183af Michael Hanselmann
  OP_PARAMS = [
1413 12da663a Michael Hanselmann
    _PGroupName,
1414 12da663a Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1415 65e183af Michael Hanselmann
    ]
1416 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1417 4fe5cf90 Adeodato Simo
1418 4fe5cf90 Adeodato Simo
1419 08f8c82c Michael Hanselmann
class OpGroupEvacuate(OpCode):
1420 08f8c82c Michael Hanselmann
  """Evacuate a node group in the cluster."""
1421 08f8c82c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
1422 08f8c82c Michael Hanselmann
  OP_PARAMS = [
1423 08f8c82c Michael Hanselmann
    _PGroupName,
1424 08f8c82c Michael Hanselmann
    _PEarlyRelease,
1425 08f8c82c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1426 08f8c82c Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1427 08f8c82c Michael Hanselmann
     "Destination group names or UUIDs"),
1428 08f8c82c Michael Hanselmann
    ]
1429 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1430 08f8c82c Michael Hanselmann
1431 08f8c82c Michael Hanselmann
1432 a8083063 Iustin Pop
# OS opcodes
1433 da2d02e7 Iustin Pop
class OpOsDiagnose(OpCode):
1434 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
1435 65e183af Michael Hanselmann
  OP_PARAMS = [
1436 65e183af Michael Hanselmann
    _POutputFields,
1437 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1438 45d4c81c Michael Hanselmann
     "Which operating systems to diagnose"),
1439 65e183af Michael Hanselmann
    ]
1440 a8083063 Iustin Pop
1441 7c0d6283 Michael Hanselmann
1442 a8083063 Iustin Pop
# Exports opcodes
1443 7ca2d4d8 Iustin Pop
class OpBackupQuery(OpCode):
1444 a8083063 Iustin Pop
  """Compute the list of exported images."""
1445 65e183af Michael Hanselmann
  OP_PARAMS = [
1446 45d4c81c Michael Hanselmann
    _PUseLocking,
1447 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1448 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1449 65e183af Michael Hanselmann
    ]
1450 a8083063 Iustin Pop
1451 7c0d6283 Michael Hanselmann
1452 71910715 Iustin Pop
class OpBackupPrepare(OpCode):
1453 1410fa8d Michael Hanselmann
  """Prepares an instance export.
1454 1410fa8d Michael Hanselmann

1455 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
1456 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1457 1410fa8d Michael Hanselmann

1458 1410fa8d Michael Hanselmann
  """
1459 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1460 65e183af Michael Hanselmann
  OP_PARAMS = [
1461 65e183af Michael Hanselmann
    _PInstanceName,
1462 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1463 45d4c81c Michael Hanselmann
     "Export mode"),
1464 1410fa8d Michael Hanselmann
    ]
1465 1410fa8d Michael Hanselmann
1466 1410fa8d Michael Hanselmann
1467 4ff922a2 Iustin Pop
class OpBackupExport(OpCode):
1468 4a96f1d1 Michael Hanselmann
  """Export an instance.
1469 4a96f1d1 Michael Hanselmann

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

1476 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1477 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
1478 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
1479 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1480 4a96f1d1 Michael Hanselmann
                             only)
1481 4a96f1d1 Michael Hanselmann

1482 4a96f1d1 Michael Hanselmann
  """
1483 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1484 65e183af Michael Hanselmann
  OP_PARAMS = [
1485 65e183af Michael Hanselmann
    _PInstanceName,
1486 65e183af Michael Hanselmann
    _PShutdownTimeout,
1487 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
1488 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
1489 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1490 45d4c81c Michael Hanselmann
     "Destination information, depends on export mode"),
1491 45d4c81c Michael Hanselmann
    ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1492 45d4c81c Michael Hanselmann
    ("remove_instance", False, ht.TBool,
1493 45d4c81c Michael Hanselmann
     "Whether to remove instance after export"),
1494 45d4c81c Michael Hanselmann
    ("ignore_remove_failures", False, ht.TBool,
1495 45d4c81c Michael Hanselmann
     "Whether to ignore failures while removing instances"),
1496 45d4c81c Michael Hanselmann
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1497 45d4c81c Michael Hanselmann
     "Export mode"),
1498 45d4c81c Michael Hanselmann
    ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1499 45d4c81c Michael Hanselmann
     "Name of X509 key (remote export only)"),
1500 45d4c81c Michael Hanselmann
    ("destination_x509_ca", None, ht.TMaybeString,
1501 45d4c81c Michael Hanselmann
     "Destination X509 CA (remote export only)"),
1502 17c3f802 Guido Trotter
    ]
1503 5c947f38 Iustin Pop
1504 0a7bed64 Michael Hanselmann
1505 ca5890ad Iustin Pop
class OpBackupRemove(OpCode):
1506 9ac99fda Guido Trotter
  """Remove an instance's export."""
1507 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1508 65e183af Michael Hanselmann
  OP_PARAMS = [
1509 65e183af Michael Hanselmann
    _PInstanceName,
1510 65e183af Michael Hanselmann
    ]
1511 5c947f38 Iustin Pop
1512 0a7bed64 Michael Hanselmann
1513 5c947f38 Iustin Pop
# Tags opcodes
1514 c6afb1ca Iustin Pop
class OpTagsGet(OpCode):
1515 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
1516 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
1517 65e183af Michael Hanselmann
  OP_PARAMS = [
1518 65e183af Michael Hanselmann
    _PTagKind,
1519 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1520 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1521 65e183af Michael Hanselmann
    ]
1522 5c947f38 Iustin Pop
1523 5c947f38 Iustin Pop
1524 715462e7 Iustin Pop
class OpTagsSearch(OpCode):
1525 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
1526 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
1527 65e183af Michael Hanselmann
  OP_PARAMS = [
1528 197b323b Michael Hanselmann
    ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
1529 65e183af Michael Hanselmann
    ]
1530 73415719 Iustin Pop
1531 73415719 Iustin Pop
1532 d1602edc Iustin Pop
class OpTagsSet(OpCode):
1533 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
1534 65e183af Michael Hanselmann
  OP_PARAMS = [
1535 65e183af Michael Hanselmann
    _PTagKind,
1536 65e183af Michael Hanselmann
    _PTags,
1537 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1538 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1539 65e183af Michael Hanselmann
    ]
1540 5c947f38 Iustin Pop
1541 5c947f38 Iustin Pop
1542 3f0ab95f Iustin Pop
class OpTagsDel(OpCode):
1543 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
1544 65e183af Michael Hanselmann
  OP_PARAMS = [
1545 65e183af Michael Hanselmann
    _PTagKind,
1546 65e183af Michael Hanselmann
    _PTags,
1547 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1548 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1549 65e183af Michael Hanselmann
    ]
1550 06009e27 Iustin Pop
1551 e687ec01 Michael Hanselmann
1552 06009e27 Iustin Pop
# Test opcodes
1553 06009e27 Iustin Pop
class OpTestDelay(OpCode):
1554 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
1555 06009e27 Iustin Pop

1556 06009e27 Iustin Pop
  This is used just for debugging and testing.
1557 06009e27 Iustin Pop

1558 06009e27 Iustin Pop
  Parameters:
1559 06009e27 Iustin Pop
    - duration: the time to sleep
1560 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
1561 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
1562 06009e27 Iustin Pop

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

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

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

1573 06009e27 Iustin Pop
  """
1574 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
1575 65e183af Michael Hanselmann
  OP_PARAMS = [
1576 b795a775 Michael Hanselmann
    ("duration", ht.NoDefault, ht.TNumber, None),
1577 197b323b Michael Hanselmann
    ("on_master", True, ht.TBool, None),
1578 197b323b Michael Hanselmann
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1579 197b323b Michael Hanselmann
    ("repeat", 0, ht.TPositiveInt, None),
1580 65e183af Michael Hanselmann
    ]
1581 d61df03e Iustin Pop
1582 d61df03e Iustin Pop
1583 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
1584 d61df03e Iustin Pop
  """Allocator framework testing.
1585 d61df03e Iustin Pop

1586 d61df03e Iustin Pop
  This opcode has two modes:
1587 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
1588 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
1589 d61df03e Iustin Pop
      'in')
1590 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
1591 d61df03e Iustin Pop
      return the allocator output (direction 'out')
1592 d61df03e Iustin Pop

1593 d61df03e Iustin Pop
  """
1594 60dd1473 Iustin Pop
  OP_DSC_FIELD = "allocator"
1595 65e183af Michael Hanselmann
  OP_PARAMS = [
1596 65e183af Michael Hanselmann
    ("direction", ht.NoDefault,
1597 197b323b Michael Hanselmann
     ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1598 197b323b Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1599 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
1600 65e183af Michael Hanselmann
    ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
1601 fdbe29ee Michael Hanselmann
     ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
1602 45d4c81c Michael Hanselmann
                ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
1603 197b323b Michael Hanselmann
    ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1604 197b323b Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, None),
1605 197b323b Michael Hanselmann
    ("allocator", None, ht.TMaybeString, None),
1606 197b323b Michael Hanselmann
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1607 dd47a0f0 Iustin Pop
    ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1608 197b323b Michael Hanselmann
    ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1609 197b323b Michael Hanselmann
    ("os", None, ht.TMaybeString, None),
1610 197b323b Michael Hanselmann
    ("disk_template", None, ht.TMaybeString, None),
1611 bee581e2 Michael Hanselmann
    ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1612 bee581e2 Michael Hanselmann
     None),
1613 60152bbe Michael Hanselmann
    ("evac_mode", None,
1614 60152bbe Michael Hanselmann
     ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1615 bee581e2 Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1616 bee581e2 Michael Hanselmann
     None),
1617 d61df03e Iustin Pop
    ]
1618 363acb1e Iustin Pop
1619 76aef8fc Michael Hanselmann
1620 b469eb4d Iustin Pop
class OpTestJqueue(OpCode):
1621 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
1622 e58f87a9 Michael Hanselmann

1623 e58f87a9 Michael Hanselmann
  """
1624 65e183af Michael Hanselmann
  OP_PARAMS = [
1625 197b323b Michael Hanselmann
    ("notify_waitlock", False, ht.TBool, None),
1626 197b323b Michael Hanselmann
    ("notify_exec", False, ht.TBool, None),
1627 197b323b Michael Hanselmann
    ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1628 197b323b Michael Hanselmann
    ("fail", False, ht.TBool, None),
1629 e58f87a9 Michael Hanselmann
    ]
1630 e58f87a9 Michael Hanselmann
1631 e58f87a9 Michael Hanselmann
1632 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
1633 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
1634 be760ba8 Michael Hanselmann

1635 be760ba8 Michael Hanselmann
  """
1636 65e183af Michael Hanselmann
  OP_PARAMS = [
1637 197b323b Michael Hanselmann
    ("result", ht.NoDefault, ht.NoType, None),
1638 197b323b Michael Hanselmann
    ("messages", ht.NoDefault, ht.NoType, None),
1639 197b323b Michael Hanselmann
    ("fail", ht.NoDefault, ht.NoType, None),
1640 6a373640 Michael Hanselmann
    ("submit_jobs", None, ht.NoType, None),
1641 be760ba8 Michael Hanselmann
    ]
1642 687c10d9 Iustin Pop
  WITH_LU = False
1643 be760ba8 Michael Hanselmann
1644 be760ba8 Michael Hanselmann
1645 dbc96028 Michael Hanselmann
def _GetOpList():
1646 dbc96028 Michael Hanselmann
  """Returns list of all defined opcodes.
1647 dbc96028 Michael Hanselmann

1648 dbc96028 Michael Hanselmann
  Does not eliminate duplicates by C{OP_ID}.
1649 dbc96028 Michael Hanselmann

1650 dbc96028 Michael Hanselmann
  """
1651 dbc96028 Michael Hanselmann
  return [v for v in globals().values()
1652 dbc96028 Michael Hanselmann
          if (isinstance(v, type) and issubclass(v, OpCode) and
1653 687c10d9 Iustin Pop
              hasattr(v, "OP_ID") and v is not OpCode)]
1654 dbc96028 Michael Hanselmann
1655 dbc96028 Michael Hanselmann
1656 dbc96028 Michael Hanselmann
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())