Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ a0c9f010

History | View | Annotate | Download (12 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 OpDestroyCluster(OpCode):
163 a8083063 Iustin Pop
  """Destroy the cluster."""
164 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DESTROY"
165 a8083063 Iustin Pop
  __slots__ = []
166 a8083063 Iustin Pop
167 a8083063 Iustin Pop
168 a8083063 Iustin Pop
class OpQueryClusterInfo(OpCode):
169 fdc267f4 Iustin Pop
  """Query cluster information."""
170 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_QUERY"
171 a8083063 Iustin Pop
  __slots__ = []
172 a8083063 Iustin Pop
173 a8083063 Iustin Pop
174 a8083063 Iustin Pop
class OpClusterCopyFile(OpCode):
175 fdc267f4 Iustin Pop
  """Copy a file to multiple nodes."""
176 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_COPYFILE"
177 a8083063 Iustin Pop
  __slots__ = ["nodes", "filename"]
178 a8083063 Iustin Pop
179 a8083063 Iustin Pop
180 a8083063 Iustin Pop
class OpRunClusterCommand(OpCode):
181 fdc267f4 Iustin Pop
  """Run a command on multiple nodes."""
182 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_RUNCOMMAND"
183 a8083063 Iustin Pop
  __slots__ = ["nodes", "command"]
184 a8083063 Iustin Pop
185 a8083063 Iustin Pop
186 a8083063 Iustin Pop
class OpVerifyCluster(OpCode):
187 fdc267f4 Iustin Pop
  """Verify the cluster state."""
188 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY"
189 e54c4c5e Guido Trotter
  __slots__ = ["skip_checks"]
190 a8083063 Iustin Pop
191 a8083063 Iustin Pop
192 150e978f Iustin Pop
class OpVerifyDisks(OpCode):
193 150e978f Iustin Pop
  """Verify the cluster disks.
194 150e978f Iustin Pop

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

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

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

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

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

426 06009e27 Iustin Pop
  This is used just for debugging and testing.
427 06009e27 Iustin Pop

428 06009e27 Iustin Pop
  Parameters:
429 06009e27 Iustin Pop
    - duration: the time to sleep
430 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
431 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
432 06009e27 Iustin Pop

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

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

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

443 06009e27 Iustin Pop
  """
444 06009e27 Iustin Pop
  OP_ID = "OP_TEST_DELAY"
445 06009e27 Iustin Pop
  __slots__ = ["duration", "on_master", "on_nodes"]
446 d61df03e Iustin Pop
447 d61df03e Iustin Pop
448 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
449 d61df03e Iustin Pop
  """Allocator framework testing.
450 d61df03e Iustin Pop

451 d61df03e Iustin Pop
  This opcode has two modes:
452 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
453 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
454 d61df03e Iustin Pop
      'in')
455 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
456 d61df03e Iustin Pop
      return the allocator output (direction 'out')
457 d61df03e Iustin Pop

458 d61df03e Iustin Pop
  """
459 d61df03e Iustin Pop
  OP_ID = "OP_TEST_ALLOCATOR"
460 d61df03e Iustin Pop
  __slots__ = [
461 d61df03e Iustin Pop
    "direction", "mode", "allocator", "name",
462 d61df03e Iustin Pop
    "mem_size", "disks", "disk_template",
463 d61df03e Iustin Pop
    "os", "tags", "nics", "vcpus",
464 d61df03e Iustin Pop
    ]