Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ bcd35e09

History | View | Annotate | Download (60 kB)

1 2f31098c Iustin Pop
#
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 fa47242b Iustin Pop
# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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 65e183af Michael Hanselmann
from ganeti import constants
40 65e183af Michael Hanselmann
from ganeti import errors
41 65e183af Michael Hanselmann
from ganeti import ht
42 415feb2e René Nussbaumer
from ganeti import objects
43 32683096 René Nussbaumer
from ganeti import objectutils
44 65e183af Michael Hanselmann
45 65e183af Michael Hanselmann
46 65e183af Michael Hanselmann
# Common opcode attributes
47 65e183af Michael Hanselmann
48 65e183af Michael Hanselmann
#: output fields for a query operation
49 197b323b Michael Hanselmann
_POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
50 45d4c81c Michael Hanselmann
                  "Selected output fields")
51 65e183af Michael Hanselmann
52 65e183af Michael Hanselmann
#: the shutdown timeout
53 45d4c81c Michael Hanselmann
_PShutdownTimeout = \
54 45d4c81c Michael Hanselmann
  ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
55 45d4c81c Michael Hanselmann
   "How long to wait for instance to shut down")
56 65e183af Michael Hanselmann
57 65e183af Michael Hanselmann
#: the force parameter
58 45d4c81c Michael Hanselmann
_PForce = ("force", False, ht.TBool, "Whether to force the operation")
59 65e183af Michael Hanselmann
60 65e183af Michael Hanselmann
#: a required instance name (for single-instance LUs)
61 45d4c81c Michael Hanselmann
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
62 45d4c81c Michael Hanselmann
                  "Instance name")
63 65e183af Michael Hanselmann
64 65e183af Michael Hanselmann
#: Whether to ignore offline nodes
65 45d4c81c Michael Hanselmann
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool,
66 45d4c81c Michael Hanselmann
                        "Whether to ignore offline nodes")
67 65e183af Michael Hanselmann
68 65e183af Michael Hanselmann
#: a required node name (for single-node LUs)
69 45d4c81c Michael Hanselmann
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name")
70 65e183af Michael Hanselmann
71 65e183af Michael Hanselmann
#: a required node group name (for single-group LUs)
72 45d4c81c Michael Hanselmann
_PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name")
73 65e183af Michael Hanselmann
74 65e183af Michael Hanselmann
#: Migration type (live/non-live)
75 65e183af Michael Hanselmann
_PMigrationMode = ("mode", None,
76 197b323b Michael Hanselmann
                   ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)),
77 45d4c81c Michael Hanselmann
                   "Migration mode")
78 65e183af Michael Hanselmann
79 65e183af Michael Hanselmann
#: Obsolete 'live' migration mode (boolean)
80 45d4c81c Michael Hanselmann
_PMigrationLive = ("live", None, ht.TMaybeBool,
81 45d4c81c Michael Hanselmann
                   "Legacy setting for live migration, do not use")
82 65e183af Michael Hanselmann
83 65e183af Michael Hanselmann
#: Tag type
84 971b3a98 Michael Hanselmann
_PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES),
85 971b3a98 Michael Hanselmann
             "Tag kind")
86 65e183af Michael Hanselmann
87 65e183af Michael Hanselmann
#: List of tag strings
88 971b3a98 Michael Hanselmann
_PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
89 971b3a98 Michael Hanselmann
          "List of tag names")
90 65e183af Michael Hanselmann
91 45d4c81c Michael Hanselmann
_PForceVariant = ("force_variant", False, ht.TBool,
92 45d4c81c Michael Hanselmann
                  "Whether to force an unknown OS variant")
93 45d4c81c Michael Hanselmann
94 45d4c81c Michael Hanselmann
_PWaitForSync = ("wait_for_sync", True, ht.TBool,
95 45d4c81c Michael Hanselmann
                 "Whether to wait for the disk to synchronize")
96 45d4c81c Michael Hanselmann
97 b69437c5 Iustin Pop
_PWaitForSyncFalse = ("wait_for_sync", False, ht.TBool,
98 b69437c5 Iustin Pop
                      "Whether to wait for the disk to synchronize"
99 b69437c5 Iustin Pop
                      " (defaults to false)")
100 b69437c5 Iustin Pop
101 45d4c81c Michael Hanselmann
_PIgnoreConsistency = ("ignore_consistency", False, ht.TBool,
102 45d4c81c Michael Hanselmann
                       "Whether to ignore disk consistency")
103 45d4c81c Michael Hanselmann
104 45d4c81c Michael Hanselmann
_PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name")
105 45d4c81c Michael Hanselmann
106 45d4c81c Michael Hanselmann
_PUseLocking = ("use_locking", False, ht.TBool,
107 45d4c81c Michael Hanselmann
                "Whether to use synchronization")
108 45d4c81c Michael Hanselmann
109 45d4c81c Michael Hanselmann
_PNameCheck = ("name_check", True, ht.TBool, "Whether to check name")
110 45d4c81c Michael Hanselmann
111 45d4c81c Michael Hanselmann
_PNodeGroupAllocPolicy = \
112 45d4c81c Michael Hanselmann
  ("alloc_policy", None,
113 45d4c81c Michael Hanselmann
   ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)),
114 45d4c81c Michael Hanselmann
   "Instance allocation policy")
115 45d4c81c Michael Hanselmann
116 45d4c81c Michael Hanselmann
_PGroupNodeParams = ("ndparams", None, ht.TMaybeDict,
117 45d4c81c Michael Hanselmann
                     "Default node parameters for group")
118 45d4c81c Michael Hanselmann
119 abd66bf8 Michael Hanselmann
_PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
120 8e7078e0 Michael Hanselmann
               "Resource(s) to query for")
121 8e7078e0 Michael Hanselmann
122 e1f23243 Michael Hanselmann
_PEarlyRelease = ("early_release", False, ht.TBool,
123 e1f23243 Michael Hanselmann
                  "Whether to release locks as soon as possible")
124 e1f23243 Michael Hanselmann
125 45d4c81c Michael Hanselmann
_PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
126 45d4c81c Michael Hanselmann
127 9b64e486 Iustin Pop
#: Do not remember instance state changes
128 6aac5aef Iustin Pop
_PNoRemember = ("no_remember", False, ht.TBool,
129 6aac5aef Iustin Pop
                "Do not remember the state change")
130 9b64e486 Iustin Pop
131 f8fa4175 Michael Hanselmann
#: Target node for instance migration/failover
132 f8fa4175 Michael Hanselmann
_PMigrationTargetNode = ("target_node", None, ht.TMaybeString,
133 f8fa4175 Michael Hanselmann
                         "Target node for shared-storage instances")
134 f8fa4175 Michael Hanselmann
135 323f9095 Stephen Shirley
_PStartupPaused = ("startup_paused", False, ht.TBool,
136 323f9095 Stephen Shirley
                   "Pause instance at startup")
137 323f9095 Stephen Shirley
138 57106b74 Michael Hanselmann
_PVerbose = ("verbose", False, ht.TBool, "Verbose mode")
139 57106b74 Michael Hanselmann
140 57106b74 Michael Hanselmann
# Parameters for cluster verification
141 57106b74 Michael Hanselmann
_PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool,
142 57106b74 Michael Hanselmann
                         "Whether to simulate errors (useful for debugging)")
143 57106b74 Michael Hanselmann
_PErrorCodes = ("error_codes", False, ht.TBool, "Error codes")
144 57106b74 Michael Hanselmann
_PSkipChecks = ("skip_checks", ht.EmptyList,
145 57106b74 Michael Hanselmann
                ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)),
146 57106b74 Michael Hanselmann
                "Which checks to skip")
147 93f2399e Andrea Spadaccini
_PIgnoreErrors = ("ignore_errors", ht.EmptyList,
148 93f2399e Andrea Spadaccini
                  ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)),
149 93f2399e Andrea Spadaccini
                  "List of error codes that should be treated as warnings")
150 323f9095 Stephen Shirley
151 bc5d0215 Andrea Spadaccini
# Disk parameters
152 bc5d0215 Andrea Spadaccini
_PDiskParams = ("diskparams", None,
153 bc5d0215 Andrea Spadaccini
                ht.TOr(
154 bc5d0215 Andrea Spadaccini
                  ht.TDictOf(ht.TElemOf(constants.DISK_TEMPLATES), ht.TDict),
155 bc5d0215 Andrea Spadaccini
                  ht.TNone),
156 bc5d0215 Andrea Spadaccini
                "Disk templates' parameter defaults")
157 bc5d0215 Andrea Spadaccini
158 0ec2ce46 René Nussbaumer
# Parameters for node resource model
159 0ec2ce46 René Nussbaumer
_PHvState = ("hv_state", None, ht.TMaybeDict, "Set hypervisor states")
160 0ec2ce46 René Nussbaumer
_PDiskState = ("disk_state", None, ht.TMaybeDict, "Set disk states")
161 0ec2ce46 René Nussbaumer
162 b6aaf437 René Nussbaumer
163 b6aaf437 René Nussbaumer
_PIgnoreIpolicy = ("ignore_ipolicy", False, ht.TBool,
164 b6aaf437 René Nussbaumer
                   "Whether to ignore ipolicy violations")
165 b6aaf437 René Nussbaumer
166 8c0b16f6 Guido Trotter
# Allow runtime changes while migrating
167 8c0b16f6 Guido Trotter
_PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool,
168 8c0b16f6 Guido Trotter
                      "Allow runtime changes (eg. memory ballooning)")
169 8c0b16f6 Guido Trotter
170 8c0b16f6 Guido Trotter
171 ff0d18e6 Iustin Pop
#: OP_ID conversion regular expression
172 ff0d18e6 Iustin Pop
_OPID_RE = re.compile("([a-z])([A-Z])")
173 ff0d18e6 Iustin Pop
174 8c9ee749 Michael Hanselmann
#: Utility function for L{OpClusterSetParams}
175 8f227489 Michael Hanselmann
_TestClusterOsListItem = \
176 8f227489 Michael Hanselmann
  ht.TAnd(ht.TIsLength(2), ht.TItems([
177 8f227489 Michael Hanselmann
    ht.TElemOf(constants.DDMS_VALUES),
178 8f227489 Michael Hanselmann
    ht.TNonEmptyString,
179 8f227489 Michael Hanselmann
    ]))
180 8c9ee749 Michael Hanselmann
181 ff8067cf Michael Hanselmann
_TestClusterOsList = ht.TMaybeListOf(_TestClusterOsListItem)
182 ff0d18e6 Iustin Pop
183 526a662a Michael Hanselmann
# TODO: Generate check from constants.INIC_PARAMS_TYPES
184 526a662a Michael Hanselmann
#: Utility function for testing NIC definitions
185 20a32e74 Michael Hanselmann
_TestNicDef = \
186 20a32e74 Michael Hanselmann
  ht.Comment("NIC parameters")(ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS),
187 20a32e74 Michael Hanselmann
                                          ht.TOr(ht.TNone, ht.TNonEmptyString)))
188 526a662a Michael Hanselmann
189 1456df62 Michael Hanselmann
_TSetParamsResultItemItems = [
190 1456df62 Michael Hanselmann
  ht.Comment("name of changed parameter")(ht.TNonEmptyString),
191 b3d2ee31 Michael Hanselmann
  ht.Comment("new value")(ht.TAny),
192 1456df62 Michael Hanselmann
  ]
193 1456df62 Michael Hanselmann
194 1456df62 Michael Hanselmann
_TSetParamsResult = \
195 1456df62 Michael Hanselmann
  ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
196 1456df62 Michael Hanselmann
                     ht.TItems(_TSetParamsResultItemItems)))
197 1456df62 Michael Hanselmann
198 735e1318 Michael Hanselmann
# TODO: Generate check from constants.IDISK_PARAMS_TYPES (however, not all users
199 735e1318 Michael Hanselmann
# of this check support all parameters)
200 20a32e74 Michael Hanselmann
_TDiskParams = \
201 20a32e74 Michael Hanselmann
  ht.Comment("Disk parameters")(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS),
202 20a32e74 Michael Hanselmann
                                           ht.TOr(ht.TNonEmptyString, ht.TInt)))
203 735e1318 Michael Hanselmann
204 aa12a891 René Nussbaumer
_TQueryRow = \
205 aa12a891 René Nussbaumer
  ht.TListOf(ht.TAnd(ht.TIsLength(2),
206 aa12a891 René Nussbaumer
                     ht.TItems([ht.TElemOf(constants.RS_ALL),
207 aa12a891 René Nussbaumer
                                ht.TAny])))
208 aa12a891 René Nussbaumer
209 415feb2e René Nussbaumer
_TQueryResult = ht.TListOf(_TQueryRow)
210 415feb2e René Nussbaumer
211 415feb2e René Nussbaumer
_TOldQueryRow = ht.TListOf(ht.TAny)
212 415feb2e René Nussbaumer
213 415feb2e René Nussbaumer
_TOldQueryResult = ht.TListOf(_TOldQueryRow)
214 415feb2e René Nussbaumer
215 415feb2e René Nussbaumer
216 3ce9a5e7 Michael Hanselmann
_SUMMARY_PREFIX = {
217 3ce9a5e7 Michael Hanselmann
  "CLUSTER_": "C_",
218 3ce9a5e7 Michael Hanselmann
  "GROUP_": "G_",
219 3ce9a5e7 Michael Hanselmann
  "NODE_": "N_",
220 3ce9a5e7 Michael Hanselmann
  "INSTANCE_": "I_",
221 3ce9a5e7 Michael Hanselmann
  }
222 3ce9a5e7 Michael Hanselmann
223 b95479a5 Michael Hanselmann
#: Attribute name for dependencies
224 b95479a5 Michael Hanselmann
DEPEND_ATTR = "depends"
225 b95479a5 Michael Hanselmann
226 018ae30b Michael Hanselmann
#: Attribute name for comment
227 018ae30b Michael Hanselmann
COMMENT_ATTR = "comment"
228 018ae30b Michael Hanselmann
229 526a662a Michael Hanselmann
230 ff0d18e6 Iustin Pop
def _NameToId(name):
231 ff0d18e6 Iustin Pop
  """Convert an opcode class name to an OP_ID.
232 ff0d18e6 Iustin Pop

233 ff0d18e6 Iustin Pop
  @type name: string
234 ff0d18e6 Iustin Pop
  @param name: the class name, as OpXxxYyy
235 ff0d18e6 Iustin Pop
  @rtype: string
236 ff0d18e6 Iustin Pop
  @return: the name in the OP_XXXX_YYYY format
237 ff0d18e6 Iustin Pop

238 ff0d18e6 Iustin Pop
  """
239 ff0d18e6 Iustin Pop
  if not name.startswith("Op"):
240 ff0d18e6 Iustin Pop
    return None
241 ff0d18e6 Iustin Pop
  # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
242 ff0d18e6 Iustin Pop
  # consume any input, and hence we would just have all the elements
243 ff0d18e6 Iustin Pop
  # in the list, one by one; but it seems that split doesn't work on
244 ff0d18e6 Iustin Pop
  # non-consuming input, hence we have to process the input string a
245 ff0d18e6 Iustin Pop
  # bit
246 ff0d18e6 Iustin Pop
  name = _OPID_RE.sub(r"\1,\2", name)
247 ff0d18e6 Iustin Pop
  elems = name.split(",")
248 ff0d18e6 Iustin Pop
  return "_".join(n.upper() for n in elems)
249 ff0d18e6 Iustin Pop
250 65e183af Michael Hanselmann
251 415feb2e René Nussbaumer
def _GenerateObjectTypeCheck(obj, fields_types):
252 415feb2e René Nussbaumer
  """Helper to generate type checks for objects.
253 415feb2e René Nussbaumer

254 415feb2e René Nussbaumer
  @param obj: The object to generate type checks
255 415feb2e René Nussbaumer
  @param fields_types: The fields and their types as a dict
256 415feb2e René Nussbaumer
  @return: A ht type check function
257 415feb2e René Nussbaumer

258 415feb2e René Nussbaumer
  """
259 415feb2e René Nussbaumer
  assert set(obj.GetAllSlots()) == set(fields_types.keys()), \
260 415feb2e René Nussbaumer
    "%s != %s" % (set(obj.GetAllSlots()), set(fields_types.keys()))
261 415feb2e René Nussbaumer
  return ht.TStrictDict(True, True, fields_types)
262 415feb2e René Nussbaumer
263 415feb2e René Nussbaumer
264 b02c6bdf Michael Hanselmann
_TQueryFieldDef = \
265 b02c6bdf Michael Hanselmann
  _GenerateObjectTypeCheck(objects.QueryFieldDefinition, {
266 b02c6bdf Michael Hanselmann
    "name": ht.TNonEmptyString,
267 b02c6bdf Michael Hanselmann
    "title": ht.TNonEmptyString,
268 b02c6bdf Michael Hanselmann
    "kind": ht.TElemOf(constants.QFT_ALL),
269 b02c6bdf Michael Hanselmann
    "doc": ht.TNonEmptyString,
270 b02c6bdf Michael Hanselmann
    })
271 415feb2e René Nussbaumer
272 415feb2e René Nussbaumer
273 65e183af Michael Hanselmann
def RequireFileStorage():
274 65e183af Michael Hanselmann
  """Checks that file storage is enabled.
275 65e183af Michael Hanselmann

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

279 65e183af Michael Hanselmann
  @raise errors.OpPrereqError: when file storage is disabled
280 65e183af Michael Hanselmann

281 65e183af Michael Hanselmann
  """
282 65e183af Michael Hanselmann
  if not constants.ENABLE_FILE_STORAGE:
283 65e183af Michael Hanselmann
    raise errors.OpPrereqError("File storage disabled at configure time",
284 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
285 65e183af Michael Hanselmann
286 65e183af Michael Hanselmann
287 4b97f902 Apollon Oikonomopoulos
def RequireSharedFileStorage():
288 4b97f902 Apollon Oikonomopoulos
  """Checks that shared file storage is enabled.
289 4b97f902 Apollon Oikonomopoulos

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

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

295 4b97f902 Apollon Oikonomopoulos
  """
296 4b97f902 Apollon Oikonomopoulos
  if not constants.ENABLE_SHARED_FILE_STORAGE:
297 4b97f902 Apollon Oikonomopoulos
    raise errors.OpPrereqError("Shared file storage disabled at"
298 4b97f902 Apollon Oikonomopoulos
                               " configure time", errors.ECODE_INVAL)
299 4b97f902 Apollon Oikonomopoulos
300 4b97f902 Apollon Oikonomopoulos
301 8c9ee749 Michael Hanselmann
@ht.WithDesc("CheckFileStorage")
302 8c9ee749 Michael Hanselmann
def _CheckFileStorage(value):
303 8c9ee749 Michael Hanselmann
  """Ensures file storage is enabled if used.
304 65e183af Michael Hanselmann

305 65e183af Michael Hanselmann
  """
306 8c9ee749 Michael Hanselmann
  if value == constants.DT_FILE:
307 65e183af Michael Hanselmann
    RequireFileStorage()
308 4b97f902 Apollon Oikonomopoulos
  elif value == constants.DT_SHARED_FILE:
309 4b97f902 Apollon Oikonomopoulos
    RequireSharedFileStorage()
310 65e183af Michael Hanselmann
  return True
311 65e183af Michael Hanselmann
312 65e183af Michael Hanselmann
313 45fe090b Michael Hanselmann
def _BuildDiskTemplateCheck(accept_none):
314 45fe090b Michael Hanselmann
  """Builds check for disk template.
315 45fe090b Michael Hanselmann

316 45fe090b Michael Hanselmann
  @type accept_none: bool
317 45fe090b Michael Hanselmann
  @param accept_none: whether to accept None as a correct value
318 45fe090b Michael Hanselmann
  @rtype: callable
319 45fe090b Michael Hanselmann

320 45fe090b Michael Hanselmann
  """
321 45fe090b Michael Hanselmann
  template_check = ht.TElemOf(constants.DISK_TEMPLATES)
322 45fe090b Michael Hanselmann
323 45fe090b Michael Hanselmann
  if accept_none:
324 45fe090b Michael Hanselmann
    template_check = ht.TOr(template_check, ht.TNone)
325 45fe090b Michael Hanselmann
326 45fe090b Michael Hanselmann
  return ht.TAnd(template_check, _CheckFileStorage)
327 8c9ee749 Michael Hanselmann
328 8c9ee749 Michael Hanselmann
329 65e183af Michael Hanselmann
def _CheckStorageType(storage_type):
330 65e183af Michael Hanselmann
  """Ensure a given storage type is valid.
331 65e183af Michael Hanselmann

332 65e183af Michael Hanselmann
  """
333 65e183af Michael Hanselmann
  if storage_type not in constants.VALID_STORAGE_TYPES:
334 65e183af Michael Hanselmann
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
335 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
336 65e183af Michael Hanselmann
  if storage_type == constants.ST_FILE:
337 63a3d8f7 Michael Hanselmann
    # TODO: What about shared file storage?
338 65e183af Michael Hanselmann
    RequireFileStorage()
339 65e183af Michael Hanselmann
  return True
340 65e183af Michael Hanselmann
341 65e183af Michael Hanselmann
342 65e183af Michael Hanselmann
#: Storage type parameter
343 45d4c81c Michael Hanselmann
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
344 45d4c81c Michael Hanselmann
                 "Storage type")
345 65e183af Michael Hanselmann
346 65e183af Michael Hanselmann
347 32683096 René Nussbaumer
class _AutoOpParamSlots(objectutils.AutoSlots):
348 65e183af Michael Hanselmann
  """Meta class for opcode definitions.
349 65e183af Michael Hanselmann

350 65e183af Michael Hanselmann
  """
351 65e183af Michael Hanselmann
  def __new__(mcs, name, bases, attrs):
352 65e183af Michael Hanselmann
    """Called when a class should be created.
353 65e183af Michael Hanselmann

354 65e183af Michael Hanselmann
    @param mcs: The meta class
355 65e183af Michael Hanselmann
    @param name: Name of created class
356 65e183af Michael Hanselmann
    @param bases: Base classes
357 65e183af Michael Hanselmann
    @type attrs: dict
358 65e183af Michael Hanselmann
    @param attrs: Class attributes
359 65e183af Michael Hanselmann

360 65e183af Michael Hanselmann
    """
361 e89a9021 Iustin Pop
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
362 ff0d18e6 Iustin Pop
363 32683096 René Nussbaumer
    slots = mcs._GetSlots(attrs)
364 32683096 René Nussbaumer
    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
365 32683096 René Nussbaumer
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name
366 32683096 René Nussbaumer
367 e89a9021 Iustin Pop
    attrs["OP_ID"] = _NameToId(name)
368 65e183af Michael Hanselmann
369 32683096 René Nussbaumer
    return objectutils.AutoSlots.__new__(mcs, name, bases, attrs)
370 32683096 René Nussbaumer
371 32683096 René Nussbaumer
  @classmethod
372 32683096 René Nussbaumer
  def _GetSlots(mcs, attrs):
373 32683096 René Nussbaumer
    """Build the slots out of OP_PARAMS.
374 32683096 René Nussbaumer

375 32683096 René Nussbaumer
    """
376 65e183af Michael Hanselmann
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
377 65e183af Michael Hanselmann
    params = attrs.setdefault("OP_PARAMS", [])
378 65e183af Michael Hanselmann
379 65e183af Michael Hanselmann
    # Use parameter names as slots
380 32683096 René Nussbaumer
    return [pname for (pname, _, _, _) in params]
381 65e183af Michael Hanselmann
382 df458e0b Iustin Pop
383 32683096 René Nussbaumer
class BaseOpCode(objectutils.ValidatedSlots):
384 df458e0b Iustin Pop
  """A simple serializable object.
385 df458e0b Iustin Pop

386 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
387 0e46916d Iustin Pop
  field handling.
388 0e46916d Iustin Pop

389 df458e0b Iustin Pop
  """
390 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
391 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
392 65e183af Michael Hanselmann
  __metaclass__ = _AutoOpParamSlots
393 65e183af Michael Hanselmann
394 df458e0b Iustin Pop
  def __getstate__(self):
395 a7399f66 Iustin Pop
    """Generic serializer.
396 a7399f66 Iustin Pop

397 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
398 a7399f66 Iustin Pop
    dictionary.
399 a7399f66 Iustin Pop

400 a7399f66 Iustin Pop
    @rtype:  C{dict}
401 a7399f66 Iustin Pop
    @return: the instance attributes and their values
402 a7399f66 Iustin Pop

403 a7399f66 Iustin Pop
    """
404 df458e0b Iustin Pop
    state = {}
405 32683096 René Nussbaumer
    for name in self.GetAllSlots():
406 df458e0b Iustin Pop
      if hasattr(self, name):
407 df458e0b Iustin Pop
        state[name] = getattr(self, name)
408 df458e0b Iustin Pop
    return state
409 df458e0b Iustin Pop
410 df458e0b Iustin Pop
  def __setstate__(self, state):
411 a7399f66 Iustin Pop
    """Generic unserializer.
412 a7399f66 Iustin Pop

413 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
414 a7399f66 Iustin Pop
    of the current instance.
415 a7399f66 Iustin Pop

416 a7399f66 Iustin Pop
    @param state: the serialized opcode data
417 a7399f66 Iustin Pop
    @type state:  C{dict}
418 a7399f66 Iustin Pop

419 a7399f66 Iustin Pop
    """
420 df458e0b Iustin Pop
    if not isinstance(state, dict):
421 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
422 df458e0b Iustin Pop
                       type(state))
423 df458e0b Iustin Pop
424 32683096 René Nussbaumer
    for name in self.GetAllSlots():
425 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
426 df458e0b Iustin Pop
        delattr(self, name)
427 df458e0b Iustin Pop
428 df458e0b Iustin Pop
    for name in state:
429 df458e0b Iustin Pop
      setattr(self, name, state[name])
430 df458e0b Iustin Pop
431 adf385c7 Iustin Pop
  @classmethod
432 65e183af Michael Hanselmann
  def GetAllParams(cls):
433 65e183af Michael Hanselmann
    """Compute list of all parameters for an opcode.
434 65e183af Michael Hanselmann

435 65e183af Michael Hanselmann
    """
436 65e183af Michael Hanselmann
    slots = []
437 65e183af Michael Hanselmann
    for parent in cls.__mro__:
438 65e183af Michael Hanselmann
      slots.extend(getattr(parent, "OP_PARAMS", []))
439 65e183af Michael Hanselmann
    return slots
440 65e183af Michael Hanselmann
441 32683096 René Nussbaumer
  def Validate(self, set_defaults): # pylint: disable=W0221
442 1cbef6d8 Michael Hanselmann
    """Validate opcode parameters, optionally setting default values.
443 1cbef6d8 Michael Hanselmann

444 1cbef6d8 Michael Hanselmann
    @type set_defaults: bool
445 1cbef6d8 Michael Hanselmann
    @param set_defaults: Whether to set default values
446 1cbef6d8 Michael Hanselmann
    @raise errors.OpPrereqError: When a parameter value doesn't match
447 1cbef6d8 Michael Hanselmann
                                 requirements
448 1cbef6d8 Michael Hanselmann

449 1cbef6d8 Michael Hanselmann
    """
450 197b323b Michael Hanselmann
    for (attr_name, default, test, _) in self.GetAllParams():
451 1cbef6d8 Michael Hanselmann
      assert test == ht.NoType or callable(test)
452 1cbef6d8 Michael Hanselmann
453 1cbef6d8 Michael Hanselmann
      if not hasattr(self, attr_name):
454 1cbef6d8 Michael Hanselmann
        if default == ht.NoDefault:
455 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
456 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
457 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
458 1cbef6d8 Michael Hanselmann
        elif set_defaults:
459 1cbef6d8 Michael Hanselmann
          if callable(default):
460 1cbef6d8 Michael Hanselmann
            dval = default()
461 1cbef6d8 Michael Hanselmann
          else:
462 1cbef6d8 Michael Hanselmann
            dval = default
463 1cbef6d8 Michael Hanselmann
          setattr(self, attr_name, dval)
464 1cbef6d8 Michael Hanselmann
465 1cbef6d8 Michael Hanselmann
      if test == ht.NoType:
466 1cbef6d8 Michael Hanselmann
        # no tests here
467 1cbef6d8 Michael Hanselmann
        continue
468 1cbef6d8 Michael Hanselmann
469 1cbef6d8 Michael Hanselmann
      if set_defaults or hasattr(self, attr_name):
470 1cbef6d8 Michael Hanselmann
        attr_val = getattr(self, attr_name)
471 1cbef6d8 Michael Hanselmann
        if not test(attr_val):
472 68b2e985 René Nussbaumer
          logging.error("OpCode %s, parameter %s, has invalid type %s/value %s"
473 68b2e985 René Nussbaumer
                        " expecting type %s",
474 68b2e985 René Nussbaumer
                        self.OP_ID, attr_name, type(attr_val), attr_val, test)
475 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
476 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
477 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
478 1cbef6d8 Michael Hanselmann
479 df458e0b Iustin Pop
480 b247c6fc Michael Hanselmann
def _BuildJobDepCheck(relative):
481 b247c6fc Michael Hanselmann
  """Builds check for job dependencies (L{DEPEND_ATTR}).
482 b247c6fc Michael Hanselmann

483 b247c6fc Michael Hanselmann
  @type relative: bool
484 b247c6fc Michael Hanselmann
  @param relative: Whether to accept relative job IDs (negative)
485 b247c6fc Michael Hanselmann
  @rtype: callable
486 b247c6fc Michael Hanselmann

487 b247c6fc Michael Hanselmann
  """
488 b247c6fc Michael Hanselmann
  if relative:
489 b247c6fc Michael Hanselmann
    job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
490 b247c6fc Michael Hanselmann
  else:
491 b247c6fc Michael Hanselmann
    job_id = ht.TJobId
492 b247c6fc Michael Hanselmann
493 b247c6fc Michael Hanselmann
  job_dep = \
494 b247c6fc Michael Hanselmann
    ht.TAnd(ht.TIsLength(2),
495 b247c6fc Michael Hanselmann
            ht.TItems([job_id,
496 b247c6fc Michael Hanselmann
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
497 b247c6fc Michael Hanselmann
498 ff8067cf Michael Hanselmann
  return ht.TMaybeListOf(job_dep)
499 b247c6fc Michael Hanselmann
500 b247c6fc Michael Hanselmann
501 b247c6fc Michael Hanselmann
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
502 b247c6fc Michael Hanselmann
503 1ce03fb1 Michael Hanselmann
#: List of submission status and job ID as returned by C{SubmitManyJobs}
504 1456df62 Michael Hanselmann
_TJobIdListItem = \
505 1456df62 Michael Hanselmann
  ht.TAnd(ht.TIsLength(2),
506 1456df62 Michael Hanselmann
          ht.TItems([ht.Comment("success")(ht.TBool),
507 1456df62 Michael Hanselmann
                     ht.Comment("Job ID if successful, error message"
508 1456df62 Michael Hanselmann
                                " otherwise")(ht.TOr(ht.TString,
509 1456df62 Michael Hanselmann
                                                     ht.TJobId))]))
510 1456df62 Michael Hanselmann
TJobIdList = ht.TListOf(_TJobIdListItem)
511 1ce03fb1 Michael Hanselmann
512 f7686867 Michael Hanselmann
#: Result containing only list of submitted jobs
513 f7686867 Michael Hanselmann
TJobIdListOnly = ht.TStrictDict(True, True, {
514 1456df62 Michael Hanselmann
  constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
515 f7686867 Michael Hanselmann
  })
516 f7686867 Michael Hanselmann
517 b247c6fc Michael Hanselmann
518 0e46916d Iustin Pop
class OpCode(BaseOpCode):
519 a7399f66 Iustin Pop
  """Abstract OpCode.
520 a7399f66 Iustin Pop

521 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
522 a7399f66 Iustin Pop
  from this class should override OP_ID.
523 a7399f66 Iustin Pop

524 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
525 20777413 Iustin Pop
               children of this class.
526 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
527 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
528 bde8f481 Adeodato Simo
                      method for details).
529 65e183af Michael Hanselmann
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
530 65e183af Michael Hanselmann
                   get if not already defined, and types they must match.
531 1ce03fb1 Michael Hanselmann
  @cvar OP_RESULT: Callable to verify opcode result
532 687c10d9 Iustin Pop
  @cvar WITH_LU: Boolean that specifies whether this should be included in
533 687c10d9 Iustin Pop
      mcpu's dispatch table
534 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
535 20777413 Iustin Pop
                 the check steps
536 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
537 a7399f66 Iustin Pop

538 a7399f66 Iustin Pop
  """
539 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
540 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
541 687c10d9 Iustin Pop
  WITH_LU = True
542 65e183af Michael Hanselmann
  OP_PARAMS = [
543 45d4c81c Michael Hanselmann
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
544 45d4c81c Michael Hanselmann
    ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"),
545 65e183af Michael Hanselmann
    ("priority", constants.OP_PRIO_DEFAULT,
546 45d4c81c Michael Hanselmann
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
547 b247c6fc Michael Hanselmann
    (DEPEND_ATTR, None, _BuildJobDepCheck(True),
548 b247c6fc Michael Hanselmann
     "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
549 822a50c4 Michael Hanselmann
     " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
550 822a50c4 Michael Hanselmann
     " for details"),
551 018ae30b Michael Hanselmann
    (COMMENT_ATTR, None, ht.TMaybeString,
552 018ae30b Michael Hanselmann
     "Comment describing the purpose of the opcode"),
553 65e183af Michael Hanselmann
    ]
554 1ce03fb1 Michael Hanselmann
  OP_RESULT = None
555 df458e0b Iustin Pop
556 df458e0b Iustin Pop
  def __getstate__(self):
557 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
558 df458e0b Iustin Pop

559 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
560 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
561 a7399f66 Iustin Pop
    instantiating the opcode.
562 a7399f66 Iustin Pop

563 a7399f66 Iustin Pop
    @rtype:   C{dict}
564 a7399f66 Iustin Pop
    @return:  the state as a dictionary
565 a7399f66 Iustin Pop

566 df458e0b Iustin Pop
    """
567 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
568 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
569 df458e0b Iustin Pop
    return data
570 df458e0b Iustin Pop
571 df458e0b Iustin Pop
  @classmethod
572 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
573 df458e0b Iustin Pop
    """Generic load opcode method.
574 df458e0b Iustin Pop

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

579 a7399f66 Iustin Pop
    @type data:  C{dict}
580 a7399f66 Iustin Pop
    @param data: the serialized opcode
581 a7399f66 Iustin Pop

582 df458e0b Iustin Pop
    """
583 df458e0b Iustin Pop
    if not isinstance(data, dict):
584 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
585 df458e0b Iustin Pop
    if "OP_ID" not in data:
586 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
587 df458e0b Iustin Pop
    op_id = data["OP_ID"]
588 df458e0b Iustin Pop
    op_class = None
589 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
590 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
591 363acb1e Iustin Pop
    else:
592 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
593 df458e0b Iustin Pop
                       op_id)
594 df458e0b Iustin Pop
    op = op_class()
595 df458e0b Iustin Pop
    new_data = data.copy()
596 df458e0b Iustin Pop
    del new_data["OP_ID"]
597 df458e0b Iustin Pop
    op.__setstate__(new_data)
598 df458e0b Iustin Pop
    return op
599 df458e0b Iustin Pop
600 60dd1473 Iustin Pop
  def Summary(self):
601 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
602 60dd1473 Iustin Pop

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

609 60dd1473 Iustin Pop
    """
610 ff0d18e6 Iustin Pop
    assert self.OP_ID is not None and len(self.OP_ID) > 3
611 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
612 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
613 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
614 60dd1473 Iustin Pop
    if field_name:
615 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
616 bc8bbda1 Iustin Pop
      if isinstance(field_value, (list, tuple)):
617 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
618 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
619 60dd1473 Iustin Pop
    return txt
620 60dd1473 Iustin Pop
621 3ce9a5e7 Michael Hanselmann
  def TinySummary(self):
622 3ce9a5e7 Michael Hanselmann
    """Generates a compact summary description of the opcode.
623 3ce9a5e7 Michael Hanselmann

624 3ce9a5e7 Michael Hanselmann
    """
625 3ce9a5e7 Michael Hanselmann
    assert self.OP_ID.startswith("OP_")
626 3ce9a5e7 Michael Hanselmann
627 3ce9a5e7 Michael Hanselmann
    text = self.OP_ID[3:]
628 3ce9a5e7 Michael Hanselmann
629 3ce9a5e7 Michael Hanselmann
    for (prefix, supplement) in _SUMMARY_PREFIX.items():
630 3ce9a5e7 Michael Hanselmann
      if text.startswith(prefix):
631 3ce9a5e7 Michael Hanselmann
        return supplement + text[len(prefix):]
632 3ce9a5e7 Michael Hanselmann
633 3ce9a5e7 Michael Hanselmann
    return text
634 3ce9a5e7 Michael Hanselmann
635 a8083063 Iustin Pop
636 afee0879 Iustin Pop
# cluster opcodes
637 afee0879 Iustin Pop
638 bc84ffa7 Iustin Pop
class OpClusterPostInit(OpCode):
639 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
640 b5f5fae9 Luca Bigliardi

641 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
642 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
643 b5f5fae9 Luca Bigliardi

644 b5f5fae9 Luca Bigliardi
  """
645 c363310d René Nussbaumer
  OP_RESULT = ht.TBool
646 b5f5fae9 Luca Bigliardi
647 b5f5fae9 Luca Bigliardi
648 c6d43e9e Iustin Pop
class OpClusterDestroy(OpCode):
649 a7399f66 Iustin Pop
  """Destroy the cluster.
650 a7399f66 Iustin Pop

651 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
652 a7399f66 Iustin Pop
  lost after the execution of this opcode.
653 a7399f66 Iustin Pop

654 a7399f66 Iustin Pop
  """
655 c363310d René Nussbaumer
  OP_RESULT = ht.TNonEmptyString
656 a8083063 Iustin Pop
657 a8083063 Iustin Pop
658 a2f7ab92 Iustin Pop
class OpClusterQuery(OpCode):
659 fdc267f4 Iustin Pop
  """Query cluster information."""
660 415feb2e René Nussbaumer
  OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TAny)
661 a8083063 Iustin Pop
662 a8083063 Iustin Pop
663 fcad7225 Michael Hanselmann
class OpClusterVerify(OpCode):
664 fcad7225 Michael Hanselmann
  """Submits all jobs necessary to verify the cluster.
665 fcad7225 Michael Hanselmann

666 fcad7225 Michael Hanselmann
  """
667 fcad7225 Michael Hanselmann
  OP_PARAMS = [
668 fcad7225 Michael Hanselmann
    _PDebugSimulateErrors,
669 fcad7225 Michael Hanselmann
    _PErrorCodes,
670 fcad7225 Michael Hanselmann
    _PSkipChecks,
671 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
672 fcad7225 Michael Hanselmann
    _PVerbose,
673 fcad7225 Michael Hanselmann
    ("group_name", None, ht.TMaybeString, "Group to verify")
674 fcad7225 Michael Hanselmann
    ]
675 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
676 fcad7225 Michael Hanselmann
677 fcad7225 Michael Hanselmann
678 bf93ae69 Adeodato Simo
class OpClusterVerifyConfig(OpCode):
679 bf93ae69 Adeodato Simo
  """Verify the cluster config.
680 bf93ae69 Adeodato Simo

681 bf93ae69 Adeodato Simo
  """
682 bf93ae69 Adeodato Simo
  OP_PARAMS = [
683 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
684 57106b74 Michael Hanselmann
    _PErrorCodes,
685 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
686 57106b74 Michael Hanselmann
    _PVerbose,
687 bf93ae69 Adeodato Simo
    ]
688 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
689 bf93ae69 Adeodato Simo
690 bf93ae69 Adeodato Simo
691 bf93ae69 Adeodato Simo
class OpClusterVerifyGroup(OpCode):
692 bf93ae69 Adeodato Simo
  """Run verify on a node group from the cluster.
693 a7399f66 Iustin Pop

694 a7399f66 Iustin Pop
  @type skip_checks: C{list}
695 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
696 a7399f66 Iustin Pop
                     needs to be a subset of
697 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
698 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
699 a7399f66 Iustin Pop

700 a7399f66 Iustin Pop
  """
701 bf93ae69 Adeodato Simo
  OP_DSC_FIELD = "group_name"
702 65e183af Michael Hanselmann
  OP_PARAMS = [
703 57106b74 Michael Hanselmann
    _PGroupName,
704 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
705 57106b74 Michael Hanselmann
    _PErrorCodes,
706 57106b74 Michael Hanselmann
    _PSkipChecks,
707 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
708 57106b74 Michael Hanselmann
    _PVerbose,
709 65e183af Michael Hanselmann
    ]
710 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
711 a8083063 Iustin Pop
712 a8083063 Iustin Pop
713 bd8210a7 Iustin Pop
class OpClusterVerifyDisks(OpCode):
714 150e978f Iustin Pop
  """Verify the cluster disks.
715 150e978f Iustin Pop

716 ae1a845c Michael Hanselmann
  """
717 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
718 ae1a845c Michael Hanselmann
719 ae1a845c Michael Hanselmann
720 ae1a845c Michael Hanselmann
class OpGroupVerifyDisks(OpCode):
721 ae1a845c Michael Hanselmann
  """Verifies the status of all disks in a node group.
722 150e978f Iustin Pop

723 ae1a845c Michael Hanselmann
  Result: a tuple of three elements:
724 ae1a845c Michael Hanselmann
    - dict of node names with issues (values: error msg)
725 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
726 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
727 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
728 150e978f Iustin Pop

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

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

737 150e978f Iustin Pop
  """
738 ae1a845c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
739 ae1a845c Michael Hanselmann
  OP_PARAMS = [
740 ae1a845c Michael Hanselmann
    _PGroupName,
741 ae1a845c Michael Hanselmann
    ]
742 1ce03fb1 Michael Hanselmann
  OP_RESULT = \
743 1ce03fb1 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3),
744 1ce03fb1 Michael Hanselmann
            ht.TItems([ht.TDictOf(ht.TString, ht.TString),
745 1ce03fb1 Michael Hanselmann
                       ht.TListOf(ht.TString),
746 6973587f Michael Hanselmann
                       ht.TDictOf(ht.TString,
747 6973587f Michael Hanselmann
                                  ht.TListOf(ht.TListOf(ht.TString)))]))
748 150e978f Iustin Pop
749 150e978f Iustin Pop
750 5d01aca3 Iustin Pop
class OpClusterRepairDiskSizes(OpCode):
751 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
752 60975797 Iustin Pop
  mimatches.
753 60975797 Iustin Pop

754 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
755 60975797 Iustin Pop
  checks to only a subset of the instances.
756 60975797 Iustin Pop

757 60975797 Iustin Pop
  Result: a list of tuples, (instance, disk, new-size) for changed
758 60975797 Iustin Pop
  configurations.
759 60975797 Iustin Pop

760 60975797 Iustin Pop
  In normal operation, the list should be empty.
761 60975797 Iustin Pop

762 60975797 Iustin Pop
  @type instances: list
763 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
764 60975797 Iustin Pop

765 60975797 Iustin Pop
  """
766 65e183af Michael Hanselmann
  OP_PARAMS = [
767 197b323b Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
768 65e183af Michael Hanselmann
    ]
769 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
770 c363310d René Nussbaumer
                                 ht.TItems([ht.TNonEmptyString,
771 c363310d René Nussbaumer
                                            ht.TPositiveInt,
772 c363310d René Nussbaumer
                                            ht.TPositiveInt])))
773 60975797 Iustin Pop
774 60975797 Iustin Pop
775 2f093ea0 Iustin Pop
class OpClusterConfigQuery(OpCode):
776 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
777 65e183af Michael Hanselmann
  OP_PARAMS = [
778 65e183af Michael Hanselmann
    _POutputFields
779 65e183af Michael Hanselmann
    ]
780 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAny)
781 a8083063 Iustin Pop
782 a8083063 Iustin Pop
783 e126df25 Iustin Pop
class OpClusterRename(OpCode):
784 a7399f66 Iustin Pop
  """Rename the cluster.
785 a7399f66 Iustin Pop

786 a7399f66 Iustin Pop
  @type name: C{str}
787 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
788 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
789 a7399f66 Iustin Pop
              address.
790 a7399f66 Iustin Pop

791 a7399f66 Iustin Pop
  """
792 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
793 65e183af Michael Hanselmann
  OP_PARAMS = [
794 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
795 65e183af Michael Hanselmann
    ]
796 c363310d René Nussbaumer
  OP_RESULT = ht.TNonEmptyString
797 07bd8a51 Iustin Pop
798 07bd8a51 Iustin Pop
799 a6682fdc Iustin Pop
class OpClusterSetParams(OpCode):
800 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
801 a7399f66 Iustin Pop

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

805 a7399f66 Iustin Pop
  """
806 65e183af Michael Hanselmann
  OP_PARAMS = [
807 2da9f556 René Nussbaumer
    _PHvState,
808 2da9f556 René Nussbaumer
    _PDiskState,
809 8e66b9bf Iustin Pop
    ("vg_name", None, ht.TOr(ht.TString, ht.TNone), "Volume group name"),
810 65e183af Michael Hanselmann
    ("enabled_hypervisors", None,
811 65e183af Michael Hanselmann
     ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue),
812 45d4c81c Michael Hanselmann
            ht.TNone),
813 45d4c81c Michael Hanselmann
     "List of enabled hypervisors"),
814 65e183af Michael Hanselmann
    ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
815 45d4c81c Michael Hanselmann
                              ht.TNone),
816 45d4c81c Michael Hanselmann
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
817 45d4c81c Michael Hanselmann
    ("beparams", None, ht.TOr(ht.TDict, ht.TNone),
818 45d4c81c Michael Hanselmann
     "Cluster-wide backend parameter defaults"),
819 65e183af Michael Hanselmann
    ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
820 45d4c81c Michael Hanselmann
                            ht.TNone),
821 45d4c81c Michael Hanselmann
     "Cluster-wide per-OS hypervisor parameter defaults"),
822 65e183af Michael Hanselmann
    ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict),
823 45d4c81c Michael Hanselmann
                              ht.TNone),
824 45d4c81c Michael Hanselmann
     "Cluster-wide OS parameter defaults"),
825 bc5d0215 Andrea Spadaccini
    _PDiskParams,
826 197b323b Michael Hanselmann
    ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone),
827 45d4c81c Michael Hanselmann
     "Master candidate pool size"),
828 45d4c81c Michael Hanselmann
    ("uid_pool", None, ht.NoType,
829 45d4c81c Michael Hanselmann
     "Set UID pool, must be list of lists describing UID ranges (two items,"
830 45d4c81c Michael Hanselmann
     " start and end inclusive)"),
831 45d4c81c Michael Hanselmann
    ("add_uids", None, ht.NoType,
832 45d4c81c Michael Hanselmann
     "Extend UID pool, must be list of lists describing UID ranges (two"
833 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be added"),
834 45d4c81c Michael Hanselmann
    ("remove_uids", None, ht.NoType,
835 45d4c81c Michael Hanselmann
     "Shrink UID pool, must be list of lists describing UID ranges (two"
836 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be removed"),
837 45d4c81c Michael Hanselmann
    ("maintain_node_health", None, ht.TMaybeBool,
838 45d4c81c Michael Hanselmann
     "Whether to automatically maintain node health"),
839 45d4c81c Michael Hanselmann
    ("prealloc_wipe_disks", None, ht.TMaybeBool,
840 45d4c81c Michael Hanselmann
     "Whether to wipe disks before allocating them to instances"),
841 45d4c81c Michael Hanselmann
    ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
842 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
843 1b01390b René Nussbaumer
    ("ipolicy", None, ht.TMaybeDict,
844 1b01390b René Nussbaumer
     "Cluster-wide :ref:`instance policy <rapi-ipolicy>` specs"),
845 45d4c81c Michael Hanselmann
    ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"),
846 45d4c81c Michael Hanselmann
    ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone),
847 45d4c81c Michael Hanselmann
     "Default iallocator for cluster"),
848 45d4c81c Michael Hanselmann
    ("master_netdev", None, ht.TOr(ht.TString, ht.TNone),
849 45d4c81c Michael Hanselmann
     "Master network device"),
850 5a8648eb Andrea Spadaccini
    ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone),
851 5a8648eb Andrea Spadaccini
     "Netmask of the master IP"),
852 ff8067cf Michael Hanselmann
    ("reserved_lvs", None, ht.TMaybeListOf(ht.TNonEmptyString),
853 45d4c81c Michael Hanselmann
     "List of reserved LVs"),
854 45d4c81c Michael Hanselmann
    ("hidden_os", None, _TestClusterOsList,
855 0fb66bb1 Iustin Pop
     "Modify list of hidden operating systems: each modification must have"
856 0fb66bb1 Iustin Pop
     " two items, the operation and the OS name; the operation can be"
857 0fb66bb1 Iustin Pop
     " ``%s`` or ``%s``" % (constants.DDM_ADD, constants.DDM_REMOVE)),
858 45d4c81c Michael Hanselmann
    ("blacklisted_os", None, _TestClusterOsList,
859 0fb66bb1 Iustin Pop
     "Modify list of blacklisted operating systems: each modification must"
860 0fb66bb1 Iustin Pop
     " have two items, the operation and the OS name; the operation can be"
861 0fb66bb1 Iustin Pop
     " ``%s`` or ``%s``" % (constants.DDM_ADD, constants.DDM_REMOVE)),
862 bf689b7a Andrea Spadaccini
    ("use_external_mip_script", None, ht.TMaybeBool,
863 bf689b7a Andrea Spadaccini
     "Whether to use an external master IP address setup script"),
864 4b7735f9 Iustin Pop
    ]
865 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
866 12515db7 Manuel Franceschini
867 12515db7 Manuel Franceschini
868 d1240007 Iustin Pop
class OpClusterRedistConf(OpCode):
869 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
870 afee0879 Iustin Pop

871 afee0879 Iustin Pop
  """
872 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
873 afee0879 Iustin Pop
874 83f72637 Michael Hanselmann
875 fb926117 Andrea Spadaccini
class OpClusterActivateMasterIp(OpCode):
876 fb926117 Andrea Spadaccini
  """Activate the master IP on the master node.
877 fb926117 Andrea Spadaccini

878 fb926117 Andrea Spadaccini
  """
879 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
880 fb926117 Andrea Spadaccini
881 fb926117 Andrea Spadaccini
882 fb926117 Andrea Spadaccini
class OpClusterDeactivateMasterIp(OpCode):
883 fb926117 Andrea Spadaccini
  """Deactivate the master IP on the master node.
884 fb926117 Andrea Spadaccini

885 fb926117 Andrea Spadaccini
  """
886 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
887 fb926117 Andrea Spadaccini
888 fb926117 Andrea Spadaccini
889 83f72637 Michael Hanselmann
class OpQuery(OpCode):
890 83f72637 Michael Hanselmann
  """Query for resources/items.
891 83f72637 Michael Hanselmann

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

896 83f72637 Michael Hanselmann
  """
897 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
898 65e183af Michael Hanselmann
  OP_PARAMS = [
899 8e7078e0 Michael Hanselmann
    _PQueryWhat,
900 ee13764f Michael Hanselmann
    _PUseLocking,
901 45d4c81c Michael Hanselmann
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
902 45d4c81c Michael Hanselmann
     "Requested fields"),
903 7bfb3367 Iustin Pop
    ("qfilter", None, ht.TOr(ht.TNone, ht.TList),
904 45d4c81c Michael Hanselmann
     "Query filter"),
905 83f72637 Michael Hanselmann
    ]
906 415feb2e René Nussbaumer
  OP_RESULT = \
907 b02c6bdf Michael Hanselmann
    _GenerateObjectTypeCheck(objects.QueryResponse, {
908 b02c6bdf Michael Hanselmann
      "fields": ht.TListOf(_TQueryFieldDef),
909 b02c6bdf Michael Hanselmann
      "data": _TQueryResult,
910 b02c6bdf Michael Hanselmann
      })
911 83f72637 Michael Hanselmann
912 83f72637 Michael Hanselmann
913 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
914 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
915 83f72637 Michael Hanselmann

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

919 83f72637 Michael Hanselmann
  """
920 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
921 65e183af Michael Hanselmann
  OP_PARAMS = [
922 8e7078e0 Michael Hanselmann
    _PQueryWhat,
923 ff8067cf Michael Hanselmann
    ("fields", None, ht.TMaybeListOf(ht.TNonEmptyString),
924 8e7078e0 Michael Hanselmann
     "Requested fields; if not given, all are returned"),
925 83f72637 Michael Hanselmann
    ]
926 415feb2e René Nussbaumer
  OP_RESULT = \
927 b02c6bdf Michael Hanselmann
    _GenerateObjectTypeCheck(objects.QueryFieldsResponse, {
928 b02c6bdf Michael Hanselmann
      "fields": ht.TListOf(_TQueryFieldDef),
929 b02c6bdf Michael Hanselmann
      })
930 83f72637 Michael Hanselmann
931 83f72637 Michael Hanselmann
932 792af3ad René Nussbaumer
class OpOobCommand(OpCode):
933 eb64da59 René Nussbaumer
  """Interact with OOB."""
934 65e183af Michael Hanselmann
  OP_PARAMS = [
935 c4ec0755 René Nussbaumer
    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
936 c4ec0755 René Nussbaumer
     "List of nodes to run the OOB command against"),
937 c4ec0755 René Nussbaumer
    ("command", None, ht.TElemOf(constants.OOB_COMMANDS),
938 c4ec0755 René Nussbaumer
     "OOB command to be run"),
939 c4ec0755 René Nussbaumer
    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
940 c4ec0755 René Nussbaumer
     "Timeout before the OOB helper will be terminated"),
941 c4ec0755 René Nussbaumer
    ("ignore_status", False, ht.TBool,
942 c4ec0755 René Nussbaumer
     "Ignores the node offline status for power off"),
943 beff3779 René Nussbaumer
    ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
944 beff3779 René Nussbaumer
     "Time in seconds to wait between powering on nodes"),
945 eb64da59 René Nussbaumer
    ]
946 c363310d René Nussbaumer
  # Fixme: Make it more specific with all the special cases in LUOobCommand
947 415feb2e René Nussbaumer
  OP_RESULT = _TQueryResult
948 eb64da59 René Nussbaumer
949 eb64da59 René Nussbaumer
950 07bd8a51 Iustin Pop
# node opcodes
951 07bd8a51 Iustin Pop
952 73d565a3 Iustin Pop
class OpNodeRemove(OpCode):
953 a7399f66 Iustin Pop
  """Remove a node.
954 a7399f66 Iustin Pop

955 a7399f66 Iustin Pop
  @type node_name: C{str}
956 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
957 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
958 a7399f66 Iustin Pop

959 a7399f66 Iustin Pop
  """
960 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
961 65e183af Michael Hanselmann
  OP_PARAMS = [
962 65e183af Michael Hanselmann
    _PNodeName,
963 65e183af Michael Hanselmann
    ]
964 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
965 a8083063 Iustin Pop
966 a8083063 Iustin Pop
967 d817d49f Iustin Pop
class OpNodeAdd(OpCode):
968 a7399f66 Iustin Pop
  """Add a node to the cluster.
969 a7399f66 Iustin Pop

970 a7399f66 Iustin Pop
  @type node_name: C{str}
971 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
972 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
973 a7399f66 Iustin Pop
  @type primary_ip: IP address
974 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
975 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
976 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
977 a7399f66 Iustin Pop
  @type secondary_ip: IP address
978 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
979 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
980 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
981 a7399f66 Iustin Pop
  @type readd: C{bool}
982 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
983 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
984 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
985 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
986 a7399f66 Iustin Pop
               without removal from the cluster.
987 f936c153 Iustin Pop
  @type group: C{str}
988 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
989 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
990 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
991 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
992 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
993 a7399f66 Iustin Pop

994 a7399f66 Iustin Pop
  """
995 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
996 65e183af Michael Hanselmann
  OP_PARAMS = [
997 65e183af Michael Hanselmann
    _PNodeName,
998 085e0d9f René Nussbaumer
    _PHvState,
999 085e0d9f René Nussbaumer
    _PDiskState,
1000 45d4c81c Michael Hanselmann
    ("primary_ip", None, ht.NoType, "Primary IP address"),
1001 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
1002 45d4c81c Michael Hanselmann
    ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
1003 45d4c81c Michael Hanselmann
    ("group", None, ht.TMaybeString, "Initial node group"),
1004 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
1005 45d4c81c Michael Hanselmann
     "Whether node can become master or master candidate"),
1006 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
1007 45d4c81c Michael Hanselmann
     "Whether node can host instances"),
1008 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Node parameters"),
1009 65e183af Michael Hanselmann
    ]
1010 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1011 a8083063 Iustin Pop
1012 a8083063 Iustin Pop
1013 2237687b Iustin Pop
class OpNodeQuery(OpCode):
1014 a8083063 Iustin Pop
  """Compute the list of nodes."""
1015 65e183af Michael Hanselmann
  OP_PARAMS = [
1016 65e183af Michael Hanselmann
    _POutputFields,
1017 45d4c81c Michael Hanselmann
    _PUseLocking,
1018 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1019 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1020 65e183af Michael Hanselmann
    ]
1021 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1022 a8083063 Iustin Pop
1023 a8083063 Iustin Pop
1024 8ed55bfd Iustin Pop
class OpNodeQueryvols(OpCode):
1025 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
1026 65e183af Michael Hanselmann
  OP_PARAMS = [
1027 65e183af Michael Hanselmann
    _POutputFields,
1028 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1029 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1030 65e183af Michael Hanselmann
    ]
1031 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAny)
1032 dcb93971 Michael Hanselmann
1033 dcb93971 Michael Hanselmann
1034 ad8d0595 Iustin Pop
class OpNodeQueryStorage(OpCode):
1035 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
1036 65e183af Michael Hanselmann
  OP_PARAMS = [
1037 65e183af Michael Hanselmann
    _POutputFields,
1038 65e183af Michael Hanselmann
    _PStorageType,
1039 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
1040 45d4c81c Michael Hanselmann
    ("name", None, ht.TMaybeString, "Storage name"),
1041 9e5442ce Michael Hanselmann
    ]
1042 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1043 9e5442ce Michael Hanselmann
1044 9e5442ce Michael Hanselmann
1045 2cee4077 Iustin Pop
class OpNodeModifyStorage(OpCode):
1046 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
1047 32708d0a Iustin Pop
  OP_DSC_FIELD = "node_name"
1048 65e183af Michael Hanselmann
  OP_PARAMS = [
1049 65e183af Michael Hanselmann
    _PNodeName,
1050 65e183af Michael Hanselmann
    _PStorageType,
1051 45d4c81c Michael Hanselmann
    _PStorageName,
1052 45d4c81c Michael Hanselmann
    ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
1053 efb8da02 Michael Hanselmann
    ]
1054 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1055 efb8da02 Michael Hanselmann
1056 efb8da02 Michael Hanselmann
1057 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
1058 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
1059 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1060 65e183af Michael Hanselmann
  OP_PARAMS = [
1061 65e183af Michael Hanselmann
    _PNodeName,
1062 65e183af Michael Hanselmann
    _PStorageType,
1063 45d4c81c Michael Hanselmann
    _PStorageName,
1064 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1065 76aef8fc Michael Hanselmann
    ]
1066 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1067 76aef8fc Michael Hanselmann
1068 76aef8fc Michael Hanselmann
1069 f13973c4 Iustin Pop
class OpNodeSetParams(OpCode):
1070 b31c8676 Iustin Pop
  """Change the parameters of a node."""
1071 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
1072 65e183af Michael Hanselmann
  OP_PARAMS = [
1073 65e183af Michael Hanselmann
    _PNodeName,
1074 65e183af Michael Hanselmann
    _PForce,
1075 0ec2ce46 René Nussbaumer
    _PHvState,
1076 0ec2ce46 René Nussbaumer
    _PDiskState,
1077 45d4c81c Michael Hanselmann
    ("master_candidate", None, ht.TMaybeBool,
1078 45d4c81c Michael Hanselmann
     "Whether the node should become a master candidate"),
1079 45d4c81c Michael Hanselmann
    ("offline", None, ht.TMaybeBool,
1080 45d4c81c Michael Hanselmann
     "Whether the node should be marked as offline"),
1081 45d4c81c Michael Hanselmann
    ("drained", None, ht.TMaybeBool,
1082 45d4c81c Michael Hanselmann
     "Whether the node should be marked as drained"),
1083 45d4c81c Michael Hanselmann
    ("auto_promote", False, ht.TBool,
1084 45d4c81c Michael Hanselmann
     "Whether node(s) should be promoted to master candidate if necessary"),
1085 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
1086 45d4c81c Michael Hanselmann
     "Denote whether node can become master or master candidate"),
1087 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
1088 45d4c81c Michael Hanselmann
     "Denote whether node can host instances"),
1089 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString,
1090 45d4c81c Michael Hanselmann
     "Change node's secondary IP address"),
1091 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
1092 45d4c81c Michael Hanselmann
    ("powered", None, ht.TMaybeBool,
1093 45d4c81c Michael Hanselmann
     "Whether the node should be marked as powered"),
1094 b31c8676 Iustin Pop
    ]
1095 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1096 b31c8676 Iustin Pop
1097 f5118ade Iustin Pop
1098 e0d4735f Iustin Pop
class OpNodePowercycle(OpCode):
1099 f5118ade Iustin Pop
  """Tries to powercycle a node."""
1100 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
1101 65e183af Michael Hanselmann
  OP_PARAMS = [
1102 65e183af Michael Hanselmann
    _PNodeName,
1103 65e183af Michael Hanselmann
    _PForce,
1104 f5118ade Iustin Pop
    ]
1105 c363310d René Nussbaumer
  OP_RESULT = ht.TMaybeString
1106 f5118ade Iustin Pop
1107 7ffc5a86 Michael Hanselmann
1108 5b14a488 Iustin Pop
class OpNodeMigrate(OpCode):
1109 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
1110 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1111 65e183af Michael Hanselmann
  OP_PARAMS = [
1112 65e183af Michael Hanselmann
    _PNodeName,
1113 65e183af Michael Hanselmann
    _PMigrationMode,
1114 65e183af Michael Hanselmann
    _PMigrationLive,
1115 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1116 8c0b16f6 Guido Trotter
    _PAllowRuntimeChgs,
1117 9fa567b3 René Nussbaumer
    _PIgnoreIpolicy,
1118 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1119 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1120 80cb875c Michael Hanselmann
    ]
1121 65c9591c Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1122 80cb875c Michael Hanselmann
1123 80cb875c Michael Hanselmann
1124 e1f23243 Michael Hanselmann
class OpNodeEvacuate(OpCode):
1125 e1f23243 Michael Hanselmann
  """Evacuate instances off a number of nodes."""
1126 e1f23243 Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1127 e1f23243 Michael Hanselmann
  OP_PARAMS = [
1128 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1129 e1f23243 Michael Hanselmann
    _PNodeName,
1130 e1f23243 Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1131 e1f23243 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1132 cb92e7a1 Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1133 e1f23243 Michael Hanselmann
     "Node evacuation mode"),
1134 e1f23243 Michael Hanselmann
    ]
1135 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1136 e1f23243 Michael Hanselmann
1137 e1f23243 Michael Hanselmann
1138 a8083063 Iustin Pop
# instance opcodes
1139 a8083063 Iustin Pop
1140 e1530b10 Iustin Pop
class OpInstanceCreate(OpCode):
1141 9bf56d77 Michael Hanselmann
  """Create an instance.
1142 9bf56d77 Michael Hanselmann

1143 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
1144 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1145 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
1146 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1147 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
1148 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1149 dae91d02 Michael Hanselmann
    (remote import only)
1150 9bf56d77 Michael Hanselmann

1151 9bf56d77 Michael Hanselmann
  """
1152 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1153 65e183af Michael Hanselmann
  OP_PARAMS = [
1154 65e183af Michael Hanselmann
    _PInstanceName,
1155 45d4c81c Michael Hanselmann
    _PForceVariant,
1156 45d4c81c Michael Hanselmann
    _PWaitForSync,
1157 45d4c81c Michael Hanselmann
    _PNameCheck,
1158 10889e0c René Nussbaumer
    _PIgnoreIpolicy,
1159 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1160 735e1318 Michael Hanselmann
    ("disks", ht.NoDefault, ht.TListOf(_TDiskParams),
1161 526a662a Michael Hanselmann
     "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1162 526a662a Michael Hanselmann
     " each disk definition must contain a ``%s`` value and"
1163 526a662a Michael Hanselmann
     " can contain an optional ``%s`` value denoting the disk access mode"
1164 526a662a Michael Hanselmann
     " (%s)" %
1165 526a662a Michael Hanselmann
     (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1166 526a662a Michael Hanselmann
      constants.IDISK_MODE,
1167 526a662a Michael Hanselmann
      " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1168 45fe090b Michael Hanselmann
    ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1169 45fe090b Michael Hanselmann
     "Disk template"),
1170 45d4c81c Michael Hanselmann
    ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)),
1171 45d4c81c Michael Hanselmann
     "Driver for file-backed disks"),
1172 45d4c81c Michael Hanselmann
    ("file_storage_dir", None, ht.TMaybeString,
1173 45d4c81c Michael Hanselmann
     "Directory for storing file-backed disks"),
1174 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1175 45d4c81c Michael Hanselmann
     "Hypervisor parameters for instance, hypervisor-dependent"),
1176 45d4c81c Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1177 45d4c81c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString,
1178 45d4c81c Michael Hanselmann
     "Iallocator for deciding which node(s) to use"),
1179 45d4c81c Michael Hanselmann
    ("identify_defaults", False, ht.TBool,
1180 45d4c81c Michael Hanselmann
     "Reset instance parameters to default if equal"),
1181 45d4c81c Michael Hanselmann
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
1182 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1183 45d4c81c Michael Hanselmann
     "Instance creation mode"),
1184 526a662a Michael Hanselmann
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1185 526a662a Michael Hanselmann
     "List of NIC (network interface) definitions, for example"
1186 526a662a Michael Hanselmann
     " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1187 526a662a Michael Hanselmann
     " contain the optional values %s" %
1188 526a662a Michael Hanselmann
     (constants.INIC_IP,
1189 526a662a Michael Hanselmann
      ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1190 45d4c81c Michael Hanselmann
    ("no_install", None, ht.TMaybeBool,
1191 45d4c81c Michael Hanselmann
     "Do not install the OS (will disable automatic start)"),
1192 45d4c81c Michael Hanselmann
    ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1193 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Operating system"),
1194 45d4c81c Michael Hanselmann
    ("pnode", None, ht.TMaybeString, "Primary node"),
1195 45d4c81c Michael Hanselmann
    ("snode", None, ht.TMaybeString, "Secondary node"),
1196 45d4c81c Michael Hanselmann
    ("source_handshake", None, ht.TOr(ht.TList, ht.TNone),
1197 45d4c81c Michael Hanselmann
     "Signed handshake from source (remote import only)"),
1198 45d4c81c Michael Hanselmann
    ("source_instance_name", None, ht.TMaybeString,
1199 45d4c81c Michael Hanselmann
     "Source instance name (remote import only)"),
1200 65e183af Michael Hanselmann
    ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1201 526a662a Michael Hanselmann
     ht.TPositiveInt,
1202 526a662a Michael Hanselmann
     "How long source instance was given to shut down (remote import only)"),
1203 45d4c81c Michael Hanselmann
    ("source_x509_ca", None, ht.TMaybeString,
1204 45d4c81c Michael Hanselmann
     "Source X509 CA in PEM format (remote import only)"),
1205 45d4c81c Michael Hanselmann
    ("src_node", None, ht.TMaybeString, "Source node for import"),
1206 45d4c81c Michael Hanselmann
    ("src_path", None, ht.TMaybeString, "Source directory for import"),
1207 45d4c81c Michael Hanselmann
    ("start", True, ht.TBool, "Whether to start instance after creation"),
1208 720f56c8 Apollon Oikonomopoulos
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1209 3b6d8c9b Iustin Pop
    ]
1210 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1211 a8083063 Iustin Pop
1212 a8083063 Iustin Pop
1213 12e62af5 René Nussbaumer
class OpInstanceMultiAlloc(OpCode):
1214 12e62af5 René Nussbaumer
  """Allocates multiple instances.
1215 12e62af5 René Nussbaumer

1216 12e62af5 René Nussbaumer
  """
1217 12e62af5 René Nussbaumer
  OP_PARAMS = [
1218 12e62af5 René Nussbaumer
    ("iallocator", None, ht.TMaybeString,
1219 12e62af5 René Nussbaumer
     "Iallocator used to allocate all the instances"),
1220 12e62af5 René Nussbaumer
    ("instances", [], ht.TListOf(ht.TInstanceOf(OpInstanceCreate)),
1221 12e62af5 René Nussbaumer
     "List of instance create opcodes describing the instances to allocate"),
1222 12e62af5 René Nussbaumer
    ]
1223 12e62af5 René Nussbaumer
  _JOB_LIST = ht.Comment("List of submitted jobs")(TJobIdList)
1224 12e62af5 René Nussbaumer
  ALLOCATABLE_KEY = "allocatable"
1225 12e62af5 René Nussbaumer
  FAILED_KEY = "allocatable"
1226 12e62af5 René Nussbaumer
  OP_RESULT = ht.TStrictDict(True, True, {
1227 12e62af5 René Nussbaumer
    constants.JOB_IDS_KEY: _JOB_LIST,
1228 12e62af5 René Nussbaumer
    ALLOCATABLE_KEY: ht.TListOf(ht.TNonEmptyString),
1229 12e62af5 René Nussbaumer
    FAILED_KEY: ht.TListOf(ht.TNonEmptyString)
1230 12e62af5 René Nussbaumer
    })
1231 12e62af5 René Nussbaumer
1232 12e62af5 René Nussbaumer
  def __getstate__(self):
1233 12e62af5 René Nussbaumer
    """Generic serializer.
1234 12e62af5 René Nussbaumer

1235 12e62af5 René Nussbaumer
    """
1236 12e62af5 René Nussbaumer
    state = OpCode.__getstate__(self)
1237 12e62af5 René Nussbaumer
    if hasattr(self, "instances"):
1238 12e62af5 René Nussbaumer
      # pylint: disable=E1101
1239 12e62af5 René Nussbaumer
      state["instances"] = [inst.__getstate__() for inst in self.instances]
1240 12e62af5 René Nussbaumer
    return state
1241 12e62af5 René Nussbaumer
1242 12e62af5 René Nussbaumer
  def __setstate__(self, state):
1243 12e62af5 René Nussbaumer
    """Generic unserializer.
1244 12e62af5 René Nussbaumer

1245 12e62af5 René Nussbaumer
    This method just restores from the serialized state the attributes
1246 12e62af5 René Nussbaumer
    of the current instance.
1247 12e62af5 René Nussbaumer

1248 12e62af5 René Nussbaumer
    @param state: the serialized opcode data
1249 12e62af5 René Nussbaumer
    @type state: C{dict}
1250 12e62af5 René Nussbaumer

1251 12e62af5 René Nussbaumer
    """
1252 12e62af5 René Nussbaumer
    if not isinstance(state, dict):
1253 12e62af5 René Nussbaumer
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
1254 12e62af5 René Nussbaumer
                       type(state))
1255 12e62af5 René Nussbaumer
1256 12e62af5 René Nussbaumer
    if "instances" in state:
1257 12e62af5 René Nussbaumer
      insts = [OpCode.LoadOpCode(inst) for inst in state["instances"]]
1258 12e62af5 René Nussbaumer
      state["instances"] = insts
1259 12e62af5 René Nussbaumer
    return OpCode.__setstate__(self, state)
1260 12e62af5 René Nussbaumer
1261 9bc5ac44 René Nussbaumer
  def Validate(self, set_defaults):
1262 9bc5ac44 René Nussbaumer
    """Validates this opcode.
1263 9bc5ac44 René Nussbaumer

1264 9bc5ac44 René Nussbaumer
    We do this recursively.
1265 9bc5ac44 René Nussbaumer

1266 9bc5ac44 René Nussbaumer
    """
1267 9bc5ac44 René Nussbaumer
    OpCode.Validate(self, set_defaults)
1268 9bc5ac44 René Nussbaumer
1269 3779121c René Nussbaumer
    for inst in self.instances: # pylint: disable=E1101
1270 9bc5ac44 René Nussbaumer
      inst.Validate(set_defaults)
1271 9bc5ac44 René Nussbaumer
1272 12e62af5 René Nussbaumer
1273 5073fd8f Iustin Pop
class OpInstanceReinstall(OpCode):
1274 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
1275 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1276 65e183af Michael Hanselmann
  OP_PARAMS = [
1277 65e183af Michael Hanselmann
    _PInstanceName,
1278 45d4c81c Michael Hanselmann
    _PForceVariant,
1279 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Instance operating system"),
1280 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1281 65e183af Michael Hanselmann
    ]
1282 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1283 fe7b0351 Michael Hanselmann
1284 fe7b0351 Michael Hanselmann
1285 3cd2d4b1 Iustin Pop
class OpInstanceRemove(OpCode):
1286 a8083063 Iustin Pop
  """Remove an instance."""
1287 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1288 65e183af Michael Hanselmann
  OP_PARAMS = [
1289 65e183af Michael Hanselmann
    _PInstanceName,
1290 65e183af Michael Hanselmann
    _PShutdownTimeout,
1291 45d4c81c Michael Hanselmann
    ("ignore_failures", False, ht.TBool,
1292 45d4c81c Michael Hanselmann
     "Whether to ignore failures during removal"),
1293 fc1baca9 Michael Hanselmann
    ]
1294 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1295 a8083063 Iustin Pop
1296 a8083063 Iustin Pop
1297 5659e2e2 Iustin Pop
class OpInstanceRename(OpCode):
1298 decd5f45 Iustin Pop
  """Rename an instance."""
1299 65e183af Michael Hanselmann
  OP_PARAMS = [
1300 65e183af Michael Hanselmann
    _PInstanceName,
1301 45d4c81c Michael Hanselmann
    _PNameCheck,
1302 45d4c81c Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1303 45d4c81c Michael Hanselmann
    ("ip_check", False, ht.TBool, _PIpCheckDoc),
1304 4f05fd3b Iustin Pop
    ]
1305 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1306 decd5f45 Iustin Pop
1307 decd5f45 Iustin Pop
1308 c873d91c Iustin Pop
class OpInstanceStartup(OpCode):
1309 fdc267f4 Iustin Pop
  """Startup an instance."""
1310 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1311 65e183af Michael Hanselmann
  OP_PARAMS = [
1312 65e183af Michael Hanselmann
    _PInstanceName,
1313 65e183af Michael Hanselmann
    _PForce,
1314 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1315 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1316 45d4c81c Michael Hanselmann
     "Temporary hypervisor parameters, hypervisor-dependent"),
1317 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1318 9b64e486 Iustin Pop
    _PNoRemember,
1319 323f9095 Stephen Shirley
    _PStartupPaused,
1320 4f05fd3b Iustin Pop
    ]
1321 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1322 a8083063 Iustin Pop
1323 a8083063 Iustin Pop
1324 ee3e37a7 Iustin Pop
class OpInstanceShutdown(OpCode):
1325 fdc267f4 Iustin Pop
  """Shutdown an instance."""
1326 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1327 65e183af Michael Hanselmann
  OP_PARAMS = [
1328 65e183af Michael Hanselmann
    _PInstanceName,
1329 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1330 45d4c81c Michael Hanselmann
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
1331 45d4c81c Michael Hanselmann
     "How long to wait for instance to shut down"),
1332 9b64e486 Iustin Pop
    _PNoRemember,
1333 b44bd844 Michael Hanselmann
    ]
1334 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1335 a8083063 Iustin Pop
1336 a8083063 Iustin Pop
1337 90ab1a95 Iustin Pop
class OpInstanceReboot(OpCode):
1338 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
1339 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1340 65e183af Michael Hanselmann
  OP_PARAMS = [
1341 65e183af Michael Hanselmann
    _PInstanceName,
1342 65e183af Michael Hanselmann
    _PShutdownTimeout,
1343 45d4c81c Michael Hanselmann
    ("ignore_secondaries", False, ht.TBool,
1344 45d4c81c Michael Hanselmann
     "Whether to start the instance even if secondary disks are failing"),
1345 45d4c81c Michael Hanselmann
    ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1346 45d4c81c Michael Hanselmann
     "How to reboot instance"),
1347 4f05fd3b Iustin Pop
    ]
1348 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1349 bf6929a2 Alexander Schreiber
1350 bf6929a2 Alexander Schreiber
1351 668f755d Iustin Pop
class OpInstanceReplaceDisks(OpCode):
1352 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
1353 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1354 65e183af Michael Hanselmann
  OP_PARAMS = [
1355 65e183af Michael Hanselmann
    _PInstanceName,
1356 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1357 d2fe2bfb René Nussbaumer
    _PIgnoreIpolicy,
1358 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1359 45d4c81c Michael Hanselmann
     "Replacement mode"),
1360 45d4c81c Michael Hanselmann
    ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
1361 45d4c81c Michael Hanselmann
     "Disk indexes"),
1362 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1363 45d4c81c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString,
1364 45d4c81c Michael Hanselmann
     "Iallocator for deciding new secondary node"),
1365 4f05fd3b Iustin Pop
    ]
1366 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1367 a8083063 Iustin Pop
1368 a8083063 Iustin Pop
1369 019dbee1 Iustin Pop
class OpInstanceFailover(OpCode):
1370 a8083063 Iustin Pop
  """Failover an instance."""
1371 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1372 65e183af Michael Hanselmann
  OP_PARAMS = [
1373 65e183af Michael Hanselmann
    _PInstanceName,
1374 65e183af Michael Hanselmann
    _PShutdownTimeout,
1375 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1376 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1377 b6aaf437 René Nussbaumer
    _PIgnoreIpolicy,
1378 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1379 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1380 17c3f802 Guido Trotter
    ]
1381 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1382 a8083063 Iustin Pop
1383 a8083063 Iustin Pop
1384 75c866c2 Iustin Pop
class OpInstanceMigrate(OpCode):
1385 53c776b5 Iustin Pop
  """Migrate an instance.
1386 53c776b5 Iustin Pop

1387 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
1388 53c776b5 Iustin Pop
  node.
1389 53c776b5 Iustin Pop

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

1393 53c776b5 Iustin Pop
  """
1394 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
1395 65e183af Michael Hanselmann
  OP_PARAMS = [
1396 65e183af Michael Hanselmann
    _PInstanceName,
1397 65e183af Michael Hanselmann
    _PMigrationMode,
1398 65e183af Michael Hanselmann
    _PMigrationLive,
1399 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1400 8c0b16f6 Guido Trotter
    _PAllowRuntimeChgs,
1401 3ed23330 René Nussbaumer
    _PIgnoreIpolicy,
1402 45d4c81c Michael Hanselmann
    ("cleanup", False, ht.TBool,
1403 45d4c81c Michael Hanselmann
     "Whether a previously failed migration should be cleaned up"),
1404 8eb34306 Apollon Oikonomopoulos
    ("iallocator", None, ht.TMaybeString,
1405 8eb34306 Apollon Oikonomopoulos
     "Iallocator for deciding the target node for shared-storage instances"),
1406 d5cafd31 René Nussbaumer
    ("allow_failover", False, ht.TBool,
1407 d5cafd31 René Nussbaumer
     "Whether we can fallback to failover if migration is not possible"),
1408 65e183af Michael Hanselmann
    ]
1409 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1410 53c776b5 Iustin Pop
1411 53c776b5 Iustin Pop
1412 0091b480 Iustin Pop
class OpInstanceMove(OpCode):
1413 313bcead Iustin Pop
  """Move an instance.
1414 313bcead Iustin Pop

1415 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
1416 313bcead Iustin Pop
  arbitrary node.
1417 313bcead Iustin Pop

1418 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
1419 313bcead Iustin Pop
  @ivar target_node: the destination node
1420 313bcead Iustin Pop

1421 313bcead Iustin Pop
  """
1422 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
1423 65e183af Michael Hanselmann
  OP_PARAMS = [
1424 65e183af Michael Hanselmann
    _PInstanceName,
1425 65e183af Michael Hanselmann
    _PShutdownTimeout,
1426 92cf62e3 René Nussbaumer
    _PIgnoreIpolicy,
1427 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1428 bb851c63 Iustin Pop
    _PIgnoreConsistency,
1429 154b9580 Balazs Lecz
    ]
1430 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1431 313bcead Iustin Pop
1432 313bcead Iustin Pop
1433 cc0dec7b Iustin Pop
class OpInstanceConsole(OpCode):
1434 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
1435 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1436 65e183af Michael Hanselmann
  OP_PARAMS = [
1437 65e183af Michael Hanselmann
    _PInstanceName
1438 65e183af Michael Hanselmann
    ]
1439 c363310d René Nussbaumer
  OP_RESULT = ht.TDict
1440 a8083063 Iustin Pop
1441 a8083063 Iustin Pop
1442 83f5d475 Iustin Pop
class OpInstanceActivateDisks(OpCode):
1443 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
1444 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1445 65e183af Michael Hanselmann
  OP_PARAMS = [
1446 65e183af Michael Hanselmann
    _PInstanceName,
1447 45d4c81c Michael Hanselmann
    ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1448 b69437c5 Iustin Pop
    _PWaitForSyncFalse,
1449 65e183af Michael Hanselmann
    ]
1450 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
1451 c363310d René Nussbaumer
                                 ht.TItems([ht.TNonEmptyString,
1452 c363310d René Nussbaumer
                                            ht.TNonEmptyString,
1453 c363310d René Nussbaumer
                                            ht.TNonEmptyString])))
1454 a8083063 Iustin Pop
1455 a8083063 Iustin Pop
1456 e176281f Iustin Pop
class OpInstanceDeactivateDisks(OpCode):
1457 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
1458 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1459 65e183af Michael Hanselmann
  OP_PARAMS = [
1460 c9c41373 Iustin Pop
    _PInstanceName,
1461 c9c41373 Iustin Pop
    _PForce,
1462 65e183af Michael Hanselmann
    ]
1463 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1464 a8083063 Iustin Pop
1465 a8083063 Iustin Pop
1466 6b273e78 Iustin Pop
class OpInstanceRecreateDisks(OpCode):
1467 a52978c7 Michael Hanselmann
  """Recreate an instance's disks."""
1468 735e1318 Michael Hanselmann
  _TDiskChanges = \
1469 735e1318 Michael Hanselmann
    ht.TAnd(ht.TIsLength(2),
1470 735e1318 Michael Hanselmann
            ht.TItems([ht.Comment("Disk index")(ht.TPositiveInt),
1471 735e1318 Michael Hanselmann
                       ht.Comment("Parameters")(_TDiskParams)]))
1472 735e1318 Michael Hanselmann
1473 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
1474 65e183af Michael Hanselmann
  OP_PARAMS = [
1475 65e183af Michael Hanselmann
    _PInstanceName,
1476 735e1318 Michael Hanselmann
    ("disks", ht.EmptyList,
1477 735e1318 Michael Hanselmann
     ht.TOr(ht.TListOf(ht.TPositiveInt), ht.TListOf(_TDiskChanges)),
1478 735e1318 Michael Hanselmann
     "List of disk indexes (deprecated) or a list of tuples containing a disk"
1479 735e1318 Michael Hanselmann
     " index and a possibly empty dictionary with disk parameter changes"),
1480 93384b8c Guido Trotter
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1481 93384b8c Guido Trotter
     "New instance nodes, if relocation is desired"),
1482 3d091af0 Bernardo Dal Seno
    ("iallocator", None, ht.TMaybeString,
1483 3d091af0 Bernardo Dal Seno
     "Iallocator for deciding new nodes"),
1484 65e183af Michael Hanselmann
    ]
1485 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1486 bd315bfa Iustin Pop
1487 bd315bfa Iustin Pop
1488 f2af0bec Iustin Pop
class OpInstanceQuery(OpCode):
1489 a8083063 Iustin Pop
  """Compute the list of instances."""
1490 65e183af Michael Hanselmann
  OP_PARAMS = [
1491 65e183af Michael Hanselmann
    _POutputFields,
1492 45d4c81c Michael Hanselmann
    _PUseLocking,
1493 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1494 45d4c81c Michael Hanselmann
     "Empty list to query all instances, instance names otherwise"),
1495 65e183af Michael Hanselmann
    ]
1496 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1497 a8083063 Iustin Pop
1498 a8083063 Iustin Pop
1499 dc28c4e4 Iustin Pop
class OpInstanceQueryData(OpCode):
1500 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
1501 65e183af Michael Hanselmann
  OP_PARAMS = [
1502 af7b6689 Michael Hanselmann
    _PUseLocking,
1503 af7b6689 Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1504 af7b6689 Michael Hanselmann
     "Instance names"),
1505 af7b6689 Michael Hanselmann
    ("static", False, ht.TBool,
1506 af7b6689 Michael Hanselmann
     "Whether to only return configuration data without querying"
1507 af7b6689 Michael Hanselmann
     " nodes"),
1508 65e183af Michael Hanselmann
    ]
1509 415feb2e René Nussbaumer
  OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TDict)
1510 a8083063 Iustin Pop
1511 a8083063 Iustin Pop
1512 ddc1de7c Michael Hanselmann
def _TestInstSetParamsModList(fn):
1513 ddc1de7c Michael Hanselmann
  """Generates a check for modification lists.
1514 ddc1de7c Michael Hanselmann

1515 ddc1de7c Michael Hanselmann
  """
1516 e9c3d864 Michael Hanselmann
  # Old format
1517 e9c3d864 Michael Hanselmann
  # TODO: Remove in version 2.8 including support in LUInstanceSetParams
1518 e9c3d864 Michael Hanselmann
  old_mod_item_fn = \
1519 ddc1de7c Michael Hanselmann
    ht.TAnd(ht.TIsLength(2), ht.TItems([
1520 ddc1de7c Michael Hanselmann
      ht.TOr(ht.TElemOf(constants.DDMS_VALUES), ht.TPositiveInt),
1521 ddc1de7c Michael Hanselmann
      fn,
1522 ddc1de7c Michael Hanselmann
      ]))
1523 ddc1de7c Michael Hanselmann
1524 e9c3d864 Michael Hanselmann
  # New format, supporting adding/removing disks/NICs at arbitrary indices
1525 e9c3d864 Michael Hanselmann
  mod_item_fn = \
1526 e9c3d864 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3), ht.TItems([
1527 e9c3d864 Michael Hanselmann
      ht.TElemOf(constants.DDMS_VALUES_WITH_MODIFY),
1528 e9c3d864 Michael Hanselmann
      ht.Comment("Disk index, can be negative, e.g. -1 for last disk")(ht.TInt),
1529 e9c3d864 Michael Hanselmann
      fn,
1530 e9c3d864 Michael Hanselmann
      ]))
1531 e9c3d864 Michael Hanselmann
1532 e9c3d864 Michael Hanselmann
  return ht.TOr(ht.Comment("Recommended")(ht.TListOf(mod_item_fn)),
1533 e9c3d864 Michael Hanselmann
                ht.Comment("Deprecated")(ht.TListOf(old_mod_item_fn)))
1534 ddc1de7c Michael Hanselmann
1535 ddc1de7c Michael Hanselmann
1536 9a3cc7ae Iustin Pop
class OpInstanceSetParams(OpCode):
1537 ddc1de7c Michael Hanselmann
  """Change the parameters of an instance.
1538 ddc1de7c Michael Hanselmann

1539 ddc1de7c Michael Hanselmann
  """
1540 a2aadb34 Michael Hanselmann
  TestNicModifications = _TestInstSetParamsModList(_TestNicDef)
1541 a2aadb34 Michael Hanselmann
  TestDiskModifications = _TestInstSetParamsModList(_TDiskParams)
1542 ddc1de7c Michael Hanselmann
1543 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1544 65e183af Michael Hanselmann
  OP_PARAMS = [
1545 65e183af Michael Hanselmann
    _PInstanceName,
1546 65e183af Michael Hanselmann
    _PForce,
1547 45d4c81c Michael Hanselmann
    _PForceVariant,
1548 1559e1e7 René Nussbaumer
    _PIgnoreIpolicy,
1549 a2aadb34 Michael Hanselmann
    ("nics", ht.EmptyList, TestNicModifications,
1550 0fb66bb1 Iustin Pop
     "List of NIC changes: each item is of the form ``(op, index, settings)``,"
1551 0fb66bb1 Iustin Pop
     " ``op`` is one of ``%s``, ``%s`` or ``%s``, ``index`` can be either -1"
1552 0fb66bb1 Iustin Pop
     " to refer to the last position, or a zero-based index number; a"
1553 0fb66bb1 Iustin Pop
     " deprecated version of this parameter used the form ``(op, settings)``,"
1554 0fb66bb1 Iustin Pop
     " where ``op`` can be ``%s`` to add a new NIC with the specified"
1555 0fb66bb1 Iustin Pop
     " settings, ``%s`` to remove the last NIC or a number to modify the"
1556 0fb66bb1 Iustin Pop
     " settings of the NIC with that index" %
1557 e9c3d864 Michael Hanselmann
     (constants.DDM_ADD, constants.DDM_MODIFY, constants.DDM_REMOVE,
1558 e9c3d864 Michael Hanselmann
      constants.DDM_ADD, constants.DDM_REMOVE)),
1559 a2aadb34 Michael Hanselmann
    ("disks", ht.EmptyList, TestDiskModifications,
1560 0fb66bb1 Iustin Pop
     "List of disk changes; see ``nics``"),
1561 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1562 2c0af7da Guido Trotter
    ("runtime_mem", None, ht.TMaybeStrictPositiveInt, "New runtime memory"),
1563 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1564 45d4c81c Michael Hanselmann
     "Per-instance hypervisor parameters, hypervisor-dependent"),
1565 45fe090b Michael Hanselmann
    ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)),
1566 45d4c81c Michael Hanselmann
     "Disk template for instance"),
1567 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString,
1568 45d4c81c Michael Hanselmann
     "Secondary node (used when changing disk template)"),
1569 45d4c81c Michael Hanselmann
    ("os_name", None, ht.TMaybeString,
1570 0fb66bb1 Iustin Pop
     "Change the instance's OS without reinstalling the instance"),
1571 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1572 93384b8c Guido Trotter
    ("wait_for_sync", True, ht.TBool,
1573 93384b8c Guido Trotter
     "Whether to wait for the disk to synchronize, when changing template"),
1574 3016bc1f Michael Hanselmann
    ("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
1575 973d7867 Iustin Pop
    ]
1576 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1577 a8083063 Iustin Pop
1578 a8083063 Iustin Pop
1579 60472d29 Iustin Pop
class OpInstanceGrowDisk(OpCode):
1580 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
1581 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1582 65e183af Michael Hanselmann
  OP_PARAMS = [
1583 65e183af Michael Hanselmann
    _PInstanceName,
1584 45d4c81c Michael Hanselmann
    _PWaitForSync,
1585 45d4c81c Michael Hanselmann
    ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1586 fa47242b Iustin Pop
    ("amount", ht.NoDefault, ht.TPositiveInt,
1587 45d4c81c Michael Hanselmann
     "Amount of disk space to add (megabytes)"),
1588 e7f99087 Iustin Pop
    ("absolute", False, ht.TBool,
1589 e7f99087 Iustin Pop
     "Whether the amount parameter is an absolute target or a relative one"),
1590 4f05fd3b Iustin Pop
    ]
1591 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1592 8729e0d7 Iustin Pop
1593 8729e0d7 Iustin Pop
1594 1aef3df8 Michael Hanselmann
class OpInstanceChangeGroup(OpCode):
1595 1aef3df8 Michael Hanselmann
  """Moves an instance to another node group."""
1596 1aef3df8 Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1597 1aef3df8 Michael Hanselmann
  OP_PARAMS = [
1598 1aef3df8 Michael Hanselmann
    _PInstanceName,
1599 1aef3df8 Michael Hanselmann
    _PEarlyRelease,
1600 1aef3df8 Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1601 ff8067cf Michael Hanselmann
    ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
1602 1aef3df8 Michael Hanselmann
     "Destination group names or UUIDs (defaults to \"all but current group\""),
1603 1aef3df8 Michael Hanselmann
    ]
1604 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1605 1aef3df8 Michael Hanselmann
1606 1aef3df8 Michael Hanselmann
1607 70a6a926 Adeodato Simo
# Node group opcodes
1608 70a6a926 Adeodato Simo
1609 fabf1731 Iustin Pop
class OpGroupAdd(OpCode):
1610 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
1611 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1612 65e183af Michael Hanselmann
  OP_PARAMS = [
1613 65e183af Michael Hanselmann
    _PGroupName,
1614 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1615 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1616 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1617 e4c03256 René Nussbaumer
    _PHvState,
1618 e4c03256 René Nussbaumer
    _PDiskState,
1619 1b01390b René Nussbaumer
    ("ipolicy", None, ht.TMaybeDict,
1620 1b01390b René Nussbaumer
     "Group-wide :ref:`instance policy <rapi-ipolicy>` specs"),
1621 483be60d Adeodato Simo
    ]
1622 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1623 b1ee5610 Adeodato Simo
1624 b1ee5610 Adeodato Simo
1625 934704ae Iustin Pop
class OpGroupAssignNodes(OpCode):
1626 96276ae7 Adeodato Simo
  """Assign nodes to a node group."""
1627 96276ae7 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1628 96276ae7 Adeodato Simo
  OP_PARAMS = [
1629 96276ae7 Adeodato Simo
    _PGroupName,
1630 96276ae7 Adeodato Simo
    _PForce,
1631 45d4c81c Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1632 45d4c81c Michael Hanselmann
     "List of nodes to assign"),
1633 96276ae7 Adeodato Simo
    ]
1634 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1635 96276ae7 Adeodato Simo
1636 96276ae7 Adeodato Simo
1637 d4d654bd Iustin Pop
class OpGroupQuery(OpCode):
1638 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
1639 65e183af Michael Hanselmann
  OP_PARAMS = [
1640 65e183af Michael Hanselmann
    _POutputFields,
1641 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1642 45d4c81c Michael Hanselmann
     "Empty list to query all groups, group names otherwise"),
1643 65e183af Michael Hanselmann
    ]
1644 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1645 70a6a926 Adeodato Simo
1646 70a6a926 Adeodato Simo
1647 7cbf74f0 Iustin Pop
class OpGroupSetParams(OpCode):
1648 4da7909a Adeodato Simo
  """Change the parameters of a node group."""
1649 4da7909a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1650 65e183af Michael Hanselmann
  OP_PARAMS = [
1651 65e183af Michael Hanselmann
    _PGroupName,
1652 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1653 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1654 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1655 a8282327 René Nussbaumer
    _PHvState,
1656 a8282327 René Nussbaumer
    _PDiskState,
1657 fb644e77 Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1658 4da7909a Adeodato Simo
    ]
1659 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1660 4da7909a Adeodato Simo
1661 4da7909a Adeodato Simo
1662 4d1baa51 Iustin Pop
class OpGroupRemove(OpCode):
1663 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
1664 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1665 65e183af Michael Hanselmann
  OP_PARAMS = [
1666 65e183af Michael Hanselmann
    _PGroupName,
1667 65e183af Michael Hanselmann
    ]
1668 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1669 94bd652a Adeodato Simo
1670 94bd652a Adeodato Simo
1671 a8173e82 Iustin Pop
class OpGroupRename(OpCode):
1672 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
1673 65e183af Michael Hanselmann
  OP_PARAMS = [
1674 12da663a Michael Hanselmann
    _PGroupName,
1675 12da663a Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1676 65e183af Michael Hanselmann
    ]
1677 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1678 4fe5cf90 Adeodato Simo
1679 4fe5cf90 Adeodato Simo
1680 08f8c82c Michael Hanselmann
class OpGroupEvacuate(OpCode):
1681 08f8c82c Michael Hanselmann
  """Evacuate a node group in the cluster."""
1682 08f8c82c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
1683 08f8c82c Michael Hanselmann
  OP_PARAMS = [
1684 08f8c82c Michael Hanselmann
    _PGroupName,
1685 08f8c82c Michael Hanselmann
    _PEarlyRelease,
1686 08f8c82c Michael Hanselmann
    ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"),
1687 ff8067cf Michael Hanselmann
    ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString),
1688 08f8c82c Michael Hanselmann
     "Destination group names or UUIDs"),
1689 08f8c82c Michael Hanselmann
    ]
1690 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1691 08f8c82c Michael Hanselmann
1692 08f8c82c Michael Hanselmann
1693 a8083063 Iustin Pop
# OS opcodes
1694 da2d02e7 Iustin Pop
class OpOsDiagnose(OpCode):
1695 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
1696 65e183af Michael Hanselmann
  OP_PARAMS = [
1697 65e183af Michael Hanselmann
    _POutputFields,
1698 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1699 45d4c81c Michael Hanselmann
     "Which operating systems to diagnose"),
1700 65e183af Michael Hanselmann
    ]
1701 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1702 a8083063 Iustin Pop
1703 7c0d6283 Michael Hanselmann
1704 a8083063 Iustin Pop
# Exports opcodes
1705 7ca2d4d8 Iustin Pop
class OpBackupQuery(OpCode):
1706 a8083063 Iustin Pop
  """Compute the list of exported images."""
1707 65e183af Michael Hanselmann
  OP_PARAMS = [
1708 45d4c81c Michael Hanselmann
    _PUseLocking,
1709 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1710 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1711 65e183af Michael Hanselmann
    ]
1712 202fb4e0 Michael Hanselmann
  OP_RESULT = ht.TDictOf(ht.TNonEmptyString,
1713 202fb4e0 Michael Hanselmann
                         ht.TOr(ht.Comment("False on error")(ht.TBool),
1714 202fb4e0 Michael Hanselmann
                                ht.TListOf(ht.TNonEmptyString)))
1715 a8083063 Iustin Pop
1716 7c0d6283 Michael Hanselmann
1717 71910715 Iustin Pop
class OpBackupPrepare(OpCode):
1718 1410fa8d Michael Hanselmann
  """Prepares an instance export.
1719 1410fa8d Michael Hanselmann

1720 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
1721 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1722 1410fa8d Michael Hanselmann

1723 1410fa8d Michael Hanselmann
  """
1724 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1725 65e183af Michael Hanselmann
  OP_PARAMS = [
1726 65e183af Michael Hanselmann
    _PInstanceName,
1727 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1728 45d4c81c Michael Hanselmann
     "Export mode"),
1729 1410fa8d Michael Hanselmann
    ]
1730 c363310d René Nussbaumer
  OP_RESULT = ht.TOr(ht.TNone, ht.TDict)
1731 1410fa8d Michael Hanselmann
1732 1410fa8d Michael Hanselmann
1733 4ff922a2 Iustin Pop
class OpBackupExport(OpCode):
1734 4a96f1d1 Michael Hanselmann
  """Export an instance.
1735 4a96f1d1 Michael Hanselmann

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

1742 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1743 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
1744 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
1745 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1746 4a96f1d1 Michael Hanselmann
                             only)
1747 4a96f1d1 Michael Hanselmann

1748 4a96f1d1 Michael Hanselmann
  """
1749 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1750 65e183af Michael Hanselmann
  OP_PARAMS = [
1751 65e183af Michael Hanselmann
    _PInstanceName,
1752 65e183af Michael Hanselmann
    _PShutdownTimeout,
1753 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
1754 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
1755 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1756 45d4c81c Michael Hanselmann
     "Destination information, depends on export mode"),
1757 45d4c81c Michael Hanselmann
    ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1758 45d4c81c Michael Hanselmann
    ("remove_instance", False, ht.TBool,
1759 45d4c81c Michael Hanselmann
     "Whether to remove instance after export"),
1760 45d4c81c Michael Hanselmann
    ("ignore_remove_failures", False, ht.TBool,
1761 45d4c81c Michael Hanselmann
     "Whether to ignore failures while removing instances"),
1762 45d4c81c Michael Hanselmann
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1763 45d4c81c Michael Hanselmann
     "Export mode"),
1764 45d4c81c Michael Hanselmann
    ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone),
1765 45d4c81c Michael Hanselmann
     "Name of X509 key (remote export only)"),
1766 45d4c81c Michael Hanselmann
    ("destination_x509_ca", None, ht.TMaybeString,
1767 45d4c81c Michael Hanselmann
     "Destination X509 CA (remote export only)"),
1768 17c3f802 Guido Trotter
    ]
1769 202fb4e0 Michael Hanselmann
  OP_RESULT = \
1770 202fb4e0 Michael Hanselmann
    ht.TAnd(ht.TIsLength(2), ht.TItems([
1771 202fb4e0 Michael Hanselmann
      ht.Comment("Finalizing status")(ht.TBool),
1772 202fb4e0 Michael Hanselmann
      ht.Comment("Status for every exported disk")(ht.TListOf(ht.TBool)),
1773 202fb4e0 Michael Hanselmann
      ]))
1774 5c947f38 Iustin Pop
1775 0a7bed64 Michael Hanselmann
1776 ca5890ad Iustin Pop
class OpBackupRemove(OpCode):
1777 9ac99fda Guido Trotter
  """Remove an instance's export."""
1778 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1779 65e183af Michael Hanselmann
  OP_PARAMS = [
1780 65e183af Michael Hanselmann
    _PInstanceName,
1781 65e183af Michael Hanselmann
    ]
1782 202fb4e0 Michael Hanselmann
  OP_RESULT = ht.TNone
1783 5c947f38 Iustin Pop
1784 0a7bed64 Michael Hanselmann
1785 5c947f38 Iustin Pop
# Tags opcodes
1786 c6afb1ca Iustin Pop
class OpTagsGet(OpCode):
1787 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
1788 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
1789 65e183af Michael Hanselmann
  OP_PARAMS = [
1790 65e183af Michael Hanselmann
    _PTagKind,
1791 cfdf561d Michael Hanselmann
    # Not using _PUseLocking as the default is different for historical reasons
1792 cfdf561d Michael Hanselmann
    ("use_locking", True, ht.TBool, "Whether to use synchronization"),
1793 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1794 971b3a98 Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString,
1795 971b3a98 Michael Hanselmann
     "Name of object to retrieve tags from"),
1796 65e183af Michael Hanselmann
    ]
1797 48796673 Michael Hanselmann
  OP_RESULT = ht.TListOf(ht.TNonEmptyString)
1798 5c947f38 Iustin Pop
1799 5c947f38 Iustin Pop
1800 715462e7 Iustin Pop
class OpTagsSearch(OpCode):
1801 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
1802 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
1803 65e183af Michael Hanselmann
  OP_PARAMS = [
1804 971b3a98 Michael Hanselmann
    ("pattern", ht.NoDefault, ht.TNonEmptyString,
1805 971b3a98 Michael Hanselmann
     "Search pattern (regular expression)"),
1806 65e183af Michael Hanselmann
    ]
1807 48796673 Michael Hanselmann
  OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(2), ht.TItems([
1808 48796673 Michael Hanselmann
    ht.TNonEmptyString,
1809 48796673 Michael Hanselmann
    ht.TNonEmptyString,
1810 48796673 Michael Hanselmann
    ])))
1811 73415719 Iustin Pop
1812 73415719 Iustin Pop
1813 d1602edc Iustin Pop
class OpTagsSet(OpCode):
1814 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
1815 65e183af Michael Hanselmann
  OP_PARAMS = [
1816 65e183af Michael Hanselmann
    _PTagKind,
1817 65e183af Michael Hanselmann
    _PTags,
1818 bcd35e09 Dato Simó
    # Name is only meaningful for groups, nodes and instances
1819 971b3a98 Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString,
1820 971b3a98 Michael Hanselmann
     "Name of object where tag(s) should be added"),
1821 65e183af Michael Hanselmann
    ]
1822 48796673 Michael Hanselmann
  OP_RESULT = ht.TNone
1823 5c947f38 Iustin Pop
1824 5c947f38 Iustin Pop
1825 3f0ab95f Iustin Pop
class OpTagsDel(OpCode):
1826 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
1827 65e183af Michael Hanselmann
  OP_PARAMS = [
1828 65e183af Michael Hanselmann
    _PTagKind,
1829 65e183af Michael Hanselmann
    _PTags,
1830 bcd35e09 Dato Simó
    # Name is only meaningful for groups, nodes and instances
1831 971b3a98 Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString,
1832 971b3a98 Michael Hanselmann
     "Name of object where tag(s) should be deleted"),
1833 65e183af Michael Hanselmann
    ]
1834 48796673 Michael Hanselmann
  OP_RESULT = ht.TNone
1835 06009e27 Iustin Pop
1836 e687ec01 Michael Hanselmann
1837 06009e27 Iustin Pop
# Test opcodes
1838 06009e27 Iustin Pop
class OpTestDelay(OpCode):
1839 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
1840 06009e27 Iustin Pop

1841 06009e27 Iustin Pop
  This is used just for debugging and testing.
1842 06009e27 Iustin Pop

1843 06009e27 Iustin Pop
  Parameters:
1844 06009e27 Iustin Pop
    - duration: the time to sleep
1845 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
1846 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
1847 06009e27 Iustin Pop

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

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

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

1858 06009e27 Iustin Pop
  """
1859 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
1860 65e183af Michael Hanselmann
  OP_PARAMS = [
1861 b795a775 Michael Hanselmann
    ("duration", ht.NoDefault, ht.TNumber, None),
1862 197b323b Michael Hanselmann
    ("on_master", True, ht.TBool, None),
1863 197b323b Michael Hanselmann
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1864 197b323b Michael Hanselmann
    ("repeat", 0, ht.TPositiveInt, None),
1865 65e183af Michael Hanselmann
    ]
1866 d61df03e Iustin Pop
1867 d61df03e Iustin Pop
1868 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
1869 d61df03e Iustin Pop
  """Allocator framework testing.
1870 d61df03e Iustin Pop

1871 d61df03e Iustin Pop
  This opcode has two modes:
1872 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
1873 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
1874 d61df03e Iustin Pop
      'in')
1875 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
1876 d61df03e Iustin Pop
      return the allocator output (direction 'out')
1877 d61df03e Iustin Pop

1878 d61df03e Iustin Pop
  """
1879 60dd1473 Iustin Pop
  OP_DSC_FIELD = "allocator"
1880 65e183af Michael Hanselmann
  OP_PARAMS = [
1881 65e183af Michael Hanselmann
    ("direction", ht.NoDefault,
1882 197b323b Michael Hanselmann
     ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
1883 197b323b Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
1884 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
1885 ff8067cf Michael Hanselmann
    ("nics", ht.NoDefault,
1886 ff8067cf Michael Hanselmann
     ht.TMaybeListOf(ht.TDictOf(ht.TElemOf([constants.INIC_MAC,
1887 ff8067cf Michael Hanselmann
                                            constants.INIC_IP,
1888 ff8067cf Michael Hanselmann
                                            "bridge"]),
1889 ff8067cf Michael Hanselmann
                                ht.TOr(ht.TNone, ht.TNonEmptyString))),
1890 ff8067cf Michael Hanselmann
     None),
1891 197b323b Michael Hanselmann
    ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None),
1892 197b323b Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, None),
1893 197b323b Michael Hanselmann
    ("allocator", None, ht.TMaybeString, None),
1894 197b323b Michael Hanselmann
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
1895 dd47a0f0 Iustin Pop
    ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1896 197b323b Michael Hanselmann
    ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None),
1897 197b323b Michael Hanselmann
    ("os", None, ht.TMaybeString, None),
1898 197b323b Michael Hanselmann
    ("disk_template", None, ht.TMaybeString, None),
1899 ff8067cf Michael Hanselmann
    ("instances", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
1900 60152bbe Michael Hanselmann
    ("evac_mode", None,
1901 60152bbe Michael Hanselmann
     ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
1902 ff8067cf Michael Hanselmann
    ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
1903 09123222 René Nussbaumer
    ("spindle_use", 1, ht.TPositiveInt, None),
1904 3c049cd3 René Nussbaumer
    ("count", 1, ht.TPositiveInt, None),
1905 d61df03e Iustin Pop
    ]
1906 363acb1e Iustin Pop
1907 76aef8fc Michael Hanselmann
1908 b469eb4d Iustin Pop
class OpTestJqueue(OpCode):
1909 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
1910 e58f87a9 Michael Hanselmann

1911 e58f87a9 Michael Hanselmann
  """
1912 65e183af Michael Hanselmann
  OP_PARAMS = [
1913 197b323b Michael Hanselmann
    ("notify_waitlock", False, ht.TBool, None),
1914 197b323b Michael Hanselmann
    ("notify_exec", False, ht.TBool, None),
1915 197b323b Michael Hanselmann
    ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
1916 197b323b Michael Hanselmann
    ("fail", False, ht.TBool, None),
1917 e58f87a9 Michael Hanselmann
    ]
1918 e58f87a9 Michael Hanselmann
1919 e58f87a9 Michael Hanselmann
1920 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
1921 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
1922 be760ba8 Michael Hanselmann

1923 be760ba8 Michael Hanselmann
  """
1924 65e183af Michael Hanselmann
  OP_PARAMS = [
1925 197b323b Michael Hanselmann
    ("result", ht.NoDefault, ht.NoType, None),
1926 197b323b Michael Hanselmann
    ("messages", ht.NoDefault, ht.NoType, None),
1927 197b323b Michael Hanselmann
    ("fail", ht.NoDefault, ht.NoType, None),
1928 6a373640 Michael Hanselmann
    ("submit_jobs", None, ht.NoType, None),
1929 be760ba8 Michael Hanselmann
    ]
1930 687c10d9 Iustin Pop
  WITH_LU = False
1931 be760ba8 Michael Hanselmann
1932 be760ba8 Michael Hanselmann
1933 dbc96028 Michael Hanselmann
def _GetOpList():
1934 dbc96028 Michael Hanselmann
  """Returns list of all defined opcodes.
1935 dbc96028 Michael Hanselmann

1936 dbc96028 Michael Hanselmann
  Does not eliminate duplicates by C{OP_ID}.
1937 dbc96028 Michael Hanselmann

1938 dbc96028 Michael Hanselmann
  """
1939 dbc96028 Michael Hanselmann
  return [v for v in globals().values()
1940 dbc96028 Michael Hanselmann
          if (isinstance(v, type) and issubclass(v, OpCode) and
1941 687c10d9 Iustin Pop
              hasattr(v, "OP_ID") and v is not OpCode)]
1942 dbc96028 Michael Hanselmann
1943 dbc96028 Michael Hanselmann
1944 dbc96028 Michael Hanselmann
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())