Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 3cd62121

History | View | Annotate | Download (13.9 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 a8083063 Iustin Pop
# Copyright (C) 2006, 2007 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 a8083063 Iustin Pop
    for key in kwargs:
56 a8083063 Iustin Pop
      if key not in self.__slots__:
57 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
58 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
59 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
60 a8083063 Iustin Pop
61 df458e0b Iustin Pop
  def __getstate__(self):
62 a7399f66 Iustin Pop
    """Generic serializer.
63 a7399f66 Iustin Pop

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

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

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

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

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

86 a7399f66 Iustin Pop
    """
87 df458e0b Iustin Pop
    if not isinstance(state, dict):
88 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
89 df458e0b Iustin Pop
                       type(state))
90 df458e0b Iustin Pop
91 df458e0b Iustin Pop
    for name in self.__slots__:
92 df458e0b Iustin Pop
      if name not in state:
93 df458e0b Iustin Pop
        delattr(self, name)
94 df458e0b Iustin Pop
95 df458e0b Iustin Pop
    for name in state:
96 df458e0b Iustin Pop
      setattr(self, name, state[name])
97 df458e0b Iustin Pop
98 df458e0b Iustin Pop
99 0e46916d Iustin Pop
class OpCode(BaseOpCode):
100 a7399f66 Iustin Pop
  """Abstract OpCode.
101 a7399f66 Iustin Pop

102 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
103 a7399f66 Iustin Pop
  from this class should override OP_ID.
104 a7399f66 Iustin Pop

105 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
106 a7399f66 Iustin Pop
               childre of this class.
107 a7399f66 Iustin Pop

108 a7399f66 Iustin Pop
  """
109 df458e0b Iustin Pop
  OP_ID = "OP_ABSTRACT"
110 df458e0b Iustin Pop
  __slots__ = []
111 df458e0b Iustin Pop
112 df458e0b Iustin Pop
  def __getstate__(self):
113 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
114 df458e0b Iustin Pop

115 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
116 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
117 a7399f66 Iustin Pop
    instantiating the opcode.
118 a7399f66 Iustin Pop

119 a7399f66 Iustin Pop
    @rtype:   C{dict}
120 a7399f66 Iustin Pop
    @return:  the state as a dictionary
121 a7399f66 Iustin Pop

122 df458e0b Iustin Pop
    """
123 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
124 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
125 df458e0b Iustin Pop
    return data
126 df458e0b Iustin Pop
127 df458e0b Iustin Pop
  @classmethod
128 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
129 df458e0b Iustin Pop
    """Generic load opcode method.
130 df458e0b Iustin Pop

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

135 a7399f66 Iustin Pop
    @type data:  C{dict}
136 a7399f66 Iustin Pop
    @param data: the serialized opcode
137 a7399f66 Iustin Pop

138 df458e0b Iustin Pop
    """
139 df458e0b Iustin Pop
    if not isinstance(data, dict):
140 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
141 df458e0b Iustin Pop
    if "OP_ID" not in data:
142 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
143 df458e0b Iustin Pop
    op_id = data["OP_ID"]
144 df458e0b Iustin Pop
    op_class = None
145 df458e0b Iustin Pop
    for item in globals().values():
146 df458e0b Iustin Pop
      if (isinstance(item, type) and
147 df458e0b Iustin Pop
          issubclass(item, cls) and
148 df458e0b Iustin Pop
          hasattr(item, "OP_ID") and
149 df458e0b Iustin Pop
          getattr(item, "OP_ID") == op_id):
150 df458e0b Iustin Pop
        op_class = item
151 df458e0b Iustin Pop
        break
152 df458e0b Iustin Pop
    if op_class is None:
153 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
154 df458e0b Iustin Pop
                       op_id)
155 df458e0b Iustin Pop
    op = op_class()
156 df458e0b Iustin Pop
    new_data = data.copy()
157 df458e0b Iustin Pop
    del new_data["OP_ID"]
158 df458e0b Iustin Pop
    op.__setstate__(new_data)
159 df458e0b Iustin Pop
    return op
160 df458e0b Iustin Pop
161 a8083063 Iustin Pop
162 a8083063 Iustin Pop
class OpDestroyCluster(OpCode):
163 a7399f66 Iustin Pop
  """Destroy the cluster.
164 a7399f66 Iustin Pop

165 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
166 a7399f66 Iustin Pop
  lost after the execution of this opcode.
167 a7399f66 Iustin Pop

168 a7399f66 Iustin Pop
  """
169 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DESTROY"
170 a8083063 Iustin Pop
  __slots__ = []
171 a8083063 Iustin Pop
172 a8083063 Iustin Pop
173 a8083063 Iustin Pop
class OpQueryClusterInfo(OpCode):
174 fdc267f4 Iustin Pop
  """Query cluster information."""
175 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_QUERY"
176 a8083063 Iustin Pop
  __slots__ = []
177 a8083063 Iustin Pop
178 a8083063 Iustin Pop
179 a8083063 Iustin Pop
class OpVerifyCluster(OpCode):
180 a7399f66 Iustin Pop
  """Verify the cluster state.
181 a7399f66 Iustin Pop

182 a7399f66 Iustin Pop
  @type skip_checks: C{list}
183 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
184 a7399f66 Iustin Pop
                     needs to be a subset of
185 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
186 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
187 a7399f66 Iustin Pop

188 a7399f66 Iustin Pop
  """
189 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY"
190 e54c4c5e Guido Trotter
  __slots__ = ["skip_checks"]
191 a8083063 Iustin Pop
192 a8083063 Iustin Pop
193 150e978f Iustin Pop
class OpVerifyDisks(OpCode):
194 150e978f Iustin Pop
  """Verify the cluster disks.
195 150e978f Iustin Pop

196 150e978f Iustin Pop
  Parameters: none
197 150e978f Iustin Pop

198 150e978f Iustin Pop
  Result: two lists:
199 150e978f Iustin Pop
    - list of node names with bad data returned (unreachable, etc.)
200 a7399f66 Iustin Pop
    - dict of node names with broken volume groups (values: error msg)
201 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
202 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
203 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
204 150e978f Iustin Pop

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

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

213 150e978f Iustin Pop
  """
214 150e978f Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
215 150e978f Iustin Pop
  __slots__ = []
216 150e978f Iustin Pop
217 150e978f Iustin Pop
218 a8083063 Iustin Pop
class OpMasterFailover(OpCode):
219 fdc267f4 Iustin Pop
  """Do a master failover."""
220 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_MASTERFAILOVER"
221 a8083063 Iustin Pop
  __slots__ = []
222 a8083063 Iustin Pop
223 a8083063 Iustin Pop
224 a8083063 Iustin Pop
class OpDumpClusterConfig(OpCode):
225 fdc267f4 Iustin Pop
  """Dump the cluster configuration."""
226 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DUMPCONFIG"
227 a8083063 Iustin Pop
  __slots__ = []
228 a8083063 Iustin Pop
229 a8083063 Iustin Pop
230 07bd8a51 Iustin Pop
class OpRenameCluster(OpCode):
231 a7399f66 Iustin Pop
  """Rename the cluster.
232 a7399f66 Iustin Pop

233 a7399f66 Iustin Pop
  @type name: C{str}
234 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
235 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
236 a7399f66 Iustin Pop
              address.
237 a7399f66 Iustin Pop

238 a7399f66 Iustin Pop
  """
239 07bd8a51 Iustin Pop
  OP_ID = "OP_CLUSTER_RENAME"
240 07bd8a51 Iustin Pop
  __slots__ = ["name"]
241 07bd8a51 Iustin Pop
242 07bd8a51 Iustin Pop
243 12515db7 Manuel Franceschini
class OpSetClusterParams(OpCode):
244 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
245 a7399f66 Iustin Pop

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

249 a7399f66 Iustin Pop
  """
250 12515db7 Manuel Franceschini
  OP_ID = "OP_CLUSTER_SET_PARAMS"
251 12515db7 Manuel Franceschini
  __slots__ = ["vg_name"]
252 12515db7 Manuel Franceschini
253 12515db7 Manuel Franceschini
254 07bd8a51 Iustin Pop
# node opcodes
255 07bd8a51 Iustin Pop
256 a8083063 Iustin Pop
class OpRemoveNode(OpCode):
257 a7399f66 Iustin Pop
  """Remove a node.
258 a7399f66 Iustin Pop

259 a7399f66 Iustin Pop
  @type node_name: C{str}
260 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
261 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
262 a7399f66 Iustin Pop

263 a7399f66 Iustin Pop
  """
264 a8083063 Iustin Pop
  OP_ID = "OP_NODE_REMOVE"
265 a8083063 Iustin Pop
  __slots__ = ["node_name"]
266 a8083063 Iustin Pop
267 a8083063 Iustin Pop
268 a8083063 Iustin Pop
class OpAddNode(OpCode):
269 a7399f66 Iustin Pop
  """Add a node to the cluster.
270 a7399f66 Iustin Pop

271 a7399f66 Iustin Pop
  @type node_name: C{str}
272 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
273 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
274 a7399f66 Iustin Pop
  @type primary_ip: IP address
275 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
276 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
277 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
278 a7399f66 Iustin Pop
  @type secondary_ip: IP address
279 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
280 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
281 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
282 a7399f66 Iustin Pop
  @type readd: C{bool}
283 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
284 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
285 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
286 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
287 a7399f66 Iustin Pop
               without removal from the cluster.
288 a7399f66 Iustin Pop

289 a7399f66 Iustin Pop
  """
290 a8083063 Iustin Pop
  OP_ID = "OP_NODE_ADD"
291 e7c6e02b Michael Hanselmann
  __slots__ = ["node_name", "primary_ip", "secondary_ip", "readd"]
292 a8083063 Iustin Pop
293 a8083063 Iustin Pop
294 a8083063 Iustin Pop
class OpQueryNodes(OpCode):
295 a8083063 Iustin Pop
  """Compute the list of nodes."""
296 a8083063 Iustin Pop
  OP_ID = "OP_NODE_QUERY"
297 246e180a Iustin Pop
  __slots__ = ["output_fields", "names"]
298 a8083063 Iustin Pop
299 a8083063 Iustin Pop
300 dcb93971 Michael Hanselmann
class OpQueryNodeVolumes(OpCode):
301 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
302 dcb93971 Michael Hanselmann
  OP_ID = "OP_NODE_QUERYVOLS"
303 dcb93971 Michael Hanselmann
  __slots__ = ["nodes", "output_fields"]
304 dcb93971 Michael Hanselmann
305 dcb93971 Michael Hanselmann
306 a8083063 Iustin Pop
# instance opcodes
307 a8083063 Iustin Pop
308 a8083063 Iustin Pop
class OpCreateInstance(OpCode):
309 fdc267f4 Iustin Pop
  """Create an instance."""
310 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CREATE"
311 3b6d8c9b Iustin Pop
  __slots__ = [
312 3b6d8c9b Iustin Pop
    "instance_name", "mem_size", "disk_size", "os_type", "pnode",
313 3b6d8c9b Iustin Pop
    "disk_template", "snode", "swap_size", "mode",
314 3b6d8c9b Iustin Pop
    "vcpus", "ip", "bridge", "src_node", "src_path", "start",
315 3b6d8c9b Iustin Pop
    "wait_for_sync", "ip_check", "mac",
316 31a853d2 Iustin Pop
    "kernel_path", "initrd_path", "hvm_boot_order", "hvm_acpi",
317 31a853d2 Iustin Pop
    "hvm_pae", "hvm_cdrom_image_path", "vnc_bind_address",
318 dc936b49 Manuel Franceschini
    "file_storage_dir", "file_driver",
319 538475ca Iustin Pop
    "iallocator",
320 3b6d8c9b Iustin Pop
    ]
321 a8083063 Iustin Pop
322 a8083063 Iustin Pop
323 fe7b0351 Michael Hanselmann
class OpReinstallInstance(OpCode):
324 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
325 fe7b0351 Michael Hanselmann
  OP_ID = "OP_INSTANCE_REINSTALL"
326 d0834de3 Michael Hanselmann
  __slots__ = ["instance_name", "os_type"]
327 fe7b0351 Michael Hanselmann
328 fe7b0351 Michael Hanselmann
329 a8083063 Iustin Pop
class OpRemoveInstance(OpCode):
330 a8083063 Iustin Pop
  """Remove an instance."""
331 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REMOVE"
332 1d67656e Iustin Pop
  __slots__ = ["instance_name", "ignore_failures"]
333 a8083063 Iustin Pop
334 a8083063 Iustin Pop
335 decd5f45 Iustin Pop
class OpRenameInstance(OpCode):
336 decd5f45 Iustin Pop
  """Rename an instance."""
337 decd5f45 Iustin Pop
  OP_ID = "OP_INSTANCE_RENAME"
338 decd5f45 Iustin Pop
  __slots__ = ["instance_name", "ignore_ip", "new_name"]
339 decd5f45 Iustin Pop
340 decd5f45 Iustin Pop
341 a8083063 Iustin Pop
class OpStartupInstance(OpCode):
342 fdc267f4 Iustin Pop
  """Startup an instance."""
343 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_STARTUP"
344 a8083063 Iustin Pop
  __slots__ = ["instance_name", "force", "extra_args"]
345 a8083063 Iustin Pop
346 a8083063 Iustin Pop
347 a8083063 Iustin Pop
class OpShutdownInstance(OpCode):
348 fdc267f4 Iustin Pop
  """Shutdown an instance."""
349 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_SHUTDOWN"
350 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
351 a8083063 Iustin Pop
352 a8083063 Iustin Pop
353 bf6929a2 Alexander Schreiber
class OpRebootInstance(OpCode):
354 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
355 eeb3a5f9 Iustin Pop
  OP_ID = "OP_INSTANCE_REBOOT"
356 bf6929a2 Alexander Schreiber
  __slots__ = ["instance_name", "reboot_type", "extra_args",
357 bf6929a2 Alexander Schreiber
               "ignore_secondaries" ]
358 bf6929a2 Alexander Schreiber
359 bf6929a2 Alexander Schreiber
360 a8083063 Iustin Pop
class OpReplaceDisks(OpCode):
361 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
362 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
363 b6e82a65 Iustin Pop
  __slots__ = ["instance_name", "remote_node", "mode", "disks", "iallocator"]
364 a8083063 Iustin Pop
365 a8083063 Iustin Pop
366 a8083063 Iustin Pop
class OpFailoverInstance(OpCode):
367 a8083063 Iustin Pop
  """Failover an instance."""
368 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_FAILOVER"
369 a8083063 Iustin Pop
  __slots__ = ["instance_name", "ignore_consistency"]
370 a8083063 Iustin Pop
371 a8083063 Iustin Pop
372 a8083063 Iustin Pop
class OpConnectConsole(OpCode):
373 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
374 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CONSOLE"
375 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
376 a8083063 Iustin Pop
377 a8083063 Iustin Pop
378 a8083063 Iustin Pop
class OpActivateInstanceDisks(OpCode):
379 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
380 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
381 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
382 a8083063 Iustin Pop
383 a8083063 Iustin Pop
384 a8083063 Iustin Pop
class OpDeactivateInstanceDisks(OpCode):
385 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
386 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
387 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
388 a8083063 Iustin Pop
389 a8083063 Iustin Pop
390 a8083063 Iustin Pop
class OpQueryInstances(OpCode):
391 a8083063 Iustin Pop
  """Compute the list of instances."""
392 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY"
393 069dcc86 Iustin Pop
  __slots__ = ["output_fields", "names"]
394 a8083063 Iustin Pop
395 a8083063 Iustin Pop
396 a8083063 Iustin Pop
class OpQueryInstanceData(OpCode):
397 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
398 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY_DATA"
399 a8083063 Iustin Pop
  __slots__ = ["instances"]
400 a8083063 Iustin Pop
401 a8083063 Iustin Pop
402 7767bbf5 Manuel Franceschini
class OpSetInstanceParams(OpCode):
403 a8083063 Iustin Pop
  """Change the parameters of an instance."""
404 7767bbf5 Manuel Franceschini
  OP_ID = "OP_INSTANCE_SET_PARAMS"
405 973d7867 Iustin Pop
  __slots__ = [
406 973d7867 Iustin Pop
    "instance_name", "mem", "vcpus", "ip", "bridge", "mac",
407 31a853d2 Iustin Pop
    "kernel_path", "initrd_path", "hvm_boot_order", "hvm_acpi",
408 31a853d2 Iustin Pop
    "hvm_pae", "hvm_cdrom_image_path", "vnc_bind_address"
409 973d7867 Iustin Pop
    ]
410 a8083063 Iustin Pop
411 a8083063 Iustin Pop
412 8729e0d7 Iustin Pop
class OpGrowDisk(OpCode):
413 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
414 8729e0d7 Iustin Pop
  OP_ID = "OP_INSTANCE_GROW_DISK"
415 8729e0d7 Iustin Pop
  __slots__ = ["instance_name", "disk", "amount"]
416 8729e0d7 Iustin Pop
417 8729e0d7 Iustin Pop
418 a8083063 Iustin Pop
# OS opcodes
419 a8083063 Iustin Pop
class OpDiagnoseOS(OpCode):
420 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
421 a8083063 Iustin Pop
  OP_ID = "OP_OS_DIAGNOSE"
422 1f9430d6 Iustin Pop
  __slots__ = ["output_fields", "names"]
423 a8083063 Iustin Pop
424 7c0d6283 Michael Hanselmann
425 a8083063 Iustin Pop
# Exports opcodes
426 a8083063 Iustin Pop
class OpQueryExports(OpCode):
427 a8083063 Iustin Pop
  """Compute the list of exported images."""
428 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_QUERY"
429 a8083063 Iustin Pop
  __slots__ = ["nodes"]
430 a8083063 Iustin Pop
431 7c0d6283 Michael Hanselmann
432 a8083063 Iustin Pop
class OpExportInstance(OpCode):
433 a8083063 Iustin Pop
  """Export an instance."""
434 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_EXPORT"
435 a8083063 Iustin Pop
  __slots__ = ["instance_name", "target_node", "shutdown"]
436 5c947f38 Iustin Pop
437 9ac99fda Guido Trotter
class OpRemoveExport(OpCode):
438 9ac99fda Guido Trotter
  """Remove an instance's export."""
439 9ac99fda Guido Trotter
  OP_ID = "OP_BACKUP_REMOVE"
440 9ac99fda Guido Trotter
  __slots__ = ["instance_name"]
441 5c947f38 Iustin Pop
442 5c947f38 Iustin Pop
# Tags opcodes
443 5c947f38 Iustin Pop
class OpGetTags(OpCode):
444 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
445 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_GET"
446 5c947f38 Iustin Pop
  __slots__ = ["kind", "name"]
447 5c947f38 Iustin Pop
448 5c947f38 Iustin Pop
449 73415719 Iustin Pop
class OpSearchTags(OpCode):
450 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
451 73415719 Iustin Pop
  OP_ID = "OP_TAGS_SEARCH"
452 73415719 Iustin Pop
  __slots__ = ["pattern"]
453 73415719 Iustin Pop
454 73415719 Iustin Pop
455 f27302fa Iustin Pop
class OpAddTags(OpCode):
456 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
457 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_SET"
458 f27302fa Iustin Pop
  __slots__ = ["kind", "name", "tags"]
459 5c947f38 Iustin Pop
460 5c947f38 Iustin Pop
461 f27302fa Iustin Pop
class OpDelTags(OpCode):
462 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
463 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_DEL"
464 f27302fa Iustin Pop
  __slots__ = ["kind", "name", "tags"]
465 06009e27 Iustin Pop
466 06009e27 Iustin Pop
467 06009e27 Iustin Pop
# Test opcodes
468 06009e27 Iustin Pop
class OpTestDelay(OpCode):
469 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
470 06009e27 Iustin Pop

471 06009e27 Iustin Pop
  This is used just for debugging and testing.
472 06009e27 Iustin Pop

473 06009e27 Iustin Pop
  Parameters:
474 06009e27 Iustin Pop
    - duration: the time to sleep
475 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
476 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
477 06009e27 Iustin Pop

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

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

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

488 06009e27 Iustin Pop
  """
489 06009e27 Iustin Pop
  OP_ID = "OP_TEST_DELAY"
490 06009e27 Iustin Pop
  __slots__ = ["duration", "on_master", "on_nodes"]
491 d61df03e Iustin Pop
492 d61df03e Iustin Pop
493 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
494 d61df03e Iustin Pop
  """Allocator framework testing.
495 d61df03e Iustin Pop

496 d61df03e Iustin Pop
  This opcode has two modes:
497 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
498 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
499 d61df03e Iustin Pop
      'in')
500 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
501 d61df03e Iustin Pop
      return the allocator output (direction 'out')
502 d61df03e Iustin Pop

503 d61df03e Iustin Pop
  """
504 d61df03e Iustin Pop
  OP_ID = "OP_TEST_ALLOCATOR"
505 d61df03e Iustin Pop
  __slots__ = [
506 d61df03e Iustin Pop
    "direction", "mode", "allocator", "name",
507 d61df03e Iustin Pop
    "mem_size", "disks", "disk_template",
508 d61df03e Iustin Pop
    "os", "tags", "nics", "vcpus",
509 d61df03e Iustin Pop
    ]