Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ b74159ee

History | View | Annotate | Download (12.1 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 a8083063 Iustin Pop

28 a8083063 Iustin Pop
This module implements the logic for doing operations in the cluster. There
29 a8083063 Iustin Pop
are two kinds of classes defined:
30 a8083063 Iustin Pop
  - opcodes, which are small classes only holding data for the task at hand
31 a8083063 Iustin Pop
  - logical units, which know how to deal with their specific opcode only
32 a8083063 Iustin Pop

33 a8083063 Iustin Pop
"""
34 a8083063 Iustin Pop
35 a8083063 Iustin Pop
# this are practically structures, so disable the message about too
36 a8083063 Iustin Pop
# few public methods:
37 a8083063 Iustin Pop
# pylint: disable-msg=R0903
38 a8083063 Iustin Pop
39 df458e0b Iustin Pop
40 df458e0b Iustin Pop
class BaseJO(object):
41 df458e0b Iustin Pop
  """A simple serializable object.
42 df458e0b Iustin Pop

43 df458e0b Iustin Pop
  This object serves as a parent class for both OpCode and Job since
44 df458e0b Iustin Pop
  they are serialized in the same way.
45 df458e0b Iustin Pop

46 df458e0b Iustin Pop
  """
47 a8083063 Iustin Pop
  __slots__ = []
48 a8083063 Iustin Pop
49 a8083063 Iustin Pop
  def __init__(self, **kwargs):
50 a8083063 Iustin Pop
    for key in kwargs:
51 a8083063 Iustin Pop
      if key not in self.__slots__:
52 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
53 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
54 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
55 a8083063 Iustin Pop
56 df458e0b Iustin Pop
  def __getstate__(self):
57 df458e0b Iustin Pop
    state = {}
58 df458e0b Iustin Pop
    for name in self.__slots__:
59 df458e0b Iustin Pop
      if hasattr(self, name):
60 df458e0b Iustin Pop
        state[name] = getattr(self, name)
61 df458e0b Iustin Pop
    return state
62 df458e0b Iustin Pop
63 df458e0b Iustin Pop
  def __setstate__(self, state):
64 df458e0b Iustin Pop
    if not isinstance(state, dict):
65 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
66 df458e0b Iustin Pop
                       type(state))
67 df458e0b Iustin Pop
68 df458e0b Iustin Pop
    for name in self.__slots__:
69 df458e0b Iustin Pop
      if name not in state:
70 df458e0b Iustin Pop
        delattr(self, name)
71 df458e0b Iustin Pop
72 df458e0b Iustin Pop
    for name in state:
73 df458e0b Iustin Pop
      setattr(self, name, state[name])
74 df458e0b Iustin Pop
75 df458e0b Iustin Pop
76 df458e0b Iustin Pop
class Job(BaseJO):
77 35049ff2 Iustin Pop
  """Job definition structure
78 35049ff2 Iustin Pop

79 35049ff2 Iustin Pop
  The Job definitions has two sets of parameters:
80 35049ff2 Iustin Pop
    - the parameters of the job itself (all filled by server):
81 35049ff2 Iustin Pop
      - job_id,
82 35049ff2 Iustin Pop
      - status: pending, running, successfull, failed, aborted
83 35049ff2 Iustin Pop
    - opcode parameters:
84 35049ff2 Iustin Pop
      - op_list, list of opcodes, clients creates this
85 35049ff2 Iustin Pop
      - op_status, status for each opcode, server fills in
86 35049ff2 Iustin Pop
      - op_result, result for each opcode, server fills in
87 35049ff2 Iustin Pop

88 35049ff2 Iustin Pop
  """
89 df458e0b Iustin Pop
  STATUS_PENDING = 1
90 df458e0b Iustin Pop
  STATUS_RUNNING = 2
91 35049ff2 Iustin Pop
  STATUS_SUCCESS = 3
92 35049ff2 Iustin Pop
  STATUS_FAIL = 4
93 35049ff2 Iustin Pop
  STATUS_ABORT = 5
94 35049ff2 Iustin Pop
95 35049ff2 Iustin Pop
  __slots__ = [
96 35049ff2 Iustin Pop
    "job_id",
97 35049ff2 Iustin Pop
    "status",
98 35049ff2 Iustin Pop
    "op_list",
99 35049ff2 Iustin Pop
    "op_status",
100 35049ff2 Iustin Pop
    "op_result",
101 35049ff2 Iustin Pop
    ]
102 df458e0b Iustin Pop
103 df458e0b Iustin Pop
  def __getstate__(self):
104 df458e0b Iustin Pop
    """Specialized getstate for jobs
105 df458e0b Iustin Pop

106 df458e0b Iustin Pop
    """
107 df458e0b Iustin Pop
    data = BaseJO.__getstate__(self)
108 df458e0b Iustin Pop
    if "op_list" in data:
109 df458e0b Iustin Pop
      data["op_list"] = [op.__getstate__() for op in data["op_list"]]
110 df458e0b Iustin Pop
    return data
111 df458e0b Iustin Pop
112 df458e0b Iustin Pop
  def __setstate__(self, state):
113 df458e0b Iustin Pop
    """Specialized setstate for jobs
114 df458e0b Iustin Pop

115 df458e0b Iustin Pop
    """
116 df458e0b Iustin Pop
    BaseJO.__setstate__(self, state)
117 df458e0b Iustin Pop
    if "op_list" in state:
118 00abdc96 Iustin Pop
      self.op_list = [OpCode.LoadOpCode(op) for op in state["op_list"]]
119 df458e0b Iustin Pop
120 df458e0b Iustin Pop
121 df458e0b Iustin Pop
class OpCode(BaseJO):
122 df458e0b Iustin Pop
  """Abstract OpCode"""
123 df458e0b Iustin Pop
  OP_ID = "OP_ABSTRACT"
124 df458e0b Iustin Pop
  __slots__ = []
125 df458e0b Iustin Pop
126 df458e0b Iustin Pop
  def __getstate__(self):
127 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
128 df458e0b Iustin Pop

129 df458e0b Iustin Pop
    """
130 df458e0b Iustin Pop
    data = BaseJO.__getstate__(self)
131 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
132 df458e0b Iustin Pop
    return data
133 df458e0b Iustin Pop
134 df458e0b Iustin Pop
  @classmethod
135 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
136 df458e0b Iustin Pop
    """Generic load opcode method.
137 df458e0b 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 OpInitCluster(OpCode):
163 a8083063 Iustin Pop
  """Initialise the cluster."""
164 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_INIT"
165 a8083063 Iustin Pop
  __slots__ = ["cluster_name", "secondary_ip", "hypervisor_type",
166 1322c697 Manuel Franceschini
               "vg_name", "mac_prefix", "def_bridge", "master_netdev",
167 1322c697 Manuel Franceschini
               "file_storage_dir"]
168 a8083063 Iustin Pop
169 a8083063 Iustin Pop
170 a8083063 Iustin Pop
class OpDestroyCluster(OpCode):
171 a8083063 Iustin Pop
  """Destroy the cluster."""
172 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DESTROY"
173 a8083063 Iustin Pop
  __slots__ = []
174 a8083063 Iustin Pop
175 a8083063 Iustin Pop
176 a8083063 Iustin Pop
class OpQueryClusterInfo(OpCode):
177 fdc267f4 Iustin Pop
  """Query cluster information."""
178 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_QUERY"
179 a8083063 Iustin Pop
  __slots__ = []
180 a8083063 Iustin Pop
181 a8083063 Iustin Pop
182 a8083063 Iustin Pop
class OpClusterCopyFile(OpCode):
183 fdc267f4 Iustin Pop
  """Copy a file to multiple nodes."""
184 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_COPYFILE"
185 a8083063 Iustin Pop
  __slots__ = ["nodes", "filename"]
186 a8083063 Iustin Pop
187 a8083063 Iustin Pop
188 a8083063 Iustin Pop
class OpRunClusterCommand(OpCode):
189 fdc267f4 Iustin Pop
  """Run a command on multiple nodes."""
190 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_RUNCOMMAND"
191 a8083063 Iustin Pop
  __slots__ = ["nodes", "command"]
192 a8083063 Iustin Pop
193 a8083063 Iustin Pop
194 a8083063 Iustin Pop
class OpVerifyCluster(OpCode):
195 fdc267f4 Iustin Pop
  """Verify the cluster state."""
196 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY"
197 e54c4c5e Guido Trotter
  __slots__ = ["skip_checks"]
198 a8083063 Iustin Pop
199 a8083063 Iustin Pop
200 150e978f Iustin Pop
class OpVerifyDisks(OpCode):
201 150e978f Iustin Pop
  """Verify the cluster disks.
202 150e978f Iustin Pop

203 150e978f Iustin Pop
  Parameters: none
204 150e978f Iustin Pop

205 150e978f Iustin Pop
  Result: two lists:
206 150e978f Iustin Pop
    - list of node names with bad data returned (unreachable, etc.)
207 b63ed789 Iustin Pop
    - dist of node names with broken volume groups (values: error msg)
208 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
209 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
210 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
211 150e978f Iustin Pop

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

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

220 150e978f Iustin Pop
  """
221 150e978f Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
222 150e978f Iustin Pop
  __slots__ = []
223 150e978f Iustin Pop
224 150e978f Iustin Pop
225 a8083063 Iustin Pop
class OpMasterFailover(OpCode):
226 fdc267f4 Iustin Pop
  """Do a master failover."""
227 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_MASTERFAILOVER"
228 a8083063 Iustin Pop
  __slots__ = []
229 a8083063 Iustin Pop
230 a8083063 Iustin Pop
231 a8083063 Iustin Pop
class OpDumpClusterConfig(OpCode):
232 fdc267f4 Iustin Pop
  """Dump the cluster configuration."""
233 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DUMPCONFIG"
234 a8083063 Iustin Pop
  __slots__ = []
235 a8083063 Iustin Pop
236 a8083063 Iustin Pop
237 07bd8a51 Iustin Pop
class OpRenameCluster(OpCode):
238 07bd8a51 Iustin Pop
  """Rename the cluster."""
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 12515db7 Manuel Franceschini
  """Change the parameters of the cluster."""
245 12515db7 Manuel Franceschini
  OP_ID = "OP_CLUSTER_SET_PARAMS"
246 12515db7 Manuel Franceschini
  __slots__ = ["vg_name"]
247 12515db7 Manuel Franceschini
248 12515db7 Manuel Franceschini
249 07bd8a51 Iustin Pop
# node opcodes
250 07bd8a51 Iustin Pop
251 a8083063 Iustin Pop
class OpRemoveNode(OpCode):
252 a8083063 Iustin Pop
  """Remove a node."""
253 a8083063 Iustin Pop
  OP_ID = "OP_NODE_REMOVE"
254 a8083063 Iustin Pop
  __slots__ = ["node_name"]
255 a8083063 Iustin Pop
256 a8083063 Iustin Pop
257 a8083063 Iustin Pop
class OpAddNode(OpCode):
258 a8083063 Iustin Pop
  """Add a node."""
259 a8083063 Iustin Pop
  OP_ID = "OP_NODE_ADD"
260 e7c6e02b Michael Hanselmann
  __slots__ = ["node_name", "primary_ip", "secondary_ip", "readd"]
261 a8083063 Iustin Pop
262 a8083063 Iustin Pop
263 a8083063 Iustin Pop
class OpQueryNodes(OpCode):
264 a8083063 Iustin Pop
  """Compute the list of nodes."""
265 a8083063 Iustin Pop
  OP_ID = "OP_NODE_QUERY"
266 246e180a Iustin Pop
  __slots__ = ["output_fields", "names"]
267 a8083063 Iustin Pop
268 a8083063 Iustin Pop
269 dcb93971 Michael Hanselmann
class OpQueryNodeVolumes(OpCode):
270 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
271 dcb93971 Michael Hanselmann
  OP_ID = "OP_NODE_QUERYVOLS"
272 dcb93971 Michael Hanselmann
  __slots__ = ["nodes", "output_fields"]
273 dcb93971 Michael Hanselmann
274 dcb93971 Michael Hanselmann
275 a8083063 Iustin Pop
# instance opcodes
276 a8083063 Iustin Pop
277 a8083063 Iustin Pop
class OpCreateInstance(OpCode):
278 fdc267f4 Iustin Pop
  """Create an instance."""
279 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CREATE"
280 3b6d8c9b Iustin Pop
  __slots__ = [
281 3b6d8c9b Iustin Pop
    "instance_name", "mem_size", "disk_size", "os_type", "pnode",
282 3b6d8c9b Iustin Pop
    "disk_template", "snode", "swap_size", "mode",
283 3b6d8c9b Iustin Pop
    "vcpus", "ip", "bridge", "src_node", "src_path", "start",
284 3b6d8c9b Iustin Pop
    "wait_for_sync", "ip_check", "mac",
285 25c5878d Alexander Schreiber
    "kernel_path", "initrd_path", "hvm_boot_order",
286 dc936b49 Manuel Franceschini
    "file_storage_dir", "file_driver",
287 538475ca Iustin Pop
    "iallocator",
288 3b6d8c9b Iustin Pop
    ]
289 a8083063 Iustin Pop
290 a8083063 Iustin Pop
291 fe7b0351 Michael Hanselmann
class OpReinstallInstance(OpCode):
292 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
293 fe7b0351 Michael Hanselmann
  OP_ID = "OP_INSTANCE_REINSTALL"
294 d0834de3 Michael Hanselmann
  __slots__ = ["instance_name", "os_type"]
295 fe7b0351 Michael Hanselmann
296 fe7b0351 Michael Hanselmann
297 a8083063 Iustin Pop
class OpRemoveInstance(OpCode):
298 a8083063 Iustin Pop
  """Remove an instance."""
299 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REMOVE"
300 1d67656e Iustin Pop
  __slots__ = ["instance_name", "ignore_failures"]
301 a8083063 Iustin Pop
302 a8083063 Iustin Pop
303 decd5f45 Iustin Pop
class OpRenameInstance(OpCode):
304 decd5f45 Iustin Pop
  """Rename an instance."""
305 decd5f45 Iustin Pop
  OP_ID = "OP_INSTANCE_RENAME"
306 decd5f45 Iustin Pop
  __slots__ = ["instance_name", "ignore_ip", "new_name"]
307 decd5f45 Iustin Pop
308 decd5f45 Iustin Pop
309 a8083063 Iustin Pop
class OpStartupInstance(OpCode):
310 fdc267f4 Iustin Pop
  """Startup an instance."""
311 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_STARTUP"
312 a8083063 Iustin Pop
  __slots__ = ["instance_name", "force", "extra_args"]
313 a8083063 Iustin Pop
314 a8083063 Iustin Pop
315 a8083063 Iustin Pop
class OpShutdownInstance(OpCode):
316 fdc267f4 Iustin Pop
  """Shutdown an instance."""
317 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_SHUTDOWN"
318 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
319 a8083063 Iustin Pop
320 a8083063 Iustin Pop
321 bf6929a2 Alexander Schreiber
class OpRebootInstance(OpCode):
322 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
323 eeb3a5f9 Iustin Pop
  OP_ID = "OP_INSTANCE_REBOOT"
324 bf6929a2 Alexander Schreiber
  __slots__ = ["instance_name", "reboot_type", "extra_args",
325 bf6929a2 Alexander Schreiber
               "ignore_secondaries" ]
326 bf6929a2 Alexander Schreiber
327 bf6929a2 Alexander Schreiber
328 a8083063 Iustin Pop
class OpReplaceDisks(OpCode):
329 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
330 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
331 b6e82a65 Iustin Pop
  __slots__ = ["instance_name", "remote_node", "mode", "disks", "iallocator"]
332 a8083063 Iustin Pop
333 a8083063 Iustin Pop
334 a8083063 Iustin Pop
class OpFailoverInstance(OpCode):
335 a8083063 Iustin Pop
  """Failover an instance."""
336 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_FAILOVER"
337 a8083063 Iustin Pop
  __slots__ = ["instance_name", "ignore_consistency"]
338 a8083063 Iustin Pop
339 a8083063 Iustin Pop
340 a8083063 Iustin Pop
class OpConnectConsole(OpCode):
341 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
342 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CONSOLE"
343 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
344 a8083063 Iustin Pop
345 a8083063 Iustin Pop
346 a8083063 Iustin Pop
class OpActivateInstanceDisks(OpCode):
347 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
348 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
349 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
350 a8083063 Iustin Pop
351 a8083063 Iustin Pop
352 a8083063 Iustin Pop
class OpDeactivateInstanceDisks(OpCode):
353 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
354 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
355 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
356 a8083063 Iustin Pop
357 a8083063 Iustin Pop
358 a8083063 Iustin Pop
class OpQueryInstances(OpCode):
359 a8083063 Iustin Pop
  """Compute the list of instances."""
360 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY"
361 069dcc86 Iustin Pop
  __slots__ = ["output_fields", "names"]
362 a8083063 Iustin Pop
363 a8083063 Iustin Pop
364 a8083063 Iustin Pop
class OpQueryInstanceData(OpCode):
365 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
366 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY_DATA"
367 a8083063 Iustin Pop
  __slots__ = ["instances"]
368 a8083063 Iustin Pop
369 a8083063 Iustin Pop
370 7767bbf5 Manuel Franceschini
class OpSetInstanceParams(OpCode):
371 a8083063 Iustin Pop
  """Change the parameters of an instance."""
372 7767bbf5 Manuel Franceschini
  OP_ID = "OP_INSTANCE_SET_PARAMS"
373 973d7867 Iustin Pop
  __slots__ = [
374 973d7867 Iustin Pop
    "instance_name", "mem", "vcpus", "ip", "bridge", "mac",
375 25c5878d Alexander Schreiber
    "kernel_path", "initrd_path", "hvm_boot_order",
376 973d7867 Iustin Pop
    ]
377 a8083063 Iustin Pop
378 a8083063 Iustin Pop
379 a8083063 Iustin Pop
# OS opcodes
380 a8083063 Iustin Pop
class OpDiagnoseOS(OpCode):
381 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
382 a8083063 Iustin Pop
  OP_ID = "OP_OS_DIAGNOSE"
383 1f9430d6 Iustin Pop
  __slots__ = ["output_fields", "names"]
384 a8083063 Iustin Pop
385 7c0d6283 Michael Hanselmann
386 a8083063 Iustin Pop
# Exports opcodes
387 a8083063 Iustin Pop
class OpQueryExports(OpCode):
388 a8083063 Iustin Pop
  """Compute the list of exported images."""
389 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_QUERY"
390 a8083063 Iustin Pop
  __slots__ = ["nodes"]
391 a8083063 Iustin Pop
392 7c0d6283 Michael Hanselmann
393 a8083063 Iustin Pop
class OpExportInstance(OpCode):
394 a8083063 Iustin Pop
  """Export an instance."""
395 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_EXPORT"
396 a8083063 Iustin Pop
  __slots__ = ["instance_name", "target_node", "shutdown"]
397 5c947f38 Iustin Pop
398 9ac99fda Guido Trotter
class OpRemoveExport(OpCode):
399 9ac99fda Guido Trotter
  """Remove an instance's export."""
400 9ac99fda Guido Trotter
  OP_ID = "OP_BACKUP_REMOVE"
401 9ac99fda Guido Trotter
  __slots__ = ["instance_name"]
402 5c947f38 Iustin Pop
403 5c947f38 Iustin Pop
# Tags opcodes
404 5c947f38 Iustin Pop
class OpGetTags(OpCode):
405 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
406 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_GET"
407 5c947f38 Iustin Pop
  __slots__ = ["kind", "name"]
408 5c947f38 Iustin Pop
409 5c947f38 Iustin Pop
410 73415719 Iustin Pop
class OpSearchTags(OpCode):
411 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
412 73415719 Iustin Pop
  OP_ID = "OP_TAGS_SEARCH"
413 73415719 Iustin Pop
  __slots__ = ["pattern"]
414 73415719 Iustin Pop
415 73415719 Iustin Pop
416 f27302fa Iustin Pop
class OpAddTags(OpCode):
417 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
418 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_SET"
419 f27302fa Iustin Pop
  __slots__ = ["kind", "name", "tags"]
420 5c947f38 Iustin Pop
421 5c947f38 Iustin Pop
422 f27302fa Iustin Pop
class OpDelTags(OpCode):
423 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
424 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_DEL"
425 f27302fa Iustin Pop
  __slots__ = ["kind", "name", "tags"]
426 06009e27 Iustin Pop
427 06009e27 Iustin Pop
428 06009e27 Iustin Pop
# Test opcodes
429 06009e27 Iustin Pop
class OpTestDelay(OpCode):
430 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
431 06009e27 Iustin Pop

432 06009e27 Iustin Pop
  This is used just for debugging and testing.
433 06009e27 Iustin Pop

434 06009e27 Iustin Pop
  Parameters:
435 06009e27 Iustin Pop
    - duration: the time to sleep
436 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
437 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
438 06009e27 Iustin Pop

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

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

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

449 06009e27 Iustin Pop
  """
450 06009e27 Iustin Pop
  OP_ID = "OP_TEST_DELAY"
451 06009e27 Iustin Pop
  __slots__ = ["duration", "on_master", "on_nodes"]
452 d61df03e Iustin Pop
453 d61df03e Iustin Pop
454 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
455 d61df03e Iustin Pop
  """Allocator framework testing.
456 d61df03e Iustin Pop

457 d61df03e Iustin Pop
  This opcode has two modes:
458 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
459 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
460 d61df03e Iustin Pop
      'in')
461 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
462 d61df03e Iustin Pop
      return the allocator output (direction 'out')
463 d61df03e Iustin Pop

464 d61df03e Iustin Pop
  """
465 d61df03e Iustin Pop
  OP_ID = "OP_TEST_ALLOCATOR"
466 d61df03e Iustin Pop
  __slots__ = [
467 d61df03e Iustin Pop
    "direction", "mode", "allocator", "name",
468 d61df03e Iustin Pop
    "mem_size", "disks", "disk_template",
469 d61df03e Iustin Pop
    "os", "tags", "nics", "vcpus",
470 d61df03e Iustin Pop
    ]