Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 66e884e1

History | View | Annotate | Download (23.7 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 8c35561f Iustin Pop
# Copyright (C) 2006, 2007, 2008, 2009, 2010 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 df458e0b Iustin Pop
37 0e46916d Iustin Pop
class BaseOpCode(object):
38 df458e0b Iustin Pop
  """A simple serializable object.
39 df458e0b Iustin Pop

40 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
41 0e46916d Iustin Pop
  field handling.
42 0e46916d Iustin Pop

43 df458e0b Iustin Pop
  """
44 a8083063 Iustin Pop
  __slots__ = []
45 a8083063 Iustin Pop
46 a8083063 Iustin Pop
  def __init__(self, **kwargs):
47 a7399f66 Iustin Pop
    """Constructor for BaseOpCode.
48 a7399f66 Iustin Pop

49 a7399f66 Iustin Pop
    The constructor takes only keyword arguments and will set
50 a7399f66 Iustin Pop
    attributes on this object based on the passed arguments. As such,
51 a7399f66 Iustin Pop
    it means that you should not pass arguments which are not in the
52 a7399f66 Iustin Pop
    __slots__ attribute for this class.
53 a7399f66 Iustin Pop

54 a7399f66 Iustin Pop
    """
55 adf385c7 Iustin Pop
    slots = self._all_slots()
56 a8083063 Iustin Pop
    for key in kwargs:
57 adf385c7 Iustin Pop
      if key not in slots:
58 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
59 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
60 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
61 a8083063 Iustin Pop
62 df458e0b Iustin Pop
  def __getstate__(self):
63 a7399f66 Iustin Pop
    """Generic serializer.
64 a7399f66 Iustin Pop

65 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
66 a7399f66 Iustin Pop
    dictionary.
67 a7399f66 Iustin Pop

68 a7399f66 Iustin Pop
    @rtype:  C{dict}
69 a7399f66 Iustin Pop
    @return: the instance attributes and their values
70 a7399f66 Iustin Pop

71 a7399f66 Iustin Pop
    """
72 df458e0b Iustin Pop
    state = {}
73 adf385c7 Iustin Pop
    for name in self._all_slots():
74 df458e0b Iustin Pop
      if hasattr(self, name):
75 df458e0b Iustin Pop
        state[name] = getattr(self, name)
76 df458e0b Iustin Pop
    return state
77 df458e0b Iustin Pop
78 df458e0b Iustin Pop
  def __setstate__(self, state):
79 a7399f66 Iustin Pop
    """Generic unserializer.
80 a7399f66 Iustin Pop

81 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
82 a7399f66 Iustin Pop
    of the current instance.
83 a7399f66 Iustin Pop

84 a7399f66 Iustin Pop
    @param state: the serialized opcode data
85 a7399f66 Iustin Pop
    @type state:  C{dict}
86 a7399f66 Iustin Pop

87 a7399f66 Iustin Pop
    """
88 df458e0b Iustin Pop
    if not isinstance(state, dict):
89 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
90 df458e0b Iustin Pop
                       type(state))
91 df458e0b Iustin Pop
92 adf385c7 Iustin Pop
    for name in self._all_slots():
93 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
94 df458e0b Iustin Pop
        delattr(self, name)
95 df458e0b Iustin Pop
96 df458e0b Iustin Pop
    for name in state:
97 df458e0b Iustin Pop
      setattr(self, name, state[name])
98 df458e0b Iustin Pop
99 adf385c7 Iustin Pop
  @classmethod
100 adf385c7 Iustin Pop
  def _all_slots(cls):
101 adf385c7 Iustin Pop
    """Compute the list of all declared slots for a class.
102 adf385c7 Iustin Pop

103 adf385c7 Iustin Pop
    """
104 adf385c7 Iustin Pop
    slots = []
105 adf385c7 Iustin Pop
    for parent in cls.__mro__:
106 adf385c7 Iustin Pop
      slots.extend(getattr(parent, "__slots__", []))
107 adf385c7 Iustin Pop
    return slots
108 adf385c7 Iustin Pop
109 df458e0b Iustin Pop
110 0e46916d Iustin Pop
class OpCode(BaseOpCode):
111 a7399f66 Iustin Pop
  """Abstract OpCode.
112 a7399f66 Iustin Pop

113 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
114 a7399f66 Iustin Pop
  from this class should override OP_ID.
115 a7399f66 Iustin Pop

116 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
117 20777413 Iustin Pop
               children of this class.
118 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
119 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
120 bde8f481 Adeodato Simo
                      method for details).
121 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
122 20777413 Iustin Pop
                 the check steps
123 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
124 a7399f66 Iustin Pop

125 a7399f66 Iustin Pop
  """
126 df458e0b Iustin Pop
  OP_ID = "OP_ABSTRACT"
127 8f5c488d Michael Hanselmann
  __slots__ = ["dry_run", "debug_level", "priority"]
128 df458e0b Iustin Pop
129 df458e0b Iustin Pop
  def __getstate__(self):
130 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
131 df458e0b Iustin Pop

132 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
133 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
134 a7399f66 Iustin Pop
    instantiating the opcode.
135 a7399f66 Iustin Pop

136 a7399f66 Iustin Pop
    @rtype:   C{dict}
137 a7399f66 Iustin Pop
    @return:  the state as a dictionary
138 a7399f66 Iustin Pop

139 df458e0b Iustin Pop
    """
140 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
141 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
142 df458e0b Iustin Pop
    return data
143 df458e0b Iustin Pop
144 df458e0b Iustin Pop
  @classmethod
145 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
146 df458e0b Iustin Pop
    """Generic load opcode method.
147 df458e0b Iustin Pop

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

152 a7399f66 Iustin Pop
    @type data:  C{dict}
153 a7399f66 Iustin Pop
    @param data: the serialized opcode
154 a7399f66 Iustin Pop

155 df458e0b Iustin Pop
    """
156 df458e0b Iustin Pop
    if not isinstance(data, dict):
157 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
158 df458e0b Iustin Pop
    if "OP_ID" not in data:
159 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
160 df458e0b Iustin Pop
    op_id = data["OP_ID"]
161 df458e0b Iustin Pop
    op_class = None
162 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
163 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
164 363acb1e Iustin Pop
    else:
165 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
166 df458e0b Iustin Pop
                       op_id)
167 df458e0b Iustin Pop
    op = op_class()
168 df458e0b Iustin Pop
    new_data = data.copy()
169 df458e0b Iustin Pop
    del new_data["OP_ID"]
170 df458e0b Iustin Pop
    op.__setstate__(new_data)
171 df458e0b Iustin Pop
    return op
172 df458e0b Iustin Pop
173 60dd1473 Iustin Pop
  def Summary(self):
174 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
175 60dd1473 Iustin Pop

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

181 60dd1473 Iustin Pop
    """
182 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
183 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
184 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
185 60dd1473 Iustin Pop
    if field_name:
186 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
187 bc8bbda1 Iustin Pop
      if isinstance(field_value, (list, tuple)):
188 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
189 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
190 60dd1473 Iustin Pop
    return txt
191 60dd1473 Iustin Pop
192 a8083063 Iustin Pop
193 afee0879 Iustin Pop
# cluster opcodes
194 afee0879 Iustin Pop
195 b5f5fae9 Luca Bigliardi
class OpPostInitCluster(OpCode):
196 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
197 b5f5fae9 Luca Bigliardi

198 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
199 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
200 b5f5fae9 Luca Bigliardi

201 b5f5fae9 Luca Bigliardi
  """
202 b5f5fae9 Luca Bigliardi
  OP_ID = "OP_CLUSTER_POST_INIT"
203 154b9580 Balazs Lecz
  __slots__ = []
204 b5f5fae9 Luca Bigliardi
205 b5f5fae9 Luca Bigliardi
206 a8083063 Iustin Pop
class OpDestroyCluster(OpCode):
207 a7399f66 Iustin Pop
  """Destroy the cluster.
208 a7399f66 Iustin Pop

209 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
210 a7399f66 Iustin Pop
  lost after the execution of this opcode.
211 a7399f66 Iustin Pop

212 a7399f66 Iustin Pop
  """
213 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DESTROY"
214 154b9580 Balazs Lecz
  __slots__ = []
215 a8083063 Iustin Pop
216 a8083063 Iustin Pop
217 a8083063 Iustin Pop
class OpQueryClusterInfo(OpCode):
218 fdc267f4 Iustin Pop
  """Query cluster information."""
219 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_QUERY"
220 154b9580 Balazs Lecz
  __slots__ = []
221 a8083063 Iustin Pop
222 a8083063 Iustin Pop
223 a8083063 Iustin Pop
class OpVerifyCluster(OpCode):
224 a7399f66 Iustin Pop
  """Verify the cluster state.
225 a7399f66 Iustin Pop

226 a7399f66 Iustin Pop
  @type skip_checks: C{list}
227 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
228 a7399f66 Iustin Pop
                     needs to be a subset of
229 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
230 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
231 a7399f66 Iustin Pop

232 a7399f66 Iustin Pop
  """
233 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY"
234 154b9580 Balazs Lecz
  __slots__ = ["skip_checks", "verbose", "error_codes",
235 154b9580 Balazs Lecz
               "debug_simulate_errors"]
236 a8083063 Iustin Pop
237 a8083063 Iustin Pop
238 150e978f Iustin Pop
class OpVerifyDisks(OpCode):
239 150e978f Iustin Pop
  """Verify the cluster disks.
240 150e978f Iustin Pop

241 150e978f Iustin Pop
  Parameters: none
242 150e978f Iustin Pop

243 5188ab37 Iustin Pop
  Result: a tuple of four elements:
244 150e978f Iustin Pop
    - list of node names with bad data returned (unreachable, etc.)
245 a7399f66 Iustin Pop
    - dict of node names with broken volume groups (values: error msg)
246 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
247 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
248 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
249 150e978f Iustin Pop

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

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

258 150e978f Iustin Pop
  """
259 150e978f Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
260 154b9580 Balazs Lecz
  __slots__ = []
261 150e978f Iustin Pop
262 150e978f Iustin Pop
263 60975797 Iustin Pop
class OpRepairDiskSizes(OpCode):
264 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
265 60975797 Iustin Pop
  mimatches.
266 60975797 Iustin Pop

267 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
268 60975797 Iustin Pop
  checks to only a subset of the instances.
269 60975797 Iustin Pop

270 60975797 Iustin Pop
  Result: a list of tuples, (instance, disk, new-size) for changed
271 60975797 Iustin Pop
  configurations.
272 60975797 Iustin Pop

273 60975797 Iustin Pop
  In normal operation, the list should be empty.
274 60975797 Iustin Pop

275 60975797 Iustin Pop
  @type instances: list
276 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
277 60975797 Iustin Pop

278 60975797 Iustin Pop
  """
279 60975797 Iustin Pop
  OP_ID = "OP_CLUSTER_REPAIR_DISK_SIZES"
280 60975797 Iustin Pop
  __slots__ = ["instances"]
281 60975797 Iustin Pop
282 60975797 Iustin Pop
283 ae5849b5 Michael Hanselmann
class OpQueryConfigValues(OpCode):
284 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
285 ae5849b5 Michael Hanselmann
  OP_ID = "OP_CLUSTER_CONFIG_QUERY"
286 154b9580 Balazs Lecz
  __slots__ = ["output_fields"]
287 a8083063 Iustin Pop
288 a8083063 Iustin Pop
289 07bd8a51 Iustin Pop
class OpRenameCluster(OpCode):
290 a7399f66 Iustin Pop
  """Rename the cluster.
291 a7399f66 Iustin Pop

292 a7399f66 Iustin Pop
  @type name: C{str}
293 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
294 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
295 a7399f66 Iustin Pop
              address.
296 a7399f66 Iustin Pop

297 a7399f66 Iustin Pop
  """
298 07bd8a51 Iustin Pop
  OP_ID = "OP_CLUSTER_RENAME"
299 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
300 154b9580 Balazs Lecz
  __slots__ = ["name"]
301 07bd8a51 Iustin Pop
302 07bd8a51 Iustin Pop
303 12515db7 Manuel Franceschini
class OpSetClusterParams(OpCode):
304 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
305 a7399f66 Iustin Pop

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

309 a7399f66 Iustin Pop
  """
310 12515db7 Manuel Franceschini
  OP_ID = "OP_CLUSTER_SET_PARAMS"
311 154b9580 Balazs Lecz
  __slots__ = [
312 4b7735f9 Iustin Pop
    "vg_name",
313 7b2cd2b4 Luca Bigliardi
    "drbd_helper",
314 4b7735f9 Iustin Pop
    "enabled_hypervisors",
315 4b7735f9 Iustin Pop
    "hvparams",
316 17463d22 Renรฉ Nussbaumer
    "os_hvp",
317 4b7735f9 Iustin Pop
    "beparams",
318 625ac113 Iustin Pop
    "osparams",
319 5af3da74 Guido Trotter
    "nicparams",
320 08a61d91 Renรฉ Nussbaumer
    "ndparams",
321 4b7735f9 Iustin Pop
    "candidate_pool_size",
322 3953242f Iustin Pop
    "maintain_node_health",
323 1338f2b4 Balazs Lecz
    "uid_pool",
324 fdad8c4d Balazs Lecz
    "add_uids",
325 fdad8c4d Balazs Lecz
    "remove_uids",
326 bf4af505 Apollon Oikonomopoulos
    "default_iallocator",
327 f38ea602 Iustin Pop
    "reserved_lvs",
328 87b2cd45 Iustin Pop
    "hidden_os",
329 87b2cd45 Iustin Pop
    "blacklisted_os",
330 b883637f Renรฉ Nussbaumer
    "prealloc_wipe_disks",
331 4b7735f9 Iustin Pop
    ]
332 12515db7 Manuel Franceschini
333 12515db7 Manuel Franceschini
334 afee0879 Iustin Pop
class OpRedistributeConfig(OpCode):
335 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
336 afee0879 Iustin Pop

337 afee0879 Iustin Pop
  """
338 afee0879 Iustin Pop
  OP_ID = "OP_CLUSTER_REDIST_CONF"
339 154b9580 Balazs Lecz
  __slots__ = []
340 afee0879 Iustin Pop
341 83f72637 Michael Hanselmann
342 83f72637 Michael Hanselmann
class OpQuery(OpCode):
343 83f72637 Michael Hanselmann
  """Query for resources/items.
344 83f72637 Michael Hanselmann

345 83f72637 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_OP_QUERY}
346 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
347 83f72637 Michael Hanselmann
  @ivar filter: Query filter
348 83f72637 Michael Hanselmann

349 83f72637 Michael Hanselmann
  """
350 83f72637 Michael Hanselmann
  OP_ID = "OP_QUERY"
351 83f72637 Michael Hanselmann
  __slots__ = [
352 83f72637 Michael Hanselmann
    "what",
353 83f72637 Michael Hanselmann
    "fields",
354 83f72637 Michael Hanselmann
    "filter",
355 83f72637 Michael Hanselmann
    ]
356 83f72637 Michael Hanselmann
357 83f72637 Michael Hanselmann
358 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
359 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
360 83f72637 Michael Hanselmann

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

364 83f72637 Michael Hanselmann
  """
365 83f72637 Michael Hanselmann
  OP_ID = "OP_QUERY_FIELDS"
366 83f72637 Michael Hanselmann
  __slots__ = [
367 83f72637 Michael Hanselmann
    "what",
368 83f72637 Michael Hanselmann
    "fields",
369 83f72637 Michael Hanselmann
    ]
370 83f72637 Michael Hanselmann
371 83f72637 Michael Hanselmann
372 eb64da59 Renรฉ Nussbaumer
class OpOutOfBand(OpCode):
373 eb64da59 Renรฉ Nussbaumer
  """Interact with OOB."""
374 eb64da59 Renรฉ Nussbaumer
  OP_ID = "OP_OUT_OF_BAND"
375 eb64da59 Renรฉ Nussbaumer
  __slots__ = [
376 eb64da59 Renรฉ Nussbaumer
    "node_name",
377 eb64da59 Renรฉ Nussbaumer
    "command",
378 eb64da59 Renรฉ Nussbaumer
    "timeout",
379 eb64da59 Renรฉ Nussbaumer
    ]
380 eb64da59 Renรฉ Nussbaumer
381 eb64da59 Renรฉ Nussbaumer
382 07bd8a51 Iustin Pop
# node opcodes
383 07bd8a51 Iustin Pop
384 a8083063 Iustin Pop
class OpRemoveNode(OpCode):
385 a7399f66 Iustin Pop
  """Remove a node.
386 a7399f66 Iustin Pop

387 a7399f66 Iustin Pop
  @type node_name: C{str}
388 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
389 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
390 a7399f66 Iustin Pop

391 a7399f66 Iustin Pop
  """
392 a8083063 Iustin Pop
  OP_ID = "OP_NODE_REMOVE"
393 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
394 154b9580 Balazs Lecz
  __slots__ = ["node_name"]
395 a8083063 Iustin Pop
396 a8083063 Iustin Pop
397 a8083063 Iustin Pop
class OpAddNode(OpCode):
398 a7399f66 Iustin Pop
  """Add a node to the cluster.
399 a7399f66 Iustin Pop

400 a7399f66 Iustin Pop
  @type node_name: C{str}
401 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
402 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
403 a7399f66 Iustin Pop
  @type primary_ip: IP address
404 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
405 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
406 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
407 a7399f66 Iustin Pop
  @type secondary_ip: IP address
408 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
409 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
410 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
411 a7399f66 Iustin Pop
  @type readd: C{bool}
412 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
413 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
414 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
415 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
416 a7399f66 Iustin Pop
               without removal from the cluster.
417 f936c153 Iustin Pop
  @type group: C{str}
418 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
419 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
420 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
421 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
422 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
423 a7399f66 Iustin Pop

424 a7399f66 Iustin Pop
  """
425 a8083063 Iustin Pop
  OP_ID = "OP_NODE_ADD"
426 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
427 fd3d37b6 Iustin Pop
  __slots__ = ["node_name", "primary_ip", "secondary_ip", "readd", "group",
428 08a61d91 Renรฉ Nussbaumer
               "vm_capable", "master_capable", "ndparams"]
429 a8083063 Iustin Pop
430 a8083063 Iustin Pop
431 a8083063 Iustin Pop
class OpQueryNodes(OpCode):
432 a8083063 Iustin Pop
  """Compute the list of nodes."""
433 a8083063 Iustin Pop
  OP_ID = "OP_NODE_QUERY"
434 154b9580 Balazs Lecz
  __slots__ = ["output_fields", "names", "use_locking"]
435 a8083063 Iustin Pop
436 a8083063 Iustin Pop
437 dcb93971 Michael Hanselmann
class OpQueryNodeVolumes(OpCode):
438 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
439 dcb93971 Michael Hanselmann
  OP_ID = "OP_NODE_QUERYVOLS"
440 154b9580 Balazs Lecz
  __slots__ = ["nodes", "output_fields"]
441 dcb93971 Michael Hanselmann
442 dcb93971 Michael Hanselmann
443 9e5442ce Michael Hanselmann
class OpQueryNodeStorage(OpCode):
444 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
445 9e5442ce Michael Hanselmann
  OP_ID = "OP_NODE_QUERY_STORAGE"
446 154b9580 Balazs Lecz
  __slots__ = [
447 9e5442ce Michael Hanselmann
    "nodes",
448 9e5442ce Michael Hanselmann
    "storage_type",
449 9e5442ce Michael Hanselmann
    "name",
450 9e5442ce Michael Hanselmann
    "output_fields",
451 9e5442ce Michael Hanselmann
    ]
452 9e5442ce Michael Hanselmann
453 9e5442ce Michael Hanselmann
454 efb8da02 Michael Hanselmann
class OpModifyNodeStorage(OpCode):
455 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
456 efb8da02 Michael Hanselmann
  OP_ID = "OP_NODE_MODIFY_STORAGE"
457 154b9580 Balazs Lecz
  __slots__ = [
458 efb8da02 Michael Hanselmann
    "node_name",
459 efb8da02 Michael Hanselmann
    "storage_type",
460 efb8da02 Michael Hanselmann
    "name",
461 efb8da02 Michael Hanselmann
    "changes",
462 efb8da02 Michael Hanselmann
    ]
463 efb8da02 Michael Hanselmann
464 efb8da02 Michael Hanselmann
465 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
466 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
467 76aef8fc Michael Hanselmann
  OP_ID = "OP_REPAIR_NODE_STORAGE"
468 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
469 154b9580 Balazs Lecz
  __slots__ = [
470 76aef8fc Michael Hanselmann
    "node_name",
471 76aef8fc Michael Hanselmann
    "storage_type",
472 76aef8fc Michael Hanselmann
    "name",
473 7e9c6a78 Iustin Pop
    "ignore_consistency",
474 76aef8fc Michael Hanselmann
    ]
475 76aef8fc Michael Hanselmann
476 76aef8fc Michael Hanselmann
477 b31c8676 Iustin Pop
class OpSetNodeParams(OpCode):
478 b31c8676 Iustin Pop
  """Change the parameters of a node."""
479 b31c8676 Iustin Pop
  OP_ID = "OP_NODE_SET_PARAMS"
480 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
481 154b9580 Balazs Lecz
  __slots__ = [
482 b31c8676 Iustin Pop
    "node_name",
483 b31c8676 Iustin Pop
    "force",
484 b31c8676 Iustin Pop
    "master_candidate",
485 3a5ba66a Iustin Pop
    "offline",
486 c9d443ea Iustin Pop
    "drained",
487 601908d0 Iustin Pop
    "auto_promote",
488 197e3bb2 Iustin Pop
    "master_capable",
489 077114cd Iustin Pop
    "vm_capable",
490 4d32c211 Guido Trotter
    "secondary_ip",
491 08a61d91 Renรฉ Nussbaumer
    "ndparams",
492 b31c8676 Iustin Pop
    ]
493 b31c8676 Iustin Pop
494 f5118ade Iustin Pop
495 f5118ade Iustin Pop
class OpPowercycleNode(OpCode):
496 f5118ade Iustin Pop
  """Tries to powercycle a node."""
497 f5118ade Iustin Pop
  OP_ID = "OP_NODE_POWERCYCLE"
498 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
499 154b9580 Balazs Lecz
  __slots__ = [
500 f5118ade Iustin Pop
    "node_name",
501 f5118ade Iustin Pop
    "force",
502 f5118ade Iustin Pop
    ]
503 f5118ade Iustin Pop
504 7ffc5a86 Michael Hanselmann
505 80cb875c Michael Hanselmann
class OpMigrateNode(OpCode):
506 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
507 80cb875c Michael Hanselmann
  OP_ID = "OP_NODE_MIGRATE"
508 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
509 154b9580 Balazs Lecz
  __slots__ = [
510 80cb875c Michael Hanselmann
    "node_name",
511 8c35561f Iustin Pop
    "mode",
512 46d2d8a2 Iustin Pop
    "live",
513 80cb875c Michael Hanselmann
    ]
514 80cb875c Michael Hanselmann
515 80cb875c Michael Hanselmann
516 d6aaa598 Iustin Pop
class OpNodeEvacuationStrategy(OpCode):
517 d6aaa598 Iustin Pop
  """Compute the evacuation strategy for a list of nodes."""
518 d6aaa598 Iustin Pop
  OP_ID = "OP_NODE_EVAC_STRATEGY"
519 d6aaa598 Iustin Pop
  OP_DSC_FIELD = "nodes"
520 d6aaa598 Iustin Pop
  __slots__ = ["nodes", "iallocator", "remote_node"]
521 d6aaa598 Iustin Pop
522 d6aaa598 Iustin Pop
523 a8083063 Iustin Pop
# instance opcodes
524 a8083063 Iustin Pop
525 a8083063 Iustin Pop
class OpCreateInstance(OpCode):
526 9bf56d77 Michael Hanselmann
  """Create an instance.
527 9bf56d77 Michael Hanselmann

528 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
529 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
530 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
531 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
532 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
533 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
534 dae91d02 Michael Hanselmann
    (remote import only)
535 9bf56d77 Michael Hanselmann

536 9bf56d77 Michael Hanselmann
  """
537 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CREATE"
538 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
539 154b9580 Balazs Lecz
  __slots__ = [
540 25a8792c Iustin Pop
    "instance_name",
541 25a8792c Iustin Pop
    "os_type", "force_variant", "no_install",
542 47804ec9 Guido Trotter
    "pnode", "disk_template", "snode", "mode",
543 08db7c5c Iustin Pop
    "disks", "nics",
544 e588764d Iustin Pop
    "src_node", "src_path", "start", "identify_defaults",
545 5f23e043 Iustin Pop
    "wait_for_sync", "ip_check", "name_check",
546 dc936b49 Manuel Franceschini
    "file_storage_dir", "file_driver",
547 6785674e Iustin Pop
    "iallocator",
548 062a7100 Iustin Pop
    "hypervisor", "hvparams", "beparams", "osparams",
549 9bf56d77 Michael Hanselmann
    "source_handshake",
550 9bf56d77 Michael Hanselmann
    "source_x509_ca",
551 9bf56d77 Michael Hanselmann
    "source_instance_name",
552 dae91d02 Michael Hanselmann
    "source_shutdown_timeout",
553 3b6d8c9b Iustin Pop
    ]
554 a8083063 Iustin Pop
555 a8083063 Iustin Pop
556 fe7b0351 Michael Hanselmann
class OpReinstallInstance(OpCode):
557 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
558 fe7b0351 Michael Hanselmann
  OP_ID = "OP_INSTANCE_REINSTALL"
559 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
560 8d8c4eff Michael Hanselmann
  __slots__ = ["instance_name", "os_type", "force_variant", "osparams"]
561 fe7b0351 Michael Hanselmann
562 fe7b0351 Michael Hanselmann
563 a8083063 Iustin Pop
class OpRemoveInstance(OpCode):
564 a8083063 Iustin Pop
  """Remove an instance."""
565 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REMOVE"
566 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
567 154b9580 Balazs Lecz
  __slots__ = [
568 fc1baca9 Michael Hanselmann
    "instance_name",
569 fc1baca9 Michael Hanselmann
    "ignore_failures",
570 fc1baca9 Michael Hanselmann
    "shutdown_timeout",
571 fc1baca9 Michael Hanselmann
    ]
572 a8083063 Iustin Pop
573 a8083063 Iustin Pop
574 decd5f45 Iustin Pop
class OpRenameInstance(OpCode):
575 decd5f45 Iustin Pop
  """Rename an instance."""
576 decd5f45 Iustin Pop
  OP_ID = "OP_INSTANCE_RENAME"
577 154b9580 Balazs Lecz
  __slots__ = [
578 3fe11ba3 Manuel Franceschini
    "instance_name", "ip_check", "new_name", "name_check",
579 4f05fd3b Iustin Pop
    ]
580 decd5f45 Iustin Pop
581 decd5f45 Iustin Pop
582 a8083063 Iustin Pop
class OpStartupInstance(OpCode):
583 fdc267f4 Iustin Pop
  """Startup an instance."""
584 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_STARTUP"
585 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
586 154b9580 Balazs Lecz
  __slots__ = [
587 b44bd844 Michael Hanselmann
    "instance_name", "force", "hvparams", "beparams", "ignore_offline_nodes",
588 4f05fd3b Iustin Pop
    ]
589 a8083063 Iustin Pop
590 a8083063 Iustin Pop
591 a8083063 Iustin Pop
class OpShutdownInstance(OpCode):
592 fdc267f4 Iustin Pop
  """Shutdown an instance."""
593 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_SHUTDOWN"
594 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
595 b44bd844 Michael Hanselmann
  __slots__ = [
596 b44bd844 Michael Hanselmann
    "instance_name", "timeout", "ignore_offline_nodes",
597 b44bd844 Michael Hanselmann
    ]
598 a8083063 Iustin Pop
599 a8083063 Iustin Pop
600 bf6929a2 Alexander Schreiber
class OpRebootInstance(OpCode):
601 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
602 eeb3a5f9 Iustin Pop
  OP_ID = "OP_INSTANCE_REBOOT"
603 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
604 154b9580 Balazs Lecz
  __slots__ = [
605 17c3f802 Guido Trotter
    "instance_name", "reboot_type", "ignore_secondaries", "shutdown_timeout",
606 4f05fd3b Iustin Pop
    ]
607 bf6929a2 Alexander Schreiber
608 bf6929a2 Alexander Schreiber
609 a8083063 Iustin Pop
class OpReplaceDisks(OpCode):
610 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
611 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
612 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
613 154b9580 Balazs Lecz
  __slots__ = [
614 4f05fd3b Iustin Pop
    "instance_name", "remote_node", "mode", "disks", "iallocator",
615 7ea7bcf6 Iustin Pop
    "early_release",
616 4f05fd3b Iustin Pop
    ]
617 a8083063 Iustin Pop
618 a8083063 Iustin Pop
619 a8083063 Iustin Pop
class OpFailoverInstance(OpCode):
620 a8083063 Iustin Pop
  """Failover an instance."""
621 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_FAILOVER"
622 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
623 154b9580 Balazs Lecz
  __slots__ = [
624 17c3f802 Guido Trotter
    "instance_name", "ignore_consistency", "shutdown_timeout",
625 17c3f802 Guido Trotter
    ]
626 a8083063 Iustin Pop
627 a8083063 Iustin Pop
628 53c776b5 Iustin Pop
class OpMigrateInstance(OpCode):
629 53c776b5 Iustin Pop
  """Migrate an instance.
630 53c776b5 Iustin Pop

631 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
632 53c776b5 Iustin Pop
  node.
633 53c776b5 Iustin Pop

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

637 53c776b5 Iustin Pop
  """
638 53c776b5 Iustin Pop
  OP_ID = "OP_INSTANCE_MIGRATE"
639 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
640 46d2d8a2 Iustin Pop
  __slots__ = ["instance_name", "mode", "cleanup", "live"]
641 53c776b5 Iustin Pop
642 53c776b5 Iustin Pop
643 313bcead Iustin Pop
class OpMoveInstance(OpCode):
644 313bcead Iustin Pop
  """Move an instance.
645 313bcead Iustin Pop

646 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
647 313bcead Iustin Pop
  arbitrary node.
648 313bcead Iustin Pop

649 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
650 313bcead Iustin Pop
  @ivar target_node: the destination node
651 313bcead Iustin Pop

652 313bcead Iustin Pop
  """
653 313bcead Iustin Pop
  OP_ID = "OP_INSTANCE_MOVE"
654 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
655 154b9580 Balazs Lecz
  __slots__ = [
656 17c3f802 Guido Trotter
    "instance_name", "target_node", "shutdown_timeout",
657 154b9580 Balazs Lecz
    ]
658 313bcead Iustin Pop
659 313bcead Iustin Pop
660 a8083063 Iustin Pop
class OpConnectConsole(OpCode):
661 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
662 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CONSOLE"
663 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
664 154b9580 Balazs Lecz
  __slots__ = ["instance_name"]
665 a8083063 Iustin Pop
666 a8083063 Iustin Pop
667 a8083063 Iustin Pop
class OpActivateInstanceDisks(OpCode):
668 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
669 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
670 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
671 154b9580 Balazs Lecz
  __slots__ = ["instance_name", "ignore_size"]
672 a8083063 Iustin Pop
673 a8083063 Iustin Pop
674 a8083063 Iustin Pop
class OpDeactivateInstanceDisks(OpCode):
675 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
676 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
677 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
678 154b9580 Balazs Lecz
  __slots__ = ["instance_name"]
679 a8083063 Iustin Pop
680 a8083063 Iustin Pop
681 bd315bfa Iustin Pop
class OpRecreateInstanceDisks(OpCode):
682 bd315bfa Iustin Pop
  """Deactivate an instance's disks."""
683 bd315bfa Iustin Pop
  OP_ID = "OP_INSTANCE_RECREATE_DISKS"
684 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
685 154b9580 Balazs Lecz
  __slots__ = ["instance_name", "disks"]
686 bd315bfa Iustin Pop
687 bd315bfa Iustin Pop
688 a8083063 Iustin Pop
class OpQueryInstances(OpCode):
689 a8083063 Iustin Pop
  """Compute the list of instances."""
690 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY"
691 154b9580 Balazs Lecz
  __slots__ = ["output_fields", "names", "use_locking"]
692 a8083063 Iustin Pop
693 a8083063 Iustin Pop
694 a8083063 Iustin Pop
class OpQueryInstanceData(OpCode):
695 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
696 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY_DATA"
697 154b9580 Balazs Lecz
  __slots__ = ["instances", "static"]
698 a8083063 Iustin Pop
699 a8083063 Iustin Pop
700 7767bbf5 Manuel Franceschini
class OpSetInstanceParams(OpCode):
701 a8083063 Iustin Pop
  """Change the parameters of an instance."""
702 7767bbf5 Manuel Franceschini
  OP_ID = "OP_INSTANCE_SET_PARAMS"
703 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
704 154b9580 Balazs Lecz
  __slots__ = [
705 24991749 Iustin Pop
    "instance_name",
706 1052d622 Iustin Pop
    "hvparams", "beparams", "osparams", "force",
707 e29e9550 Iustin Pop
    "nics", "disks", "disk_template",
708 96b39bcc Iustin Pop
    "remote_node", "os_name", "force_variant",
709 973d7867 Iustin Pop
    ]
710 a8083063 Iustin Pop
711 a8083063 Iustin Pop
712 8729e0d7 Iustin Pop
class OpGrowDisk(OpCode):
713 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
714 8729e0d7 Iustin Pop
  OP_ID = "OP_INSTANCE_GROW_DISK"
715 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
716 154b9580 Balazs Lecz
  __slots__ = [
717 4f05fd3b Iustin Pop
    "instance_name", "disk", "amount", "wait_for_sync",
718 4f05fd3b Iustin Pop
    ]
719 8729e0d7 Iustin Pop
720 8729e0d7 Iustin Pop
721 70a6a926 Adeodato Simo
# Node group opcodes
722 70a6a926 Adeodato Simo
723 b1ee5610 Adeodato Simo
class OpAddGroup(OpCode):
724 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
725 b1ee5610 Adeodato Simo
  OP_ID = "OP_GROUP_ADD"
726 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
727 b1ee5610 Adeodato Simo
  __slots__ = ["group_name"]
728 b1ee5610 Adeodato Simo
729 b1ee5610 Adeodato Simo
730 70a6a926 Adeodato Simo
class OpQueryGroups(OpCode):
731 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
732 70a6a926 Adeodato Simo
  OP_ID = "OP_GROUP_QUERY"
733 70a6a926 Adeodato Simo
  __slots__ = ["output_fields", "names"]
734 70a6a926 Adeodato Simo
735 70a6a926 Adeodato Simo
736 94bd652a Adeodato Simo
class OpRemoveGroup(OpCode):
737 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
738 94bd652a Adeodato Simo
  OP_ID = "OP_GROUP_REMOVE"
739 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
740 94bd652a Adeodato Simo
  __slots__ = ["group_name"]
741 94bd652a Adeodato Simo
742 94bd652a Adeodato Simo
743 4fe5cf90 Adeodato Simo
class OpRenameGroup(OpCode):
744 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
745 4fe5cf90 Adeodato Simo
  OP_ID = "OP_GROUP_RENAME"
746 4fe5cf90 Adeodato Simo
  OP_DSC_FIELD = "old_name"
747 4fe5cf90 Adeodato Simo
  __slots__ = ["old_name", "new_name"]
748 4fe5cf90 Adeodato Simo
749 4fe5cf90 Adeodato Simo
750 a8083063 Iustin Pop
# OS opcodes
751 a8083063 Iustin Pop
class OpDiagnoseOS(OpCode):
752 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
753 a8083063 Iustin Pop
  OP_ID = "OP_OS_DIAGNOSE"
754 154b9580 Balazs Lecz
  __slots__ = ["output_fields", "names"]
755 a8083063 Iustin Pop
756 7c0d6283 Michael Hanselmann
757 a8083063 Iustin Pop
# Exports opcodes
758 a8083063 Iustin Pop
class OpQueryExports(OpCode):
759 a8083063 Iustin Pop
  """Compute the list of exported images."""
760 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_QUERY"
761 154b9580 Balazs Lecz
  __slots__ = ["nodes", "use_locking"]
762 a8083063 Iustin Pop
763 7c0d6283 Michael Hanselmann
764 1410fa8d Michael Hanselmann
class OpPrepareExport(OpCode):
765 1410fa8d Michael Hanselmann
  """Prepares an instance export.
766 1410fa8d Michael Hanselmann

767 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
768 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
769 1410fa8d Michael Hanselmann

770 1410fa8d Michael Hanselmann
  """
771 1410fa8d Michael Hanselmann
  OP_ID = "OP_BACKUP_PREPARE"
772 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
773 1410fa8d Michael Hanselmann
  __slots__ = [
774 1410fa8d Michael Hanselmann
    "instance_name", "mode",
775 1410fa8d Michael Hanselmann
    ]
776 1410fa8d Michael Hanselmann
777 1410fa8d Michael Hanselmann
778 a8083063 Iustin Pop
class OpExportInstance(OpCode):
779 4a96f1d1 Michael Hanselmann
  """Export an instance.
780 4a96f1d1 Michael Hanselmann

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

787 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
788 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
789 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
790 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
791 4a96f1d1 Michael Hanselmann
                             only)
792 4a96f1d1 Michael Hanselmann

793 4a96f1d1 Michael Hanselmann
  """
794 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_EXPORT"
795 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
796 154b9580 Balazs Lecz
  __slots__ = [
797 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
798 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
799 17c3f802 Guido Trotter
    "instance_name", "target_node", "shutdown", "shutdown_timeout",
800 faba00cb Michael Hanselmann
    "remove_instance",
801 faba00cb Michael Hanselmann
    "ignore_remove_failures",
802 4a96f1d1 Michael Hanselmann
    "mode",
803 4a96f1d1 Michael Hanselmann
    "x509_key_name",
804 4a96f1d1 Michael Hanselmann
    "destination_x509_ca",
805 17c3f802 Guido Trotter
    ]
806 5c947f38 Iustin Pop
807 0a7bed64 Michael Hanselmann
808 9ac99fda Guido Trotter
class OpRemoveExport(OpCode):
809 9ac99fda Guido Trotter
  """Remove an instance's export."""
810 9ac99fda Guido Trotter
  OP_ID = "OP_BACKUP_REMOVE"
811 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
812 154b9580 Balazs Lecz
  __slots__ = ["instance_name"]
813 5c947f38 Iustin Pop
814 0a7bed64 Michael Hanselmann
815 5c947f38 Iustin Pop
# Tags opcodes
816 5c947f38 Iustin Pop
class OpGetTags(OpCode):
817 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
818 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_GET"
819 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
820 154b9580 Balazs Lecz
  __slots__ = ["kind", "name"]
821 5c947f38 Iustin Pop
822 5c947f38 Iustin Pop
823 73415719 Iustin Pop
class OpSearchTags(OpCode):
824 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
825 73415719 Iustin Pop
  OP_ID = "OP_TAGS_SEARCH"
826 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
827 154b9580 Balazs Lecz
  __slots__ = ["pattern"]
828 73415719 Iustin Pop
829 73415719 Iustin Pop
830 f27302fa Iustin Pop
class OpAddTags(OpCode):
831 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
832 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_SET"
833 154b9580 Balazs Lecz
  __slots__ = ["kind", "name", "tags"]
834 5c947f38 Iustin Pop
835 5c947f38 Iustin Pop
836 f27302fa Iustin Pop
class OpDelTags(OpCode):
837 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
838 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_DEL"
839 154b9580 Balazs Lecz
  __slots__ = ["kind", "name", "tags"]
840 06009e27 Iustin Pop
841 06009e27 Iustin Pop
842 06009e27 Iustin Pop
# Test opcodes
843 06009e27 Iustin Pop
class OpTestDelay(OpCode):
844 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
845 06009e27 Iustin Pop

846 06009e27 Iustin Pop
  This is used just for debugging and testing.
847 06009e27 Iustin Pop

848 06009e27 Iustin Pop
  Parameters:
849 06009e27 Iustin Pop
    - duration: the time to sleep
850 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
851 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
852 06009e27 Iustin Pop

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

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

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

863 06009e27 Iustin Pop
  """
864 06009e27 Iustin Pop
  OP_ID = "OP_TEST_DELAY"
865 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
866 85a87e21 Guido Trotter
  __slots__ = ["duration", "on_master", "on_nodes", "repeat"]
867 d61df03e Iustin Pop
868 d61df03e Iustin Pop
869 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
870 d61df03e Iustin Pop
  """Allocator framework testing.
871 d61df03e Iustin Pop

872 d61df03e Iustin Pop
  This opcode has two modes:
873 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
874 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
875 d61df03e Iustin Pop
      'in')
876 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
877 d61df03e Iustin Pop
      return the allocator output (direction 'out')
878 d61df03e Iustin Pop

879 d61df03e Iustin Pop
  """
880 d61df03e Iustin Pop
  OP_ID = "OP_TEST_ALLOCATOR"
881 60dd1473 Iustin Pop
  OP_DSC_FIELD = "allocator"
882 154b9580 Balazs Lecz
  __slots__ = [
883 d61df03e Iustin Pop
    "direction", "mode", "allocator", "name",
884 d61df03e Iustin Pop
    "mem_size", "disks", "disk_template",
885 8cc7e742 Guido Trotter
    "os", "tags", "nics", "vcpus", "hypervisor",
886 823a72bc Iustin Pop
    "evac_nodes",
887 d61df03e Iustin Pop
    ]
888 363acb1e Iustin Pop
889 76aef8fc Michael Hanselmann
890 e58f87a9 Michael Hanselmann
class OpTestJobqueue(OpCode):
891 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
892 e58f87a9 Michael Hanselmann

893 e58f87a9 Michael Hanselmann
  """
894 e58f87a9 Michael Hanselmann
  OP_ID = "OP_TEST_JQUEUE"
895 e58f87a9 Michael Hanselmann
  __slots__ = [
896 e58f87a9 Michael Hanselmann
    "notify_waitlock",
897 e58f87a9 Michael Hanselmann
    "notify_exec",
898 e58f87a9 Michael Hanselmann
    "log_messages",
899 e58f87a9 Michael Hanselmann
    "fail",
900 e58f87a9 Michael Hanselmann
    ]
901 e58f87a9 Michael Hanselmann
902 e58f87a9 Michael Hanselmann
903 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
904 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
905 be760ba8 Michael Hanselmann

906 be760ba8 Michael Hanselmann
  """
907 be760ba8 Michael Hanselmann
  OP_ID = "OP_TEST_DUMMY"
908 be760ba8 Michael Hanselmann
  __slots__ = [
909 be760ba8 Michael Hanselmann
    "result",
910 be760ba8 Michael Hanselmann
    "messages",
911 be760ba8 Michael Hanselmann
    "fail",
912 be760ba8 Michael Hanselmann
    ]
913 be760ba8 Michael Hanselmann
914 be760ba8 Michael Hanselmann
915 363acb1e Iustin Pop
OP_MAPPING = dict([(v.OP_ID, v) for v in globals().values()
916 363acb1e Iustin Pop
                   if (isinstance(v, type) and issubclass(v, OpCode) and
917 363acb1e Iustin Pop
                       hasattr(v, "OP_ID"))])