Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ f2af0bec

History | View | Annotate | Download (37 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 a8083063 Iustin Pop
# pylint: disable-msg=R0903
35 a8083063 Iustin Pop
36 1cbef6d8 Michael Hanselmann
import logging
37 1cbef6d8 Michael Hanselmann
38 65e183af Michael Hanselmann
from ganeti import constants
39 65e183af Michael Hanselmann
from ganeti import errors
40 65e183af Michael Hanselmann
from ganeti import ht
41 65e183af Michael Hanselmann
42 65e183af Michael Hanselmann
43 65e183af Michael Hanselmann
# Common opcode attributes
44 65e183af Michael Hanselmann
45 65e183af Michael Hanselmann
#: output fields for a query operation
46 65e183af Michael Hanselmann
_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString))
47 65e183af Michael Hanselmann
48 65e183af Michael Hanselmann
#: the shutdown timeout
49 65e183af Michael Hanselmann
_PShutdownTimeout = ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
50 65e183af Michael Hanselmann
                     ht.TPositiveInt)
51 65e183af Michael Hanselmann
52 65e183af Michael Hanselmann
#: the force parameter
53 65e183af Michael Hanselmann
_PForce = ("force", False, ht.TBool)
54 65e183af Michael Hanselmann
55 65e183af Michael Hanselmann
#: a required instance name (for single-instance LUs)
56 65e183af Michael Hanselmann
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString)
57 65e183af Michael Hanselmann
58 65e183af Michael Hanselmann
#: Whether to ignore offline nodes
59 65e183af Michael Hanselmann
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool)
60 65e183af Michael Hanselmann
61 65e183af Michael Hanselmann
#: a required node name (for single-node LUs)
62 65e183af Michael Hanselmann
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString)
63 65e183af Michael Hanselmann
64 65e183af Michael Hanselmann
#: a required node group name (for single-group LUs)
65 65e183af Michael Hanselmann
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString)
66 65e183af Michael Hanselmann
67 65e183af Michael Hanselmann
#: Migration type (live/non-live)
68 65e183af Michael Hanselmann
_PMigrationMode = ("mode", None,
69 65e183af Michael Hanselmann
                   ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)))
70 65e183af Michael Hanselmann
71 65e183af Michael Hanselmann
#: Obsolete 'live' migration mode (boolean)
72 65e183af Michael Hanselmann
_PMigrationLive = ("live", None, ht.TMaybeBool)
73 65e183af Michael Hanselmann
74 65e183af Michael Hanselmann
#: Tag type
75 65e183af Michael Hanselmann
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES))
76 65e183af Michael Hanselmann
77 65e183af Michael Hanselmann
#: List of tag strings
78 65e183af Michael Hanselmann
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString))
79 65e183af Michael Hanselmann
80 65e183af Michael Hanselmann
81 65e183af Michael Hanselmann
def RequireFileStorage():
82 65e183af Michael Hanselmann
  """Checks that file storage is enabled.
83 65e183af Michael Hanselmann

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

87 65e183af Michael Hanselmann
  @raise errors.OpPrereqError: when file storage is disabled
88 65e183af Michael Hanselmann

89 65e183af Michael Hanselmann
  """
90 65e183af Michael Hanselmann
  if not constants.ENABLE_FILE_STORAGE:
91 65e183af Michael Hanselmann
    raise errors.OpPrereqError("File storage disabled at configure time",
92 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
93 65e183af Michael Hanselmann
94 65e183af Michael Hanselmann
95 65e183af Michael Hanselmann
def _CheckDiskTemplate(template):
96 65e183af Michael Hanselmann
  """Ensure a given disk template is valid.
97 65e183af Michael Hanselmann

98 65e183af Michael Hanselmann
  """
99 65e183af Michael Hanselmann
  if template not in constants.DISK_TEMPLATES:
100 65e183af Michael Hanselmann
    # Using str.join directly to avoid importing utils for CommaJoin
101 65e183af Michael Hanselmann
    msg = ("Invalid disk template name '%s', valid templates are: %s" %
102 65e183af Michael Hanselmann
           (template, ", ".join(constants.DISK_TEMPLATES)))
103 65e183af Michael Hanselmann
    raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
104 65e183af Michael Hanselmann
  if template == constants.DT_FILE:
105 65e183af Michael Hanselmann
    RequireFileStorage()
106 65e183af Michael Hanselmann
  return True
107 65e183af Michael Hanselmann
108 65e183af Michael Hanselmann
109 65e183af Michael Hanselmann
def _CheckStorageType(storage_type):
110 65e183af Michael Hanselmann
  """Ensure a given storage type is valid.
111 65e183af Michael Hanselmann

112 65e183af Michael Hanselmann
  """
113 65e183af Michael Hanselmann
  if storage_type not in constants.VALID_STORAGE_TYPES:
114 65e183af Michael Hanselmann
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
115 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
116 65e183af Michael Hanselmann
  if storage_type == constants.ST_FILE:
117 65e183af Michael Hanselmann
    RequireFileStorage()
118 65e183af Michael Hanselmann
  return True
119 65e183af Michael Hanselmann
120 65e183af Michael Hanselmann
121 65e183af Michael Hanselmann
#: Storage type parameter
122 65e183af Michael Hanselmann
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType)
123 65e183af Michael Hanselmann
124 65e183af Michael Hanselmann
125 65e183af Michael Hanselmann
class _AutoOpParamSlots(type):
126 65e183af Michael Hanselmann
  """Meta class for opcode definitions.
127 65e183af Michael Hanselmann

128 65e183af Michael Hanselmann
  """
129 65e183af Michael Hanselmann
  def __new__(mcs, name, bases, attrs):
130 65e183af Michael Hanselmann
    """Called when a class should be created.
131 65e183af Michael Hanselmann

132 65e183af Michael Hanselmann
    @param mcs: The meta class
133 65e183af Michael Hanselmann
    @param name: Name of created class
134 65e183af Michael Hanselmann
    @param bases: Base classes
135 65e183af Michael Hanselmann
    @type attrs: dict
136 65e183af Michael Hanselmann
    @param attrs: Class attributes
137 65e183af Michael Hanselmann

138 65e183af Michael Hanselmann
    """
139 65e183af Michael Hanselmann
    assert "__slots__" not in attrs, \
140 65e183af Michael Hanselmann
      "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
141 65e183af Michael Hanselmann
    assert "OP_ID" in attrs, "Class '%s' is missing OP_ID attribute" % name
142 65e183af Michael Hanselmann
143 65e183af Michael Hanselmann
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
144 65e183af Michael Hanselmann
    params = attrs.setdefault("OP_PARAMS", [])
145 65e183af Michael Hanselmann
146 65e183af Michael Hanselmann
    # Use parameter names as slots
147 65e183af Michael Hanselmann
    slots = [pname for (pname, _, _) in params]
148 65e183af Michael Hanselmann
149 65e183af Michael Hanselmann
    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
150 65e183af Michael Hanselmann
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name
151 65e183af Michael Hanselmann
152 65e183af Michael Hanselmann
    attrs["__slots__"] = slots
153 65e183af Michael Hanselmann
154 65e183af Michael Hanselmann
    return type.__new__(mcs, name, bases, attrs)
155 65e183af Michael Hanselmann
156 df458e0b Iustin Pop
157 0e46916d Iustin Pop
class BaseOpCode(object):
158 df458e0b Iustin Pop
  """A simple serializable object.
159 df458e0b Iustin Pop

160 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
161 0e46916d Iustin Pop
  field handling.
162 0e46916d Iustin Pop

163 df458e0b Iustin Pop
  """
164 65e183af Michael Hanselmann
  __metaclass__ = _AutoOpParamSlots
165 65e183af Michael Hanselmann
166 65e183af Michael Hanselmann
  OP_ID = None
167 a8083063 Iustin Pop
168 a8083063 Iustin Pop
  def __init__(self, **kwargs):
169 a7399f66 Iustin Pop
    """Constructor for BaseOpCode.
170 a7399f66 Iustin Pop

171 a7399f66 Iustin Pop
    The constructor takes only keyword arguments and will set
172 a7399f66 Iustin Pop
    attributes on this object based on the passed arguments. As such,
173 a7399f66 Iustin Pop
    it means that you should not pass arguments which are not in the
174 a7399f66 Iustin Pop
    __slots__ attribute for this class.
175 a7399f66 Iustin Pop

176 a7399f66 Iustin Pop
    """
177 adf385c7 Iustin Pop
    slots = self._all_slots()
178 a8083063 Iustin Pop
    for key in kwargs:
179 adf385c7 Iustin Pop
      if key not in slots:
180 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
181 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
182 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
183 a8083063 Iustin Pop
184 df458e0b Iustin Pop
  def __getstate__(self):
185 a7399f66 Iustin Pop
    """Generic serializer.
186 a7399f66 Iustin Pop

187 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
188 a7399f66 Iustin Pop
    dictionary.
189 a7399f66 Iustin Pop

190 a7399f66 Iustin Pop
    @rtype:  C{dict}
191 a7399f66 Iustin Pop
    @return: the instance attributes and their values
192 a7399f66 Iustin Pop

193 a7399f66 Iustin Pop
    """
194 df458e0b Iustin Pop
    state = {}
195 adf385c7 Iustin Pop
    for name in self._all_slots():
196 df458e0b Iustin Pop
      if hasattr(self, name):
197 df458e0b Iustin Pop
        state[name] = getattr(self, name)
198 df458e0b Iustin Pop
    return state
199 df458e0b Iustin Pop
200 df458e0b Iustin Pop
  def __setstate__(self, state):
201 a7399f66 Iustin Pop
    """Generic unserializer.
202 a7399f66 Iustin Pop

203 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
204 a7399f66 Iustin Pop
    of the current instance.
205 a7399f66 Iustin Pop

206 a7399f66 Iustin Pop
    @param state: the serialized opcode data
207 a7399f66 Iustin Pop
    @type state:  C{dict}
208 a7399f66 Iustin Pop

209 a7399f66 Iustin Pop
    """
210 df458e0b Iustin Pop
    if not isinstance(state, dict):
211 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
212 df458e0b Iustin Pop
                       type(state))
213 df458e0b Iustin Pop
214 adf385c7 Iustin Pop
    for name in self._all_slots():
215 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
216 df458e0b Iustin Pop
        delattr(self, name)
217 df458e0b Iustin Pop
218 df458e0b Iustin Pop
    for name in state:
219 df458e0b Iustin Pop
      setattr(self, name, state[name])
220 df458e0b Iustin Pop
221 adf385c7 Iustin Pop
  @classmethod
222 adf385c7 Iustin Pop
  def _all_slots(cls):
223 adf385c7 Iustin Pop
    """Compute the list of all declared slots for a class.
224 adf385c7 Iustin Pop

225 adf385c7 Iustin Pop
    """
226 adf385c7 Iustin Pop
    slots = []
227 adf385c7 Iustin Pop
    for parent in cls.__mro__:
228 adf385c7 Iustin Pop
      slots.extend(getattr(parent, "__slots__", []))
229 adf385c7 Iustin Pop
    return slots
230 adf385c7 Iustin Pop
231 65e183af Michael Hanselmann
  @classmethod
232 65e183af Michael Hanselmann
  def GetAllParams(cls):
233 65e183af Michael Hanselmann
    """Compute list of all parameters for an opcode.
234 65e183af Michael Hanselmann

235 65e183af Michael Hanselmann
    """
236 65e183af Michael Hanselmann
    slots = []
237 65e183af Michael Hanselmann
    for parent in cls.__mro__:
238 65e183af Michael Hanselmann
      slots.extend(getattr(parent, "OP_PARAMS", []))
239 65e183af Michael Hanselmann
    return slots
240 65e183af Michael Hanselmann
241 1cbef6d8 Michael Hanselmann
  def Validate(self, set_defaults):
242 1cbef6d8 Michael Hanselmann
    """Validate opcode parameters, optionally setting default values.
243 1cbef6d8 Michael Hanselmann

244 1cbef6d8 Michael Hanselmann
    @type set_defaults: bool
245 1cbef6d8 Michael Hanselmann
    @param set_defaults: Whether to set default values
246 1cbef6d8 Michael Hanselmann
    @raise errors.OpPrereqError: When a parameter value doesn't match
247 1cbef6d8 Michael Hanselmann
                                 requirements
248 1cbef6d8 Michael Hanselmann

249 1cbef6d8 Michael Hanselmann
    """
250 1cbef6d8 Michael Hanselmann
    for (attr_name, default, test) in self.GetAllParams():
251 1cbef6d8 Michael Hanselmann
      assert test == ht.NoType or callable(test)
252 1cbef6d8 Michael Hanselmann
253 1cbef6d8 Michael Hanselmann
      if not hasattr(self, attr_name):
254 1cbef6d8 Michael Hanselmann
        if default == ht.NoDefault:
255 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
256 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
257 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
258 1cbef6d8 Michael Hanselmann
        elif set_defaults:
259 1cbef6d8 Michael Hanselmann
          if callable(default):
260 1cbef6d8 Michael Hanselmann
            dval = default()
261 1cbef6d8 Michael Hanselmann
          else:
262 1cbef6d8 Michael Hanselmann
            dval = default
263 1cbef6d8 Michael Hanselmann
          setattr(self, attr_name, dval)
264 1cbef6d8 Michael Hanselmann
265 1cbef6d8 Michael Hanselmann
      if test == ht.NoType:
266 1cbef6d8 Michael Hanselmann
        # no tests here
267 1cbef6d8 Michael Hanselmann
        continue
268 1cbef6d8 Michael Hanselmann
269 1cbef6d8 Michael Hanselmann
      if set_defaults or hasattr(self, attr_name):
270 1cbef6d8 Michael Hanselmann
        attr_val = getattr(self, attr_name)
271 1cbef6d8 Michael Hanselmann
        if not test(attr_val):
272 1cbef6d8 Michael Hanselmann
          logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
273 1cbef6d8 Michael Hanselmann
                        self.OP_ID, attr_name, type(attr_val), attr_val)
274 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
275 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
276 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
277 1cbef6d8 Michael Hanselmann
278 df458e0b Iustin Pop
279 0e46916d Iustin Pop
class OpCode(BaseOpCode):
280 a7399f66 Iustin Pop
  """Abstract OpCode.
281 a7399f66 Iustin Pop

282 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
283 a7399f66 Iustin Pop
  from this class should override OP_ID.
284 a7399f66 Iustin Pop

285 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
286 20777413 Iustin Pop
               children of this class.
287 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
288 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
289 bde8f481 Adeodato Simo
                      method for details).
290 65e183af Michael Hanselmann
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
291 65e183af Michael Hanselmann
                   get if not already defined, and types they must match.
292 687c10d9 Iustin Pop
  @cvar WITH_LU: Boolean that specifies whether this should be included in
293 687c10d9 Iustin Pop
      mcpu's dispatch table
294 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
295 20777413 Iustin Pop
                 the check steps
296 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
297 a7399f66 Iustin Pop

298 a7399f66 Iustin Pop
  """
299 df458e0b Iustin Pop
  OP_ID = "OP_ABSTRACT"
300 687c10d9 Iustin Pop
  WITH_LU = True
301 65e183af Michael Hanselmann
  OP_PARAMS = [
302 65e183af Michael Hanselmann
    ("dry_run", None, ht.TMaybeBool),
303 65e183af Michael Hanselmann
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt)),
304 65e183af Michael Hanselmann
    ("priority", constants.OP_PRIO_DEFAULT,
305 65e183af Michael Hanselmann
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID)),
306 65e183af Michael Hanselmann
    ]
307 df458e0b Iustin Pop
308 df458e0b Iustin Pop
  def __getstate__(self):
309 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
310 df458e0b Iustin Pop

311 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
312 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
313 a7399f66 Iustin Pop
    instantiating the opcode.
314 a7399f66 Iustin Pop

315 a7399f66 Iustin Pop
    @rtype:   C{dict}
316 a7399f66 Iustin Pop
    @return:  the state as a dictionary
317 a7399f66 Iustin Pop

318 df458e0b Iustin Pop
    """
319 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
320 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
321 df458e0b Iustin Pop
    return data
322 df458e0b Iustin Pop
323 df458e0b Iustin Pop
  @classmethod
324 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
325 df458e0b Iustin Pop
    """Generic load opcode method.
326 df458e0b Iustin Pop

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

331 a7399f66 Iustin Pop
    @type data:  C{dict}
332 a7399f66 Iustin Pop
    @param data: the serialized opcode
333 a7399f66 Iustin Pop

334 df458e0b Iustin Pop
    """
335 df458e0b Iustin Pop
    if not isinstance(data, dict):
336 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
337 df458e0b Iustin Pop
    if "OP_ID" not in data:
338 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
339 df458e0b Iustin Pop
    op_id = data["OP_ID"]
340 df458e0b Iustin Pop
    op_class = None
341 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
342 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
343 363acb1e Iustin Pop
    else:
344 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
345 df458e0b Iustin Pop
                       op_id)
346 df458e0b Iustin Pop
    op = op_class()
347 df458e0b Iustin Pop
    new_data = data.copy()
348 df458e0b Iustin Pop
    del new_data["OP_ID"]
349 df458e0b Iustin Pop
    op.__setstate__(new_data)
350 df458e0b Iustin Pop
    return op
351 df458e0b Iustin Pop
352 60dd1473 Iustin Pop
  def Summary(self):
353 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
354 60dd1473 Iustin Pop

355 bde8f481 Adeodato Simo
    The summary is the value of the OP_ID attribute (without the "OP_" prefix),
356 bde8f481 Adeodato Simo
    plus the value of the OP_DSC_FIELD attribute, if one was defined; this field
357 bde8f481 Adeodato Simo
    should allow to easily identify the operation (for an instance creation job,
358 bde8f481 Adeodato Simo
    e.g., it would be the instance name).
359 bde8f481 Adeodato Simo

360 60dd1473 Iustin Pop
    """
361 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
362 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
363 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
364 60dd1473 Iustin Pop
    if field_name:
365 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
366 bc8bbda1 Iustin Pop
      if isinstance(field_value, (list, tuple)):
367 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
368 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
369 60dd1473 Iustin Pop
    return txt
370 60dd1473 Iustin Pop
371 a8083063 Iustin Pop
372 afee0879 Iustin Pop
# cluster opcodes
373 afee0879 Iustin Pop
374 bc84ffa7 Iustin Pop
class OpClusterPostInit(OpCode):
375 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
376 b5f5fae9 Luca Bigliardi

377 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
378 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
379 b5f5fae9 Luca Bigliardi

380 b5f5fae9 Luca Bigliardi
  """
381 b5f5fae9 Luca Bigliardi
  OP_ID = "OP_CLUSTER_POST_INIT"
382 b5f5fae9 Luca Bigliardi
383 b5f5fae9 Luca Bigliardi
384 c6d43e9e Iustin Pop
class OpClusterDestroy(OpCode):
385 a7399f66 Iustin Pop
  """Destroy the cluster.
386 a7399f66 Iustin Pop

387 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
388 a7399f66 Iustin Pop
  lost after the execution of this opcode.
389 a7399f66 Iustin Pop

390 a7399f66 Iustin Pop
  """
391 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DESTROY"
392 a8083063 Iustin Pop
393 a8083063 Iustin Pop
394 a2f7ab92 Iustin Pop
class OpClusterQuery(OpCode):
395 fdc267f4 Iustin Pop
  """Query cluster information."""
396 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_QUERY"
397 a8083063 Iustin Pop
398 a8083063 Iustin Pop
399 a3d32770 Iustin Pop
class OpClusterVerify(OpCode):
400 a7399f66 Iustin Pop
  """Verify the cluster state.
401 a7399f66 Iustin Pop

402 a7399f66 Iustin Pop
  @type skip_checks: C{list}
403 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
404 a7399f66 Iustin Pop
                     needs to be a subset of
405 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
406 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
407 a7399f66 Iustin Pop

408 a7399f66 Iustin Pop
  """
409 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY"
410 65e183af Michael Hanselmann
  OP_PARAMS = [
411 65e183af Michael Hanselmann
    ("skip_checks", ht.EmptyList,
412 65e183af Michael Hanselmann
     ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS))),
413 65e183af Michael Hanselmann
    ("verbose", False, ht.TBool),
414 65e183af Michael Hanselmann
    ("error_codes", False, ht.TBool),
415 65e183af Michael Hanselmann
    ("debug_simulate_errors", False, ht.TBool),
416 65e183af Michael Hanselmann
    ]
417 a8083063 Iustin Pop
418 a8083063 Iustin Pop
419 bd8210a7 Iustin Pop
class OpClusterVerifyDisks(OpCode):
420 150e978f Iustin Pop
  """Verify the cluster disks.
421 150e978f Iustin Pop

422 150e978f Iustin Pop
  Parameters: none
423 150e978f Iustin Pop

424 5188ab37 Iustin Pop
  Result: a tuple of four elements:
425 150e978f Iustin Pop
    - list of node names with bad data returned (unreachable, etc.)
426 a7399f66 Iustin Pop
    - dict of node names with broken volume groups (values: error msg)
427 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
428 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
429 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
430 150e978f Iustin Pop

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

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

439 150e978f Iustin Pop
  """
440 150e978f Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
441 150e978f Iustin Pop
442 150e978f Iustin Pop
443 5d01aca3 Iustin Pop
class OpClusterRepairDiskSizes(OpCode):
444 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
445 60975797 Iustin Pop
  mimatches.
446 60975797 Iustin Pop

447 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
448 60975797 Iustin Pop
  checks to only a subset of the instances.
449 60975797 Iustin Pop

450 60975797 Iustin Pop
  Result: a list of tuples, (instance, disk, new-size) for changed
451 60975797 Iustin Pop
  configurations.
452 60975797 Iustin Pop

453 60975797 Iustin Pop
  In normal operation, the list should be empty.
454 60975797 Iustin Pop

455 60975797 Iustin Pop
  @type instances: list
456 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
457 60975797 Iustin Pop

458 60975797 Iustin Pop
  """
459 60975797 Iustin Pop
  OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
460 65e183af Michael Hanselmann
  OP_PARAMS = [
461 65e183af Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
462 65e183af Michael Hanselmann
    ]
463 60975797 Iustin Pop
464 60975797 Iustin Pop
465 2f093ea0 Iustin Pop
class OpClusterConfigQuery(OpCode):
466 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
467 ae5849b5 Michael Hanselmann
  OP_ID = "OP_CLUSTER_CONFIG_QUERY"
468 65e183af Michael Hanselmann
  OP_PARAMS = [
469 65e183af Michael Hanselmann
    _POutputFields
470 65e183af Michael Hanselmann
    ]
471 a8083063 Iustin Pop
472 a8083063 Iustin Pop
473 e126df25 Iustin Pop
class OpClusterRename(OpCode):
474 a7399f66 Iustin Pop
  """Rename the cluster.
475 a7399f66 Iustin Pop

476 a7399f66 Iustin Pop
  @type name: C{str}
477 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
478 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
479 a7399f66 Iustin Pop
              address.
480 a7399f66 Iustin Pop

481 a7399f66 Iustin Pop
  """
482 07bd8a51 Iustin Pop
  OP_ID = "OP_CLUSTER_RENAME"
483 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
484 65e183af Michael Hanselmann
  OP_PARAMS = [
485 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString),
486 65e183af Michael Hanselmann
    ]
487 07bd8a51 Iustin Pop
488 07bd8a51 Iustin Pop
489 a6682fdc Iustin Pop
class OpClusterSetParams(OpCode):
490 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
491 a7399f66 Iustin Pop

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

495 a7399f66 Iustin Pop
  """
496 12515db7 Manuel Franceschini
  OP_ID = "OP_CLUSTER_SET_PARAMS"
497 65e183af Michael Hanselmann
  OP_PARAMS = [
498 65e183af Michael Hanselmann
    ("vg_name", None, ht.TMaybeString),
499 65e183af Michael Hanselmann
    ("enabled_hypervisors", None,
500 65e183af Michael Hanselmann
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
501 65e183af Michael Hanselmann
            ht.TNone)),
502 65e183af Michael Hanselmann
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
503 65e183af Michael Hanselmann
                              ht.TNone)),
504 65e183af Michael Hanselmann
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone)),
505 65e183af Michael Hanselmann
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
506 65e183af Michael Hanselmann
                            ht.TNone)),
507 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
508 65e183af Michael Hanselmann
                              ht.TNone)),
509 65e183af Michael Hanselmann
    ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone)),
510 65e183af Michael Hanselmann
    ("uid_pool", None, ht.NoType),
511 65e183af Michael Hanselmann
    ("add_uids", None, ht.NoType),
512 65e183af Michael Hanselmann
    ("remove_uids", None, ht.NoType),
513 65e183af Michael Hanselmann
    ("maintain_node_health", None, ht.TMaybeBool),
514 65e183af Michael Hanselmann
    ("prealloc_wipe_disks", None, ht.TMaybeBool),
515 65e183af Michael Hanselmann
    ("nicparams", None, ht.TOr(ht.TDict, ht.TNone)),
516 65e183af Michael Hanselmann
    ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
517 65e183af Michael Hanselmann
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone)),
518 65e183af Michael Hanselmann
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone)),
519 65e183af Michael Hanselmann
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone)),
520 65e183af Michael Hanselmann
    ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone)),
521 65e183af Michael Hanselmann
    ("hidden_os", None, ht.TOr(ht.TListOf(
522 65e183af Michael Hanselmann
          ht.TAnd(ht.TList,
523 65e183af Michael Hanselmann
                ht.TIsLength(2),
524 65e183af Michael Hanselmann
                ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))),
525 65e183af Michael Hanselmann
          ht.TNone)),
526 65e183af Michael Hanselmann
    ("blacklisted_os", None, ht.TOr(ht.TListOf(
527 65e183af Michael Hanselmann
          ht.TAnd(ht.TList,
528 65e183af Michael Hanselmann
                ht.TIsLength(2),
529 65e183af Michael Hanselmann
                ht.TMap(lambda v: v[0], ht.TElemOf(constants.DDMS_VALUES)))),
530 65e183af Michael Hanselmann
          ht.TNone)),
531 4b7735f9 Iustin Pop
    ]
532 12515db7 Manuel Franceschini
533 12515db7 Manuel Franceschini
534 d1240007 Iustin Pop
class OpClusterRedistConf(OpCode):
535 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
536 afee0879 Iustin Pop

537 afee0879 Iustin Pop
  """
538 afee0879 Iustin Pop
  OP_ID = "OP_CLUSTER_REDIST_CONF"
539 afee0879 Iustin Pop
540 83f72637 Michael Hanselmann
541 83f72637 Michael Hanselmann
class OpQuery(OpCode):
542 83f72637 Michael Hanselmann
  """Query for resources/items.
543 83f72637 Michael Hanselmann

544 83f72637 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
545 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
546 83f72637 Michael Hanselmann
  @ivar filter: Query filter
547 83f72637 Michael Hanselmann

548 83f72637 Michael Hanselmann
  """
549 83f72637 Michael Hanselmann
  OP_ID = "OP_QUERY"
550 65e183af Michael Hanselmann
  OP_PARAMS = [
551 65e183af Michael Hanselmann
    ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
552 65e183af Michael Hanselmann
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
553 65e183af Michael Hanselmann
    ("filter", None, ht.TOr(ht.TNone,
554 65e183af Michael Hanselmann
                            ht.TListOf(ht.TOr(ht.TNonEmptyString, ht.TList)))),
555 83f72637 Michael Hanselmann
    ]
556 83f72637 Michael Hanselmann
557 83f72637 Michael Hanselmann
558 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
559 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
560 83f72637 Michael Hanselmann

561 83f72637 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
562 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
563 83f72637 Michael Hanselmann

564 83f72637 Michael Hanselmann
  """
565 83f72637 Michael Hanselmann
  OP_ID = "OP_QUERY_FIELDS"
566 65e183af Michael Hanselmann
  OP_PARAMS = [
567 65e183af Michael Hanselmann
    ("what", ht.NoDefault, ht.TElemOf(constants.QR_OP_QUERY)),
568 65e183af Michael Hanselmann
    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))),
569 83f72637 Michael Hanselmann
    ]
570 83f72637 Michael Hanselmann
571 83f72637 Michael Hanselmann
572 792af3ad Renรฉ Nussbaumer
class OpOobCommand(OpCode):
573 eb64da59 Renรฉ Nussbaumer
  """Interact with OOB."""
574 792af3ad Renรฉ Nussbaumer
  OP_ID = "OP_OOB_COMMAND"
575 65e183af Michael Hanselmann
  OP_PARAMS = [
576 65e183af Michael Hanselmann
    _PNodeName,
577 65e183af Michael Hanselmann
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS)),
578 65e183af Michael Hanselmann
    ("timeout", constants.OOB_TIMEOUT, ht.TInt),
579 eb64da59 Renรฉ Nussbaumer
    ]
580 eb64da59 Renรฉ Nussbaumer
581 eb64da59 Renรฉ Nussbaumer
582 07bd8a51 Iustin Pop
# node opcodes
583 07bd8a51 Iustin Pop
584 a8083063 Iustin Pop
class OpRemoveNode(OpCode):
585 a7399f66 Iustin Pop
  """Remove a node.
586 a7399f66 Iustin Pop

587 a7399f66 Iustin Pop
  @type node_name: C{str}
588 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
589 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
590 a7399f66 Iustin Pop

591 a7399f66 Iustin Pop
  """
592 a8083063 Iustin Pop
  OP_ID = "OP_NODE_REMOVE"
593 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
594 65e183af Michael Hanselmann
  OP_PARAMS = [
595 65e183af Michael Hanselmann
    _PNodeName,
596 65e183af Michael Hanselmann
    ]
597 a8083063 Iustin Pop
598 a8083063 Iustin Pop
599 a8083063 Iustin Pop
class OpAddNode(OpCode):
600 a7399f66 Iustin Pop
  """Add a node to the cluster.
601 a7399f66 Iustin Pop

602 a7399f66 Iustin Pop
  @type node_name: C{str}
603 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
604 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
605 a7399f66 Iustin Pop
  @type primary_ip: IP address
606 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
607 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
608 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
609 a7399f66 Iustin Pop
  @type secondary_ip: IP address
610 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
611 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
612 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
613 a7399f66 Iustin Pop
  @type readd: C{bool}
614 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
615 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
616 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
617 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
618 a7399f66 Iustin Pop
               without removal from the cluster.
619 f936c153 Iustin Pop
  @type group: C{str}
620 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
621 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
622 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
623 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
624 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
625 a7399f66 Iustin Pop

626 a7399f66 Iustin Pop
  """
627 a8083063 Iustin Pop
  OP_ID = "OP_NODE_ADD"
628 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
629 65e183af Michael Hanselmann
  OP_PARAMS = [
630 65e183af Michael Hanselmann
    _PNodeName,
631 65e183af Michael Hanselmann
    ("primary_ip", None, ht.NoType),
632 65e183af Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString),
633 65e183af Michael Hanselmann
    ("readd", False, ht.TBool),
634 65e183af Michael Hanselmann
    ("group", None, ht.TMaybeString),
635 65e183af Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool),
636 65e183af Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool),
637 65e183af Michael Hanselmann
    ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
638 65e183af Michael Hanselmann
    ]
639 a8083063 Iustin Pop
640 a8083063 Iustin Pop
641 a8083063 Iustin Pop
class OpQueryNodes(OpCode):
642 a8083063 Iustin Pop
  """Compute the list of nodes."""
643 a8083063 Iustin Pop
  OP_ID = "OP_NODE_QUERY"
644 65e183af Michael Hanselmann
  OP_PARAMS = [
645 65e183af Michael Hanselmann
    _POutputFields,
646 65e183af Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
647 65e183af Michael Hanselmann
    ("use_locking", False, ht.TBool),
648 65e183af Michael Hanselmann
    ]
649 a8083063 Iustin Pop
650 a8083063 Iustin Pop
651 dcb93971 Michael Hanselmann
class OpQueryNodeVolumes(OpCode):
652 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
653 dcb93971 Michael Hanselmann
  OP_ID = "OP_NODE_QUERYVOLS"
654 65e183af Michael Hanselmann
  OP_PARAMS = [
655 65e183af Michael Hanselmann
    _POutputFields,
656 65e183af Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
657 65e183af Michael Hanselmann
    ]
658 dcb93971 Michael Hanselmann
659 dcb93971 Michael Hanselmann
660 9e5442ce Michael Hanselmann
class OpQueryNodeStorage(OpCode):
661 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
662 9e5442ce Michael Hanselmann
  OP_ID = "OP_NODE_QUERY_STORAGE"
663 65e183af Michael Hanselmann
  OP_PARAMS = [
664 65e183af Michael Hanselmann
    _POutputFields,
665 65e183af Michael Hanselmann
    _PStorageType,
666 65e183af Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
667 65e183af Michael Hanselmann
    ("name", None, ht.TMaybeString),
668 9e5442ce Michael Hanselmann
    ]
669 9e5442ce Michael Hanselmann
670 9e5442ce Michael Hanselmann
671 efb8da02 Michael Hanselmann
class OpModifyNodeStorage(OpCode):
672 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
673 efb8da02 Michael Hanselmann
  OP_ID = "OP_NODE_MODIFY_STORAGE"
674 65e183af Michael Hanselmann
  OP_PARAMS = [
675 65e183af Michael Hanselmann
    _PNodeName,
676 65e183af Michael Hanselmann
    _PStorageType,
677 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString),
678 65e183af Michael Hanselmann
    ("changes", ht.NoDefault, ht.TDict),
679 efb8da02 Michael Hanselmann
    ]
680 efb8da02 Michael Hanselmann
681 efb8da02 Michael Hanselmann
682 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
683 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
684 76aef8fc Michael Hanselmann
  OP_ID = "OP_REPAIR_NODE_STORAGE"
685 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
686 65e183af Michael Hanselmann
  OP_PARAMS = [
687 65e183af Michael Hanselmann
    _PNodeName,
688 65e183af Michael Hanselmann
    _PStorageType,
689 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString),
690 65e183af Michael Hanselmann
    ("ignore_consistency", False, ht.TBool),
691 76aef8fc Michael Hanselmann
    ]
692 76aef8fc Michael Hanselmann
693 76aef8fc Michael Hanselmann
694 b31c8676 Iustin Pop
class OpSetNodeParams(OpCode):
695 b31c8676 Iustin Pop
  """Change the parameters of a node."""
696 b31c8676 Iustin Pop
  OP_ID = "OP_NODE_SET_PARAMS"
697 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
698 65e183af Michael Hanselmann
  OP_PARAMS = [
699 65e183af Michael Hanselmann
    _PNodeName,
700 65e183af Michael Hanselmann
    _PForce,
701 65e183af Michael Hanselmann
    ("master_candidate", None, ht.TMaybeBool),
702 65e183af Michael Hanselmann
    ("offline", None, ht.TMaybeBool),
703 65e183af Michael Hanselmann
    ("drained", None, ht.TMaybeBool),
704 65e183af Michael Hanselmann
    ("auto_promote", False, ht.TBool),
705 65e183af Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool),
706 65e183af Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool),
707 65e183af Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString),
708 65e183af Michael Hanselmann
    ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
709 65e183af Michael Hanselmann
    ("powered", None, ht.TMaybeBool),
710 b31c8676 Iustin Pop
    ]
711 b31c8676 Iustin Pop
712 f5118ade Iustin Pop
713 f5118ade Iustin Pop
class OpPowercycleNode(OpCode):
714 f5118ade Iustin Pop
  """Tries to powercycle a node."""
715 f5118ade Iustin Pop
  OP_ID = "OP_NODE_POWERCYCLE"
716 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
717 65e183af Michael Hanselmann
  OP_PARAMS = [
718 65e183af Michael Hanselmann
    _PNodeName,
719 65e183af Michael Hanselmann
    _PForce,
720 f5118ade Iustin Pop
    ]
721 f5118ade Iustin Pop
722 7ffc5a86 Michael Hanselmann
723 80cb875c Michael Hanselmann
class OpMigrateNode(OpCode):
724 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
725 80cb875c Michael Hanselmann
  OP_ID = "OP_NODE_MIGRATE"
726 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
727 65e183af Michael Hanselmann
  OP_PARAMS = [
728 65e183af Michael Hanselmann
    _PNodeName,
729 65e183af Michael Hanselmann
    _PMigrationMode,
730 65e183af Michael Hanselmann
    _PMigrationLive,
731 80cb875c Michael Hanselmann
    ]
732 80cb875c Michael Hanselmann
733 80cb875c Michael Hanselmann
734 d6aaa598 Iustin Pop
class OpNodeEvacuationStrategy(OpCode):
735 d6aaa598 Iustin Pop
  """Compute the evacuation strategy for a list of nodes."""
736 d6aaa598 Iustin Pop
  OP_ID = "OP_NODE_EVAC_STRATEGY"
737 d6aaa598 Iustin Pop
  OP_DSC_FIELD = "nodes"
738 65e183af Michael Hanselmann
  OP_PARAMS = [
739 65e183af Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
740 65e183af Michael Hanselmann
    ("remote_node", None, ht.TMaybeString),
741 65e183af Michael Hanselmann
    ("iallocator", None, ht.TMaybeString),
742 65e183af Michael Hanselmann
    ]
743 d6aaa598 Iustin Pop
744 d6aaa598 Iustin Pop
745 a8083063 Iustin Pop
# instance opcodes
746 a8083063 Iustin Pop
747 e1530b10 Iustin Pop
class OpInstanceCreate(OpCode):
748 9bf56d77 Michael Hanselmann
  """Create an instance.
749 9bf56d77 Michael Hanselmann

750 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
751 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
752 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
753 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
754 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
755 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
756 dae91d02 Michael Hanselmann
    (remote import only)
757 9bf56d77 Michael Hanselmann

758 9bf56d77 Michael Hanselmann
  """
759 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CREATE"
760 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
761 65e183af Michael Hanselmann
  OP_PARAMS = [
762 65e183af Michael Hanselmann
    _PInstanceName,
763 65e183af Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict),
764 65e183af Michael Hanselmann
    ("disks", ht.NoDefault, ht.TListOf(ht.TDict)),
765 65e183af Michael Hanselmann
    ("disk_template", ht.NoDefault, _CheckDiskTemplate),
766 65e183af Michael Hanselmann
    ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER))),
767 65e183af Michael Hanselmann
    ("file_storage_dir", None, ht.TMaybeString),
768 65e183af Michael Hanselmann
    ("force_variant", False, ht.TBool),
769 65e183af Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict),
770 65e183af Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString),
771 65e183af Michael Hanselmann
    ("iallocator", None, ht.TMaybeString),
772 65e183af Michael Hanselmann
    ("identify_defaults", False, ht.TBool),
773 65e183af Michael Hanselmann
    ("ip_check", True, ht.TBool),
774 65e183af Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES)),
775 65e183af Michael Hanselmann
    ("name_check", True, ht.TBool),
776 65e183af Michael Hanselmann
    ("nics", ht.NoDefault, ht.TListOf(ht.TDict)),
777 65e183af Michael Hanselmann
    ("no_install", None, ht.TMaybeBool),
778 65e183af Michael Hanselmann
    ("osparams", ht.EmptyDict, ht.TDict),
779 65e183af Michael Hanselmann
    ("os_type", None, ht.TMaybeString),
780 65e183af Michael Hanselmann
    ("pnode", None, ht.TMaybeString),
781 65e183af Michael Hanselmann
    ("snode", None, ht.TMaybeString),
782 65e183af Michael Hanselmann
    ("source_handshake", None, ht.TOr(ht.TList, ht.TNone)),
783 65e183af Michael Hanselmann
    ("source_instance_name", None, ht.TMaybeString),
784 65e183af Michael Hanselmann
    ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
785 65e183af Michael Hanselmann
     ht.TPositiveInt),
786 65e183af Michael Hanselmann
    ("source_x509_ca", None, ht.TMaybeString),
787 65e183af Michael Hanselmann
    ("src_node", None, ht.TMaybeString),
788 65e183af Michael Hanselmann
    ("src_path", None, ht.TMaybeString),
789 65e183af Michael Hanselmann
    ("start", True, ht.TBool),
790 65e183af Michael Hanselmann
    ("wait_for_sync", True, ht.TBool),
791 3b6d8c9b Iustin Pop
    ]
792 a8083063 Iustin Pop
793 a8083063 Iustin Pop
794 fe7b0351 Michael Hanselmann
class OpReinstallInstance(OpCode):
795 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
796 fe7b0351 Michael Hanselmann
  OP_ID = "OP_INSTANCE_REINSTALL"
797 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
798 65e183af Michael Hanselmann
  OP_PARAMS = [
799 65e183af Michael Hanselmann
    _PInstanceName,
800 65e183af Michael Hanselmann
    ("os_type", None, ht.TMaybeString),
801 65e183af Michael Hanselmann
    ("force_variant", False, ht.TBool),
802 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDict, ht.TNone)),
803 65e183af Michael Hanselmann
    ]
804 fe7b0351 Michael Hanselmann
805 fe7b0351 Michael Hanselmann
806 a8083063 Iustin Pop
class OpRemoveInstance(OpCode):
807 a8083063 Iustin Pop
  """Remove an instance."""
808 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REMOVE"
809 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
810 65e183af Michael Hanselmann
  OP_PARAMS = [
811 65e183af Michael Hanselmann
    _PInstanceName,
812 65e183af Michael Hanselmann
    _PShutdownTimeout,
813 65e183af Michael Hanselmann
    ("ignore_failures", False, ht.TBool),
814 fc1baca9 Michael Hanselmann
    ]
815 a8083063 Iustin Pop
816 a8083063 Iustin Pop
817 decd5f45 Iustin Pop
class OpRenameInstance(OpCode):
818 decd5f45 Iustin Pop
  """Rename an instance."""
819 decd5f45 Iustin Pop
  OP_ID = "OP_INSTANCE_RENAME"
820 65e183af Michael Hanselmann
  OP_PARAMS = [
821 65e183af Michael Hanselmann
    _PInstanceName,
822 65e183af Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString),
823 65e183af Michael Hanselmann
    ("ip_check", False, ht.TBool),
824 65e183af Michael Hanselmann
    ("name_check", True, ht.TBool),
825 4f05fd3b Iustin Pop
    ]
826 decd5f45 Iustin Pop
827 decd5f45 Iustin Pop
828 a8083063 Iustin Pop
class OpStartupInstance(OpCode):
829 fdc267f4 Iustin Pop
  """Startup an instance."""
830 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_STARTUP"
831 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
832 65e183af Michael Hanselmann
  OP_PARAMS = [
833 65e183af Michael Hanselmann
    _PInstanceName,
834 65e183af Michael Hanselmann
    _PForce,
835 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
836 65e183af Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict),
837 65e183af Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict),
838 4f05fd3b Iustin Pop
    ]
839 a8083063 Iustin Pop
840 a8083063 Iustin Pop
841 a8083063 Iustin Pop
class OpShutdownInstance(OpCode):
842 fdc267f4 Iustin Pop
  """Shutdown an instance."""
843 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_SHUTDOWN"
844 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
845 65e183af Michael Hanselmann
  OP_PARAMS = [
846 65e183af Michael Hanselmann
    _PInstanceName,
847 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
848 65e183af Michael Hanselmann
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt),
849 b44bd844 Michael Hanselmann
    ]
850 a8083063 Iustin Pop
851 a8083063 Iustin Pop
852 bf6929a2 Alexander Schreiber
class OpRebootInstance(OpCode):
853 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
854 eeb3a5f9 Iustin Pop
  OP_ID = "OP_INSTANCE_REBOOT"
855 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
856 65e183af Michael Hanselmann
  OP_PARAMS = [
857 65e183af Michael Hanselmann
    _PInstanceName,
858 65e183af Michael Hanselmann
    _PShutdownTimeout,
859 65e183af Michael Hanselmann
    ("ignore_secondaries", False, ht.TBool),
860 65e183af Michael Hanselmann
    ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES)),
861 4f05fd3b Iustin Pop
    ]
862 bf6929a2 Alexander Schreiber
863 bf6929a2 Alexander Schreiber
864 a8083063 Iustin Pop
class OpReplaceDisks(OpCode):
865 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
866 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
867 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
868 65e183af Michael Hanselmann
  OP_PARAMS = [
869 65e183af Michael Hanselmann
    _PInstanceName,
870 65e183af Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES)),
871 65e183af Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
872 65e183af Michael Hanselmann
    ("remote_node", None, ht.TMaybeString),
873 65e183af Michael Hanselmann
    ("iallocator", None, ht.TMaybeString),
874 65e183af Michael Hanselmann
    ("early_release", False, ht.TBool),
875 4f05fd3b Iustin Pop
    ]
876 a8083063 Iustin Pop
877 a8083063 Iustin Pop
878 019dbee1 Iustin Pop
class OpInstanceFailover(OpCode):
879 a8083063 Iustin Pop
  """Failover an instance."""
880 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_FAILOVER"
881 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
882 65e183af Michael Hanselmann
  OP_PARAMS = [
883 65e183af Michael Hanselmann
    _PInstanceName,
884 65e183af Michael Hanselmann
    _PShutdownTimeout,
885 65e183af Michael Hanselmann
    ("ignore_consistency", False, ht.TBool),
886 17c3f802 Guido Trotter
    ]
887 a8083063 Iustin Pop
888 a8083063 Iustin Pop
889 75c866c2 Iustin Pop
class OpInstanceMigrate(OpCode):
890 53c776b5 Iustin Pop
  """Migrate an instance.
891 53c776b5 Iustin Pop

892 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
893 53c776b5 Iustin Pop
  node.
894 53c776b5 Iustin Pop

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

898 53c776b5 Iustin Pop
  """
899 53c776b5 Iustin Pop
  OP_ID = "OP_INSTANCE_MIGRATE"
900 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
901 65e183af Michael Hanselmann
  OP_PARAMS = [
902 65e183af Michael Hanselmann
    _PInstanceName,
903 65e183af Michael Hanselmann
    _PMigrationMode,
904 65e183af Michael Hanselmann
    _PMigrationLive,
905 65e183af Michael Hanselmann
    ("cleanup", False, ht.TBool),
906 65e183af Michael Hanselmann
    ]
907 53c776b5 Iustin Pop
908 53c776b5 Iustin Pop
909 0091b480 Iustin Pop
class OpInstanceMove(OpCode):
910 313bcead Iustin Pop
  """Move an instance.
911 313bcead Iustin Pop

912 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
913 313bcead Iustin Pop
  arbitrary node.
914 313bcead Iustin Pop

915 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
916 313bcead Iustin Pop
  @ivar target_node: the destination node
917 313bcead Iustin Pop

918 313bcead Iustin Pop
  """
919 313bcead Iustin Pop
  OP_ID = "OP_INSTANCE_MOVE"
920 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
921 65e183af Michael Hanselmann
  OP_PARAMS = [
922 65e183af Michael Hanselmann
    _PInstanceName,
923 65e183af Michael Hanselmann
    _PShutdownTimeout,
924 65e183af Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TNonEmptyString),
925 154b9580 Balazs Lecz
    ]
926 313bcead Iustin Pop
927 313bcead Iustin Pop
928 cc0dec7b Iustin Pop
class OpInstanceConsole(OpCode):
929 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
930 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CONSOLE"
931 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
932 65e183af Michael Hanselmann
  OP_PARAMS = [
933 65e183af Michael Hanselmann
    _PInstanceName
934 65e183af Michael Hanselmann
    ]
935 a8083063 Iustin Pop
936 a8083063 Iustin Pop
937 83f5d475 Iustin Pop
class OpInstanceActivateDisks(OpCode):
938 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
939 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
940 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
941 65e183af Michael Hanselmann
  OP_PARAMS = [
942 65e183af Michael Hanselmann
    _PInstanceName,
943 65e183af Michael Hanselmann
    ("ignore_size", False, ht.TBool),
944 65e183af Michael Hanselmann
    ]
945 a8083063 Iustin Pop
946 a8083063 Iustin Pop
947 e176281f Iustin Pop
class OpInstanceDeactivateDisks(OpCode):
948 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
949 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
950 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
951 65e183af Michael Hanselmann
  OP_PARAMS = [
952 65e183af Michael Hanselmann
    _PInstanceName
953 65e183af Michael Hanselmann
    ]
954 a8083063 Iustin Pop
955 a8083063 Iustin Pop
956 bd315bfa Iustin Pop
class OpRecreateInstanceDisks(OpCode):
957 bd315bfa Iustin Pop
  """Deactivate an instance's disks."""
958 bd315bfa Iustin Pop
  OP_ID = "OP_INSTANCE_RECREATE_DISKS"
959 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
960 65e183af Michael Hanselmann
  OP_PARAMS = [
961 65e183af Michael Hanselmann
    _PInstanceName,
962 65e183af Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt)),
963 65e183af Michael Hanselmann
    ]
964 bd315bfa Iustin Pop
965 bd315bfa Iustin Pop
966 f2af0bec Iustin Pop
class OpInstanceQuery(OpCode):
967 a8083063 Iustin Pop
  """Compute the list of instances."""
968 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY"
969 65e183af Michael Hanselmann
  OP_PARAMS = [
970 65e183af Michael Hanselmann
    _POutputFields,
971 65e183af Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
972 65e183af Michael Hanselmann
    ("use_locking", False, ht.TBool),
973 65e183af Michael Hanselmann
    ]
974 a8083063 Iustin Pop
975 a8083063 Iustin Pop
976 a8083063 Iustin Pop
class OpQueryInstanceData(OpCode):
977 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
978 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY_DATA"
979 65e183af Michael Hanselmann
  OP_PARAMS = [
980 65e183af Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
981 65e183af Michael Hanselmann
    ("static", False, ht.TBool),
982 65e183af Michael Hanselmann
    ]
983 a8083063 Iustin Pop
984 a8083063 Iustin Pop
985 7767bbf5 Manuel Franceschini
class OpSetInstanceParams(OpCode):
986 a8083063 Iustin Pop
  """Change the parameters of an instance."""
987 7767bbf5 Manuel Franceschini
  OP_ID = "OP_INSTANCE_SET_PARAMS"
988 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
989 65e183af Michael Hanselmann
  OP_PARAMS = [
990 65e183af Michael Hanselmann
    _PInstanceName,
991 65e183af Michael Hanselmann
    _PForce,
992 65e183af Michael Hanselmann
    ("nics", ht.EmptyList, ht.TList),
993 65e183af Michael Hanselmann
    ("disks", ht.EmptyList, ht.TList),
994 65e183af Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict),
995 65e183af Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict),
996 f7c8f153 Michael Hanselmann
    ("disk_template", None, ht.TOr(ht.TNone, _CheckDiskTemplate)),
997 65e183af Michael Hanselmann
    ("remote_node", None, ht.TMaybeString),
998 65e183af Michael Hanselmann
    ("os_name", None, ht.TMaybeString),
999 65e183af Michael Hanselmann
    ("force_variant", False, ht.TBool),
1000 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDict, ht.TNone)),
1001 973d7867 Iustin Pop
    ]
1002 a8083063 Iustin Pop
1003 a8083063 Iustin Pop
1004 60472d29 Iustin Pop
class OpInstanceGrowDisk(OpCode):
1005 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
1006 8729e0d7 Iustin Pop
  OP_ID = "OP_INSTANCE_GROW_DISK"
1007 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1008 65e183af Michael Hanselmann
  OP_PARAMS = [
1009 65e183af Michael Hanselmann
    _PInstanceName,
1010 65e183af Michael Hanselmann
    ("disk", ht.NoDefault, ht.TInt),
1011 65e183af Michael Hanselmann
    ("amount", ht.NoDefault, ht.TInt),
1012 65e183af Michael Hanselmann
    ("wait_for_sync", True, ht.TBool),
1013 4f05fd3b Iustin Pop
    ]
1014 8729e0d7 Iustin Pop
1015 8729e0d7 Iustin Pop
1016 70a6a926 Adeodato Simo
# Node group opcodes
1017 70a6a926 Adeodato Simo
1018 fabf1731 Iustin Pop
class OpGroupAdd(OpCode):
1019 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
1020 b1ee5610 Adeodato Simo
  OP_ID = "OP_GROUP_ADD"
1021 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1022 65e183af Michael Hanselmann
  OP_PARAMS = [
1023 65e183af Michael Hanselmann
    _PGroupName,
1024 65e183af Michael Hanselmann
    ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
1025 65e183af Michael Hanselmann
    ("alloc_policy", None,
1026 65e183af Michael Hanselmann
     ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES))),
1027 483be60d Adeodato Simo
    ]
1028 b1ee5610 Adeodato Simo
1029 b1ee5610 Adeodato Simo
1030 934704ae Iustin Pop
class OpGroupAssignNodes(OpCode):
1031 96276ae7 Adeodato Simo
  """Assign nodes to a node group."""
1032 a703bf43 Iustin Pop
  OP_ID = "OP_GROUP_ASSIGN_NODES"
1033 96276ae7 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1034 96276ae7 Adeodato Simo
  OP_PARAMS = [
1035 96276ae7 Adeodato Simo
    _PGroupName,
1036 96276ae7 Adeodato Simo
    _PForce,
1037 96276ae7 Adeodato Simo
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString)),
1038 96276ae7 Adeodato Simo
    ]
1039 96276ae7 Adeodato Simo
1040 96276ae7 Adeodato Simo
1041 d4d654bd Iustin Pop
class OpGroupQuery(OpCode):
1042 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
1043 70a6a926 Adeodato Simo
  OP_ID = "OP_GROUP_QUERY"
1044 65e183af Michael Hanselmann
  OP_PARAMS = [
1045 65e183af Michael Hanselmann
    _POutputFields,
1046 65e183af Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1047 65e183af Michael Hanselmann
    ]
1048 70a6a926 Adeodato Simo
1049 70a6a926 Adeodato Simo
1050 7cbf74f0 Iustin Pop
class OpGroupSetParams(OpCode):
1051 4da7909a Adeodato Simo
  """Change the parameters of a node group."""
1052 4da7909a Adeodato Simo
  OP_ID = "OP_GROUP_SET_PARAMS"
1053 4da7909a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1054 65e183af Michael Hanselmann
  OP_PARAMS = [
1055 65e183af Michael Hanselmann
    _PGroupName,
1056 65e183af Michael Hanselmann
    ("ndparams", None, ht.TOr(ht.TDict, ht.TNone)),
1057 65e183af Michael Hanselmann
    ("alloc_policy", None, ht.TOr(ht.TNone,
1058 65e183af Michael Hanselmann
                                  ht.TElemOf(constants.VALID_ALLOC_POLICIES))),
1059 4da7909a Adeodato Simo
    ]
1060 4da7909a Adeodato Simo
1061 4da7909a Adeodato Simo
1062 4d1baa51 Iustin Pop
class OpGroupRemove(OpCode):
1063 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
1064 94bd652a Adeodato Simo
  OP_ID = "OP_GROUP_REMOVE"
1065 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1066 65e183af Michael Hanselmann
  OP_PARAMS = [
1067 65e183af Michael Hanselmann
    _PGroupName,
1068 65e183af Michael Hanselmann
    ]
1069 94bd652a Adeodato Simo
1070 94bd652a Adeodato Simo
1071 a8173e82 Iustin Pop
class OpGroupRename(OpCode):
1072 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
1073 4fe5cf90 Adeodato Simo
  OP_ID = "OP_GROUP_RENAME"
1074 4fe5cf90 Adeodato Simo
  OP_DSC_FIELD = "old_name"
1075 65e183af Michael Hanselmann
  OP_PARAMS = [
1076 65e183af Michael Hanselmann
    ("old_name", ht.NoDefault, ht.TNonEmptyString),
1077 65e183af Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString),
1078 65e183af Michael Hanselmann
    ]
1079 4fe5cf90 Adeodato Simo
1080 4fe5cf90 Adeodato Simo
1081 a8083063 Iustin Pop
# OS opcodes
1082 a8083063 Iustin Pop
class OpDiagnoseOS(OpCode):
1083 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
1084 a8083063 Iustin Pop
  OP_ID = "OP_OS_DIAGNOSE"
1085 65e183af Michael Hanselmann
  OP_PARAMS = [
1086 65e183af Michael Hanselmann
    _POutputFields,
1087 65e183af Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1088 65e183af Michael Hanselmann
    ]
1089 a8083063 Iustin Pop
1090 7c0d6283 Michael Hanselmann
1091 a8083063 Iustin Pop
# Exports opcodes
1092 7ca2d4d8 Iustin Pop
class OpBackupQuery(OpCode):
1093 a8083063 Iustin Pop
  """Compute the list of exported images."""
1094 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_QUERY"
1095 65e183af Michael Hanselmann
  OP_PARAMS = [
1096 65e183af Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1097 65e183af Michael Hanselmann
    ("use_locking", False, ht.TBool),
1098 65e183af Michael Hanselmann
    ]
1099 a8083063 Iustin Pop
1100 7c0d6283 Michael Hanselmann
1101 71910715 Iustin Pop
class OpBackupPrepare(OpCode):
1102 1410fa8d Michael Hanselmann
  """Prepares an instance export.
1103 1410fa8d Michael Hanselmann

1104 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
1105 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1106 1410fa8d Michael Hanselmann

1107 1410fa8d Michael Hanselmann
  """
1108 1410fa8d Michael Hanselmann
  OP_ID = "OP_BACKUP_PREPARE"
1109 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1110 65e183af Michael Hanselmann
  OP_PARAMS = [
1111 65e183af Michael Hanselmann
    _PInstanceName,
1112 65e183af Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES)),
1113 1410fa8d Michael Hanselmann
    ]
1114 1410fa8d Michael Hanselmann
1115 1410fa8d Michael Hanselmann
1116 4ff922a2 Iustin Pop
class OpBackupExport(OpCode):
1117 4a96f1d1 Michael Hanselmann
  """Export an instance.
1118 4a96f1d1 Michael Hanselmann

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

1125 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1126 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
1127 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
1128 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1129 4a96f1d1 Michael Hanselmann
                             only)
1130 4a96f1d1 Michael Hanselmann

1131 4a96f1d1 Michael Hanselmann
  """
1132 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_EXPORT"
1133 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1134 65e183af Michael Hanselmann
  OP_PARAMS = [
1135 65e183af Michael Hanselmann
    _PInstanceName,
1136 65e183af Michael Hanselmann
    _PShutdownTimeout,
1137 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
1138 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
1139 65e183af Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList)),
1140 65e183af Michael Hanselmann
    ("shutdown", True, ht.TBool),
1141 65e183af Michael Hanselmann
    ("remove_instance", False, ht.TBool),
1142 65e183af Michael Hanselmann
    ("ignore_remove_failures", False, ht.TBool),
1143 65e183af Michael Hanselmann
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES)),
1144 65e183af Michael Hanselmann
    ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone)),
1145 65e183af Michael Hanselmann
    ("destination_x509_ca", None, ht.TMaybeString),
1146 17c3f802 Guido Trotter
    ]
1147 5c947f38 Iustin Pop
1148 0a7bed64 Michael Hanselmann
1149 ca5890ad Iustin Pop
class OpBackupRemove(OpCode):
1150 9ac99fda Guido Trotter
  """Remove an instance's export."""
1151 9ac99fda Guido Trotter
  OP_ID = "OP_BACKUP_REMOVE"
1152 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1153 65e183af Michael Hanselmann
  OP_PARAMS = [
1154 65e183af Michael Hanselmann
    _PInstanceName,
1155 65e183af Michael Hanselmann
    ]
1156 5c947f38 Iustin Pop
1157 0a7bed64 Michael Hanselmann
1158 5c947f38 Iustin Pop
# Tags opcodes
1159 5c947f38 Iustin Pop
class OpGetTags(OpCode):
1160 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
1161 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_GET"
1162 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
1163 65e183af Michael Hanselmann
  OP_PARAMS = [
1164 65e183af Michael Hanselmann
    _PTagKind,
1165 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1166 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString),
1167 65e183af Michael Hanselmann
    ]
1168 5c947f38 Iustin Pop
1169 5c947f38 Iustin Pop
1170 73415719 Iustin Pop
class OpSearchTags(OpCode):
1171 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
1172 73415719 Iustin Pop
  OP_ID = "OP_TAGS_SEARCH"
1173 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
1174 65e183af Michael Hanselmann
  OP_PARAMS = [
1175 65e183af Michael Hanselmann
    ("pattern", ht.NoDefault, ht.TNonEmptyString),
1176 65e183af Michael Hanselmann
    ]
1177 73415719 Iustin Pop
1178 73415719 Iustin Pop
1179 f27302fa Iustin Pop
class OpAddTags(OpCode):
1180 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
1181 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_SET"
1182 65e183af Michael Hanselmann
  OP_PARAMS = [
1183 65e183af Michael Hanselmann
    _PTagKind,
1184 65e183af Michael Hanselmann
    _PTags,
1185 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1186 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString),
1187 65e183af Michael Hanselmann
    ]
1188 5c947f38 Iustin Pop
1189 5c947f38 Iustin Pop
1190 f27302fa Iustin Pop
class OpDelTags(OpCode):
1191 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
1192 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_DEL"
1193 65e183af Michael Hanselmann
  OP_PARAMS = [
1194 65e183af Michael Hanselmann
    _PTagKind,
1195 65e183af Michael Hanselmann
    _PTags,
1196 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1197 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString),
1198 65e183af Michael Hanselmann
    ]
1199 06009e27 Iustin Pop
1200 06009e27 Iustin Pop
# Test opcodes
1201 06009e27 Iustin Pop
class OpTestDelay(OpCode):
1202 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
1203 06009e27 Iustin Pop

1204 06009e27 Iustin Pop
  This is used just for debugging and testing.
1205 06009e27 Iustin Pop

1206 06009e27 Iustin Pop
  Parameters:
1207 06009e27 Iustin Pop
    - duration: the time to sleep
1208 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
1209 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
1210 06009e27 Iustin Pop

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

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

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

1221 06009e27 Iustin Pop
  """
1222 06009e27 Iustin Pop
  OP_ID = "OP_TEST_DELAY"
1223 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
1224 65e183af Michael Hanselmann
  OP_PARAMS = [
1225 65e183af Michael Hanselmann
    ("duration", ht.NoDefault, ht.TFloat),
1226 65e183af Michael Hanselmann
    ("on_master", True, ht.TBool),
1227 65e183af Michael Hanselmann
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1228 65e183af Michael Hanselmann
    ("repeat", 0, ht.TPositiveInt)
1229 65e183af Michael Hanselmann
    ]
1230 d61df03e Iustin Pop
1231 d61df03e Iustin Pop
1232 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
1233 d61df03e Iustin Pop
  """Allocator framework testing.
1234 d61df03e Iustin Pop

1235 d61df03e Iustin Pop
  This opcode has two modes:
1236 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
1237 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
1238 d61df03e Iustin Pop
      'in')
1239 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
1240 d61df03e Iustin Pop
      return the allocator output (direction 'out')
1241 d61df03e Iustin Pop

1242 d61df03e Iustin Pop
  """
1243 d61df03e Iustin Pop
  OP_ID = "OP_TEST_ALLOCATOR"
1244 60dd1473 Iustin Pop
  OP_DSC_FIELD = "allocator"
1245 65e183af Michael Hanselmann
  OP_PARAMS = [
1246 65e183af Michael Hanselmann
    ("direction", ht.NoDefault,
1247 65e183af Michael Hanselmann
     ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS)),
1248 65e183af Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES)),
1249 65e183af Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString),
1250 65e183af Michael Hanselmann
    ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
1251 65e183af Michael Hanselmann
      ht.TDictOf(ht.TElemOf(["mac", "ip", "bridge"]),
1252 65e183af Michael Hanselmann
               ht.TOr(ht.TNone, ht.TNonEmptyString))))),
1253 65e183af Michael Hanselmann
    ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList)),
1254 65e183af Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString),
1255 65e183af Michael Hanselmann
    ("allocator", None, ht.TMaybeString),
1256 65e183af Michael Hanselmann
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString)),
1257 65e183af Michael Hanselmann
    ("mem_size", None, ht.TOr(ht.TNone, ht.TPositiveInt)),
1258 65e183af Michael Hanselmann
    ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt)),
1259 65e183af Michael Hanselmann
    ("os", None, ht.TMaybeString),
1260 65e183af Michael Hanselmann
    ("disk_template", None, ht.TMaybeString),
1261 65e183af Michael Hanselmann
    ("evac_nodes", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString))),
1262 d61df03e Iustin Pop
    ]
1263 363acb1e Iustin Pop
1264 76aef8fc Michael Hanselmann
1265 e58f87a9 Michael Hanselmann
class OpTestJobqueue(OpCode):
1266 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
1267 e58f87a9 Michael Hanselmann

1268 e58f87a9 Michael Hanselmann
  """
1269 e58f87a9 Michael Hanselmann
  OP_ID = "OP_TEST_JQUEUE"
1270 65e183af Michael Hanselmann
  OP_PARAMS = [
1271 65e183af Michael Hanselmann
    ("notify_waitlock", False, ht.TBool),
1272 65e183af Michael Hanselmann
    ("notify_exec", False, ht.TBool),
1273 65e183af Michael Hanselmann
    ("log_messages", ht.EmptyList, ht.TListOf(ht.TString)),
1274 65e183af Michael Hanselmann
    ("fail", False, ht.TBool),
1275 e58f87a9 Michael Hanselmann
    ]
1276 e58f87a9 Michael Hanselmann
1277 e58f87a9 Michael Hanselmann
1278 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
1279 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
1280 be760ba8 Michael Hanselmann

1281 be760ba8 Michael Hanselmann
  """
1282 be760ba8 Michael Hanselmann
  OP_ID = "OP_TEST_DUMMY"
1283 65e183af Michael Hanselmann
  OP_PARAMS = [
1284 65e183af Michael Hanselmann
    ("result", ht.NoDefault, ht.NoType),
1285 65e183af Michael Hanselmann
    ("messages", ht.NoDefault, ht.NoType),
1286 65e183af Michael Hanselmann
    ("fail", ht.NoDefault, ht.NoType),
1287 be760ba8 Michael Hanselmann
    ]
1288 687c10d9 Iustin Pop
  WITH_LU = False
1289 be760ba8 Michael Hanselmann
1290 be760ba8 Michael Hanselmann
1291 dbc96028 Michael Hanselmann
def _GetOpList():
1292 dbc96028 Michael Hanselmann
  """Returns list of all defined opcodes.
1293 dbc96028 Michael Hanselmann

1294 dbc96028 Michael Hanselmann
  Does not eliminate duplicates by C{OP_ID}.
1295 dbc96028 Michael Hanselmann

1296 dbc96028 Michael Hanselmann
  """
1297 dbc96028 Michael Hanselmann
  return [v for v in globals().values()
1298 dbc96028 Michael Hanselmann
          if (isinstance(v, type) and issubclass(v, OpCode) and
1299 687c10d9 Iustin Pop
              hasattr(v, "OP_ID") and v is not OpCode)]
1300 dbc96028 Michael Hanselmann
1301 dbc96028 Michael Hanselmann
1302 dbc96028 Michael Hanselmann
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())