Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 9fa567b3

History | View | Annotate | Download (52.7 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 687c10d9 Iustin Pop
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 a8083063 Iustin Pop
"""OpCodes module
23 a8083063 Iustin Pop

24 a8083063 Iustin Pop
This module implements the data structures which define the cluster
25 a8083063 Iustin Pop
operations - the so-called opcodes.
26 a8083063 Iustin Pop

27 0e46916d Iustin Pop
Every operation which modifies the cluster state is expressed via
28 0e46916d Iustin Pop
opcodes.
29 a8083063 Iustin Pop

30 a8083063 Iustin Pop
"""
31 a8083063 Iustin Pop
32 a8083063 Iustin Pop
# this are practically structures, so disable the message about too
33 a8083063 Iustin Pop
# few public methods:
34 b459a848 Andrea Spadaccini
# pylint: disable=R0903
35 a8083063 Iustin Pop
36 1cbef6d8 Michael Hanselmann
import logging
37 ff0d18e6 Iustin Pop
import re
38 1cbef6d8 Michael Hanselmann
39 eb62069e Iustin Pop
from ganeti import compat
40 65e183af Michael Hanselmann
from ganeti import constants
41 65e183af Michael Hanselmann
from ganeti import errors
42 65e183af Michael Hanselmann
from ganeti import ht
43 65e183af Michael Hanselmann
44 65e183af Michael Hanselmann
45 65e183af Michael Hanselmann
# Common opcode attributes
46 65e183af Michael Hanselmann
47 65e183af Michael Hanselmann
#: output fields for a query operation
48 197b323b Michael Hanselmann
_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
49 45d4c81c Michael Hanselmann
                  "Selected output fields")
50 65e183af Michael Hanselmann
51 65e183af Michael Hanselmann
#: the shutdown timeout
52 45d4c81c Michael Hanselmann
_PShutdownTimeout = \
53 45d4c81c Michael Hanselmann
  ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
54 45d4c81c Michael Hanselmann
   "How long to wait for instance to shut down")
55 65e183af Michael Hanselmann
56 65e183af Michael Hanselmann
#: the force parameter
57 45d4c81c Michael Hanselmann
_PForce = ("force", False, ht.TBool, "Whether to force the operation")
58 65e183af Michael Hanselmann
59 65e183af Michael Hanselmann
#: a required instance name (for single-instance LUs)
60 45d4c81c Michael Hanselmann
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
61 45d4c81c Michael Hanselmann
                  "Instance name")
62 65e183af Michael Hanselmann
63 65e183af Michael Hanselmann
#: Whether to ignore offline nodes
64 45d4c81c Michael Hanselmann
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
65 45d4c81c Michael Hanselmann
                        "Whether to ignore offline nodes")
66 65e183af Michael Hanselmann
67 65e183af Michael Hanselmann
#: a required node name (for single-node LUs)
68 45d4c81c Michael Hanselmann
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
69 65e183af Michael Hanselmann
70 65e183af Michael Hanselmann
#: a required node group name (for single-group LUs)
71 45d4c81c Michael Hanselmann
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
72 65e183af Michael Hanselmann
73 65e183af Michael Hanselmann
#: Migration type (live/non-live)
74 65e183af Michael Hanselmann
_PMigrationMode = ("mode", None,
75 197b323b Michael Hanselmann
                   ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
76 45d4c81c Michael Hanselmann
                   "Migration mode")
77 65e183af Michael Hanselmann
78 65e183af Michael Hanselmann
#: Obsolete 'live' migration mode (boolean)
79 45d4c81c Michael Hanselmann
_PMigrationLive = ("live", None, ht.TMaybeBool,
80 45d4c81c Michael Hanselmann
                   "Legacy setting for live migration, do not use")
81 65e183af Michael Hanselmann
82 65e183af Michael Hanselmann
#: Tag type
83 197b323b Michael Hanselmann
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None)
84 65e183af Michael Hanselmann
85 65e183af Michael Hanselmann
#: List of tag strings
86 197b323b Michael Hanselmann
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None)
87 65e183af Michael Hanselmann
88 45d4c81c Michael Hanselmann
_PForceVariant = ("force_variant", False, ht.TBool,
89 45d4c81c Michael Hanselmann
                  "Whether to force an unknown OS variant")
90 45d4c81c Michael Hanselmann
91 45d4c81c Michael Hanselmann
_PWaitForSync = ("wait_for_sync", True, ht.TBool,
92 45d4c81c Michael Hanselmann
                 "Whether to wait for the disk to synchronize")
93 45d4c81c Michael Hanselmann
94 45d4c81c Michael Hanselmann
_PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
95 45d4c81c Michael Hanselmann
                       "Whether to ignore disk consistency")
96 45d4c81c Michael Hanselmann
97 45d4c81c Michael Hanselmann
_PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")
98 45d4c81c Michael Hanselmann
99 45d4c81c Michael Hanselmann
_PUseLocking = ("use_locking", False, ht.TBool,
100 45d4c81c Michael Hanselmann
                "Whether to use synchronization")
101 45d4c81c Michael Hanselmann
102 45d4c81c Michael Hanselmann
_PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")
103 45d4c81c Michael Hanselmann
104 45d4c81c Michael Hanselmann
_PNodeGroupAllocPolicy = \
105 45d4c81c Michael Hanselmann
  ("alloc_policy", None,
106 45d4c81c Michael Hanselmann
   ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
107 45d4c81c Michael Hanselmann
   "Instance allocation policy")
108 45d4c81c Michael Hanselmann
109 45d4c81c Michael Hanselmann
_PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
110 45d4c81c Michael Hanselmann
                     "Default node parameters for group")
111 45d4c81c Michael Hanselmann
112 abd66bf8 Michael Hanselmann
_PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
113 8e7078e0 Michael Hanselmann
               "Resource(s) to query for")
114 8e7078e0 Michael Hanselmann
115 e1f23243 Michael Hanselmann
_PEarlyRelease = ("early_release", False, ht.TBool,
116 e1f23243 Michael Hanselmann
                  "Whether to release locks as soon as possible")
117 e1f23243 Michael Hanselmann
118 45d4c81c Michael Hanselmann
_PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
119 45d4c81c Michael Hanselmann
120 9b64e486 Iustin Pop
#: Do not remember instance state changes
121 6aac5aef Iustin Pop
_PNoRemember = ("no_remember", False, ht.TBool,
122 6aac5aef Iustin Pop
                "Do not remember the state change")
123 9b64e486 Iustin Pop
124 f8fa4175 Michael Hanselmann
#: Target node for instance migration/failover
125 f8fa4175 Michael Hanselmann
_PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
126 f8fa4175 Michael Hanselmann
                         "Target node for shared-storage instances")
127 f8fa4175 Michael Hanselmann
128 323f9095 Stephen Shirley
_PStartupPaused = ("startup_paused", False, ht.TBool,
129 323f9095 Stephen Shirley
                   "Pause instance at startup")
130 323f9095 Stephen Shirley
131 57106b74 Michael Hanselmann
_PVerbose = ("verbose", False, ht.TBool, "Verbose mode")
132 57106b74 Michael Hanselmann
133 57106b74 Michael Hanselmann
# Parameters for cluster verification
134 57106b74 Michael Hanselmann
_PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool,
135 57106b74 Michael Hanselmann
                         "Whether to simulate errors (useful for debugging)")
136 57106b74 Michael Hanselmann
_PErrorCodes = ("error_codes", False, ht.TBool, "Error codes")
137 57106b74 Michael Hanselmann
_PSkipChecks = ("skip_checks", ht.EmptyList,
138 57106b74 Michael Hanselmann
                ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)),
139 57106b74 Michael Hanselmann
                "Which checks to skip")
140 93f2399e Andrea Spadaccini
_PIgnoreErrors = ("ignore_errors", ht.EmptyList,
141 93f2399e Andrea Spadaccini
                  ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
142 93f2399e Andrea Spadaccini
                  "List of error codes that should be treated as warnings")
143 323f9095 Stephen Shirley
144 bc5d0215 Andrea Spadaccini
# Disk parameters
145 bc5d0215 Andrea Spadaccini
_PDiskParams = ("diskparams", None,
146 bc5d0215 Andrea Spadaccini
                ht.TOr(
147 bc5d0215 Andrea Spadaccini
                  ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict),
148 bc5d0215 Andrea Spadaccini
                  ht.TNone),
149 bc5d0215 Andrea Spadaccini
                "Disk templates' parameter defaults")
150 bc5d0215 Andrea Spadaccini
151 0ec2ce46 Renรฉ Nussbaumer
# Parameters for node resource model
152 0ec2ce46 Renรฉ Nussbaumer
_PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states")
153 0ec2ce46 Renรฉ Nussbaumer
_PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states")
154 0ec2ce46 Renรฉ Nussbaumer
155 b6aaf437 Renรฉ Nussbaumer
156 b6aaf437 Renรฉ Nussbaumer
_PIgnoreIpolicy = ("ignore_ipolicy", False, ht.TBool,
157 b6aaf437 Renรฉ Nussbaumer
                   "Whether to ignore ipolicy violations")
158 b6aaf437 Renรฉ Nussbaumer
159 ff0d18e6 Iustin Pop
#: OP_ID conversion regular expression
160 ff0d18e6 Iustin Pop
_OPID_RE = re.compile("([a-z])([A-Z])")
161 ff0d18e6 Iustin Pop
162 8c9ee749 Michael Hanselmann
#: Utility function for L{OpClusterSetParams}
163 8c9ee749 Michael Hanselmann
_TestClusterOsList = ht.TOr(ht.TNone,
164 8c9ee749 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
165 eb62069e Iustin Pop
    ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
166 8c9ee749 Michael Hanselmann
            ht.TElemOf(constants.DDMS_VALUES)))))
167 8c9ee749 Michael Hanselmann
168 ff0d18e6 Iustin Pop
169 526a662a Michael Hanselmann
# TODO: Generate check from constants.INIC_PARAMS_TYPES
170 526a662a Michael Hanselmann
#: Utility function for testing NIC definitions
171 526a662a Michael Hanselmann
_TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
172 526a662a Michael Hanselmann
                         ht.TOr(ht.TNone, ht.TNonEmptyString))
173 526a662a Michael Hanselmann
174 1456df62 Michael Hanselmann
_TSetParamsResultItemItems = [
175 1456df62 Michael Hanselmann
  ht.Comment("name of changed parameter")(ht.TNonEmptyString),
176 b3d2ee31 Michael Hanselmann
  ht.Comment("new value")(ht.TAny),
177 1456df62 Michael Hanselmann
  ]
178 1456df62 Michael Hanselmann
179 1456df62 Michael Hanselmann
_TSetParamsResult = \
180 1456df62 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
181 1456df62 Michael Hanselmann
                     ht.TItems(_TSetParamsResultItemItems)))
182 1456df62 Michael Hanselmann
183 3ce9a5e7 Michael Hanselmann
_SUMMARY_PREFIX = {
184 3ce9a5e7 Michael Hanselmann
  "CLUSTER_": "C_",
185 3ce9a5e7 Michael Hanselmann
  "GROUP_": "G_",
186 3ce9a5e7 Michael Hanselmann
  "NODE_": "N_",
187 3ce9a5e7 Michael Hanselmann
  "INSTANCE_": "I_",
188 3ce9a5e7 Michael Hanselmann
  }
189 3ce9a5e7 Michael Hanselmann
190 b95479a5 Michael Hanselmann
#: Attribute name for dependencies
191 b95479a5 Michael Hanselmann
DEPEND_ATTR = "depends"
192 b95479a5 Michael Hanselmann
193 018ae30b Michael Hanselmann
#: Attribute name for comment
194 018ae30b Michael Hanselmann
COMMENT_ATTR = "comment"
195 018ae30b Michael Hanselmann
196 526a662a Michael Hanselmann
197 ff0d18e6 Iustin Pop
def _NameToId(name):
198 ff0d18e6 Iustin Pop
  """Convert an opcode class name to an OP_ID.
199 ff0d18e6 Iustin Pop

200 ff0d18e6 Iustin Pop
  @type name: string
201 ff0d18e6 Iustin Pop
  @param name: the class name, as OpXxxYyy
202 ff0d18e6 Iustin Pop
  @rtype: string
203 ff0d18e6 Iustin Pop
  @return: the name in the OP_XXXX_YYYY format
204 ff0d18e6 Iustin Pop

205 ff0d18e6 Iustin Pop
  """
206 ff0d18e6 Iustin Pop
  if not name.startswith("Op"):
207 ff0d18e6 Iustin Pop
    return None
208 ff0d18e6 Iustin Pop
  # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
209 ff0d18e6 Iustin Pop
  # consume any input, and hence we would just have all the elements
210 ff0d18e6 Iustin Pop
  # in the list, one by one; but it seems that split doesn't work on
211 ff0d18e6 Iustin Pop
  # non-consuming input, hence we have to process the input string a
212 ff0d18e6 Iustin Pop
  # bit
213 ff0d18e6 Iustin Pop
  name = _OPID_RE.sub(r"\1,\2", name)
214 ff0d18e6 Iustin Pop
  elems = name.split(",")
215 ff0d18e6 Iustin Pop
  return "_".join(n.upper() for n in elems)
216 ff0d18e6 Iustin Pop
217 65e183af Michael Hanselmann
218 65e183af Michael Hanselmann
def RequireFileStorage():
219 65e183af Michael Hanselmann
  """Checks that file storage is enabled.
220 65e183af Michael Hanselmann

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

224 65e183af Michael Hanselmann
  @raise errors.OpPrereqError: when file storage is disabled
225 65e183af Michael Hanselmann

226 65e183af Michael Hanselmann
  """
227 65e183af Michael Hanselmann
  if not constants.ENABLE_FILE_STORAGE:
228 65e183af Michael Hanselmann
    raise errors.OpPrereqError("File storage disabled at configure time",
229 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
230 65e183af Michael Hanselmann
231 65e183af Michael Hanselmann
232 4b97f902 Apollon Oikonomopoulos
def RequireSharedFileStorage():
233 4b97f902 Apollon Oikonomopoulos
  """Checks that shared file storage is enabled.
234 4b97f902 Apollon Oikonomopoulos

235 4b97f902 Apollon Oikonomopoulos
  While it doesn't really fit into this module, L{utils} was deemed too large
236 4b97f902 Apollon Oikonomopoulos
  of a dependency to be imported for just one or two functions.
237 4b97f902 Apollon Oikonomopoulos

238 4b97f902 Apollon Oikonomopoulos
  @raise errors.OpPrereqError: when shared file storage is disabled
239 4b97f902 Apollon Oikonomopoulos

240 4b97f902 Apollon Oikonomopoulos
  """
241 4b97f902 Apollon Oikonomopoulos
  if not constants.ENABLE_SHARED_FILE_STORAGE:
242 4b97f902 Apollon Oikonomopoulos
    raise errors.OpPrereqError("Shared file storage disabled at"
243 4b97f902 Apollon Oikonomopoulos
                               " configure time", errors.ECODE_INVAL)
244 4b97f902 Apollon Oikonomopoulos
245 4b97f902 Apollon Oikonomopoulos
246 8c9ee749 Michael Hanselmann
@ht.WithDesc("CheckFileStorage")
247 8c9ee749 Michael Hanselmann
def _CheckFileStorage(value):
248 8c9ee749 Michael Hanselmann
  """Ensures file storage is enabled if used.
249 65e183af Michael Hanselmann

250 65e183af Michael Hanselmann
  """
251 8c9ee749 Michael Hanselmann
  if value == constants.DT_FILE:
252 65e183af Michael Hanselmann
    RequireFileStorage()
253 4b97f902 Apollon Oikonomopoulos
  elif value == constants.DT_SHARED_FILE:
254 4b97f902 Apollon Oikonomopoulos
    RequireSharedFileStorage()
255 65e183af Michael Hanselmann
  return True
256 65e183af Michael Hanselmann
257 65e183af Michael Hanselmann
258 45fe090b Michael Hanselmann
def _BuildDiskTemplateCheck(accept_none):
259 45fe090b Michael Hanselmann
  """Builds check for disk template.
260 45fe090b Michael Hanselmann

261 45fe090b Michael Hanselmann
  @type accept_none: bool
262 45fe090b Michael Hanselmann
  @param accept_none: whether to accept None as a correct value
263 45fe090b Michael Hanselmann
  @rtype: callable
264 45fe090b Michael Hanselmann

265 45fe090b Michael Hanselmann
  """
266 45fe090b Michael Hanselmann
  template_check = ht.TElemOf(constants.DISK_TEMPLATES)
267 45fe090b Michael Hanselmann
268 45fe090b Michael Hanselmann
  if accept_none:
269 45fe090b Michael Hanselmann
    template_check = ht.TOr(template_check, ht.TNone)
270 45fe090b Michael Hanselmann
271 45fe090b Michael Hanselmann
  return ht.TAnd(template_check, _CheckFileStorage)
272 8c9ee749 Michael Hanselmann
273 8c9ee749 Michael Hanselmann
274 65e183af Michael Hanselmann
def _CheckStorageType(storage_type):
275 65e183af Michael Hanselmann
  """Ensure a given storage type is valid.
276 65e183af Michael Hanselmann

277 65e183af Michael Hanselmann
  """
278 65e183af Michael Hanselmann
  if storage_type not in constants.VALID_STORAGE_TYPES:
279 65e183af Michael Hanselmann
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
280 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
281 65e183af Michael Hanselmann
  if storage_type == constants.ST_FILE:
282 65e183af Michael Hanselmann
    RequireFileStorage()
283 65e183af Michael Hanselmann
  return True
284 65e183af Michael Hanselmann
285 65e183af Michael Hanselmann
286 65e183af Michael Hanselmann
#: Storage type parameter
287 45d4c81c Michael Hanselmann
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
288 45d4c81c Michael Hanselmann
                 "Storage type")
289 65e183af Michael Hanselmann
290 65e183af Michael Hanselmann
291 65e183af Michael Hanselmann
class _AutoOpParamSlots(type):
292 65e183af Michael Hanselmann
  """Meta class for opcode definitions.
293 65e183af Michael Hanselmann

294 65e183af Michael Hanselmann
  """
295 65e183af Michael Hanselmann
  def __new__(mcs, name, bases, attrs):
296 65e183af Michael Hanselmann
    """Called when a class should be created.
297 65e183af Michael Hanselmann

298 65e183af Michael Hanselmann
    @param mcs: The meta class
299 65e183af Michael Hanselmann
    @param name: Name of created class
300 65e183af Michael Hanselmann
    @param bases: Base classes
301 65e183af Michael Hanselmann
    @type attrs: dict
302 65e183af Michael Hanselmann
    @param attrs: Class attributes
303 65e183af Michael Hanselmann

304 65e183af Michael Hanselmann
    """
305 65e183af Michael Hanselmann
    assert "__slots__" not in attrs, \
306 65e183af Michael Hanselmann
      "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
307 e89a9021 Iustin Pop
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
308 ff0d18e6 Iustin Pop
309 e89a9021 Iustin Pop
    attrs["OP_ID"] = _NameToId(name)
310 65e183af Michael Hanselmann
311 65e183af Michael Hanselmann
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
312 65e183af Michael Hanselmann
    params = attrs.setdefault("OP_PARAMS", [])
313 65e183af Michael Hanselmann
314 65e183af Michael Hanselmann
    # Use parameter names as slots
315 197b323b Michael Hanselmann
    slots = [pname for (pname, _, _, _) in params]
316 65e183af Michael Hanselmann
317 65e183af Michael Hanselmann
    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
318 65e183af Michael Hanselmann
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name
319 65e183af Michael Hanselmann
320 65e183af Michael Hanselmann
    attrs["__slots__"] = slots
321 65e183af Michael Hanselmann
322 65e183af Michael Hanselmann
    return type.__new__(mcs, name, bases, attrs)
323 65e183af Michael Hanselmann
324 df458e0b Iustin Pop
325 0e46916d Iustin Pop
class BaseOpCode(object):
326 df458e0b Iustin Pop
  """A simple serializable object.
327 df458e0b Iustin Pop

328 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
329 0e46916d Iustin Pop
  field handling.
330 0e46916d Iustin Pop

331 df458e0b Iustin Pop
  """
332 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
333 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
334 65e183af Michael Hanselmann
  __metaclass__ = _AutoOpParamSlots
335 65e183af Michael Hanselmann
336 a8083063 Iustin Pop
  def __init__(self, **kwargs):
337 a7399f66 Iustin Pop
    """Constructor for BaseOpCode.
338 a7399f66 Iustin Pop

339 a7399f66 Iustin Pop
    The constructor takes only keyword arguments and will set
340 a7399f66 Iustin Pop
    attributes on this object based on the passed arguments. As such,
341 a7399f66 Iustin Pop
    it means that you should not pass arguments which are not in the
342 a7399f66 Iustin Pop
    __slots__ attribute for this class.
343 a7399f66 Iustin Pop

344 a7399f66 Iustin Pop
    """
345 adf385c7 Iustin Pop
    slots = self._all_slots()
346 a8083063 Iustin Pop
    for key in kwargs:
347 adf385c7 Iustin Pop
      if key not in slots:
348 df458e0b Iustin Pop
        raise TypeError("Object %s doesn't support the parameter '%s'" %
349 3ecf6786 Iustin Pop
                        (self.__class__.__name__, key))
350 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
351 a8083063 Iustin Pop
352 df458e0b Iustin Pop
  def __getstate__(self):
353 a7399f66 Iustin Pop
    """Generic serializer.
354 a7399f66 Iustin Pop

355 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
356 a7399f66 Iustin Pop
    dictionary.
357 a7399f66 Iustin Pop

358 a7399f66 Iustin Pop
    @rtype:  C{dict}
359 a7399f66 Iustin Pop
    @return: the instance attributes and their values
360 a7399f66 Iustin Pop

361 a7399f66 Iustin Pop
    """
362 df458e0b Iustin Pop
    state = {}
363 adf385c7 Iustin Pop
    for name in self._all_slots():
364 df458e0b Iustin Pop
      if hasattr(self, name):
365 df458e0b Iustin Pop
        state[name] = getattr(self, name)
366 df458e0b Iustin Pop
    return state
367 df458e0b Iustin Pop
368 df458e0b Iustin Pop
  def __setstate__(self, state):
369 a7399f66 Iustin Pop
    """Generic unserializer.
370 a7399f66 Iustin Pop

371 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
372 a7399f66 Iustin Pop
    of the current instance.
373 a7399f66 Iustin Pop

374 a7399f66 Iustin Pop
    @param state: the serialized opcode data
375 a7399f66 Iustin Pop
    @type state:  C{dict}
376 a7399f66 Iustin Pop

377 a7399f66 Iustin Pop
    """
378 df458e0b Iustin Pop
    if not isinstance(state, dict):
379 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
380 df458e0b Iustin Pop
                       type(state))
381 df458e0b Iustin Pop
382 adf385c7 Iustin Pop
    for name in self._all_slots():
383 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
384 df458e0b Iustin Pop
        delattr(self, name)
385 df458e0b Iustin Pop
386 df458e0b Iustin Pop
    for name in state:
387 df458e0b Iustin Pop
      setattr(self, name, state[name])
388 df458e0b Iustin Pop
389 adf385c7 Iustin Pop
  @classmethod
390 adf385c7 Iustin Pop
  def _all_slots(cls):
391 adf385c7 Iustin Pop
    """Compute the list of all declared slots for a class.
392 adf385c7 Iustin Pop

393 adf385c7 Iustin Pop
    """
394 adf385c7 Iustin Pop
    slots = []
395 adf385c7 Iustin Pop
    for parent in cls.__mro__:
396 adf385c7 Iustin Pop
      slots.extend(getattr(parent, "__slots__", []))
397 adf385c7 Iustin Pop
    return slots
398 adf385c7 Iustin Pop
399 65e183af Michael Hanselmann
  @classmethod
400 65e183af Michael Hanselmann
  def GetAllParams(cls):
401 65e183af Michael Hanselmann
    """Compute list of all parameters for an opcode.
402 65e183af Michael Hanselmann

403 65e183af Michael Hanselmann
    """
404 65e183af Michael Hanselmann
    slots = []
405 65e183af Michael Hanselmann
    for parent in cls.__mro__:
406 65e183af Michael Hanselmann
      slots.extend(getattr(parent, "OP_PARAMS", []))
407 65e183af Michael Hanselmann
    return slots
408 65e183af Michael Hanselmann
409 1cbef6d8 Michael Hanselmann
  def Validate(self, set_defaults):
410 1cbef6d8 Michael Hanselmann
    """Validate opcode parameters, optionally setting default values.
411 1cbef6d8 Michael Hanselmann

412 1cbef6d8 Michael Hanselmann
    @type set_defaults: bool
413 1cbef6d8 Michael Hanselmann
    @param set_defaults: Whether to set default values
414 1cbef6d8 Michael Hanselmann
    @raise errors.OpPrereqError: When a parameter value doesn't match
415 1cbef6d8 Michael Hanselmann
                                 requirements
416 1cbef6d8 Michael Hanselmann

417 1cbef6d8 Michael Hanselmann
    """
418 197b323b Michael Hanselmann
    for (attr_name, default, test, _) in self.GetAllParams():
419 1cbef6d8 Michael Hanselmann
      assert test == ht.NoType or callable(test)
420 1cbef6d8 Michael Hanselmann
421 1cbef6d8 Michael Hanselmann
      if not hasattr(self, attr_name):
422 1cbef6d8 Michael Hanselmann
        if default == ht.NoDefault:
423 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
424 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
425 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
426 1cbef6d8 Michael Hanselmann
        elif set_defaults:
427 1cbef6d8 Michael Hanselmann
          if callable(default):
428 1cbef6d8 Michael Hanselmann
            dval = default()
429 1cbef6d8 Michael Hanselmann
          else:
430 1cbef6d8 Michael Hanselmann
            dval = default
431 1cbef6d8 Michael Hanselmann
          setattr(self, attr_name, dval)
432 1cbef6d8 Michael Hanselmann
433 1cbef6d8 Michael Hanselmann
      if test == ht.NoType:
434 1cbef6d8 Michael Hanselmann
        # no tests here
435 1cbef6d8 Michael Hanselmann
        continue
436 1cbef6d8 Michael Hanselmann
437 1cbef6d8 Michael Hanselmann
      if set_defaults or hasattr(self, attr_name):
438 1cbef6d8 Michael Hanselmann
        attr_val = getattr(self, attr_name)
439 1cbef6d8 Michael Hanselmann
        if not test(attr_val):
440 1cbef6d8 Michael Hanselmann
          logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
441 1cbef6d8 Michael Hanselmann
                        self.OP_ID, attr_name, type(attr_val), attr_val)
442 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
443 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
444 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
445 1cbef6d8 Michael Hanselmann
446 df458e0b Iustin Pop
447 b247c6fc Michael Hanselmann
def _BuildJobDepCheck(relative):
448 b247c6fc Michael Hanselmann
  """Builds check for job dependencies (L{DEPEND_ATTR}).
449 b247c6fc Michael Hanselmann

450 b247c6fc Michael Hanselmann
  @type relative: bool
451 b247c6fc Michael Hanselmann
  @param relative: Whether to accept relative job IDs (negative)
452 b247c6fc Michael Hanselmann
  @rtype: callable
453 b247c6fc Michael Hanselmann

454 b247c6fc Michael Hanselmann
  """
455 b247c6fc Michael Hanselmann
  if relative:
456 b247c6fc Michael Hanselmann
    job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
457 b247c6fc Michael Hanselmann
  else:
458 b247c6fc Michael Hanselmann
    job_id = ht.TJobId
459 b247c6fc Michael Hanselmann
460 b247c6fc Michael Hanselmann
  job_dep = \
461 b247c6fc Michael Hanselmann
    ht.TAnd(ht.TIsLength(2),
462 b247c6fc Michael Hanselmann
            ht.TItems([job_id,
463 b247c6fc Michael Hanselmann
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
464 b247c6fc Michael Hanselmann
465 b247c6fc Michael Hanselmann
  return ht.TOr(ht.TNone, ht.TListOf(job_dep))
466 b247c6fc Michael Hanselmann
467 b247c6fc Michael Hanselmann
468 b247c6fc Michael Hanselmann
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
469 b247c6fc Michael Hanselmann
470 1ce03fb1 Michael Hanselmann
#: List of submission status and job ID as returned by C{SubmitManyJobs}
471 1456df62 Michael Hanselmann
_TJobIdListItem = \
472 1456df62 Michael Hanselmann
  ht.TAnd(ht.TIsLength(2),
473 1456df62 Michael Hanselmann
          ht.TItems([ht.Comment("success")(ht.TBool),
474 1456df62 Michael Hanselmann
                     ht.Comment("Job ID if successful, error message"
475 1456df62 Michael Hanselmann
                                " otherwise")(ht.TOr(ht.TString,
476 1456df62 Michael Hanselmann
                                                     ht.TJobId))]))
477 1456df62 Michael Hanselmann
TJobIdList = ht.TListOf(_TJobIdListItem)
478 1ce03fb1 Michael Hanselmann
479 f7686867 Michael Hanselmann
#: Result containing only list of submitted jobs
480 f7686867 Michael Hanselmann
TJobIdListOnly = ht.TStrictDict(True, True, {
481 1456df62 Michael Hanselmann
  constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
482 f7686867 Michael Hanselmann
  })
483 f7686867 Michael Hanselmann
484 b247c6fc Michael Hanselmann
485 0e46916d Iustin Pop
class OpCode(BaseOpCode):
486 a7399f66 Iustin Pop
  """Abstract OpCode.
487 a7399f66 Iustin Pop

488 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
489 a7399f66 Iustin Pop
  from this class should override OP_ID.
490 a7399f66 Iustin Pop

491 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
492 20777413 Iustin Pop
               children of this class.
493 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
494 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
495 bde8f481 Adeodato Simo
                      method for details).
496 65e183af Michael Hanselmann
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
497 65e183af Michael Hanselmann
                   get if not already defined, and types they must match.
498 1ce03fb1 Michael Hanselmann
  @cvar OP_RESULT: Callable to verify opcode result
499 687c10d9 Iustin Pop
  @cvar WITH_LU: Boolean that specifies whether this should be included in
500 687c10d9 Iustin Pop
      mcpu's dispatch table
501 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
502 20777413 Iustin Pop
                 the check steps
503 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
504 a7399f66 Iustin Pop

505 a7399f66 Iustin Pop
  """
506 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
507 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
508 687c10d9 Iustin Pop
  WITH_LU = True
509 65e183af Michael Hanselmann
  OP_PARAMS = [
510 45d4c81c Michael Hanselmann
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
511 45d4c81c Michael Hanselmann
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
512 65e183af Michael Hanselmann
    ("priority", constants.OP_PRIO_DEFAULT,
513 45d4c81c Michael Hanselmann
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
514 b247c6fc Michael Hanselmann
    (DEPEND_ATTR, None, _BuildJobDepCheck(True),
515 b247c6fc Michael Hanselmann
     "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
516 822a50c4 Michael Hanselmann
     " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
517 822a50c4 Michael Hanselmann
     " for details"),
518 018ae30b Michael Hanselmann
    (COMMENT_ATTR, None, ht.TMaybeString,
519 018ae30b Michael Hanselmann
     "Comment describing the purpose of the opcode"),
520 65e183af Michael Hanselmann
    ]
521 1ce03fb1 Michael Hanselmann
  OP_RESULT = None
522 df458e0b Iustin Pop
523 df458e0b Iustin Pop
  def __getstate__(self):
524 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
525 df458e0b Iustin Pop

526 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
527 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
528 a7399f66 Iustin Pop
    instantiating the opcode.
529 a7399f66 Iustin Pop

530 a7399f66 Iustin Pop
    @rtype:   C{dict}
531 a7399f66 Iustin Pop
    @return:  the state as a dictionary
532 a7399f66 Iustin Pop

533 df458e0b Iustin Pop
    """
534 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
535 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
536 df458e0b Iustin Pop
    return data
537 df458e0b Iustin Pop
538 df458e0b Iustin Pop
  @classmethod
539 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
540 df458e0b Iustin Pop
    """Generic load opcode method.
541 df458e0b Iustin Pop

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

546 a7399f66 Iustin Pop
    @type data:  C{dict}
547 a7399f66 Iustin Pop
    @param data: the serialized opcode
548 a7399f66 Iustin Pop

549 df458e0b Iustin Pop
    """
550 df458e0b Iustin Pop
    if not isinstance(data, dict):
551 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
552 df458e0b Iustin Pop
    if "OP_ID" not in data:
553 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
554 df458e0b Iustin Pop
    op_id = data["OP_ID"]
555 df458e0b Iustin Pop
    op_class = None
556 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
557 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
558 363acb1e Iustin Pop
    else:
559 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
560 df458e0b Iustin Pop
                       op_id)
561 df458e0b Iustin Pop
    op = op_class()
562 df458e0b Iustin Pop
    new_data = data.copy()
563 df458e0b Iustin Pop
    del new_data["OP_ID"]
564 df458e0b Iustin Pop
    op.__setstate__(new_data)
565 df458e0b Iustin Pop
    return op
566 df458e0b Iustin Pop
567 60dd1473 Iustin Pop
  def Summary(self):
568 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
569 60dd1473 Iustin Pop

570 ff0d18e6 Iustin Pop
    The summary is the value of the OP_ID attribute (without the "OP_"
571 ff0d18e6 Iustin Pop
    prefix), plus the value of the OP_DSC_FIELD attribute, if one was
572 ff0d18e6 Iustin Pop
    defined; this field should allow to easily identify the operation
573 ff0d18e6 Iustin Pop
    (for an instance creation job, e.g., it would be the instance
574 ff0d18e6 Iustin Pop
    name).
575 bde8f481 Adeodato Simo

576 60dd1473 Iustin Pop
    """
577 ff0d18e6 Iustin Pop
    assert self.OP_ID is not None and len(self.OP_ID) > 3
578 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
579 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
580 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
581 60dd1473 Iustin Pop
    if field_name:
582 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
583 bc8bbda1 Iustin Pop
      if isinstance(field_value, (list, tuple)):
584 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
585 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
586 60dd1473 Iustin Pop
    return txt
587 60dd1473 Iustin Pop
588 3ce9a5e7 Michael Hanselmann
  def TinySummary(self):
589 3ce9a5e7 Michael Hanselmann
    """Generates a compact summary description of the opcode.
590 3ce9a5e7 Michael Hanselmann

591 3ce9a5e7 Michael Hanselmann
    """
592 3ce9a5e7 Michael Hanselmann
    assert self.OP_ID.startswith("OP_")
593 3ce9a5e7 Michael Hanselmann
594 3ce9a5e7 Michael Hanselmann
    text = self.OP_ID[3:]
595 3ce9a5e7 Michael Hanselmann
596 3ce9a5e7 Michael Hanselmann
    for (prefix, supplement) in _SUMMARY_PREFIX.items():
597 3ce9a5e7 Michael Hanselmann
      if text.startswith(prefix):
598 3ce9a5e7 Michael Hanselmann
        return supplement + text[len(prefix):]
599 3ce9a5e7 Michael Hanselmann
600 3ce9a5e7 Michael Hanselmann
    return text
601 3ce9a5e7 Michael Hanselmann
602 a8083063 Iustin Pop
603 afee0879 Iustin Pop
# cluster opcodes
604 afee0879 Iustin Pop
605 bc84ffa7 Iustin Pop
class OpClusterPostInit(OpCode):
606 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
607 b5f5fae9 Luca Bigliardi

608 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
609 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
610 b5f5fae9 Luca Bigliardi

611 b5f5fae9 Luca Bigliardi
  """
612 b5f5fae9 Luca Bigliardi
613 b5f5fae9 Luca Bigliardi
614 c6d43e9e Iustin Pop
class OpClusterDestroy(OpCode):
615 a7399f66 Iustin Pop
  """Destroy the cluster.
616 a7399f66 Iustin Pop

617 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
618 a7399f66 Iustin Pop
  lost after the execution of this opcode.
619 a7399f66 Iustin Pop

620 a7399f66 Iustin Pop
  """
621 a8083063 Iustin Pop
622 a8083063 Iustin Pop
623 a2f7ab92 Iustin Pop
class OpClusterQuery(OpCode):
624 fdc267f4 Iustin Pop
  """Query cluster information."""
625 a8083063 Iustin Pop
626 a8083063 Iustin Pop
627 fcad7225 Michael Hanselmann
class OpClusterVerify(OpCode):
628 fcad7225 Michael Hanselmann
  """Submits all jobs necessary to verify the cluster.
629 fcad7225 Michael Hanselmann

630 fcad7225 Michael Hanselmann
  """
631 fcad7225 Michael Hanselmann
  OP_PARAMS = [
632 fcad7225 Michael Hanselmann
    _PDebugSimulateErrors,
633 fcad7225 Michael Hanselmann
    _PErrorCodes,
634 fcad7225 Michael Hanselmann
    _PSkipChecks,
635 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
636 fcad7225 Michael Hanselmann
    _PVerbose,
637 fcad7225 Michael Hanselmann
    ("group_name", None, ht.TMaybeString, "Group to verify")
638 fcad7225 Michael Hanselmann
    ]
639 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
640 fcad7225 Michael Hanselmann
641 fcad7225 Michael Hanselmann
642 bf93ae69 Adeodato Simo
class OpClusterVerifyConfig(OpCode):
643 bf93ae69 Adeodato Simo
  """Verify the cluster config.
644 bf93ae69 Adeodato Simo

645 bf93ae69 Adeodato Simo
  """
646 bf93ae69 Adeodato Simo
  OP_PARAMS = [
647 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
648 57106b74 Michael Hanselmann
    _PErrorCodes,
649 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
650 57106b74 Michael Hanselmann
    _PVerbose,
651 bf93ae69 Adeodato Simo
    ]
652 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
653 bf93ae69 Adeodato Simo
654 bf93ae69 Adeodato Simo
655 bf93ae69 Adeodato Simo
class OpClusterVerifyGroup(OpCode):
656 bf93ae69 Adeodato Simo
  """Run verify on a node group from the cluster.
657 a7399f66 Iustin Pop

658 a7399f66 Iustin Pop
  @type skip_checks: C{list}
659 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
660 a7399f66 Iustin Pop
                     needs to be a subset of
661 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
662 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
663 a7399f66 Iustin Pop

664 a7399f66 Iustin Pop
  """
665 bf93ae69 Adeodato Simo
  OP_DSC_FIELD = "group_name"
666 65e183af Michael Hanselmann
  OP_PARAMS = [
667 57106b74 Michael Hanselmann
    _PGroupName,
668 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
669 57106b74 Michael Hanselmann
    _PErrorCodes,
670 57106b74 Michael Hanselmann
    _PSkipChecks,
671 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
672 57106b74 Michael Hanselmann
    _PVerbose,
673 65e183af Michael Hanselmann
    ]
674 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
675 a8083063 Iustin Pop
676 a8083063 Iustin Pop
677 bd8210a7 Iustin Pop
class OpClusterVerifyDisks(OpCode):
678 150e978f Iustin Pop
  """Verify the cluster disks.
679 150e978f Iustin Pop

680 ae1a845c Michael Hanselmann
  """
681 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
682 ae1a845c Michael Hanselmann
683 ae1a845c Michael Hanselmann
684 ae1a845c Michael Hanselmann
class OpGroupVerifyDisks(OpCode):
685 ae1a845c Michael Hanselmann
  """Verifies the status of all disks in a node group.
686 150e978f Iustin Pop

687 ae1a845c Michael Hanselmann
  Result: a tuple of three elements:
688 ae1a845c Michael Hanselmann
    - dict of node names with issues (values: error msg)
689 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
690 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
691 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
692 150e978f Iustin Pop

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

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

701 150e978f Iustin Pop
  """
702 ae1a845c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
703 ae1a845c Michael Hanselmann
  OP_PARAMS = [
704 ae1a845c Michael Hanselmann
    _PGroupName,
705 ae1a845c Michael Hanselmann
    ]
706 1ce03fb1 Michael Hanselmann
  OP_RESULT = \
707 1ce03fb1 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3),
708 1ce03fb1 Michael Hanselmann
            ht.TItems([ht.TDictOf(ht.TString, ht.TString),
709 1ce03fb1 Michael Hanselmann
                       ht.TListOf(ht.TString),
710 6973587f Michael Hanselmann
                       ht.TDictOf(ht.TString,
711 6973587f Michael Hanselmann
                                  ht.TListOf(ht.TListOf(ht.TString)))]))
712 150e978f Iustin Pop
713 150e978f Iustin Pop
714 5d01aca3 Iustin Pop
class OpClusterRepairDiskSizes(OpCode):
715 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
716 60975797 Iustin Pop
  mimatches.
717 60975797 Iustin Pop

718 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
719 60975797 Iustin Pop
  checks to only a subset of the instances.
720 60975797 Iustin Pop

721 60975797 Iustin Pop
  Result: a list of tuples, (instance, disk, new-size) for changed
722 60975797 Iustin Pop
  configurations.
723 60975797 Iustin Pop

724 60975797 Iustin Pop
  In normal operation, the list should be empty.
725 60975797 Iustin Pop

726 60975797 Iustin Pop
  @type instances: list
727 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
728 60975797 Iustin Pop

729 60975797 Iustin Pop
  """
730 65e183af Michael Hanselmann
  OP_PARAMS = [
731 197b323b Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
732 65e183af Michael Hanselmann
    ]
733 60975797 Iustin Pop
734 60975797 Iustin Pop
735 2f093ea0 Iustin Pop
class OpClusterConfigQuery(OpCode):
736 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
737 65e183af Michael Hanselmann
  OP_PARAMS = [
738 65e183af Michael Hanselmann
    _POutputFields
739 65e183af Michael Hanselmann
    ]
740 a8083063 Iustin Pop
741 a8083063 Iustin Pop
742 e126df25 Iustin Pop
class OpClusterRename(OpCode):
743 a7399f66 Iustin Pop
  """Rename the cluster.
744 a7399f66 Iustin Pop

745 a7399f66 Iustin Pop
  @type name: C{str}
746 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
747 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
748 a7399f66 Iustin Pop
              address.
749 a7399f66 Iustin Pop

750 a7399f66 Iustin Pop
  """
751 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
752 65e183af Michael Hanselmann
  OP_PARAMS = [
753 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
754 65e183af Michael Hanselmann
    ]
755 07bd8a51 Iustin Pop
756 07bd8a51 Iustin Pop
757 a6682fdc Iustin Pop
class OpClusterSetParams(OpCode):
758 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
759 a7399f66 Iustin Pop

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

763 a7399f66 Iustin Pop
  """
764 65e183af Michael Hanselmann
  OP_PARAMS = [
765 2da9f556 Renรฉ Nussbaumer
    _PHvState,
766 2da9f556 Renรฉ Nussbaumer
    _PDiskState,
767 45d4c81c Michael Hanselmann
    ("vg_name", None, ht.TMaybeString, "Volume group name"),
768 65e183af Michael Hanselmann
    ("enabled_hypervisors", None,
769 65e183af Michael Hanselmann
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
770 45d4c81c Michael Hanselmann
            ht.TNone),
771 45d4c81c Michael Hanselmann
     "List of enabled hypervisors"),
772 65e183af Michael Hanselmann
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
773 45d4c81c Michael Hanselmann
                              ht.TNone),
774 45d4c81c Michael Hanselmann
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
775 45d4c81c Michael Hanselmann
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
776 45d4c81c Michael Hanselmann
     "Cluster-wide backend parameter defaults"),
777 65e183af Michael Hanselmann
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
778 45d4c81c Michael Hanselmann
                            ht.TNone),
779 45d4c81c Michael Hanselmann
     "Cluster-wide per-OS hypervisor parameter defaults"),
780 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
781 45d4c81c Michael Hanselmann
                              ht.TNone),
782 45d4c81c Michael Hanselmann
     "Cluster-wide OS parameter defaults"),
783 bc5d0215 Andrea Spadaccini
    _PDiskParams,
784 197b323b Michael Hanselmann
    ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
785 45d4c81c Michael Hanselmann
     "Master candidate pool size"),
786 45d4c81c Michael Hanselmann
    ("uid_pool", None, ht.NoType,
787 45d4c81c Michael Hanselmann
     "Set UID pool, must be list of lists describing UID ranges (two items,"
788 45d4c81c Michael Hanselmann
     " start and end inclusive)"),
789 45d4c81c Michael Hanselmann
    ("add_uids", None, ht.NoType,
790 45d4c81c Michael Hanselmann
     "Extend UID pool, must be list of lists describing UID ranges (two"
791 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be added"),
792 45d4c81c Michael Hanselmann
    ("remove_uids", None, ht.NoType,
793 45d4c81c Michael Hanselmann
     "Shrink UID pool, must be list of lists describing UID ranges (two"
794 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be removed"),
795 45d4c81c Michael Hanselmann
    ("maintain_node_health", None, ht.TMaybeBool,
796 45d4c81c Michael Hanselmann
     "Whether to automatically maintain node health"),
797 45d4c81c Michael Hanselmann
    ("prealloc_wipe_disks", None, ht.TMaybeBool,
798 45d4c81c Michael Hanselmann
     "Whether to wipe disks before allocating them to instances"),
799 45d4c81c Michael Hanselmann
    ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
800 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
801 e1a6850f Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Cluster-wide instance policy specs"),
802 45d4c81c Michael Hanselmann
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
803 45d4c81c Michael Hanselmann
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
804 45d4c81c Michael Hanselmann
     "Default iallocator for cluster"),
805 45d4c81c Michael Hanselmann
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
806 45d4c81c Michael Hanselmann
     "Master network device"),
807 5a8648eb Andrea Spadaccini
    ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
808 5a8648eb Andrea Spadaccini
     "Netmask of the master IP"),
809 45d4c81c Michael Hanselmann
    ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone),
810 45d4c81c Michael Hanselmann
     "List of reserved LVs"),
811 45d4c81c Michael Hanselmann
    ("hidden_os", None, _TestClusterOsList,
812 45d4c81c Michael Hanselmann
     "Modify list of hidden operating systems. Each modification must have"
813 45d4c81c Michael Hanselmann
     " two items, the operation and the OS name. The operation can be"
814 45d4c81c Michael Hanselmann
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
815 45d4c81c Michael Hanselmann
    ("blacklisted_os", None, _TestClusterOsList,
816 45d4c81c Michael Hanselmann
     "Modify list of blacklisted operating systems. Each modification must have"
817 45d4c81c Michael Hanselmann
     " two items, the operation and the OS name. The operation can be"
818 45d4c81c Michael Hanselmann
     " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
819 bf689b7a Andrea Spadaccini
    ("use_external_mip_script", None, ht.TMaybeBool,
820 bf689b7a Andrea Spadaccini
     "Whether to use an external master IP address setup script"),
821 4b7735f9 Iustin Pop
    ]
822 12515db7 Manuel Franceschini
823 12515db7 Manuel Franceschini
824 d1240007 Iustin Pop
class OpClusterRedistConf(OpCode):
825 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
826 afee0879 Iustin Pop

827 afee0879 Iustin Pop
  """
828 afee0879 Iustin Pop
829 83f72637 Michael Hanselmann
830 fb926117 Andrea Spadaccini
class OpClusterActivateMasterIp(OpCode):
831 fb926117 Andrea Spadaccini
  """Activate the master IP on the master node.
832 fb926117 Andrea Spadaccini

833 fb926117 Andrea Spadaccini
  """
834 fb926117 Andrea Spadaccini
835 fb926117 Andrea Spadaccini
836 fb926117 Andrea Spadaccini
class OpClusterDeactivateMasterIp(OpCode):
837 fb926117 Andrea Spadaccini
  """Deactivate the master IP on the master node.
838 fb926117 Andrea Spadaccini

839 fb926117 Andrea Spadaccini
  """
840 fb926117 Andrea Spadaccini
841 fb926117 Andrea Spadaccini
842 83f72637 Michael Hanselmann
class OpQuery(OpCode):
843 83f72637 Michael Hanselmann
  """Query for resources/items.
844 83f72637 Michael Hanselmann

845 abd66bf8 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
846 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
847 2e5c33db Iustin Pop
  @ivar qfilter: Query filter
848 83f72637 Michael Hanselmann

849 83f72637 Michael Hanselmann
  """
850 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
851 65e183af Michael Hanselmann
  OP_PARAMS = [
852 8e7078e0 Michael Hanselmann
    _PQueryWhat,
853 ee13764f Michael Hanselmann
    _PUseLocking,
854 45d4c81c Michael Hanselmann
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
855 45d4c81c Michael Hanselmann
     "Requested fields"),
856 2e5c33db Iustin Pop
    ("qfilter", None, ht.TOr(ht.TNone, ht.TListOf),
857 45d4c81c Michael Hanselmann
     "Query filter"),
858 83f72637 Michael Hanselmann
    ]
859 83f72637 Michael Hanselmann
860 83f72637 Michael Hanselmann
861 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
862 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
863 83f72637 Michael Hanselmann

864 abd66bf8 Michael Hanselmann
  @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
865 83f72637 Michael Hanselmann
  @ivar fields: List of fields to retrieve
866 83f72637 Michael Hanselmann

867 83f72637 Michael Hanselmann
  """
868 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
869 65e183af Michael Hanselmann
  OP_PARAMS = [
870 8e7078e0 Michael Hanselmann
    _PQueryWhat,
871 8e7078e0 Michael Hanselmann
    ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
872 8e7078e0 Michael Hanselmann
     "Requested fields; if not given, all are returned"),
873 83f72637 Michael Hanselmann
    ]
874 83f72637 Michael Hanselmann
875 83f72637 Michael Hanselmann
876 792af3ad Renรฉ Nussbaumer
class OpOobCommand(OpCode):
877 eb64da59 Renรฉ Nussbaumer
  """Interact with OOB."""
878 65e183af Michael Hanselmann
  OP_PARAMS = [
879 c4ec0755 Renรฉ Nussbaumer
    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
880 c4ec0755 Renรฉ Nussbaumer
     "List of nodes to run the OOB command against"),
881 c4ec0755 Renรฉ Nussbaumer
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
882 c4ec0755 Renรฉ Nussbaumer
     "OOB command to be run"),
883 c4ec0755 Renรฉ Nussbaumer
    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
884 c4ec0755 Renรฉ Nussbaumer
     "Timeout before the OOB helper will be terminated"),
885 c4ec0755 Renรฉ Nussbaumer
    ("ignore_status", False, ht.TBool,
886 c4ec0755 Renรฉ Nussbaumer
     "Ignores the node offline status for power off"),
887 beff3779 Renรฉ Nussbaumer
    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
888 beff3779 Renรฉ Nussbaumer
     "Time in seconds to wait between powering on nodes"),
889 eb64da59 Renรฉ Nussbaumer
    ]
890 eb64da59 Renรฉ Nussbaumer
891 eb64da59 Renรฉ Nussbaumer
892 07bd8a51 Iustin Pop
# node opcodes
893 07bd8a51 Iustin Pop
894 73d565a3 Iustin Pop
class OpNodeRemove(OpCode):
895 a7399f66 Iustin Pop
  """Remove a node.
896 a7399f66 Iustin Pop

897 a7399f66 Iustin Pop
  @type node_name: C{str}
898 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
899 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
900 a7399f66 Iustin Pop

901 a7399f66 Iustin Pop
  """
902 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
903 65e183af Michael Hanselmann
  OP_PARAMS = [
904 65e183af Michael Hanselmann
    _PNodeName,
905 65e183af Michael Hanselmann
    ]
906 a8083063 Iustin Pop
907 a8083063 Iustin Pop
908 d817d49f Iustin Pop
class OpNodeAdd(OpCode):
909 a7399f66 Iustin Pop
  """Add a node to the cluster.
910 a7399f66 Iustin Pop

911 a7399f66 Iustin Pop
  @type node_name: C{str}
912 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
913 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
914 a7399f66 Iustin Pop
  @type primary_ip: IP address
915 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
916 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
917 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
918 a7399f66 Iustin Pop
  @type secondary_ip: IP address
919 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
920 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
921 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
922 a7399f66 Iustin Pop
  @type readd: C{bool}
923 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
924 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
925 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
926 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
927 a7399f66 Iustin Pop
               without removal from the cluster.
928 f936c153 Iustin Pop
  @type group: C{str}
929 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
930 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
931 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
932 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
933 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
934 a7399f66 Iustin Pop

935 a7399f66 Iustin Pop
  """
936 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
937 65e183af Michael Hanselmann
  OP_PARAMS = [
938 65e183af Michael Hanselmann
    _PNodeName,
939 085e0d9f Renรฉ Nussbaumer
    _PHvState,
940 085e0d9f Renรฉ Nussbaumer
    _PDiskState,
941 45d4c81c Michael Hanselmann
    ("primary_ip", None, ht.NoType, "Primary IP address"),
942 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
943 45d4c81c Michael Hanselmann
    ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
944 45d4c81c Michael Hanselmann
    ("group", None, ht.TMaybeString, "Initial node group"),
945 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
946 45d4c81c Michael Hanselmann
     "Whether node can become master or master candidate"),
947 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
948 45d4c81c Michael Hanselmann
     "Whether node can host instances"),
949 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Node parameters"),
950 65e183af Michael Hanselmann
    ]
951 a8083063 Iustin Pop
952 a8083063 Iustin Pop
953 2237687b Iustin Pop
class OpNodeQuery(OpCode):
954 a8083063 Iustin Pop
  """Compute the list of nodes."""
955 65e183af Michael Hanselmann
  OP_PARAMS = [
956 65e183af Michael Hanselmann
    _POutputFields,
957 45d4c81c Michael Hanselmann
    _PUseLocking,
958 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
959 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
960 65e183af Michael Hanselmann
    ]
961 a8083063 Iustin Pop
962 a8083063 Iustin Pop
963 8ed55bfd Iustin Pop
class OpNodeQueryvols(OpCode):
964 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
965 65e183af Michael Hanselmann
  OP_PARAMS = [
966 65e183af Michael Hanselmann
    _POutputFields,
967 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
968 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
969 65e183af Michael Hanselmann
    ]
970 dcb93971 Michael Hanselmann
971 dcb93971 Michael Hanselmann
972 ad8d0595 Iustin Pop
class OpNodeQueryStorage(OpCode):
973 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
974 65e183af Michael Hanselmann
  OP_PARAMS = [
975 65e183af Michael Hanselmann
    _POutputFields,
976 65e183af Michael Hanselmann
    _PStorageType,
977 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
978 45d4c81c Michael Hanselmann
    ("name", None, ht.TMaybeString, "Storage name"),
979 9e5442ce Michael Hanselmann
    ]
980 9e5442ce Michael Hanselmann
981 9e5442ce Michael Hanselmann
982 2cee4077 Iustin Pop
class OpNodeModifyStorage(OpCode):
983 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
984 65e183af Michael Hanselmann
  OP_PARAMS = [
985 65e183af Michael Hanselmann
    _PNodeName,
986 65e183af Michael Hanselmann
    _PStorageType,
987 45d4c81c Michael Hanselmann
    _PStorageName,
988 45d4c81c Michael Hanselmann
    ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
989 efb8da02 Michael Hanselmann
    ]
990 efb8da02 Michael Hanselmann
991 efb8da02 Michael Hanselmann
992 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
993 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
994 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
995 65e183af Michael Hanselmann
  OP_PARAMS = [
996 65e183af Michael Hanselmann
    _PNodeName,
997 65e183af Michael Hanselmann
    _PStorageType,
998 45d4c81c Michael Hanselmann
    _PStorageName,
999 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1000 76aef8fc Michael Hanselmann
    ]
1001 76aef8fc Michael Hanselmann
1002 76aef8fc Michael Hanselmann
1003 f13973c4 Iustin Pop
class OpNodeSetParams(OpCode):
1004 b31c8676 Iustin Pop
  """Change the parameters of a node."""
1005 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
1006 65e183af Michael Hanselmann
  OP_PARAMS = [
1007 65e183af Michael Hanselmann
    _PNodeName,
1008 65e183af Michael Hanselmann
    _PForce,
1009 0ec2ce46 Renรฉ Nussbaumer
    _PHvState,
1010 0ec2ce46 Renรฉ Nussbaumer
    _PDiskState,
1011 45d4c81c Michael Hanselmann
    ("master_candidate", None, ht.TMaybeBool,
1012 45d4c81c Michael Hanselmann
     "Whether the node should become a master candidate"),
1013 45d4c81c Michael Hanselmann
    ("offline", None, ht.TMaybeBool,
1014 45d4c81c Michael Hanselmann
     "Whether the node should be marked as offline"),
1015 45d4c81c Michael Hanselmann
    ("drained", None, ht.TMaybeBool,
1016 45d4c81c Michael Hanselmann
     "Whether the node should be marked as drained"),
1017 45d4c81c Michael Hanselmann
    ("auto_promote", False, ht.TBool,
1018 45d4c81c Michael Hanselmann
     "Whether node(s) should be promoted to master candidate if necessary"),
1019 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
1020 45d4c81c Michael Hanselmann
     "Denote whether node can become master or master candidate"),
1021 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
1022 45d4c81c Michael Hanselmann
     "Denote whether node can host instances"),
1023 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString,
1024 45d4c81c Michael Hanselmann
     "Change node's secondary IP address"),
1025 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
1026 45d4c81c Michael Hanselmann
    ("powered", None, ht.TMaybeBool,
1027 45d4c81c Michael Hanselmann
     "Whether the node should be marked as powered"),
1028 b31c8676 Iustin Pop
    ]
1029 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1030 b31c8676 Iustin Pop
1031 f5118ade Iustin Pop
1032 e0d4735f Iustin Pop
class OpNodePowercycle(OpCode):
1033 f5118ade Iustin Pop
  """Tries to powercycle a node."""
1034 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
1035 65e183af Michael Hanselmann
  OP_PARAMS = [
1036 65e183af Michael Hanselmann
    _PNodeName,
1037 65e183af Michael Hanselmann
    _PForce,
1038 f5118ade Iustin Pop
    ]
1039 f5118ade Iustin Pop
1040 7ffc5a86 Michael Hanselmann
1041 5b14a488 Iustin Pop
class OpNodeMigrate(OpCode):
1042 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
1043 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1044 65e183af Michael Hanselmann
  OP_PARAMS = [
1045 65e183af Michael Hanselmann
    _PNodeName,
1046 65e183af Michael Hanselmann
    _PMigrationMode,
1047 65e183af Michael Hanselmann
    _PMigrationLive,
1048 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1049 9fa567b3 Renรฉ Nussbaumer
    _PIgnoreIpolicy,
1050 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1051 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1052 80cb875c Michael Hanselmann
    ]
1053 65c9591c Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1054 80cb875c Michael Hanselmann
1055 80cb875c Michael Hanselmann
1056 e1f23243 Michael Hanselmann
class OpNodeEvacuate(OpCode):
1057 e1f23243 Michael Hanselmann
  """Evacuate instances off a number of nodes."""
1058 e1f23243 Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1059 e1f23243 Michael Hanselmann
  OP_PARAMS = [
1060 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1061 e1f23243 Michael Hanselmann
    _PNodeName,
1062 e1f23243 Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1063 e1f23243 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1064 cb92e7a1 Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1065 e1f23243 Michael Hanselmann
     "Node evacuation mode"),
1066 e1f23243 Michael Hanselmann
    ]
1067 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1068 e1f23243 Michael Hanselmann
1069 e1f23243 Michael Hanselmann
1070 a8083063 Iustin Pop
# instance opcodes
1071 a8083063 Iustin Pop
1072 e1530b10 Iustin Pop
class OpInstanceCreate(OpCode):
1073 9bf56d77 Michael Hanselmann
  """Create an instance.
1074 9bf56d77 Michael Hanselmann

1075 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
1076 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1077 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
1078 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1079 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
1080 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1081 dae91d02 Michael Hanselmann
    (remote import only)
1082 9bf56d77 Michael Hanselmann

1083 9bf56d77 Michael Hanselmann
  """
1084 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1085 65e183af Michael Hanselmann
  OP_PARAMS = [
1086 65e183af Michael Hanselmann
    _PInstanceName,
1087 45d4c81c Michael Hanselmann
    _PForceVariant,
1088 45d4c81c Michael Hanselmann
    _PWaitForSync,
1089 45d4c81c Michael Hanselmann
    _PNameCheck,
1090 10889e0c Renรฉ Nussbaumer
    _PIgnoreIpolicy,
1091 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1092 526a662a Michael Hanselmann
    ("disks", ht.NoDefault,
1093 526a662a Michael Hanselmann
     # TODO: Generate check from constants.IDISK_PARAMS_TYPES
1094 526a662a Michael Hanselmann
     ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
1095 526a662a Michael Hanselmann
                           ht.TOr(ht.TNonEmptyString, ht.TInt))),
1096 526a662a Michael Hanselmann
     "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1097 526a662a Michael Hanselmann
     " each disk definition must contain a ``%s`` value and"
1098 526a662a Michael Hanselmann
     " can contain an optional ``%s`` value denoting the disk access mode"
1099 526a662a Michael Hanselmann
     " (%s)" %
1100 526a662a Michael Hanselmann
     (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1101 526a662a Michael Hanselmann
      constants.IDISK_MODE,
1102 526a662a Michael Hanselmann
      " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1103 45fe090b Michael Hanselmann
    ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1104 45fe090b Michael Hanselmann
     "Disk template"),
1105 45d4c81c Michael Hanselmann
    ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1106 45d4c81c Michael Hanselmann
     "Driver for file-backed disks"),
1107 45d4c81c Michael Hanselmann
    ("file_storage_dir", None, ht.TMaybeString,
1108 45d4c81c Michael Hanselmann
     "Directory for storing file-backed disks"),
1109 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1110 45d4c81c Michael Hanselmann
     "Hypervisor parameters for instance, hypervisor-dependent"),
1111 45d4c81c Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1112 45d4c81c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString,
1113 45d4c81c Michael Hanselmann
     "Iallocator for deciding which node(s) to use"),
1114 45d4c81c Michael Hanselmann
    ("identify_defaults", False, ht.TBool,
1115 45d4c81c Michael Hanselmann
     "Reset instance parameters to default if equal"),
1116 45d4c81c Michael Hanselmann
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
1117 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1118 45d4c81c Michael Hanselmann
     "Instance creation mode"),
1119 526a662a Michael Hanselmann
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1120 526a662a Michael Hanselmann
     "List of NIC (network interface) definitions, for example"
1121 526a662a Michael Hanselmann
     " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1122 526a662a Michael Hanselmann
     " contain the optional values %s" %
1123 526a662a Michael Hanselmann
     (constants.INIC_IP,
1124 526a662a Michael Hanselmann
      ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1125 45d4c81c Michael Hanselmann
    ("no_install", None, ht.TMaybeBool,
1126 45d4c81c Michael Hanselmann
     "Do not install the OS (will disable automatic start)"),
1127 45d4c81c Michael Hanselmann
    ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1128 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Operating system"),
1129 45d4c81c Michael Hanselmann
    ("pnode", None, ht.TMaybeString, "Primary node"),
1130 45d4c81c Michael Hanselmann
    ("snode", None, ht.TMaybeString, "Secondary node"),
1131 45d4c81c Michael Hanselmann
    ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1132 45d4c81c Michael Hanselmann
     "Signed handshake from source (remote import only)"),
1133 45d4c81c Michael Hanselmann
    ("source_instance_name", None, ht.TMaybeString,
1134 45d4c81c Michael Hanselmann
     "Source instance name (remote import only)"),
1135 65e183af Michael Hanselmann
    ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1136 526a662a Michael Hanselmann
     ht.TPositiveInt,
1137 526a662a Michael Hanselmann
     "How long source instance was given to shut down (remote import only)"),
1138 45d4c81c Michael Hanselmann
    ("source_x509_ca", None, ht.TMaybeString,
1139 45d4c81c Michael Hanselmann
     "Source X509 CA in PEM format (remote import only)"),
1140 45d4c81c Michael Hanselmann
    ("src_node", None, ht.TMaybeString, "Source node for import"),
1141 45d4c81c Michael Hanselmann
    ("src_path", None, ht.TMaybeString, "Source directory for import"),
1142 45d4c81c Michael Hanselmann
    ("start", True, ht.TBool, "Whether to start instance after creation"),
1143 720f56c8 Apollon Oikonomopoulos
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1144 3b6d8c9b Iustin Pop
    ]
1145 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1146 a8083063 Iustin Pop
1147 a8083063 Iustin Pop
1148 5073fd8f Iustin Pop
class OpInstanceReinstall(OpCode):
1149 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
1150 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1151 65e183af Michael Hanselmann
  OP_PARAMS = [
1152 65e183af Michael Hanselmann
    _PInstanceName,
1153 45d4c81c Michael Hanselmann
    _PForceVariant,
1154 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Instance operating system"),
1155 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1156 65e183af Michael Hanselmann
    ]
1157 fe7b0351 Michael Hanselmann
1158 fe7b0351 Michael Hanselmann
1159 3cd2d4b1 Iustin Pop
class OpInstanceRemove(OpCode):
1160 a8083063 Iustin Pop
  """Remove an instance."""
1161 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1162 65e183af Michael Hanselmann
  OP_PARAMS = [
1163 65e183af Michael Hanselmann
    _PInstanceName,
1164 65e183af Michael Hanselmann
    _PShutdownTimeout,
1165 45d4c81c Michael Hanselmann
    ("ignore_failures", False, ht.TBool,
1166 45d4c81c Michael Hanselmann
     "Whether to ignore failures during removal"),
1167 fc1baca9 Michael Hanselmann
    ]
1168 a8083063 Iustin Pop
1169 a8083063 Iustin Pop
1170 5659e2e2 Iustin Pop
class OpInstanceRename(OpCode):
1171 decd5f45 Iustin Pop
  """Rename an instance."""
1172 65e183af Michael Hanselmann
  OP_PARAMS = [
1173 65e183af Michael Hanselmann
    _PInstanceName,
1174 45d4c81c Michael Hanselmann
    _PNameCheck,
1175 45d4c81c Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1176 45d4c81c Michael Hanselmann
    ("ip_check", False, ht.TBool, _PIpCheckDoc),
1177 4f05fd3b Iustin Pop
    ]
1178 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1179 decd5f45 Iustin Pop
1180 decd5f45 Iustin Pop
1181 c873d91c Iustin Pop
class OpInstanceStartup(OpCode):
1182 fdc267f4 Iustin Pop
  """Startup an instance."""
1183 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1184 65e183af Michael Hanselmann
  OP_PARAMS = [
1185 65e183af Michael Hanselmann
    _PInstanceName,
1186 65e183af Michael Hanselmann
    _PForce,
1187 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1188 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1189 45d4c81c Michael Hanselmann
     "Temporary hypervisor parameters, hypervisor-dependent"),
1190 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1191 9b64e486 Iustin Pop
    _PNoRemember,
1192 323f9095 Stephen Shirley
    _PStartupPaused,
1193 4f05fd3b Iustin Pop
    ]
1194 a8083063 Iustin Pop
1195 a8083063 Iustin Pop
1196 ee3e37a7 Iustin Pop
class OpInstanceShutdown(OpCode):
1197 fdc267f4 Iustin Pop
  """Shutdown an instance."""
1198 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1199 65e183af Michael Hanselmann
  OP_PARAMS = [
1200 65e183af Michael Hanselmann
    _PInstanceName,
1201 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1202 45d4c81c Michael Hanselmann
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1203 45d4c81c Michael Hanselmann
     "How long to wait for instance to shut down"),
1204 9b64e486 Iustin Pop
    _PNoRemember,
1205 b44bd844 Michael Hanselmann
    ]
1206 a8083063 Iustin Pop
1207 a8083063 Iustin Pop
1208 90ab1a95 Iustin Pop
class OpInstanceReboot(OpCode):
1209 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
1210 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1211 65e183af Michael Hanselmann
  OP_PARAMS = [
1212 65e183af Michael Hanselmann
    _PInstanceName,
1213 65e183af Michael Hanselmann
    _PShutdownTimeout,
1214 45d4c81c Michael Hanselmann
    ("ignore_secondaries", False, ht.TBool,
1215 45d4c81c Michael Hanselmann
     "Whether to start the instance even if secondary disks are failing"),
1216 45d4c81c Michael Hanselmann
    ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1217 45d4c81c Michael Hanselmann
     "How to reboot instance"),
1218 4f05fd3b Iustin Pop
    ]
1219 bf6929a2 Alexander Schreiber
1220 bf6929a2 Alexander Schreiber
1221 668f755d Iustin Pop
class OpInstanceReplaceDisks(OpCode):
1222 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
1223 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1224 65e183af Michael Hanselmann
  OP_PARAMS = [
1225 65e183af Michael Hanselmann
    _PInstanceName,
1226 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1227 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1228 45d4c81c Michael Hanselmann
     "Replacement mode"),
1229 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1230 45d4c81c Michael Hanselmann
     "Disk indexes"),
1231 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1232 45d4c81c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString,
1233 45d4c81c Michael Hanselmann
     "Iallocator for deciding new secondary node"),
1234 4f05fd3b Iustin Pop
    ]
1235 a8083063 Iustin Pop
1236 a8083063 Iustin Pop
1237 019dbee1 Iustin Pop
class OpInstanceFailover(OpCode):
1238 a8083063 Iustin Pop
  """Failover an instance."""
1239 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1240 65e183af Michael Hanselmann
  OP_PARAMS = [
1241 65e183af Michael Hanselmann
    _PInstanceName,
1242 65e183af Michael Hanselmann
    _PShutdownTimeout,
1243 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1244 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1245 b6aaf437 Renรฉ Nussbaumer
    _PIgnoreIpolicy,
1246 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1247 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1248 17c3f802 Guido Trotter
    ]
1249 a8083063 Iustin Pop
1250 a8083063 Iustin Pop
1251 75c866c2 Iustin Pop
class OpInstanceMigrate(OpCode):
1252 53c776b5 Iustin Pop
  """Migrate an instance.
1253 53c776b5 Iustin Pop

1254 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
1255 53c776b5 Iustin Pop
  node.
1256 53c776b5 Iustin Pop

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

1260 53c776b5 Iustin Pop
  """
1261 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
1262 65e183af Michael Hanselmann
  OP_PARAMS = [
1263 65e183af Michael Hanselmann
    _PInstanceName,
1264 65e183af Michael Hanselmann
    _PMigrationMode,
1265 65e183af Michael Hanselmann
    _PMigrationLive,
1266 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1267 3ed23330 Renรฉ Nussbaumer
    _PIgnoreIpolicy,
1268 45d4c81c Michael Hanselmann
    ("cleanup", False, ht.TBool,
1269 45d4c81c Michael Hanselmann
     "Whether a previously failed migration should be cleaned up"),
1270 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1271 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1272 d5cafd31 Renรฉ Nussbaumer
    ("allow_failover", False, ht.TBool,
1273 d5cafd31 Renรฉ Nussbaumer
     "Whether we can fallback to failover if migration is not possible"),
1274 65e183af Michael Hanselmann
    ]
1275 53c776b5 Iustin Pop
1276 53c776b5 Iustin Pop
1277 0091b480 Iustin Pop
class OpInstanceMove(OpCode):
1278 313bcead Iustin Pop
  """Move an instance.
1279 313bcead Iustin Pop

1280 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
1281 313bcead Iustin Pop
  arbitrary node.
1282 313bcead Iustin Pop

1283 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
1284 313bcead Iustin Pop
  @ivar target_node: the destination node
1285 313bcead Iustin Pop

1286 313bcead Iustin Pop
  """
1287 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
1288 65e183af Michael Hanselmann
  OP_PARAMS = [
1289 65e183af Michael Hanselmann
    _PInstanceName,
1290 65e183af Michael Hanselmann
    _PShutdownTimeout,
1291 92cf62e3 Renรฉ Nussbaumer
    _PIgnoreIpolicy,
1292 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1293 bb851c63 Iustin Pop
    _PIgnoreConsistency,
1294 154b9580 Balazs Lecz
    ]
1295 313bcead Iustin Pop
1296 313bcead Iustin Pop
1297 cc0dec7b Iustin Pop
class OpInstanceConsole(OpCode):
1298 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
1299 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1300 65e183af Michael Hanselmann
  OP_PARAMS = [
1301 65e183af Michael Hanselmann
    _PInstanceName
1302 65e183af Michael Hanselmann
    ]
1303 a8083063 Iustin Pop
1304 a8083063 Iustin Pop
1305 83f5d475 Iustin Pop
class OpInstanceActivateDisks(OpCode):
1306 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
1307 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1308 65e183af Michael Hanselmann
  OP_PARAMS = [
1309 65e183af Michael Hanselmann
    _PInstanceName,
1310 45d4c81c Michael Hanselmann
    ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1311 65e183af Michael Hanselmann
    ]
1312 a8083063 Iustin Pop
1313 a8083063 Iustin Pop
1314 e176281f Iustin Pop
class OpInstanceDeactivateDisks(OpCode):
1315 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
1316 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1317 65e183af Michael Hanselmann
  OP_PARAMS = [
1318 c9c41373 Iustin Pop
    _PInstanceName,
1319 c9c41373 Iustin Pop
    _PForce,
1320 65e183af Michael Hanselmann
    ]
1321 a8083063 Iustin Pop
1322 a8083063 Iustin Pop
1323 6b273e78 Iustin Pop
class OpInstanceRecreateDisks(OpCode):
1324 a52978c7 Michael Hanselmann
  """Recreate an instance's disks."""
1325 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
1326 65e183af Michael Hanselmann
  OP_PARAMS = [
1327 65e183af Michael Hanselmann
    _PInstanceName,
1328 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1329 45d4c81c Michael Hanselmann
     "List of disk indexes"),
1330 93384b8c Guido Trotter
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1331 93384b8c Guido Trotter
     "New instance nodes, if relocation is desired"),
1332 65e183af Michael Hanselmann
    ]
1333 bd315bfa Iustin Pop
1334 bd315bfa Iustin Pop
1335 f2af0bec Iustin Pop
class OpInstanceQuery(OpCode):
1336 a8083063 Iustin Pop
  """Compute the list of instances."""
1337 65e183af Michael Hanselmann
  OP_PARAMS = [
1338 65e183af Michael Hanselmann
    _POutputFields,
1339 45d4c81c Michael Hanselmann
    _PUseLocking,
1340 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1341 45d4c81c Michael Hanselmann
     "Empty list to query all instances, instance names otherwise"),
1342 65e183af Michael Hanselmann
    ]
1343 a8083063 Iustin Pop
1344 a8083063 Iustin Pop
1345 dc28c4e4 Iustin Pop
class OpInstanceQueryData(OpCode):
1346 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
1347 65e183af Michael Hanselmann
  OP_PARAMS = [
1348 af7b6689 Michael Hanselmann
    _PUseLocking,
1349 af7b6689 Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1350 af7b6689 Michael Hanselmann
     "Instance names"),
1351 af7b6689 Michael Hanselmann
    ("static", False, ht.TBool,
1352 af7b6689 Michael Hanselmann
     "Whether to only return configuration data without querying"
1353 af7b6689 Michael Hanselmann
     " nodes"),
1354 65e183af Michael Hanselmann
    ]
1355 a8083063 Iustin Pop
1356 a8083063 Iustin Pop
1357 9a3cc7ae Iustin Pop
class OpInstanceSetParams(OpCode):
1358 a8083063 Iustin Pop
  """Change the parameters of an instance."""
1359 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1360 65e183af Michael Hanselmann
  OP_PARAMS = [
1361 65e183af Michael Hanselmann
    _PInstanceName,
1362 65e183af Michael Hanselmann
    _PForce,
1363 45d4c81c Michael Hanselmann
    _PForceVariant,
1364 1559e1e7 Renรฉ Nussbaumer
    _PIgnoreIpolicy,
1365 526a662a Michael Hanselmann
    # TODO: Use _TestNicDef
1366 45d4c81c Michael Hanselmann
    ("nics", ht.EmptyList, ht.TList,
1367 45d4c81c Michael Hanselmann
     "List of NIC changes. Each item is of the form ``(op, settings)``."
1368 45d4c81c Michael Hanselmann
     " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
1369 45d4c81c Michael Hanselmann
     " ``%s`` to remove the last NIC or a number to modify the settings"
1370 45d4c81c Michael Hanselmann
     " of the NIC with that index." %
1371 45d4c81c Michael Hanselmann
     (constants.DDM_ADD, constants.DDM_REMOVE)),
1372 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."),
1373 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1374 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1375 45d4c81c Michael Hanselmann
     "Per-instance hypervisor parameters, hypervisor-dependent"),
1376 45fe090b Michael Hanselmann
    ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1377 45d4c81c Michael Hanselmann
     "Disk template for instance"),
1378 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString,
1379 45d4c81c Michael Hanselmann
     "Secondary node (used when changing disk template)"),
1380 45d4c81c Michael Hanselmann
    ("os_name", None, ht.TMaybeString,
1381 45d4c81c Michael Hanselmann
     "Change instance's OS name. Does not reinstall the instance."),
1382 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1383 93384b8c Guido Trotter
    ("wait_for_sync", True, ht.TBool,
1384 93384b8c Guido Trotter
     "Whether to wait for the disk to synchronize, when changing template"),
1385 57de31c0 Agata Murawska
    ("offline_inst", False, ht.TBool,
1386 57de31c0 Agata Murawska
     "Whether to turn off the down instance completely"),
1387 57de31c0 Agata Murawska
    ("online_inst", False, ht.TBool,
1388 57de31c0 Agata Murawska
     "Whether to enable the offline instance"),
1389 973d7867 Iustin Pop
    ]
1390 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1391 a8083063 Iustin Pop
1392 a8083063 Iustin Pop
1393 60472d29 Iustin Pop
class OpInstanceGrowDisk(OpCode):
1394 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
1395 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1396 65e183af Michael Hanselmann
  OP_PARAMS = [
1397 65e183af Michael Hanselmann
    _PInstanceName,
1398 45d4c81c Michael Hanselmann
    _PWaitForSync,
1399 45d4c81c Michael Hanselmann
    ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1400 45d4c81c Michael Hanselmann
    ("amount", ht.NoDefault, ht.TInt,
1401 45d4c81c Michael Hanselmann
     "Amount of disk space to add (megabytes)"),
1402 4f05fd3b Iustin Pop
    ]
1403 8729e0d7 Iustin Pop
1404 8729e0d7 Iustin Pop
1405 1aef3df8 Michael Hanselmann
class OpInstanceChangeGroup(OpCode):
1406 1aef3df8 Michael Hanselmann
  """Moves an instance to another node group."""
1407 1aef3df8 Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1408 1aef3df8 Michael Hanselmann
  OP_PARAMS = [
1409 1aef3df8 Michael Hanselmann
    _PInstanceName,
1410 1aef3df8 Michael Hanselmann
    _PEarlyRelease,
1411 1aef3df8 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1412 1aef3df8 Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1413 1aef3df8 Michael Hanselmann
     "Destination group names or UUIDs (defaults to \"all but current group\""),
1414 1aef3df8 Michael Hanselmann
    ]
1415 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1416 1aef3df8 Michael Hanselmann
1417 1aef3df8 Michael Hanselmann
1418 70a6a926 Adeodato Simo
# Node group opcodes
1419 70a6a926 Adeodato Simo
1420 fabf1731 Iustin Pop
class OpGroupAdd(OpCode):
1421 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
1422 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1423 65e183af Michael Hanselmann
  OP_PARAMS = [
1424 65e183af Michael Hanselmann
    _PGroupName,
1425 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1426 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1427 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1428 e4c03256 Renรฉ Nussbaumer
    _PHvState,
1429 e4c03256 Renรฉ Nussbaumer
    _PDiskState,
1430 1f5d9bf8 Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1431 483be60d Adeodato Simo
    ]
1432 b1ee5610 Adeodato Simo
1433 b1ee5610 Adeodato Simo
1434 934704ae Iustin Pop
class OpGroupAssignNodes(OpCode):
1435 96276ae7 Adeodato Simo
  """Assign nodes to a node group."""
1436 96276ae7 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1437 96276ae7 Adeodato Simo
  OP_PARAMS = [
1438 96276ae7 Adeodato Simo
    _PGroupName,
1439 96276ae7 Adeodato Simo
    _PForce,
1440 45d4c81c Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1441 45d4c81c Michael Hanselmann
     "List of nodes to assign"),
1442 96276ae7 Adeodato Simo
    ]
1443 96276ae7 Adeodato Simo
1444 96276ae7 Adeodato Simo
1445 d4d654bd Iustin Pop
class OpGroupQuery(OpCode):
1446 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
1447 65e183af Michael Hanselmann
  OP_PARAMS = [
1448 65e183af Michael Hanselmann
    _POutputFields,
1449 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1450 45d4c81c Michael Hanselmann
     "Empty list to query all groups, group names otherwise"),
1451 65e183af Michael Hanselmann
    ]
1452 70a6a926 Adeodato Simo
1453 70a6a926 Adeodato Simo
1454 7cbf74f0 Iustin Pop
class OpGroupSetParams(OpCode):
1455 4da7909a Adeodato Simo
  """Change the parameters of a node group."""
1456 4da7909a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1457 65e183af Michael Hanselmann
  OP_PARAMS = [
1458 65e183af Michael Hanselmann
    _PGroupName,
1459 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1460 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1461 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1462 a8282327 Renรฉ Nussbaumer
    _PHvState,
1463 a8282327 Renรฉ Nussbaumer
    _PDiskState,
1464 fb644e77 Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1465 4da7909a Adeodato Simo
    ]
1466 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1467 4da7909a Adeodato Simo
1468 4da7909a Adeodato Simo
1469 4d1baa51 Iustin Pop
class OpGroupRemove(OpCode):
1470 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
1471 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1472 65e183af Michael Hanselmann
  OP_PARAMS = [
1473 65e183af Michael Hanselmann
    _PGroupName,
1474 65e183af Michael Hanselmann
    ]
1475 94bd652a Adeodato Simo
1476 94bd652a Adeodato Simo
1477 a8173e82 Iustin Pop
class OpGroupRename(OpCode):
1478 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
1479 65e183af Michael Hanselmann
  OP_PARAMS = [
1480 12da663a Michael Hanselmann
    _PGroupName,
1481 12da663a Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1482 65e183af Michael Hanselmann
    ]
1483 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1484 4fe5cf90 Adeodato Simo
1485 4fe5cf90 Adeodato Simo
1486 08f8c82c Michael Hanselmann
class OpGroupEvacuate(OpCode):
1487 08f8c82c Michael Hanselmann
  """Evacuate a node group in the cluster."""
1488 08f8c82c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
1489 08f8c82c Michael Hanselmann
  OP_PARAMS = [
1490 08f8c82c Michael Hanselmann
    _PGroupName,
1491 08f8c82c Michael Hanselmann
    _PEarlyRelease,
1492 08f8c82c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1493 08f8c82c Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1494 08f8c82c Michael Hanselmann
     "Destination group names or UUIDs"),
1495 08f8c82c Michael Hanselmann
    ]
1496 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1497 08f8c82c Michael Hanselmann
1498 08f8c82c Michael Hanselmann
1499 a8083063 Iustin Pop
# OS opcodes
1500 da2d02e7 Iustin Pop
class OpOsDiagnose(OpCode):
1501 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
1502 65e183af Michael Hanselmann
  OP_PARAMS = [
1503 65e183af Michael Hanselmann
    _POutputFields,
1504 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1505 45d4c81c Michael Hanselmann
     "Which operating systems to diagnose"),
1506 65e183af Michael Hanselmann
    ]
1507 a8083063 Iustin Pop
1508 7c0d6283 Michael Hanselmann
1509 a8083063 Iustin Pop
# Exports opcodes
1510 7ca2d4d8 Iustin Pop
class OpBackupQuery(OpCode):
1511 a8083063 Iustin Pop
  """Compute the list of exported images."""
1512 65e183af Michael Hanselmann
  OP_PARAMS = [
1513 45d4c81c Michael Hanselmann
    _PUseLocking,
1514 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1515 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1516 65e183af Michael Hanselmann
    ]
1517 a8083063 Iustin Pop
1518 7c0d6283 Michael Hanselmann
1519 71910715 Iustin Pop
class OpBackupPrepare(OpCode):
1520 1410fa8d Michael Hanselmann
  """Prepares an instance export.
1521 1410fa8d Michael Hanselmann

1522 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
1523 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1524 1410fa8d Michael Hanselmann

1525 1410fa8d Michael Hanselmann
  """
1526 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1527 65e183af Michael Hanselmann
  OP_PARAMS = [
1528 65e183af Michael Hanselmann
    _PInstanceName,
1529 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1530 45d4c81c Michael Hanselmann
     "Export mode"),
1531 1410fa8d Michael Hanselmann
    ]
1532 1410fa8d Michael Hanselmann
1533 1410fa8d Michael Hanselmann
1534 4ff922a2 Iustin Pop
class OpBackupExport(OpCode):
1535 4a96f1d1 Michael Hanselmann
  """Export an instance.
1536 4a96f1d1 Michael Hanselmann

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

1543 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1544 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
1545 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
1546 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1547 4a96f1d1 Michael Hanselmann
                             only)
1548 4a96f1d1 Michael Hanselmann

1549 4a96f1d1 Michael Hanselmann
  """
1550 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1551 65e183af Michael Hanselmann
  OP_PARAMS = [
1552 65e183af Michael Hanselmann
    _PInstanceName,
1553 65e183af Michael Hanselmann
    _PShutdownTimeout,
1554 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
1555 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
1556 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1557 45d4c81c Michael Hanselmann
     "Destination information, depends on export mode"),
1558 45d4c81c Michael Hanselmann
    ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1559 45d4c81c Michael Hanselmann
    ("remove_instance", False, ht.TBool,
1560 45d4c81c Michael Hanselmann
     "Whether to remove instance after export"),
1561 45d4c81c Michael Hanselmann
    ("ignore_remove_failures", False, ht.TBool,
1562 45d4c81c Michael Hanselmann
     "Whether to ignore failures while removing instances"),
1563 45d4c81c Michael Hanselmann
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1564 45d4c81c Michael Hanselmann
     "Export mode"),
1565 45d4c81c Michael Hanselmann
    ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1566 45d4c81c Michael Hanselmann
     "Name of X509 key (remote export only)"),
1567 45d4c81c Michael Hanselmann
    ("destination_x509_ca", None, ht.TMaybeString,
1568 45d4c81c Michael Hanselmann
     "Destination X509 CA (remote export only)"),
1569 17c3f802 Guido Trotter
    ]
1570 5c947f38 Iustin Pop
1571 0a7bed64 Michael Hanselmann
1572 ca5890ad Iustin Pop
class OpBackupRemove(OpCode):
1573 9ac99fda Guido Trotter
  """Remove an instance's export."""
1574 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1575 65e183af Michael Hanselmann
  OP_PARAMS = [
1576 65e183af Michael Hanselmann
    _PInstanceName,
1577 65e183af Michael Hanselmann
    ]
1578 5c947f38 Iustin Pop
1579 0a7bed64 Michael Hanselmann
1580 5c947f38 Iustin Pop
# Tags opcodes
1581 c6afb1ca Iustin Pop
class OpTagsGet(OpCode):
1582 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
1583 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
1584 65e183af Michael Hanselmann
  OP_PARAMS = [
1585 65e183af Michael Hanselmann
    _PTagKind,
1586 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1587 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1588 65e183af Michael Hanselmann
    ]
1589 5c947f38 Iustin Pop
1590 5c947f38 Iustin Pop
1591 715462e7 Iustin Pop
class OpTagsSearch(OpCode):
1592 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
1593 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
1594 65e183af Michael Hanselmann
  OP_PARAMS = [
1595 197b323b Michael Hanselmann
    ("pattern", ht.NoDefault, ht.TNonEmptyString, None),
1596 65e183af Michael Hanselmann
    ]
1597 73415719 Iustin Pop
1598 73415719 Iustin Pop
1599 d1602edc Iustin Pop
class OpTagsSet(OpCode):
1600 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
1601 65e183af Michael Hanselmann
  OP_PARAMS = [
1602 65e183af Michael Hanselmann
    _PTagKind,
1603 65e183af Michael Hanselmann
    _PTags,
1604 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1605 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1606 65e183af Michael Hanselmann
    ]
1607 5c947f38 Iustin Pop
1608 5c947f38 Iustin Pop
1609 3f0ab95f Iustin Pop
class OpTagsDel(OpCode):
1610 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
1611 65e183af Michael Hanselmann
  OP_PARAMS = [
1612 65e183af Michael Hanselmann
    _PTagKind,
1613 65e183af Michael Hanselmann
    _PTags,
1614 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1615 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString, None),
1616 65e183af Michael Hanselmann
    ]
1617 06009e27 Iustin Pop
1618 e687ec01 Michael Hanselmann
1619 06009e27 Iustin Pop
# Test opcodes
1620 06009e27 Iustin Pop
class OpTestDelay(OpCode):
1621 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
1622 06009e27 Iustin Pop

1623 06009e27 Iustin Pop
  This is used just for debugging and testing.
1624 06009e27 Iustin Pop

1625 06009e27 Iustin Pop
  Parameters:
1626 06009e27 Iustin Pop
    - duration: the time to sleep
1627 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
1628 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
1629 06009e27 Iustin Pop

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

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

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

1640 06009e27 Iustin Pop
  """
1641 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
1642 65e183af Michael Hanselmann
  OP_PARAMS = [
1643 b795a775 Michael Hanselmann
    ("duration", ht.NoDefault, ht.TNumber, None),
1644 197b323b Michael Hanselmann
    ("on_master", True, ht.TBool, None),
1645 197b323b Michael Hanselmann
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1646 197b323b Michael Hanselmann
    ("repeat", 0, ht.TPositiveInt, None),
1647 65e183af Michael Hanselmann
    ]
1648 d61df03e Iustin Pop
1649 d61df03e Iustin Pop
1650 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
1651 d61df03e Iustin Pop
  """Allocator framework testing.
1652 d61df03e Iustin Pop

1653 d61df03e Iustin Pop
  This opcode has two modes:
1654 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
1655 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
1656 d61df03e Iustin Pop
      'in')
1657 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
1658 d61df03e Iustin Pop
      return the allocator output (direction 'out')
1659 d61df03e Iustin Pop

1660 d61df03e Iustin Pop
  """
1661 60dd1473 Iustin Pop
  OP_DSC_FIELD = "allocator"
1662 65e183af Michael Hanselmann
  OP_PARAMS = [
1663 65e183af Michael Hanselmann
    ("direction", ht.NoDefault,
1664 197b323b Michael Hanselmann
     ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1665 197b323b Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1666 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
1667 65e183af Michael Hanselmann
    ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
1668 fdbe29ee Michael Hanselmann
     ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
1669 45d4c81c Michael Hanselmann
                ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
1670 197b323b Michael Hanselmann
    ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1671 197b323b Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, None),
1672 197b323b Michael Hanselmann
    ("allocator", None, ht.TMaybeString, None),
1673 197b323b Michael Hanselmann
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1674 dd47a0f0 Iustin Pop
    ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1675 197b323b Michael Hanselmann
    ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1676 197b323b Michael Hanselmann
    ("os", None, ht.TMaybeString, None),
1677 197b323b Michael Hanselmann
    ("disk_template", None, ht.TMaybeString, None),
1678 bee581e2 Michael Hanselmann
    ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1679 bee581e2 Michael Hanselmann
     None),
1680 60152bbe Michael Hanselmann
    ("evac_mode", None,
1681 60152bbe Michael Hanselmann
     ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1682 bee581e2 Michael Hanselmann
    ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)),
1683 bee581e2 Michael Hanselmann
     None),
1684 d61df03e Iustin Pop
    ]
1685 363acb1e Iustin Pop
1686 76aef8fc Michael Hanselmann
1687 b469eb4d Iustin Pop
class OpTestJqueue(OpCode):
1688 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
1689 e58f87a9 Michael Hanselmann

1690 e58f87a9 Michael Hanselmann
  """
1691 65e183af Michael Hanselmann
  OP_PARAMS = [
1692 197b323b Michael Hanselmann
    ("notify_waitlock", False, ht.TBool, None),
1693 197b323b Michael Hanselmann
    ("notify_exec", False, ht.TBool, None),
1694 197b323b Michael Hanselmann
    ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1695 197b323b Michael Hanselmann
    ("fail", False, ht.TBool, None),
1696 e58f87a9 Michael Hanselmann
    ]
1697 e58f87a9 Michael Hanselmann
1698 e58f87a9 Michael Hanselmann
1699 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
1700 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
1701 be760ba8 Michael Hanselmann

1702 be760ba8 Michael Hanselmann
  """
1703 65e183af Michael Hanselmann
  OP_PARAMS = [
1704 197b323b Michael Hanselmann
    ("result", ht.NoDefault, ht.NoType, None),
1705 197b323b Michael Hanselmann
    ("messages", ht.NoDefault, ht.NoType, None),
1706 197b323b Michael Hanselmann
    ("fail", ht.NoDefault, ht.NoType, None),
1707 6a373640 Michael Hanselmann
    ("submit_jobs", None, ht.NoType, None),
1708 be760ba8 Michael Hanselmann
    ]
1709 687c10d9 Iustin Pop
  WITH_LU = False
1710 be760ba8 Michael Hanselmann
1711 be760ba8 Michael Hanselmann
1712 dbc96028 Michael Hanselmann
def _GetOpList():
1713 dbc96028 Michael Hanselmann
  """Returns list of all defined opcodes.
1714 dbc96028 Michael Hanselmann

1715 dbc96028 Michael Hanselmann
  Does not eliminate duplicates by C{OP_ID}.
1716 dbc96028 Michael Hanselmann

1717 dbc96028 Michael Hanselmann
  """
1718 dbc96028 Michael Hanselmann
  return [v for v in globals().values()
1719 dbc96028 Michael Hanselmann
          if (isinstance(v, type) and issubclass(v, OpCode) and
1720 687c10d9 Iustin Pop
              hasattr(v, "OP_ID") and v is not OpCode)]
1721 dbc96028 Michael Hanselmann
1722 dbc96028 Michael Hanselmann
1723 dbc96028 Michael Hanselmann
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())