Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 30b12688

History | View | Annotate | Download (68.7 kB)

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

261 ff0d18e6 Iustin Pop
  @type name: string
262 ff0d18e6 Iustin Pop
  @param name: the class name, as OpXxxYyy
263 d634b4e0 Michele Tartara
  @rtype: array of strings
264 d634b4e0 Michele Tartara
  @return: the components of the name
265 ff0d18e6 Iustin Pop

266 ff0d18e6 Iustin Pop
  """
267 d634b4e0 Michele Tartara
  assert name.startswith("Op")
268 ff0d18e6 Iustin Pop
  # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
269 ff0d18e6 Iustin Pop
  # consume any input, and hence we would just have all the elements
270 ff0d18e6 Iustin Pop
  # in the list, one by one; but it seems that split doesn't work on
271 ff0d18e6 Iustin Pop
  # non-consuming input, hence we have to process the input string a
272 ff0d18e6 Iustin Pop
  # bit
273 ff0d18e6 Iustin Pop
  name = _OPID_RE.sub(r"\1,\2", name)
274 ff0d18e6 Iustin Pop
  elems = name.split(",")
275 d634b4e0 Michele Tartara
  return elems
276 d634b4e0 Michele Tartara
277 d634b4e0 Michele Tartara
278 d634b4e0 Michele Tartara
def _NameToId(name):
279 d634b4e0 Michele Tartara
  """Convert an opcode class name to an OP_ID.
280 d634b4e0 Michele Tartara

281 d634b4e0 Michele Tartara
  @type name: string
282 d634b4e0 Michele Tartara
  @param name: the class name, as OpXxxYyy
283 d634b4e0 Michele Tartara
  @rtype: string
284 d634b4e0 Michele Tartara
  @return: the name in the OP_XXXX_YYYY format
285 d634b4e0 Michele Tartara

286 d634b4e0 Michele Tartara
  """
287 d634b4e0 Michele Tartara
  if not name.startswith("Op"):
288 d634b4e0 Michele Tartara
    return None
289 d634b4e0 Michele Tartara
  return "_".join(n.upper() for n in _NameComponents(name))
290 d634b4e0 Michele Tartara
291 d634b4e0 Michele Tartara
292 d634b4e0 Michele Tartara
def NameToReasonSrc(name):
293 d634b4e0 Michele Tartara
  """Convert an opcode class name to a source string for the reason trail
294 d634b4e0 Michele Tartara

295 d634b4e0 Michele Tartara
  @type name: string
296 d634b4e0 Michele Tartara
  @param name: the class name, as OpXxxYyy
297 d634b4e0 Michele Tartara
  @rtype: string
298 d634b4e0 Michele Tartara
  @return: the name in the OP_XXXX_YYYY format
299 d634b4e0 Michele Tartara

300 d634b4e0 Michele Tartara
  """
301 d634b4e0 Michele Tartara
  if not name.startswith("Op"):
302 d634b4e0 Michele Tartara
    return None
303 d634b4e0 Michele Tartara
  return "%s:%s" % (constants.OPCODE_REASON_SRC_OPCODE,
304 d634b4e0 Michele Tartara
                    "_".join(n.lower() for n in _NameComponents(name)))
305 ff0d18e6 Iustin Pop
306 65e183af Michael Hanselmann
307 415feb2e René Nussbaumer
def _GenerateObjectTypeCheck(obj, fields_types):
308 415feb2e René Nussbaumer
  """Helper to generate type checks for objects.
309 415feb2e René Nussbaumer

310 415feb2e René Nussbaumer
  @param obj: The object to generate type checks
311 415feb2e René Nussbaumer
  @param fields_types: The fields and their types as a dict
312 415feb2e René Nussbaumer
  @return: A ht type check function
313 415feb2e René Nussbaumer

314 415feb2e René Nussbaumer
  """
315 415feb2e René Nussbaumer
  assert set(obj.GetAllSlots()) == set(fields_types.keys()), \
316 415feb2e René Nussbaumer
    "%s != %s" % (set(obj.GetAllSlots()), set(fields_types.keys()))
317 415feb2e René Nussbaumer
  return ht.TStrictDict(True, True, fields_types)
318 415feb2e René Nussbaumer
319 415feb2e René Nussbaumer
320 b02c6bdf Michael Hanselmann
_TQueryFieldDef = \
321 b02c6bdf Michael Hanselmann
  _GenerateObjectTypeCheck(objects.QueryFieldDefinition, {
322 b02c6bdf Michael Hanselmann
    "name": ht.TNonEmptyString,
323 b02c6bdf Michael Hanselmann
    "title": ht.TNonEmptyString,
324 b02c6bdf Michael Hanselmann
    "kind": ht.TElemOf(constants.QFT_ALL),
325 b02c6bdf Michael Hanselmann
    "doc": ht.TNonEmptyString,
326 b02c6bdf Michael Hanselmann
    })
327 415feb2e René Nussbaumer
328 415feb2e René Nussbaumer
329 45fe090b Michael Hanselmann
def _BuildDiskTemplateCheck(accept_none):
330 45fe090b Michael Hanselmann
  """Builds check for disk template.
331 45fe090b Michael Hanselmann

332 45fe090b Michael Hanselmann
  @type accept_none: bool
333 45fe090b Michael Hanselmann
  @param accept_none: whether to accept None as a correct value
334 45fe090b Michael Hanselmann
  @rtype: callable
335 45fe090b Michael Hanselmann

336 45fe090b Michael Hanselmann
  """
337 45fe090b Michael Hanselmann
  template_check = ht.TElemOf(constants.DISK_TEMPLATES)
338 45fe090b Michael Hanselmann
339 45fe090b Michael Hanselmann
  if accept_none:
340 fd9f58fd Iustin Pop
    template_check = ht.TMaybe(template_check)
341 45fe090b Michael Hanselmann
342 9d276e93 Helga Velroyen
  return template_check
343 8c9ee749 Michael Hanselmann
344 8c9ee749 Michael Hanselmann
345 65e183af Michael Hanselmann
def _CheckStorageType(storage_type):
346 65e183af Michael Hanselmann
  """Ensure a given storage type is valid.
347 65e183af Michael Hanselmann

348 65e183af Michael Hanselmann
  """
349 d8e55568 Helga Velroyen
  if storage_type not in constants.STORAGE_TYPES:
350 65e183af Michael Hanselmann
    raise errors.OpPrereqError("Unknown storage type: %s" % storage_type,
351 65e183af Michael Hanselmann
                               errors.ECODE_INVAL)
352 65e183af Michael Hanselmann
  return True
353 65e183af Michael Hanselmann
354 65e183af Michael Hanselmann
355 65e183af Michael Hanselmann
#: Storage type parameter
356 45d4c81c Michael Hanselmann
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
357 45d4c81c Michael Hanselmann
                 "Storage type")
358 65e183af Michael Hanselmann
359 3c286190 Dimitris Aragiorgis
360 16091a6e Michael Hanselmann
@ht.WithDesc("IPv4 network")
361 eaa4c57c Dimitris Aragiorgis
def _CheckCIDRNetNotation(value):
362 16091a6e Michael Hanselmann
  """Ensure a given CIDR notation type is valid.
363 eaa4c57c Dimitris Aragiorgis

364 eaa4c57c Dimitris Aragiorgis
  """
365 eaa4c57c Dimitris Aragiorgis
  try:
366 eaa4c57c Dimitris Aragiorgis
    ipaddr.IPv4Network(value)
367 eaa4c57c Dimitris Aragiorgis
  except ipaddr.AddressValueError:
368 eaa4c57c Dimitris Aragiorgis
    return False
369 eaa4c57c Dimitris Aragiorgis
  return True
370 eaa4c57c Dimitris Aragiorgis
371 3c286190 Dimitris Aragiorgis
372 16091a6e Michael Hanselmann
@ht.WithDesc("IPv4 address")
373 eaa4c57c Dimitris Aragiorgis
def _CheckCIDRAddrNotation(value):
374 16091a6e Michael Hanselmann
  """Ensure a given CIDR notation type is valid.
375 eaa4c57c Dimitris Aragiorgis

376 eaa4c57c Dimitris Aragiorgis
  """
377 eaa4c57c Dimitris Aragiorgis
  try:
378 eaa4c57c Dimitris Aragiorgis
    ipaddr.IPv4Address(value)
379 eaa4c57c Dimitris Aragiorgis
  except ipaddr.AddressValueError:
380 eaa4c57c Dimitris Aragiorgis
    return False
381 eaa4c57c Dimitris Aragiorgis
  return True
382 eaa4c57c Dimitris Aragiorgis
383 3c286190 Dimitris Aragiorgis
384 16091a6e Michael Hanselmann
@ht.WithDesc("IPv6 address")
385 eaa4c57c Dimitris Aragiorgis
def _CheckCIDR6AddrNotation(value):
386 16091a6e Michael Hanselmann
  """Ensure a given CIDR notation type is valid.
387 eaa4c57c Dimitris Aragiorgis

388 eaa4c57c Dimitris Aragiorgis
  """
389 eaa4c57c Dimitris Aragiorgis
  try:
390 eaa4c57c Dimitris Aragiorgis
    ipaddr.IPv6Address(value)
391 eaa4c57c Dimitris Aragiorgis
  except ipaddr.AddressValueError:
392 eaa4c57c Dimitris Aragiorgis
    return False
393 eaa4c57c Dimitris Aragiorgis
  return True
394 eaa4c57c Dimitris Aragiorgis
395 3c286190 Dimitris Aragiorgis
396 16091a6e Michael Hanselmann
@ht.WithDesc("IPv6 network")
397 eaa4c57c Dimitris Aragiorgis
def _CheckCIDR6NetNotation(value):
398 16091a6e Michael Hanselmann
  """Ensure a given CIDR notation type is valid.
399 eaa4c57c Dimitris Aragiorgis

400 eaa4c57c Dimitris Aragiorgis
  """
401 eaa4c57c Dimitris Aragiorgis
  try:
402 eaa4c57c Dimitris Aragiorgis
    ipaddr.IPv6Network(value)
403 eaa4c57c Dimitris Aragiorgis
  except ipaddr.AddressValueError:
404 eaa4c57c Dimitris Aragiorgis
    return False
405 eaa4c57c Dimitris Aragiorgis
  return True
406 65e183af Michael Hanselmann
407 3c286190 Dimitris Aragiorgis
408 e1494c96 Iustin Pop
_TIpAddress4 = ht.TAnd(ht.TString, _CheckCIDRAddrNotation)
409 e1494c96 Iustin Pop
_TIpAddress6 = ht.TAnd(ht.TString, _CheckCIDR6AddrNotation)
410 e1494c96 Iustin Pop
_TIpNetwork4 = ht.TAnd(ht.TString, _CheckCIDRNetNotation)
411 e1494c96 Iustin Pop
_TIpNetwork6 = ht.TAnd(ht.TString, _CheckCIDR6NetNotation)
412 e1494c96 Iustin Pop
_TMaybeAddr4List = ht.TMaybe(ht.TListOf(_TIpAddress4))
413 32e3d8b1 Michael Hanselmann
414 32e3d8b1 Michael Hanselmann
415 473d87a3 Iustin Pop
class _AutoOpParamSlots(outils.AutoSlots):
416 65e183af Michael Hanselmann
  """Meta class for opcode definitions.
417 65e183af Michael Hanselmann

418 65e183af Michael Hanselmann
  """
419 65e183af Michael Hanselmann
  def __new__(mcs, name, bases, attrs):
420 65e183af Michael Hanselmann
    """Called when a class should be created.
421 65e183af Michael Hanselmann

422 65e183af Michael Hanselmann
    @param mcs: The meta class
423 65e183af Michael Hanselmann
    @param name: Name of created class
424 65e183af Michael Hanselmann
    @param bases: Base classes
425 65e183af Michael Hanselmann
    @type attrs: dict
426 65e183af Michael Hanselmann
    @param attrs: Class attributes
427 65e183af Michael Hanselmann

428 65e183af Michael Hanselmann
    """
429 e89a9021 Iustin Pop
    assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name
430 ff0d18e6 Iustin Pop
431 32683096 René Nussbaumer
    slots = mcs._GetSlots(attrs)
432 32683096 René Nussbaumer
    assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \
433 32683096 René Nussbaumer
      "Class '%s' uses unknown field in OP_DSC_FIELD" % name
434 8bc17ebb Iustin Pop
    assert ("OP_DSC_FORMATTER" not in attrs or
435 8bc17ebb Iustin Pop
            callable(attrs["OP_DSC_FORMATTER"])), \
436 8bc17ebb Iustin Pop
      ("Class '%s' uses non-callable in OP_DSC_FORMATTER (%s)" %
437 8bc17ebb Iustin Pop
       (name, type(attrs["OP_DSC_FORMATTER"])))
438 32683096 René Nussbaumer
439 e89a9021 Iustin Pop
    attrs["OP_ID"] = _NameToId(name)
440 65e183af Michael Hanselmann
441 473d87a3 Iustin Pop
    return outils.AutoSlots.__new__(mcs, name, bases, attrs)
442 32683096 René Nussbaumer
443 32683096 René Nussbaumer
  @classmethod
444 32683096 René Nussbaumer
  def _GetSlots(mcs, attrs):
445 32683096 René Nussbaumer
    """Build the slots out of OP_PARAMS.
446 32683096 René Nussbaumer

447 32683096 René Nussbaumer
    """
448 65e183af Michael Hanselmann
    # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
449 65e183af Michael Hanselmann
    params = attrs.setdefault("OP_PARAMS", [])
450 65e183af Michael Hanselmann
451 65e183af Michael Hanselmann
    # Use parameter names as slots
452 32683096 René Nussbaumer
    return [pname for (pname, _, _, _) in params]
453 65e183af Michael Hanselmann
454 df458e0b Iustin Pop
455 473d87a3 Iustin Pop
class BaseOpCode(outils.ValidatedSlots):
456 df458e0b Iustin Pop
  """A simple serializable object.
457 df458e0b Iustin Pop

458 0e46916d Iustin Pop
  This object serves as a parent class for OpCode without any custom
459 0e46916d Iustin Pop
  field handling.
460 0e46916d Iustin Pop

461 df458e0b Iustin Pop
  """
462 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
463 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
464 65e183af Michael Hanselmann
  __metaclass__ = _AutoOpParamSlots
465 65e183af Michael Hanselmann
466 df458e0b Iustin Pop
  def __getstate__(self):
467 a7399f66 Iustin Pop
    """Generic serializer.
468 a7399f66 Iustin Pop

469 a7399f66 Iustin Pop
    This method just returns the contents of the instance as a
470 a7399f66 Iustin Pop
    dictionary.
471 a7399f66 Iustin Pop

472 a7399f66 Iustin Pop
    @rtype:  C{dict}
473 a7399f66 Iustin Pop
    @return: the instance attributes and their values
474 a7399f66 Iustin Pop

475 a7399f66 Iustin Pop
    """
476 df458e0b Iustin Pop
    state = {}
477 32683096 René Nussbaumer
    for name in self.GetAllSlots():
478 df458e0b Iustin Pop
      if hasattr(self, name):
479 df458e0b Iustin Pop
        state[name] = getattr(self, name)
480 df458e0b Iustin Pop
    return state
481 df458e0b Iustin Pop
482 df458e0b Iustin Pop
  def __setstate__(self, state):
483 a7399f66 Iustin Pop
    """Generic unserializer.
484 a7399f66 Iustin Pop

485 a7399f66 Iustin Pop
    This method just restores from the serialized state the attributes
486 a7399f66 Iustin Pop
    of the current instance.
487 a7399f66 Iustin Pop

488 a7399f66 Iustin Pop
    @param state: the serialized opcode data
489 a7399f66 Iustin Pop
    @type state:  C{dict}
490 a7399f66 Iustin Pop

491 a7399f66 Iustin Pop
    """
492 df458e0b Iustin Pop
    if not isinstance(state, dict):
493 df458e0b Iustin Pop
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
494 df458e0b Iustin Pop
                       type(state))
495 df458e0b Iustin Pop
496 32683096 René Nussbaumer
    for name in self.GetAllSlots():
497 44db3a6f Iustin Pop
      if name not in state and hasattr(self, name):
498 df458e0b Iustin Pop
        delattr(self, name)
499 df458e0b Iustin Pop
500 df458e0b Iustin Pop
    for name in state:
501 df458e0b Iustin Pop
      setattr(self, name, state[name])
502 df458e0b Iustin Pop
503 adf385c7 Iustin Pop
  @classmethod
504 65e183af Michael Hanselmann
  def GetAllParams(cls):
505 65e183af Michael Hanselmann
    """Compute list of all parameters for an opcode.
506 65e183af Michael Hanselmann

507 65e183af Michael Hanselmann
    """
508 65e183af Michael Hanselmann
    slots = []
509 65e183af Michael Hanselmann
    for parent in cls.__mro__:
510 65e183af Michael Hanselmann
      slots.extend(getattr(parent, "OP_PARAMS", []))
511 65e183af Michael Hanselmann
    return slots
512 65e183af Michael Hanselmann
513 32683096 René Nussbaumer
  def Validate(self, set_defaults): # pylint: disable=W0221
514 1cbef6d8 Michael Hanselmann
    """Validate opcode parameters, optionally setting default values.
515 1cbef6d8 Michael Hanselmann

516 1cbef6d8 Michael Hanselmann
    @type set_defaults: bool
517 1cbef6d8 Michael Hanselmann
    @param set_defaults: Whether to set default values
518 1cbef6d8 Michael Hanselmann
    @raise errors.OpPrereqError: When a parameter value doesn't match
519 1cbef6d8 Michael Hanselmann
                                 requirements
520 1cbef6d8 Michael Hanselmann

521 1cbef6d8 Michael Hanselmann
    """
522 197b323b Michael Hanselmann
    for (attr_name, default, test, _) in self.GetAllParams():
523 1cbef6d8 Michael Hanselmann
      assert test == ht.NoType or callable(test)
524 1cbef6d8 Michael Hanselmann
525 1cbef6d8 Michael Hanselmann
      if not hasattr(self, attr_name):
526 1cbef6d8 Michael Hanselmann
        if default == ht.NoDefault:
527 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Required parameter '%s.%s' missing" %
528 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
529 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
530 1cbef6d8 Michael Hanselmann
        elif set_defaults:
531 1cbef6d8 Michael Hanselmann
          if callable(default):
532 1cbef6d8 Michael Hanselmann
            dval = default()
533 1cbef6d8 Michael Hanselmann
          else:
534 1cbef6d8 Michael Hanselmann
            dval = default
535 1cbef6d8 Michael Hanselmann
          setattr(self, attr_name, dval)
536 1cbef6d8 Michael Hanselmann
537 1cbef6d8 Michael Hanselmann
      if test == ht.NoType:
538 1cbef6d8 Michael Hanselmann
        # no tests here
539 1cbef6d8 Michael Hanselmann
        continue
540 1cbef6d8 Michael Hanselmann
541 1cbef6d8 Michael Hanselmann
      if set_defaults or hasattr(self, attr_name):
542 1cbef6d8 Michael Hanselmann
        attr_val = getattr(self, attr_name)
543 1cbef6d8 Michael Hanselmann
        if not test(attr_val):
544 e1ebbfcf Iustin Pop
          logging.error("OpCode %s, parameter %s, has invalid type %s/value"
545 e1ebbfcf Iustin Pop
                        " '%s' expecting type %s",
546 68b2e985 René Nussbaumer
                        self.OP_ID, attr_name, type(attr_val), attr_val, test)
547 1cbef6d8 Michael Hanselmann
          raise errors.OpPrereqError("Parameter '%s.%s' fails validation" %
548 1cbef6d8 Michael Hanselmann
                                     (self.OP_ID, attr_name),
549 1cbef6d8 Michael Hanselmann
                                     errors.ECODE_INVAL)
550 1cbef6d8 Michael Hanselmann
551 df458e0b Iustin Pop
552 b247c6fc Michael Hanselmann
def _BuildJobDepCheck(relative):
553 b247c6fc Michael Hanselmann
  """Builds check for job dependencies (L{DEPEND_ATTR}).
554 b247c6fc Michael Hanselmann

555 b247c6fc Michael Hanselmann
  @type relative: bool
556 b247c6fc Michael Hanselmann
  @param relative: Whether to accept relative job IDs (negative)
557 b247c6fc Michael Hanselmann
  @rtype: callable
558 b247c6fc Michael Hanselmann

559 b247c6fc Michael Hanselmann
  """
560 b247c6fc Michael Hanselmann
  if relative:
561 b247c6fc Michael Hanselmann
    job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId)
562 b247c6fc Michael Hanselmann
  else:
563 b247c6fc Michael Hanselmann
    job_id = ht.TJobId
564 b247c6fc Michael Hanselmann
565 b247c6fc Michael Hanselmann
  job_dep = \
566 dd076c21 Iustin Pop
    ht.TAnd(ht.TOr(ht.TList, ht.TTuple),
567 dd076c21 Iustin Pop
            ht.TIsLength(2),
568 b247c6fc Michael Hanselmann
            ht.TItems([job_id,
569 b247c6fc Michael Hanselmann
                       ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))]))
570 b247c6fc Michael Hanselmann
571 ff8067cf Michael Hanselmann
  return ht.TMaybeListOf(job_dep)
572 b247c6fc Michael Hanselmann
573 b247c6fc Michael Hanselmann
574 b247c6fc Michael Hanselmann
TNoRelativeJobDependencies = _BuildJobDepCheck(False)
575 b247c6fc Michael Hanselmann
576 1ce03fb1 Michael Hanselmann
#: List of submission status and job ID as returned by C{SubmitManyJobs}
577 1456df62 Michael Hanselmann
_TJobIdListItem = \
578 1456df62 Michael Hanselmann
  ht.TAnd(ht.TIsLength(2),
579 1456df62 Michael Hanselmann
          ht.TItems([ht.Comment("success")(ht.TBool),
580 1456df62 Michael Hanselmann
                     ht.Comment("Job ID if successful, error message"
581 1456df62 Michael Hanselmann
                                " otherwise")(ht.TOr(ht.TString,
582 1456df62 Michael Hanselmann
                                                     ht.TJobId))]))
583 1456df62 Michael Hanselmann
TJobIdList = ht.TListOf(_TJobIdListItem)
584 1ce03fb1 Michael Hanselmann
585 f7686867 Michael Hanselmann
#: Result containing only list of submitted jobs
586 f7686867 Michael Hanselmann
TJobIdListOnly = ht.TStrictDict(True, True, {
587 1456df62 Michael Hanselmann
  constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
588 f7686867 Michael Hanselmann
  })
589 f7686867 Michael Hanselmann
590 b247c6fc Michael Hanselmann
591 0e46916d Iustin Pop
class OpCode(BaseOpCode):
592 a7399f66 Iustin Pop
  """Abstract OpCode.
593 a7399f66 Iustin Pop

594 a7399f66 Iustin Pop
  This is the root of the actual OpCode hierarchy. All clases derived
595 a7399f66 Iustin Pop
  from this class should override OP_ID.
596 a7399f66 Iustin Pop

597 a7399f66 Iustin Pop
  @cvar OP_ID: The ID of this opcode. This should be unique amongst all
598 20777413 Iustin Pop
               children of this class.
599 bde8f481 Adeodato Simo
  @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
600 bde8f481 Adeodato Simo
                      string returned by Summary(); see the docstring of that
601 bde8f481 Adeodato Simo
                      method for details).
602 8bc17ebb Iustin Pop
  @cvar OP_DSC_FORMATTER: A callable that should format the OP_DSC_FIELD; if
603 8bc17ebb Iustin Pop
                          not present, then the field will be simply converted
604 8bc17ebb Iustin Pop
                          to string
605 65e183af Michael Hanselmann
  @cvar OP_PARAMS: List of opcode attributes, the default values they should
606 65e183af Michael Hanselmann
                   get if not already defined, and types they must match.
607 1ce03fb1 Michael Hanselmann
  @cvar OP_RESULT: Callable to verify opcode result
608 687c10d9 Iustin Pop
  @cvar WITH_LU: Boolean that specifies whether this should be included in
609 687c10d9 Iustin Pop
      mcpu's dispatch table
610 20777413 Iustin Pop
  @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
611 20777413 Iustin Pop
                 the check steps
612 8f5c488d Michael Hanselmann
  @ivar priority: Opcode priority for queue
613 a7399f66 Iustin Pop

614 a7399f66 Iustin Pop
  """
615 b459a848 Andrea Spadaccini
  # pylint: disable=E1101
616 e89a9021 Iustin Pop
  # as OP_ID is dynamically defined
617 687c10d9 Iustin Pop
  WITH_LU = True
618 65e183af Michael Hanselmann
  OP_PARAMS = [
619 45d4c81c Michael Hanselmann
    ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"),
620 fd9f58fd Iustin Pop
    ("debug_level", None, ht.TMaybe(ht.TNonNegativeInt), "Debug level"),
621 65e183af Michael Hanselmann
    ("priority", constants.OP_PRIO_DEFAULT,
622 45d4c81c Michael Hanselmann
     ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
623 b247c6fc Michael Hanselmann
    (DEPEND_ATTR, None, _BuildJobDepCheck(True),
624 b247c6fc Michael Hanselmann
     "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
625 822a50c4 Michael Hanselmann
     " job IDs can be used; see :doc:`design document <design-chained-jobs>`"
626 822a50c4 Michael Hanselmann
     " for details"),
627 018ae30b Michael Hanselmann
    (COMMENT_ATTR, None, ht.TMaybeString,
628 018ae30b Michael Hanselmann
     "Comment describing the purpose of the opcode"),
629 33b52bdc Thomas Thrainer
    (constants.OPCODE_REASON, ht.EmptyList, ht.TMaybeList,
630 dbae804a Michele Tartara
     "The reason trail, describing why the OpCode is executed"),
631 65e183af Michael Hanselmann
    ]
632 1ce03fb1 Michael Hanselmann
  OP_RESULT = None
633 df458e0b Iustin Pop
634 df458e0b Iustin Pop
  def __getstate__(self):
635 df458e0b Iustin Pop
    """Specialized getstate for opcodes.
636 df458e0b Iustin Pop

637 a7399f66 Iustin Pop
    This method adds to the state dictionary the OP_ID of the class,
638 a7399f66 Iustin Pop
    so that on unload we can identify the correct class for
639 a7399f66 Iustin Pop
    instantiating the opcode.
640 a7399f66 Iustin Pop

641 a7399f66 Iustin Pop
    @rtype:   C{dict}
642 a7399f66 Iustin Pop
    @return:  the state as a dictionary
643 a7399f66 Iustin Pop

644 df458e0b Iustin Pop
    """
645 0e46916d Iustin Pop
    data = BaseOpCode.__getstate__(self)
646 df458e0b Iustin Pop
    data["OP_ID"] = self.OP_ID
647 df458e0b Iustin Pop
    return data
648 df458e0b Iustin Pop
649 df458e0b Iustin Pop
  @classmethod
650 00abdc96 Iustin Pop
  def LoadOpCode(cls, data):
651 df458e0b Iustin Pop
    """Generic load opcode method.
652 df458e0b Iustin Pop

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

657 a7399f66 Iustin Pop
    @type data:  C{dict}
658 a7399f66 Iustin Pop
    @param data: the serialized opcode
659 a7399f66 Iustin Pop

660 df458e0b Iustin Pop
    """
661 df458e0b Iustin Pop
    if not isinstance(data, dict):
662 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode (%s)" % type(data))
663 df458e0b Iustin Pop
    if "OP_ID" not in data:
664 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpcode, missing OP_ID")
665 df458e0b Iustin Pop
    op_id = data["OP_ID"]
666 df458e0b Iustin Pop
    op_class = None
667 363acb1e Iustin Pop
    if op_id in OP_MAPPING:
668 363acb1e Iustin Pop
      op_class = OP_MAPPING[op_id]
669 363acb1e Iustin Pop
    else:
670 df458e0b Iustin Pop
      raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" %
671 df458e0b Iustin Pop
                       op_id)
672 df458e0b Iustin Pop
    op = op_class()
673 df458e0b Iustin Pop
    new_data = data.copy()
674 df458e0b Iustin Pop
    del new_data["OP_ID"]
675 df458e0b Iustin Pop
    op.__setstate__(new_data)
676 df458e0b Iustin Pop
    return op
677 df458e0b Iustin Pop
678 60dd1473 Iustin Pop
  def Summary(self):
679 60dd1473 Iustin Pop
    """Generates a summary description of this opcode.
680 60dd1473 Iustin Pop

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

687 60dd1473 Iustin Pop
    """
688 ff0d18e6 Iustin Pop
    assert self.OP_ID is not None and len(self.OP_ID) > 3
689 60dd1473 Iustin Pop
    # all OP_ID start with OP_, we remove that
690 60dd1473 Iustin Pop
    txt = self.OP_ID[3:]
691 60dd1473 Iustin Pop
    field_name = getattr(self, "OP_DSC_FIELD", None)
692 60dd1473 Iustin Pop
    if field_name:
693 60dd1473 Iustin Pop
      field_value = getattr(self, field_name, None)
694 8bc17ebb Iustin Pop
      field_formatter = getattr(self, "OP_DSC_FORMATTER", None)
695 8bc17ebb Iustin Pop
      if callable(field_formatter):
696 8bc17ebb Iustin Pop
        field_value = field_formatter(field_value)
697 8bc17ebb Iustin Pop
      elif isinstance(field_value, (list, tuple)):
698 bc8bbda1 Iustin Pop
        field_value = ",".join(str(i) for i in field_value)
699 60dd1473 Iustin Pop
      txt = "%s(%s)" % (txt, field_value)
700 60dd1473 Iustin Pop
    return txt
701 60dd1473 Iustin Pop
702 3ce9a5e7 Michael Hanselmann
  def TinySummary(self):
703 3ce9a5e7 Michael Hanselmann
    """Generates a compact summary description of the opcode.
704 3ce9a5e7 Michael Hanselmann

705 3ce9a5e7 Michael Hanselmann
    """
706 3ce9a5e7 Michael Hanselmann
    assert self.OP_ID.startswith("OP_")
707 3ce9a5e7 Michael Hanselmann
708 3ce9a5e7 Michael Hanselmann
    text = self.OP_ID[3:]
709 3ce9a5e7 Michael Hanselmann
710 3ce9a5e7 Michael Hanselmann
    for (prefix, supplement) in _SUMMARY_PREFIX.items():
711 3ce9a5e7 Michael Hanselmann
      if text.startswith(prefix):
712 3ce9a5e7 Michael Hanselmann
        return supplement + text[len(prefix):]
713 3ce9a5e7 Michael Hanselmann
714 3ce9a5e7 Michael Hanselmann
    return text
715 3ce9a5e7 Michael Hanselmann
716 a8083063 Iustin Pop
717 afee0879 Iustin Pop
# cluster opcodes
718 afee0879 Iustin Pop
719 bc84ffa7 Iustin Pop
class OpClusterPostInit(OpCode):
720 b5f5fae9 Luca Bigliardi
  """Post cluster initialization.
721 b5f5fae9 Luca Bigliardi

722 b5f5fae9 Luca Bigliardi
  This opcode does not touch the cluster at all. Its purpose is to run hooks
723 b5f5fae9 Luca Bigliardi
  after the cluster has been initialized.
724 b5f5fae9 Luca Bigliardi

725 b5f5fae9 Luca Bigliardi
  """
726 c363310d René Nussbaumer
  OP_RESULT = ht.TBool
727 b5f5fae9 Luca Bigliardi
728 b5f5fae9 Luca Bigliardi
729 c6d43e9e Iustin Pop
class OpClusterDestroy(OpCode):
730 a7399f66 Iustin Pop
  """Destroy the cluster.
731 a7399f66 Iustin Pop

732 a7399f66 Iustin Pop
  This opcode has no other parameters. All the state is irreversibly
733 a7399f66 Iustin Pop
  lost after the execution of this opcode.
734 a7399f66 Iustin Pop

735 a7399f66 Iustin Pop
  """
736 c363310d René Nussbaumer
  OP_RESULT = ht.TNonEmptyString
737 a8083063 Iustin Pop
738 a8083063 Iustin Pop
739 a2f7ab92 Iustin Pop
class OpClusterQuery(OpCode):
740 fdc267f4 Iustin Pop
  """Query cluster information."""
741 415feb2e René Nussbaumer
  OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TAny)
742 a8083063 Iustin Pop
743 a8083063 Iustin Pop
744 fcad7225 Michael Hanselmann
class OpClusterVerify(OpCode):
745 fcad7225 Michael Hanselmann
  """Submits all jobs necessary to verify the cluster.
746 fcad7225 Michael Hanselmann

747 fcad7225 Michael Hanselmann
  """
748 fcad7225 Michael Hanselmann
  OP_PARAMS = [
749 fcad7225 Michael Hanselmann
    _PDebugSimulateErrors,
750 fcad7225 Michael Hanselmann
    _PErrorCodes,
751 fcad7225 Michael Hanselmann
    _PSkipChecks,
752 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
753 fcad7225 Michael Hanselmann
    _PVerbose,
754 3c286190 Dimitris Aragiorgis
    ("group_name", None, ht.TMaybeString, "Group to verify"),
755 fcad7225 Michael Hanselmann
    ]
756 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
757 fcad7225 Michael Hanselmann
758 fcad7225 Michael Hanselmann
759 bf93ae69 Adeodato Simo
class OpClusterVerifyConfig(OpCode):
760 bf93ae69 Adeodato Simo
  """Verify the cluster config.
761 bf93ae69 Adeodato Simo

762 bf93ae69 Adeodato Simo
  """
763 bf93ae69 Adeodato Simo
  OP_PARAMS = [
764 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
765 57106b74 Michael Hanselmann
    _PErrorCodes,
766 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
767 57106b74 Michael Hanselmann
    _PVerbose,
768 bf93ae69 Adeodato Simo
    ]
769 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
770 bf93ae69 Adeodato Simo
771 bf93ae69 Adeodato Simo
772 bf93ae69 Adeodato Simo
class OpClusterVerifyGroup(OpCode):
773 bf93ae69 Adeodato Simo
  """Run verify on a node group from the cluster.
774 a7399f66 Iustin Pop

775 a7399f66 Iustin Pop
  @type skip_checks: C{list}
776 a7399f66 Iustin Pop
  @ivar skip_checks: steps to be skipped from the verify process; this
777 a7399f66 Iustin Pop
                     needs to be a subset of
778 a7399f66 Iustin Pop
                     L{constants.VERIFY_OPTIONAL_CHECKS}; currently
779 a7399f66 Iustin Pop
                     only L{constants.VERIFY_NPLUSONE_MEM} can be passed
780 a7399f66 Iustin Pop

781 a7399f66 Iustin Pop
  """
782 bf93ae69 Adeodato Simo
  OP_DSC_FIELD = "group_name"
783 65e183af Michael Hanselmann
  OP_PARAMS = [
784 57106b74 Michael Hanselmann
    _PGroupName,
785 57106b74 Michael Hanselmann
    _PDebugSimulateErrors,
786 57106b74 Michael Hanselmann
    _PErrorCodes,
787 57106b74 Michael Hanselmann
    _PSkipChecks,
788 93f2399e Andrea Spadaccini
    _PIgnoreErrors,
789 57106b74 Michael Hanselmann
    _PVerbose,
790 65e183af Michael Hanselmann
    ]
791 f7686867 Michael Hanselmann
  OP_RESULT = ht.TBool
792 a8083063 Iustin Pop
793 a8083063 Iustin Pop
794 bd8210a7 Iustin Pop
class OpClusterVerifyDisks(OpCode):
795 150e978f Iustin Pop
  """Verify the cluster disks.
796 150e978f Iustin Pop

797 ae1a845c Michael Hanselmann
  """
798 f7686867 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
799 ae1a845c Michael Hanselmann
800 ae1a845c Michael Hanselmann
801 ae1a845c Michael Hanselmann
class OpGroupVerifyDisks(OpCode):
802 ae1a845c Michael Hanselmann
  """Verifies the status of all disks in a node group.
803 150e978f Iustin Pop

804 ae1a845c Michael Hanselmann
  Result: a tuple of three elements:
805 ae1a845c Michael Hanselmann
    - dict of node names with issues (values: error msg)
806 150e978f Iustin Pop
    - list of instances with degraded disks (that should be activated)
807 b63ed789 Iustin Pop
    - dict of instances with missing logical volumes (values: (node, vol)
808 b63ed789 Iustin Pop
      pairs with details about the missing volumes)
809 150e978f Iustin Pop

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

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

818 150e978f Iustin Pop
  """
819 ae1a845c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
820 ae1a845c Michael Hanselmann
  OP_PARAMS = [
821 ae1a845c Michael Hanselmann
    _PGroupName,
822 ae1a845c Michael Hanselmann
    ]
823 1ce03fb1 Michael Hanselmann
  OP_RESULT = \
824 1ce03fb1 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3),
825 1ce03fb1 Michael Hanselmann
            ht.TItems([ht.TDictOf(ht.TString, ht.TString),
826 1ce03fb1 Michael Hanselmann
                       ht.TListOf(ht.TString),
827 6973587f Michael Hanselmann
                       ht.TDictOf(ht.TString,
828 6973587f Michael Hanselmann
                                  ht.TListOf(ht.TListOf(ht.TString)))]))
829 150e978f Iustin Pop
830 150e978f Iustin Pop
831 5d01aca3 Iustin Pop
class OpClusterRepairDiskSizes(OpCode):
832 60975797 Iustin Pop
  """Verify the disk sizes of the instances and fixes configuration
833 60975797 Iustin Pop
  mimatches.
834 60975797 Iustin Pop

835 60975797 Iustin Pop
  Parameters: optional instances list, in case we want to restrict the
836 60975797 Iustin Pop
  checks to only a subset of the instances.
837 60975797 Iustin Pop

838 40d93e3b Bernardo Dal Seno
  Result: a list of tuples, (instance, disk, parameter, new-size) for changed
839 60975797 Iustin Pop
  configurations.
840 60975797 Iustin Pop

841 60975797 Iustin Pop
  In normal operation, the list should be empty.
842 60975797 Iustin Pop

843 60975797 Iustin Pop
  @type instances: list
844 60975797 Iustin Pop
  @ivar instances: the list of instances to check, or empty for all instances
845 60975797 Iustin Pop

846 60975797 Iustin Pop
  """
847 65e183af Michael Hanselmann
  OP_PARAMS = [
848 197b323b Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
849 65e183af Michael Hanselmann
    ]
850 40d93e3b Bernardo Dal Seno
  OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(4),
851 c363310d René Nussbaumer
                                 ht.TItems([ht.TNonEmptyString,
852 2c9fa1ff Iustin Pop
                                            ht.TNonNegativeInt,
853 40d93e3b Bernardo Dal Seno
                                            ht.TNonEmptyString,
854 2c9fa1ff Iustin Pop
                                            ht.TNonNegativeInt])))
855 60975797 Iustin Pop
856 60975797 Iustin Pop
857 2f093ea0 Iustin Pop
class OpClusterConfigQuery(OpCode):
858 ae5849b5 Michael Hanselmann
  """Query cluster configuration values."""
859 65e183af Michael Hanselmann
  OP_PARAMS = [
860 3c286190 Dimitris Aragiorgis
    _POutputFields,
861 65e183af Michael Hanselmann
    ]
862 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAny)
863 a8083063 Iustin Pop
864 a8083063 Iustin Pop
865 e126df25 Iustin Pop
class OpClusterRename(OpCode):
866 a7399f66 Iustin Pop
  """Rename the cluster.
867 a7399f66 Iustin Pop

868 a7399f66 Iustin Pop
  @type name: C{str}
869 a7399f66 Iustin Pop
  @ivar name: The new name of the cluster. The name and/or the master IP
870 a7399f66 Iustin Pop
              address will be changed to match the new name and its IP
871 a7399f66 Iustin Pop
              address.
872 a7399f66 Iustin Pop

873 a7399f66 Iustin Pop
  """
874 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
875 65e183af Michael Hanselmann
  OP_PARAMS = [
876 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
877 65e183af Michael Hanselmann
    ]
878 c363310d René Nussbaumer
  OP_RESULT = ht.TNonEmptyString
879 07bd8a51 Iustin Pop
880 07bd8a51 Iustin Pop
881 a6682fdc Iustin Pop
class OpClusterSetParams(OpCode):
882 a7399f66 Iustin Pop
  """Change the parameters of the cluster.
883 a7399f66 Iustin Pop

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

887 a7399f66 Iustin Pop
  """
888 65e183af Michael Hanselmann
  OP_PARAMS = [
889 e5c92cfb Klaus Aehlig
    _PForce,
890 2da9f556 René Nussbaumer
    _PHvState,
891 2da9f556 René Nussbaumer
    _PDiskState,
892 fd9f58fd Iustin Pop
    ("vg_name", None, ht.TMaybe(ht.TString), "Volume group name"),
893 65e183af Michael Hanselmann
    ("enabled_hypervisors", None,
894 fd9f58fd Iustin Pop
     ht.TMaybe(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)),
895 fd9f58fd Iustin Pop
                       ht.TTrue)),
896 45d4c81c Michael Hanselmann
     "List of enabled hypervisors"),
897 a138ead7 Michael Hanselmann
    ("hvparams", None,
898 fd9f58fd Iustin Pop
     ht.TMaybe(ht.TDictOf(ht.TNonEmptyString, ht.TDict)),
899 45d4c81c Michael Hanselmann
     "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
900 fd9f58fd Iustin Pop
    ("beparams", None, ht.TMaybeDict,
901 45d4c81c Michael Hanselmann
     "Cluster-wide backend parameter defaults"),
902 fd9f58fd Iustin Pop
    ("os_hvp", None, ht.TMaybe(ht.TDictOf(ht.TNonEmptyString, ht.TDict)),
903 45d4c81c Michael Hanselmann
     "Cluster-wide per-OS hypervisor parameter defaults"),
904 a138ead7 Michael Hanselmann
    ("osparams", None,
905 fd9f58fd Iustin Pop
     ht.TMaybe(ht.TDictOf(ht.TNonEmptyString, ht.TDict)),
906 45d4c81c Michael Hanselmann
     "Cluster-wide OS parameter defaults"),
907 bc5d0215 Andrea Spadaccini
    _PDiskParams,
908 fd9f58fd Iustin Pop
    ("candidate_pool_size", None, ht.TMaybe(ht.TPositiveInt),
909 45d4c81c Michael Hanselmann
     "Master candidate pool size"),
910 45d4c81c Michael Hanselmann
    ("uid_pool", None, ht.NoType,
911 45d4c81c Michael Hanselmann
     "Set UID pool, must be list of lists describing UID ranges (two items,"
912 45d4c81c Michael Hanselmann
     " start and end inclusive)"),
913 45d4c81c Michael Hanselmann
    ("add_uids", None, ht.NoType,
914 45d4c81c Michael Hanselmann
     "Extend UID pool, must be list of lists describing UID ranges (two"
915 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be added"),
916 45d4c81c Michael Hanselmann
    ("remove_uids", None, ht.NoType,
917 45d4c81c Michael Hanselmann
     "Shrink UID pool, must be list of lists describing UID ranges (two"
918 45d4c81c Michael Hanselmann
     " items, start and end inclusive) to be removed"),
919 45d4c81c Michael Hanselmann
    ("maintain_node_health", None, ht.TMaybeBool,
920 45d4c81c Michael Hanselmann
     "Whether to automatically maintain node health"),
921 45d4c81c Michael Hanselmann
    ("prealloc_wipe_disks", None, ht.TMaybeBool,
922 45d4c81c Michael Hanselmann
     "Whether to wipe disks before allocating them to instances"),
923 45d4c81c Michael Hanselmann
    ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"),
924 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"),
925 1b01390b René Nussbaumer
    ("ipolicy", None, ht.TMaybeDict,
926 1b01390b René Nussbaumer
     "Cluster-wide :ref:`instance policy <rapi-ipolicy>` specs"),
927 fd9f58fd Iustin Pop
    ("drbd_helper", None, ht.TMaybe(ht.TString), "DRBD helper program"),
928 fd9f58fd Iustin Pop
    ("default_iallocator", None, ht.TMaybe(ht.TString),
929 45d4c81c Michael Hanselmann
     "Default iallocator for cluster"),
930 fd9f58fd Iustin Pop
    ("master_netdev", None, ht.TMaybe(ht.TString),
931 45d4c81c Michael Hanselmann
     "Master network device"),
932 fd9f58fd Iustin Pop
    ("master_netmask", None, ht.TMaybe(ht.TNonNegativeInt),
933 5a8648eb Andrea Spadaccini
     "Netmask of the master IP"),
934 ff8067cf Michael Hanselmann
    ("reserved_lvs", None, ht.TMaybeListOf(ht.TNonEmptyString),
935 45d4c81c Michael Hanselmann
     "List of reserved LVs"),
936 45d4c81c Michael Hanselmann
    ("hidden_os", None, _TestClusterOsList,
937 0fb66bb1 Iustin Pop
     "Modify list of hidden operating systems: each modification must have"
938 0fb66bb1 Iustin Pop
     " two items, the operation and the OS name; the operation can be"
939 0fb66bb1 Iustin Pop
     " ``%s`` or ``%s``" % (constants.DDM_ADD, constants.DDM_REMOVE)),
940 45d4c81c Michael Hanselmann
    ("blacklisted_os", None, _TestClusterOsList,
941 0fb66bb1 Iustin Pop
     "Modify list of blacklisted operating systems: each modification must"
942 0fb66bb1 Iustin Pop
     " have two items, the operation and the OS name; the operation can be"
943 0fb66bb1 Iustin Pop
     " ``%s`` or ``%s``" % (constants.DDM_ADD, constants.DDM_REMOVE)),
944 bf689b7a Andrea Spadaccini
    ("use_external_mip_script", None, ht.TMaybeBool,
945 bf689b7a Andrea Spadaccini
     "Whether to use an external master IP address setup script"),
946 66af5ec5 Helga Velroyen
    ("enabled_disk_templates", None,
947 66af5ec5 Helga Velroyen
     ht.TMaybe(ht.TAnd(ht.TListOf(ht.TElemOf(constants.DISK_TEMPLATES)),
948 66af5ec5 Helga Velroyen
                       ht.TTrue)),
949 66af5ec5 Helga Velroyen
     "List of enabled disk templates"),
950 75f2ff7d Michele Tartara
    ("modify_etc_hosts", None, ht.TMaybeBool,
951 75f2ff7d Michele Tartara
     "Whether the cluster can modify and keep in sync the /etc/hosts files"),
952 b24b52d9 Helga Velroyen
    ("file_storage_dir", None, ht.TMaybe(ht.TString),
953 3039e2dc Helga Velroyen
     "Default directory for storing file-backed disks"),
954 b24b52d9 Helga Velroyen
    ("shared_file_storage_dir", None, ht.TMaybe(ht.TString),
955 4e6cfd11 Helga Velroyen
     "Default directory for storing shared-file-backed disks"),
956 4b7735f9 Iustin Pop
    ]
957 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
958 12515db7 Manuel Franceschini
959 12515db7 Manuel Franceschini
960 d1240007 Iustin Pop
class OpClusterRedistConf(OpCode):
961 afee0879 Iustin Pop
  """Force a full push of the cluster configuration.
962 afee0879 Iustin Pop

963 afee0879 Iustin Pop
  """
964 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
965 afee0879 Iustin Pop
966 83f72637 Michael Hanselmann
967 fb926117 Andrea Spadaccini
class OpClusterActivateMasterIp(OpCode):
968 fb926117 Andrea Spadaccini
  """Activate the master IP on the master node.
969 fb926117 Andrea Spadaccini

970 fb926117 Andrea Spadaccini
  """
971 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
972 fb926117 Andrea Spadaccini
973 fb926117 Andrea Spadaccini
974 fb926117 Andrea Spadaccini
class OpClusterDeactivateMasterIp(OpCode):
975 fb926117 Andrea Spadaccini
  """Deactivate the master IP on the master node.
976 fb926117 Andrea Spadaccini

977 fb926117 Andrea Spadaccini
  """
978 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
979 fb926117 Andrea Spadaccini
980 fb926117 Andrea Spadaccini
981 83f72637 Michael Hanselmann
class OpQuery(OpCode):
982 83f72637 Michael Hanselmann
  """Query for resources/items.
983 83f72637 Michael Hanselmann

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

988 83f72637 Michael Hanselmann
  """
989 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
990 65e183af Michael Hanselmann
  OP_PARAMS = [
991 8e7078e0 Michael Hanselmann
    _PQueryWhat,
992 ee13764f Michael Hanselmann
    _PUseLocking,
993 45d4c81c Michael Hanselmann
    ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
994 45d4c81c Michael Hanselmann
     "Requested fields"),
995 fd9f58fd Iustin Pop
    ("qfilter", None, ht.TMaybe(ht.TList),
996 45d4c81c Michael Hanselmann
     "Query filter"),
997 83f72637 Michael Hanselmann
    ]
998 415feb2e René Nussbaumer
  OP_RESULT = \
999 b02c6bdf Michael Hanselmann
    _GenerateObjectTypeCheck(objects.QueryResponse, {
1000 b02c6bdf Michael Hanselmann
      "fields": ht.TListOf(_TQueryFieldDef),
1001 b02c6bdf Michael Hanselmann
      "data": _TQueryResult,
1002 b02c6bdf Michael Hanselmann
      })
1003 83f72637 Michael Hanselmann
1004 83f72637 Michael Hanselmann
1005 83f72637 Michael Hanselmann
class OpQueryFields(OpCode):
1006 83f72637 Michael Hanselmann
  """Query for available resource/item fields.
1007 83f72637 Michael Hanselmann

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

1011 83f72637 Michael Hanselmann
  """
1012 e50d8412 Michael Hanselmann
  OP_DSC_FIELD = "what"
1013 65e183af Michael Hanselmann
  OP_PARAMS = [
1014 8e7078e0 Michael Hanselmann
    _PQueryWhat,
1015 ff8067cf Michael Hanselmann
    ("fields", None, ht.TMaybeListOf(ht.TNonEmptyString),
1016 8e7078e0 Michael Hanselmann
     "Requested fields; if not given, all are returned"),
1017 83f72637 Michael Hanselmann
    ]
1018 415feb2e René Nussbaumer
  OP_RESULT = \
1019 b02c6bdf Michael Hanselmann
    _GenerateObjectTypeCheck(objects.QueryFieldsResponse, {
1020 b02c6bdf Michael Hanselmann
      "fields": ht.TListOf(_TQueryFieldDef),
1021 b02c6bdf Michael Hanselmann
      })
1022 83f72637 Michael Hanselmann
1023 83f72637 Michael Hanselmann
1024 792af3ad René Nussbaumer
class OpOobCommand(OpCode):
1025 eb64da59 René Nussbaumer
  """Interact with OOB."""
1026 65e183af Michael Hanselmann
  OP_PARAMS = [
1027 c4ec0755 René Nussbaumer
    ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1028 1c3231aa Thomas Thrainer
     "List of node names to run the OOB command against"),
1029 1c3231aa Thomas Thrainer
    ("node_uuids", None, ht.TMaybeListOf(ht.TNonEmptyString),
1030 1c3231aa Thomas Thrainer
     "List of node UUIDs to run the OOB command against"),
1031 70296981 Iustin Pop
    ("command", ht.NoDefault, ht.TElemOf(constants.OOB_COMMANDS),
1032 c4ec0755 René Nussbaumer
     "OOB command to be run"),
1033 c4ec0755 René Nussbaumer
    ("timeout", constants.OOB_TIMEOUT, ht.TInt,
1034 c4ec0755 René Nussbaumer
     "Timeout before the OOB helper will be terminated"),
1035 c4ec0755 René Nussbaumer
    ("ignore_status", False, ht.TBool,
1036 c4ec0755 René Nussbaumer
     "Ignores the node offline status for power off"),
1037 2c9fa1ff Iustin Pop
    ("power_delay", constants.OOB_POWER_DELAY, ht.TNonNegativeFloat,
1038 beff3779 René Nussbaumer
     "Time in seconds to wait between powering on nodes"),
1039 eb64da59 René Nussbaumer
    ]
1040 c363310d René Nussbaumer
  # Fixme: Make it more specific with all the special cases in LUOobCommand
1041 415feb2e René Nussbaumer
  OP_RESULT = _TQueryResult
1042 eb64da59 René Nussbaumer
1043 eb64da59 René Nussbaumer
1044 e4d745a7 Michael Hanselmann
class OpRestrictedCommand(OpCode):
1045 e4d745a7 Michael Hanselmann
  """Runs a restricted command on node(s).
1046 e4d745a7 Michael Hanselmann

1047 e4d745a7 Michael Hanselmann
  """
1048 e4d745a7 Michael Hanselmann
  OP_PARAMS = [
1049 e4d745a7 Michael Hanselmann
    _PUseLocking,
1050 e4d745a7 Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1051 e4d745a7 Michael Hanselmann
     "Nodes on which the command should be run (at least one)"),
1052 1c3231aa Thomas Thrainer
    ("node_uuids", None, ht.TMaybeListOf(ht.TNonEmptyString),
1053 1c3231aa Thomas Thrainer
     "Node UUIDs on which the command should be run (at least one)"),
1054 e4d745a7 Michael Hanselmann
    ("command", ht.NoDefault, ht.TNonEmptyString,
1055 e4d745a7 Michael Hanselmann
     "Command name (no parameters)"),
1056 e4d745a7 Michael Hanselmann
    ]
1057 e4d745a7 Michael Hanselmann
1058 e4d745a7 Michael Hanselmann
  _RESULT_ITEMS = [
1059 e4d745a7 Michael Hanselmann
    ht.Comment("success")(ht.TBool),
1060 e4d745a7 Michael Hanselmann
    ht.Comment("output or error message")(ht.TString),
1061 e4d745a7 Michael Hanselmann
    ]
1062 e4d745a7 Michael Hanselmann
1063 e4d745a7 Michael Hanselmann
  OP_RESULT = \
1064 e4d745a7 Michael Hanselmann
    ht.TListOf(ht.TAnd(ht.TIsLength(len(_RESULT_ITEMS)),
1065 e4d745a7 Michael Hanselmann
                       ht.TItems(_RESULT_ITEMS)))
1066 e4d745a7 Michael Hanselmann
1067 e4d745a7 Michael Hanselmann
1068 07bd8a51 Iustin Pop
# node opcodes
1069 07bd8a51 Iustin Pop
1070 73d565a3 Iustin Pop
class OpNodeRemove(OpCode):
1071 a7399f66 Iustin Pop
  """Remove a node.
1072 a7399f66 Iustin Pop

1073 a7399f66 Iustin Pop
  @type node_name: C{str}
1074 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to remove. If the node still has
1075 a7399f66 Iustin Pop
                   instances on it, the operation will fail.
1076 a7399f66 Iustin Pop

1077 a7399f66 Iustin Pop
  """
1078 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
1079 65e183af Michael Hanselmann
  OP_PARAMS = [
1080 65e183af Michael Hanselmann
    _PNodeName,
1081 1c3231aa Thomas Thrainer
    _PNodeUuid
1082 65e183af Michael Hanselmann
    ]
1083 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1084 a8083063 Iustin Pop
1085 a8083063 Iustin Pop
1086 d817d49f Iustin Pop
class OpNodeAdd(OpCode):
1087 a7399f66 Iustin Pop
  """Add a node to the cluster.
1088 a7399f66 Iustin Pop

1089 a7399f66 Iustin Pop
  @type node_name: C{str}
1090 a7399f66 Iustin Pop
  @ivar node_name: The name of the node to add. This can be a short name,
1091 a7399f66 Iustin Pop
                   but it will be expanded to the FQDN.
1092 a7399f66 Iustin Pop
  @type primary_ip: IP address
1093 a7399f66 Iustin Pop
  @ivar primary_ip: The primary IP of the node. This will be ignored when the
1094 a7399f66 Iustin Pop
                    opcode is submitted, but will be filled during the node
1095 a7399f66 Iustin Pop
                    add (so it will be visible in the job query).
1096 a7399f66 Iustin Pop
  @type secondary_ip: IP address
1097 a7399f66 Iustin Pop
  @ivar secondary_ip: The secondary IP of the node. This needs to be passed
1098 a7399f66 Iustin Pop
                      if the cluster has been initialized in 'dual-network'
1099 a7399f66 Iustin Pop
                      mode, otherwise it must not be given.
1100 a7399f66 Iustin Pop
  @type readd: C{bool}
1101 a7399f66 Iustin Pop
  @ivar readd: Whether to re-add an existing node to the cluster. If
1102 a7399f66 Iustin Pop
               this is not passed, then the operation will abort if the node
1103 a7399f66 Iustin Pop
               name is already in the cluster; use this parameter to 'repair'
1104 a7399f66 Iustin Pop
               a node that had its configuration broken, or was reinstalled
1105 a7399f66 Iustin Pop
               without removal from the cluster.
1106 f936c153 Iustin Pop
  @type group: C{str}
1107 f936c153 Iustin Pop
  @ivar group: The node group to which this node will belong.
1108 fd3d37b6 Iustin Pop
  @type vm_capable: C{bool}
1109 fd3d37b6 Iustin Pop
  @ivar vm_capable: The vm_capable node attribute
1110 fd3d37b6 Iustin Pop
  @type master_capable: C{bool}
1111 fd3d37b6 Iustin Pop
  @ivar master_capable: The master_capable node attribute
1112 a7399f66 Iustin Pop

1113 a7399f66 Iustin Pop
  """
1114 60dd1473 Iustin Pop
  OP_DSC_FIELD = "node_name"
1115 65e183af Michael Hanselmann
  OP_PARAMS = [
1116 65e183af Michael Hanselmann
    _PNodeName,
1117 085e0d9f René Nussbaumer
    _PHvState,
1118 085e0d9f René Nussbaumer
    _PDiskState,
1119 45d4c81c Michael Hanselmann
    ("primary_ip", None, ht.NoType, "Primary IP address"),
1120 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"),
1121 45d4c81c Michael Hanselmann
    ("readd", False, ht.TBool, "Whether node is re-added to cluster"),
1122 45d4c81c Michael Hanselmann
    ("group", None, ht.TMaybeString, "Initial node group"),
1123 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
1124 45d4c81c Michael Hanselmann
     "Whether node can become master or master candidate"),
1125 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
1126 45d4c81c Michael Hanselmann
     "Whether node can host instances"),
1127 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Node parameters"),
1128 65e183af Michael Hanselmann
    ]
1129 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1130 a8083063 Iustin Pop
1131 a8083063 Iustin Pop
1132 2237687b Iustin Pop
class OpNodeQuery(OpCode):
1133 a8083063 Iustin Pop
  """Compute the list of nodes."""
1134 65e183af Michael Hanselmann
  OP_PARAMS = [
1135 65e183af Michael Hanselmann
    _POutputFields,
1136 45d4c81c Michael Hanselmann
    _PUseLocking,
1137 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1138 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1139 65e183af Michael Hanselmann
    ]
1140 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1141 a8083063 Iustin Pop
1142 a8083063 Iustin Pop
1143 8ed55bfd Iustin Pop
class OpNodeQueryvols(OpCode):
1144 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
1145 65e183af Michael Hanselmann
  OP_PARAMS = [
1146 65e183af Michael Hanselmann
    _POutputFields,
1147 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1148 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1149 65e183af Michael Hanselmann
    ]
1150 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAny)
1151 dcb93971 Michael Hanselmann
1152 dcb93971 Michael Hanselmann
1153 ad8d0595 Iustin Pop
class OpNodeQueryStorage(OpCode):
1154 9e5442ce Michael Hanselmann
  """Get information on storage for node(s)."""
1155 65e183af Michael Hanselmann
  OP_PARAMS = [
1156 65e183af Michael Hanselmann
    _POutputFields,
1157 65e183af Michael Hanselmann
    _PStorageType,
1158 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"),
1159 45d4c81c Michael Hanselmann
    ("name", None, ht.TMaybeString, "Storage name"),
1160 9e5442ce Michael Hanselmann
    ]
1161 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1162 9e5442ce Michael Hanselmann
1163 9e5442ce Michael Hanselmann
1164 2cee4077 Iustin Pop
class OpNodeModifyStorage(OpCode):
1165 099c52ad Iustin Pop
  """Modifies the properies of a storage unit"""
1166 32708d0a Iustin Pop
  OP_DSC_FIELD = "node_name"
1167 65e183af Michael Hanselmann
  OP_PARAMS = [
1168 65e183af Michael Hanselmann
    _PNodeName,
1169 1c3231aa Thomas Thrainer
    _PNodeUuid,
1170 65e183af Michael Hanselmann
    _PStorageType,
1171 45d4c81c Michael Hanselmann
    _PStorageName,
1172 45d4c81c Michael Hanselmann
    ("changes", ht.NoDefault, ht.TDict, "Requested changes"),
1173 efb8da02 Michael Hanselmann
    ]
1174 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1175 efb8da02 Michael Hanselmann
1176 efb8da02 Michael Hanselmann
1177 76aef8fc Michael Hanselmann
class OpRepairNodeStorage(OpCode):
1178 76aef8fc Michael Hanselmann
  """Repairs the volume group on a node."""
1179 76aef8fc Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1180 65e183af Michael Hanselmann
  OP_PARAMS = [
1181 65e183af Michael Hanselmann
    _PNodeName,
1182 1c3231aa Thomas Thrainer
    _PNodeUuid,
1183 65e183af Michael Hanselmann
    _PStorageType,
1184 45d4c81c Michael Hanselmann
    _PStorageName,
1185 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1186 76aef8fc Michael Hanselmann
    ]
1187 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1188 76aef8fc Michael Hanselmann
1189 76aef8fc Michael Hanselmann
1190 f13973c4 Iustin Pop
class OpNodeSetParams(OpCode):
1191 b31c8676 Iustin Pop
  """Change the parameters of a node."""
1192 b31c8676 Iustin Pop
  OP_DSC_FIELD = "node_name"
1193 65e183af Michael Hanselmann
  OP_PARAMS = [
1194 65e183af Michael Hanselmann
    _PNodeName,
1195 1c3231aa Thomas Thrainer
    _PNodeUuid,
1196 65e183af Michael Hanselmann
    _PForce,
1197 0ec2ce46 René Nussbaumer
    _PHvState,
1198 0ec2ce46 René Nussbaumer
    _PDiskState,
1199 45d4c81c Michael Hanselmann
    ("master_candidate", None, ht.TMaybeBool,
1200 45d4c81c Michael Hanselmann
     "Whether the node should become a master candidate"),
1201 45d4c81c Michael Hanselmann
    ("offline", None, ht.TMaybeBool,
1202 45d4c81c Michael Hanselmann
     "Whether the node should be marked as offline"),
1203 45d4c81c Michael Hanselmann
    ("drained", None, ht.TMaybeBool,
1204 45d4c81c Michael Hanselmann
     "Whether the node should be marked as drained"),
1205 45d4c81c Michael Hanselmann
    ("auto_promote", False, ht.TBool,
1206 45d4c81c Michael Hanselmann
     "Whether node(s) should be promoted to master candidate if necessary"),
1207 45d4c81c Michael Hanselmann
    ("master_capable", None, ht.TMaybeBool,
1208 45d4c81c Michael Hanselmann
     "Denote whether node can become master or master candidate"),
1209 45d4c81c Michael Hanselmann
    ("vm_capable", None, ht.TMaybeBool,
1210 45d4c81c Michael Hanselmann
     "Denote whether node can host instances"),
1211 45d4c81c Michael Hanselmann
    ("secondary_ip", None, ht.TMaybeString,
1212 45d4c81c Michael Hanselmann
     "Change node's secondary IP address"),
1213 45d4c81c Michael Hanselmann
    ("ndparams", None, ht.TMaybeDict, "Set node parameters"),
1214 45d4c81c Michael Hanselmann
    ("powered", None, ht.TMaybeBool,
1215 45d4c81c Michael Hanselmann
     "Whether the node should be marked as powered"),
1216 b31c8676 Iustin Pop
    ]
1217 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1218 b31c8676 Iustin Pop
1219 f5118ade Iustin Pop
1220 e0d4735f Iustin Pop
class OpNodePowercycle(OpCode):
1221 f5118ade Iustin Pop
  """Tries to powercycle a node."""
1222 f5118ade Iustin Pop
  OP_DSC_FIELD = "node_name"
1223 65e183af Michael Hanselmann
  OP_PARAMS = [
1224 65e183af Michael Hanselmann
    _PNodeName,
1225 1c3231aa Thomas Thrainer
    _PNodeUuid,
1226 65e183af Michael Hanselmann
    _PForce,
1227 f5118ade Iustin Pop
    ]
1228 c363310d René Nussbaumer
  OP_RESULT = ht.TMaybeString
1229 f5118ade Iustin Pop
1230 7ffc5a86 Michael Hanselmann
1231 5b14a488 Iustin Pop
class OpNodeMigrate(OpCode):
1232 80cb875c Michael Hanselmann
  """Migrate all instances from a node."""
1233 80cb875c Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1234 65e183af Michael Hanselmann
  OP_PARAMS = [
1235 65e183af Michael Hanselmann
    _PNodeName,
1236 1c3231aa Thomas Thrainer
    _PNodeUuid,
1237 65e183af Michael Hanselmann
    _PMigrationMode,
1238 65e183af Michael Hanselmann
    _PMigrationLive,
1239 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1240 1c3231aa Thomas Thrainer
    _PMigrationTargetNodeUuid,
1241 8c0b16f6 Guido Trotter
    _PAllowRuntimeChgs,
1242 9fa567b3 René Nussbaumer
    _PIgnoreIpolicy,
1243 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for deciding the target node"
1244 89514061 Iustin Pop
                     " for shared-storage instances"),
1245 80cb875c Michael Hanselmann
    ]
1246 65c9591c Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1247 80cb875c Michael Hanselmann
1248 80cb875c Michael Hanselmann
1249 e1f23243 Michael Hanselmann
class OpNodeEvacuate(OpCode):
1250 e1f23243 Michael Hanselmann
  """Evacuate instances off a number of nodes."""
1251 e1f23243 Michael Hanselmann
  OP_DSC_FIELD = "node_name"
1252 e1f23243 Michael Hanselmann
  OP_PARAMS = [
1253 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1254 e1f23243 Michael Hanselmann
    _PNodeName,
1255 1c3231aa Thomas Thrainer
    _PNodeUuid,
1256 e1f23243 Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1257 1c3231aa Thomas Thrainer
    ("remote_node_uuid", None, ht.TMaybeString, "New secondary node UUID"),
1258 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for computing solution"),
1259 cb92e7a1 Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.NODE_EVAC_MODES),
1260 e1f23243 Michael Hanselmann
     "Node evacuation mode"),
1261 e1f23243 Michael Hanselmann
    ]
1262 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1263 e1f23243 Michael Hanselmann
1264 e1f23243 Michael Hanselmann
1265 a8083063 Iustin Pop
# instance opcodes
1266 a8083063 Iustin Pop
1267 e1530b10 Iustin Pop
class OpInstanceCreate(OpCode):
1268 9bf56d77 Michael Hanselmann
  """Create an instance.
1269 9bf56d77 Michael Hanselmann

1270 9bf56d77 Michael Hanselmann
  @ivar instance_name: Instance name
1271 9bf56d77 Michael Hanselmann
  @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
1272 9bf56d77 Michael Hanselmann
  @ivar source_handshake: Signed handshake from source (remote import only)
1273 9bf56d77 Michael Hanselmann
  @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
1274 9bf56d77 Michael Hanselmann
  @ivar source_instance_name: Previous name of instance (remote import only)
1275 dae91d02 Michael Hanselmann
  @ivar source_shutdown_timeout: Shutdown timeout used for source instance
1276 dae91d02 Michael Hanselmann
    (remote import only)
1277 9bf56d77 Michael Hanselmann

1278 9bf56d77 Michael Hanselmann
  """
1279 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1280 65e183af Michael Hanselmann
  OP_PARAMS = [
1281 65e183af Michael Hanselmann
    _PInstanceName,
1282 45d4c81c Michael Hanselmann
    _PForceVariant,
1283 45d4c81c Michael Hanselmann
    _PWaitForSync,
1284 45d4c81c Michael Hanselmann
    _PNameCheck,
1285 10889e0c René Nussbaumer
    _PIgnoreIpolicy,
1286 1f1188c3 Michael Hanselmann
    _POpportunisticLocking,
1287 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"),
1288 735e1318 Michael Hanselmann
    ("disks", ht.NoDefault, ht.TListOf(_TDiskParams),
1289 526a662a Michael Hanselmann
     "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
1290 526a662a Michael Hanselmann
     " each disk definition must contain a ``%s`` value and"
1291 526a662a Michael Hanselmann
     " can contain an optional ``%s`` value denoting the disk access mode"
1292 526a662a Michael Hanselmann
     " (%s)" %
1293 526a662a Michael Hanselmann
     (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE,
1294 526a662a Michael Hanselmann
      constants.IDISK_MODE,
1295 526a662a Michael Hanselmann
      " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))),
1296 45fe090b Michael Hanselmann
    ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True),
1297 45fe090b Michael Hanselmann
     "Disk template"),
1298 fd9f58fd Iustin Pop
    ("file_driver", None, ht.TMaybe(ht.TElemOf(constants.FILE_DRIVER)),
1299 45d4c81c Michael Hanselmann
     "Driver for file-backed disks"),
1300 45d4c81c Michael Hanselmann
    ("file_storage_dir", None, ht.TMaybeString,
1301 45d4c81c Michael Hanselmann
     "Directory for storing file-backed disks"),
1302 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1303 45d4c81c Michael Hanselmann
     "Hypervisor parameters for instance, hypervisor-dependent"),
1304 45d4c81c Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, "Hypervisor"),
1305 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for deciding which node(s) to use"),
1306 45d4c81c Michael Hanselmann
    ("identify_defaults", False, ht.TBool,
1307 45d4c81c Michael Hanselmann
     "Reset instance parameters to default if equal"),
1308 45d4c81c Michael Hanselmann
    ("ip_check", True, ht.TBool, _PIpCheckDoc),
1309 eaa4c57c Dimitris Aragiorgis
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1310 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
1311 45d4c81c Michael Hanselmann
     "Instance creation mode"),
1312 526a662a Michael Hanselmann
    ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
1313 526a662a Michael Hanselmann
     "List of NIC (network interface) definitions, for example"
1314 526a662a Michael Hanselmann
     " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
1315 526a662a Michael Hanselmann
     " contain the optional values %s" %
1316 526a662a Michael Hanselmann
     (constants.INIC_IP,
1317 526a662a Michael Hanselmann
      ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))),
1318 45d4c81c Michael Hanselmann
    ("no_install", None, ht.TMaybeBool,
1319 45d4c81c Michael Hanselmann
     "Do not install the OS (will disable automatic start)"),
1320 45d4c81c Michael Hanselmann
    ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"),
1321 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Operating system"),
1322 45d4c81c Michael Hanselmann
    ("pnode", None, ht.TMaybeString, "Primary node"),
1323 1c3231aa Thomas Thrainer
    ("pnode_uuid", None, ht.TMaybeString, "Primary node UUID"),
1324 45d4c81c Michael Hanselmann
    ("snode", None, ht.TMaybeString, "Secondary node"),
1325 1c3231aa Thomas Thrainer
    ("snode_uuid", None, ht.TMaybeString, "Secondary node UUID"),
1326 fd9f58fd Iustin Pop
    ("source_handshake", None, ht.TMaybe(ht.TList),
1327 45d4c81c Michael Hanselmann
     "Signed handshake from source (remote import only)"),
1328 45d4c81c Michael Hanselmann
    ("source_instance_name", None, ht.TMaybeString,
1329 45d4c81c Michael Hanselmann
     "Source instance name (remote import only)"),
1330 65e183af Michael Hanselmann
    ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
1331 2c9fa1ff Iustin Pop
     ht.TNonNegativeInt,
1332 526a662a Michael Hanselmann
     "How long source instance was given to shut down (remote import only)"),
1333 45d4c81c Michael Hanselmann
    ("source_x509_ca", None, ht.TMaybeString,
1334 45d4c81c Michael Hanselmann
     "Source X509 CA in PEM format (remote import only)"),
1335 45d4c81c Michael Hanselmann
    ("src_node", None, ht.TMaybeString, "Source node for import"),
1336 1c3231aa Thomas Thrainer
    ("src_node_uuid", None, ht.TMaybeString, "Source node UUID for import"),
1337 45d4c81c Michael Hanselmann
    ("src_path", None, ht.TMaybeString, "Source directory for import"),
1338 45d4c81c Michael Hanselmann
    ("start", True, ht.TBool, "Whether to start instance after creation"),
1339 720f56c8 Apollon Oikonomopoulos
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"),
1340 3b6d8c9b Iustin Pop
    ]
1341 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
1342 a8083063 Iustin Pop
1343 a8083063 Iustin Pop
1344 12e62af5 René Nussbaumer
class OpInstanceMultiAlloc(OpCode):
1345 12e62af5 René Nussbaumer
  """Allocates multiple instances.
1346 12e62af5 René Nussbaumer

1347 12e62af5 René Nussbaumer
  """
1348 12e62af5 René Nussbaumer
  OP_PARAMS = [
1349 1f1188c3 Michael Hanselmann
    _POpportunisticLocking,
1350 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator used to allocate all the instances"),
1351 4c405df7 Iustin Pop
    ("instances", ht.EmptyList, ht.TListOf(ht.TInstanceOf(OpInstanceCreate)),
1352 12e62af5 René Nussbaumer
     "List of instance create opcodes describing the instances to allocate"),
1353 12e62af5 René Nussbaumer
    ]
1354 12e62af5 René Nussbaumer
  _JOB_LIST = ht.Comment("List of submitted jobs")(TJobIdList)
1355 12e62af5 René Nussbaumer
  ALLOCATABLE_KEY = "allocatable"
1356 12e62af5 René Nussbaumer
  FAILED_KEY = "allocatable"
1357 12e62af5 René Nussbaumer
  OP_RESULT = ht.TStrictDict(True, True, {
1358 12e62af5 René Nussbaumer
    constants.JOB_IDS_KEY: _JOB_LIST,
1359 12e62af5 René Nussbaumer
    ALLOCATABLE_KEY: ht.TListOf(ht.TNonEmptyString),
1360 3c286190 Dimitris Aragiorgis
    FAILED_KEY: ht.TListOf(ht.TNonEmptyString),
1361 12e62af5 René Nussbaumer
    })
1362 12e62af5 René Nussbaumer
1363 12e62af5 René Nussbaumer
  def __getstate__(self):
1364 12e62af5 René Nussbaumer
    """Generic serializer.
1365 12e62af5 René Nussbaumer

1366 12e62af5 René Nussbaumer
    """
1367 12e62af5 René Nussbaumer
    state = OpCode.__getstate__(self)
1368 12e62af5 René Nussbaumer
    if hasattr(self, "instances"):
1369 12e62af5 René Nussbaumer
      # pylint: disable=E1101
1370 12e62af5 René Nussbaumer
      state["instances"] = [inst.__getstate__() for inst in self.instances]
1371 12e62af5 René Nussbaumer
    return state
1372 12e62af5 René Nussbaumer
1373 12e62af5 René Nussbaumer
  def __setstate__(self, state):
1374 12e62af5 René Nussbaumer
    """Generic unserializer.
1375 12e62af5 René Nussbaumer

1376 12e62af5 René Nussbaumer
    This method just restores from the serialized state the attributes
1377 12e62af5 René Nussbaumer
    of the current instance.
1378 12e62af5 René Nussbaumer

1379 12e62af5 René Nussbaumer
    @param state: the serialized opcode data
1380 12e62af5 René Nussbaumer
    @type state: C{dict}
1381 12e62af5 René Nussbaumer

1382 12e62af5 René Nussbaumer
    """
1383 12e62af5 René Nussbaumer
    if not isinstance(state, dict):
1384 12e62af5 René Nussbaumer
      raise ValueError("Invalid data to __setstate__: expected dict, got %s" %
1385 12e62af5 René Nussbaumer
                       type(state))
1386 12e62af5 René Nussbaumer
1387 12e62af5 René Nussbaumer
    if "instances" in state:
1388 5dff65da Michael Hanselmann
      state["instances"] = map(OpCode.LoadOpCode, state["instances"])
1389 5dff65da Michael Hanselmann
1390 12e62af5 René Nussbaumer
    return OpCode.__setstate__(self, state)
1391 12e62af5 René Nussbaumer
1392 9bc5ac44 René Nussbaumer
  def Validate(self, set_defaults):
1393 9bc5ac44 René Nussbaumer
    """Validates this opcode.
1394 9bc5ac44 René Nussbaumer

1395 9bc5ac44 René Nussbaumer
    We do this recursively.
1396 9bc5ac44 René Nussbaumer

1397 9bc5ac44 René Nussbaumer
    """
1398 9bc5ac44 René Nussbaumer
    OpCode.Validate(self, set_defaults)
1399 9bc5ac44 René Nussbaumer
1400 3779121c René Nussbaumer
    for inst in self.instances: # pylint: disable=E1101
1401 9bc5ac44 René Nussbaumer
      inst.Validate(set_defaults)
1402 9bc5ac44 René Nussbaumer
1403 12e62af5 René Nussbaumer
1404 5073fd8f Iustin Pop
class OpInstanceReinstall(OpCode):
1405 fdc267f4 Iustin Pop
  """Reinstall an instance's OS."""
1406 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1407 65e183af Michael Hanselmann
  OP_PARAMS = [
1408 65e183af Michael Hanselmann
    _PInstanceName,
1409 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1410 45d4c81c Michael Hanselmann
    _PForceVariant,
1411 45d4c81c Michael Hanselmann
    ("os_type", None, ht.TMaybeString, "Instance operating system"),
1412 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"),
1413 65e183af Michael Hanselmann
    ]
1414 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1415 fe7b0351 Michael Hanselmann
1416 fe7b0351 Michael Hanselmann
1417 3cd2d4b1 Iustin Pop
class OpInstanceRemove(OpCode):
1418 a8083063 Iustin Pop
  """Remove an instance."""
1419 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1420 65e183af Michael Hanselmann
  OP_PARAMS = [
1421 65e183af Michael Hanselmann
    _PInstanceName,
1422 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1423 65e183af Michael Hanselmann
    _PShutdownTimeout,
1424 45d4c81c Michael Hanselmann
    ("ignore_failures", False, ht.TBool,
1425 45d4c81c Michael Hanselmann
     "Whether to ignore failures during removal"),
1426 fc1baca9 Michael Hanselmann
    ]
1427 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1428 a8083063 Iustin Pop
1429 a8083063 Iustin Pop
1430 5659e2e2 Iustin Pop
class OpInstanceRename(OpCode):
1431 decd5f45 Iustin Pop
  """Rename an instance."""
1432 65e183af Michael Hanselmann
  OP_PARAMS = [
1433 65e183af Michael Hanselmann
    _PInstanceName,
1434 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1435 45d4c81c Michael Hanselmann
    _PNameCheck,
1436 45d4c81c Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"),
1437 45d4c81c Michael Hanselmann
    ("ip_check", False, ht.TBool, _PIpCheckDoc),
1438 4f05fd3b Iustin Pop
    ]
1439 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
1440 decd5f45 Iustin Pop
1441 decd5f45 Iustin Pop
1442 c873d91c Iustin Pop
class OpInstanceStartup(OpCode):
1443 fdc267f4 Iustin Pop
  """Startup an instance."""
1444 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1445 65e183af Michael Hanselmann
  OP_PARAMS = [
1446 65e183af Michael Hanselmann
    _PInstanceName,
1447 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1448 65e183af Michael Hanselmann
    _PForce,
1449 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1450 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1451 45d4c81c Michael Hanselmann
     "Temporary hypervisor parameters, hypervisor-dependent"),
1452 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"),
1453 9b64e486 Iustin Pop
    _PNoRemember,
1454 323f9095 Stephen Shirley
    _PStartupPaused,
1455 4f05fd3b Iustin Pop
    ]
1456 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1457 a8083063 Iustin Pop
1458 a8083063 Iustin Pop
1459 ee3e37a7 Iustin Pop
class OpInstanceShutdown(OpCode):
1460 fdc267f4 Iustin Pop
  """Shutdown an instance."""
1461 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1462 65e183af Michael Hanselmann
  OP_PARAMS = [
1463 65e183af Michael Hanselmann
    _PInstanceName,
1464 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1465 0d57ce24 Guido Trotter
    _PForce,
1466 65e183af Michael Hanselmann
    _PIgnoreOfflineNodes,
1467 2c9fa1ff Iustin Pop
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TNonNegativeInt,
1468 45d4c81c Michael Hanselmann
     "How long to wait for instance to shut down"),
1469 9b64e486 Iustin Pop
    _PNoRemember,
1470 b44bd844 Michael Hanselmann
    ]
1471 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1472 a8083063 Iustin Pop
1473 a8083063 Iustin Pop
1474 90ab1a95 Iustin Pop
class OpInstanceReboot(OpCode):
1475 bf6929a2 Alexander Schreiber
  """Reboot an instance."""
1476 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1477 65e183af Michael Hanselmann
  OP_PARAMS = [
1478 65e183af Michael Hanselmann
    _PInstanceName,
1479 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1480 65e183af Michael Hanselmann
    _PShutdownTimeout,
1481 45d4c81c Michael Hanselmann
    ("ignore_secondaries", False, ht.TBool,
1482 45d4c81c Michael Hanselmann
     "Whether to start the instance even if secondary disks are failing"),
1483 45d4c81c Michael Hanselmann
    ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
1484 45d4c81c Michael Hanselmann
     "How to reboot instance"),
1485 4f05fd3b Iustin Pop
    ]
1486 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1487 bf6929a2 Alexander Schreiber
1488 bf6929a2 Alexander Schreiber
1489 668f755d Iustin Pop
class OpInstanceReplaceDisks(OpCode):
1490 fdc267f4 Iustin Pop
  """Replace the disks of an instance."""
1491 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1492 65e183af Michael Hanselmann
  OP_PARAMS = [
1493 65e183af Michael Hanselmann
    _PInstanceName,
1494 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1495 e1f23243 Michael Hanselmann
    _PEarlyRelease,
1496 d2fe2bfb René Nussbaumer
    _PIgnoreIpolicy,
1497 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
1498 45d4c81c Michael Hanselmann
     "Replacement mode"),
1499 2c9fa1ff Iustin Pop
    ("disks", ht.EmptyList, ht.TListOf(ht.TNonNegativeInt),
1500 45d4c81c Michael Hanselmann
     "Disk indexes"),
1501 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString, "New secondary node"),
1502 1c3231aa Thomas Thrainer
    ("remote_node_uuid", None, ht.TMaybeString, "New secondary node UUID"),
1503 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for deciding new secondary node"),
1504 4f05fd3b Iustin Pop
    ]
1505 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1506 a8083063 Iustin Pop
1507 a8083063 Iustin Pop
1508 019dbee1 Iustin Pop
class OpInstanceFailover(OpCode):
1509 a8083063 Iustin Pop
  """Failover an instance."""
1510 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1511 65e183af Michael Hanselmann
  OP_PARAMS = [
1512 65e183af Michael Hanselmann
    _PInstanceName,
1513 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1514 65e183af Michael Hanselmann
    _PShutdownTimeout,
1515 45d4c81c Michael Hanselmann
    _PIgnoreConsistency,
1516 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1517 1c3231aa Thomas Thrainer
    _PMigrationTargetNodeUuid,
1518 b6aaf437 René Nussbaumer
    _PIgnoreIpolicy,
1519 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for deciding the target node for"
1520 89514061 Iustin Pop
                     " shared-storage instances"),
1521 aa7a5c90 Michele Tartara
    ("cleanup", False, ht.TBool,
1522 aa7a5c90 Michele Tartara
     "Whether a previously failed failover should be cleaned up"),
1523 17c3f802 Guido Trotter
    ]
1524 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1525 a8083063 Iustin Pop
1526 a8083063 Iustin Pop
1527 75c866c2 Iustin Pop
class OpInstanceMigrate(OpCode):
1528 53c776b5 Iustin Pop
  """Migrate an instance.
1529 53c776b5 Iustin Pop

1530 53c776b5 Iustin Pop
  This migrates (without shutting down an instance) to its secondary
1531 53c776b5 Iustin Pop
  node.
1532 53c776b5 Iustin Pop

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

1536 53c776b5 Iustin Pop
  """
1537 ee69c97f Iustin Pop
  OP_DSC_FIELD = "instance_name"
1538 65e183af Michael Hanselmann
  OP_PARAMS = [
1539 65e183af Michael Hanselmann
    _PInstanceName,
1540 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1541 65e183af Michael Hanselmann
    _PMigrationMode,
1542 65e183af Michael Hanselmann
    _PMigrationLive,
1543 f8fa4175 Michael Hanselmann
    _PMigrationTargetNode,
1544 1c3231aa Thomas Thrainer
    _PMigrationTargetNodeUuid,
1545 8c0b16f6 Guido Trotter
    _PAllowRuntimeChgs,
1546 3ed23330 René Nussbaumer
    _PIgnoreIpolicy,
1547 45d4c81c Michael Hanselmann
    ("cleanup", False, ht.TBool,
1548 45d4c81c Michael Hanselmann
     "Whether a previously failed migration should be cleaned up"),
1549 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for deciding the target node for"
1550 89514061 Iustin Pop
                     " shared-storage instances"),
1551 d5cafd31 René Nussbaumer
    ("allow_failover", False, ht.TBool,
1552 d5cafd31 René Nussbaumer
     "Whether we can fallback to failover if migration is not possible"),
1553 65e183af Michael Hanselmann
    ]
1554 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1555 53c776b5 Iustin Pop
1556 53c776b5 Iustin Pop
1557 0091b480 Iustin Pop
class OpInstanceMove(OpCode):
1558 313bcead Iustin Pop
  """Move an instance.
1559 313bcead Iustin Pop

1560 313bcead Iustin Pop
  This move (with shutting down an instance and data copying) to an
1561 313bcead Iustin Pop
  arbitrary node.
1562 313bcead Iustin Pop

1563 313bcead Iustin Pop
  @ivar instance_name: the name of the instance
1564 313bcead Iustin Pop
  @ivar target_node: the destination node
1565 313bcead Iustin Pop

1566 313bcead Iustin Pop
  """
1567 313bcead Iustin Pop
  OP_DSC_FIELD = "instance_name"
1568 65e183af Michael Hanselmann
  OP_PARAMS = [
1569 65e183af Michael Hanselmann
    _PInstanceName,
1570 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1571 65e183af Michael Hanselmann
    _PShutdownTimeout,
1572 92cf62e3 René Nussbaumer
    _PIgnoreIpolicy,
1573 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"),
1574 1c3231aa Thomas Thrainer
    ("target_node_uuid", None, ht.TMaybeString, "Target node UUID"),
1575 bb851c63 Iustin Pop
    _PIgnoreConsistency,
1576 154b9580 Balazs Lecz
    ]
1577 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1578 313bcead Iustin Pop
1579 313bcead Iustin Pop
1580 cc0dec7b Iustin Pop
class OpInstanceConsole(OpCode):
1581 fdc267f4 Iustin Pop
  """Connect to an instance's console."""
1582 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1583 65e183af Michael Hanselmann
  OP_PARAMS = [
1584 3c286190 Dimitris Aragiorgis
    _PInstanceName,
1585 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1586 65e183af Michael Hanselmann
    ]
1587 c363310d René Nussbaumer
  OP_RESULT = ht.TDict
1588 a8083063 Iustin Pop
1589 a8083063 Iustin Pop
1590 83f5d475 Iustin Pop
class OpInstanceActivateDisks(OpCode):
1591 fdc267f4 Iustin Pop
  """Activate an instance's disks."""
1592 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1593 65e183af Michael Hanselmann
  OP_PARAMS = [
1594 65e183af Michael Hanselmann
    _PInstanceName,
1595 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1596 45d4c81c Michael Hanselmann
    ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"),
1597 b69437c5 Iustin Pop
    _PWaitForSyncFalse,
1598 65e183af Michael Hanselmann
    ]
1599 c363310d René Nussbaumer
  OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(3),
1600 c363310d René Nussbaumer
                                 ht.TItems([ht.TNonEmptyString,
1601 c363310d René Nussbaumer
                                            ht.TNonEmptyString,
1602 c363310d René Nussbaumer
                                            ht.TNonEmptyString])))
1603 a8083063 Iustin Pop
1604 a8083063 Iustin Pop
1605 e176281f Iustin Pop
class OpInstanceDeactivateDisks(OpCode):
1606 fdc267f4 Iustin Pop
  """Deactivate an instance's disks."""
1607 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1608 65e183af Michael Hanselmann
  OP_PARAMS = [
1609 c9c41373 Iustin Pop
    _PInstanceName,
1610 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1611 c9c41373 Iustin Pop
    _PForce,
1612 65e183af Michael Hanselmann
    ]
1613 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1614 a8083063 Iustin Pop
1615 a8083063 Iustin Pop
1616 6b273e78 Iustin Pop
class OpInstanceRecreateDisks(OpCode):
1617 a52978c7 Michael Hanselmann
  """Recreate an instance's disks."""
1618 735e1318 Michael Hanselmann
  _TDiskChanges = \
1619 735e1318 Michael Hanselmann
    ht.TAnd(ht.TIsLength(2),
1620 2c9fa1ff Iustin Pop
            ht.TItems([ht.Comment("Disk index")(ht.TNonNegativeInt),
1621 735e1318 Michael Hanselmann
                       ht.Comment("Parameters")(_TDiskParams)]))
1622 735e1318 Michael Hanselmann
1623 bd315bfa Iustin Pop
  OP_DSC_FIELD = "instance_name"
1624 65e183af Michael Hanselmann
  OP_PARAMS = [
1625 65e183af Michael Hanselmann
    _PInstanceName,
1626 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1627 735e1318 Michael Hanselmann
    ("disks", ht.EmptyList,
1628 2c9fa1ff Iustin Pop
     ht.TOr(ht.TListOf(ht.TNonNegativeInt), ht.TListOf(_TDiskChanges)),
1629 735e1318 Michael Hanselmann
     "List of disk indexes (deprecated) or a list of tuples containing a disk"
1630 735e1318 Michael Hanselmann
     " index and a possibly empty dictionary with disk parameter changes"),
1631 93384b8c Guido Trotter
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1632 93384b8c Guido Trotter
     "New instance nodes, if relocation is desired"),
1633 1c3231aa Thomas Thrainer
    ("node_uuids", None, ht.TMaybeListOf(ht.TNonEmptyString),
1634 1c3231aa Thomas Thrainer
     "New instance node UUIDs, if relocation is desired"),
1635 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for deciding new nodes"),
1636 65e183af Michael Hanselmann
    ]
1637 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1638 bd315bfa Iustin Pop
1639 bd315bfa Iustin Pop
1640 f2af0bec Iustin Pop
class OpInstanceQuery(OpCode):
1641 a8083063 Iustin Pop
  """Compute the list of instances."""
1642 65e183af Michael Hanselmann
  OP_PARAMS = [
1643 65e183af Michael Hanselmann
    _POutputFields,
1644 45d4c81c Michael Hanselmann
    _PUseLocking,
1645 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1646 45d4c81c Michael Hanselmann
     "Empty list to query all instances, instance names otherwise"),
1647 65e183af Michael Hanselmann
    ]
1648 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1649 a8083063 Iustin Pop
1650 a8083063 Iustin Pop
1651 dc28c4e4 Iustin Pop
class OpInstanceQueryData(OpCode):
1652 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
1653 65e183af Michael Hanselmann
  OP_PARAMS = [
1654 af7b6689 Michael Hanselmann
    _PUseLocking,
1655 af7b6689 Michael Hanselmann
    ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1656 af7b6689 Michael Hanselmann
     "Instance names"),
1657 af7b6689 Michael Hanselmann
    ("static", False, ht.TBool,
1658 af7b6689 Michael Hanselmann
     "Whether to only return configuration data without querying"
1659 af7b6689 Michael Hanselmann
     " nodes"),
1660 65e183af Michael Hanselmann
    ]
1661 415feb2e René Nussbaumer
  OP_RESULT = ht.TDictOf(ht.TNonEmptyString, ht.TDict)
1662 a8083063 Iustin Pop
1663 a8083063 Iustin Pop
1664 ddc1de7c Michael Hanselmann
def _TestInstSetParamsModList(fn):
1665 ddc1de7c Michael Hanselmann
  """Generates a check for modification lists.
1666 ddc1de7c Michael Hanselmann

1667 ddc1de7c Michael Hanselmann
  """
1668 e9c3d864 Michael Hanselmann
  # Old format
1669 e9c3d864 Michael Hanselmann
  # TODO: Remove in version 2.8 including support in LUInstanceSetParams
1670 e9c3d864 Michael Hanselmann
  old_mod_item_fn = \
1671 ddc1de7c Michael Hanselmann
    ht.TAnd(ht.TIsLength(2), ht.TItems([
1672 2c9fa1ff Iustin Pop
      ht.TOr(ht.TElemOf(constants.DDMS_VALUES), ht.TNonNegativeInt),
1673 ddc1de7c Michael Hanselmann
      fn,
1674 ddc1de7c Michael Hanselmann
      ]))
1675 ddc1de7c Michael Hanselmann
1676 e9c3d864 Michael Hanselmann
  # New format, supporting adding/removing disks/NICs at arbitrary indices
1677 e9c3d864 Michael Hanselmann
  mod_item_fn = \
1678 e9c3d864 Michael Hanselmann
    ht.TAnd(ht.TIsLength(3), ht.TItems([
1679 e9c3d864 Michael Hanselmann
      ht.TElemOf(constants.DDMS_VALUES_WITH_MODIFY),
1680 b21d488b Christos Stavrakakis
      ht.Comment("Device index, can be negative, e.g. -1 for last disk")
1681 b21d488b Christos Stavrakakis
                 (ht.TOr(ht.TInt, ht.TString)),
1682 e9c3d864 Michael Hanselmann
      fn,
1683 e9c3d864 Michael Hanselmann
      ]))
1684 e9c3d864 Michael Hanselmann
1685 e9c3d864 Michael Hanselmann
  return ht.TOr(ht.Comment("Recommended")(ht.TListOf(mod_item_fn)),
1686 e9c3d864 Michael Hanselmann
                ht.Comment("Deprecated")(ht.TListOf(old_mod_item_fn)))
1687 ddc1de7c Michael Hanselmann
1688 ddc1de7c Michael Hanselmann
1689 9a3cc7ae Iustin Pop
class OpInstanceSetParams(OpCode):
1690 ddc1de7c Michael Hanselmann
  """Change the parameters of an instance.
1691 ddc1de7c Michael Hanselmann

1692 ddc1de7c Michael Hanselmann
  """
1693 a2aadb34 Michael Hanselmann
  TestNicModifications = _TestInstSetParamsModList(_TestNicDef)
1694 a2aadb34 Michael Hanselmann
  TestDiskModifications = _TestInstSetParamsModList(_TDiskParams)
1695 ddc1de7c Michael Hanselmann
1696 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1697 65e183af Michael Hanselmann
  OP_PARAMS = [
1698 65e183af Michael Hanselmann
    _PInstanceName,
1699 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1700 65e183af Michael Hanselmann
    _PForce,
1701 45d4c81c Michael Hanselmann
    _PForceVariant,
1702 1559e1e7 René Nussbaumer
    _PIgnoreIpolicy,
1703 a2aadb34 Michael Hanselmann
    ("nics", ht.EmptyList, TestNicModifications,
1704 b21d488b Christos Stavrakakis
     "List of NIC changes: each item is of the form"
1705 b21d488b Christos Stavrakakis
     " ``(op, identifier, settings)``, ``op`` is one of ``%s``, ``%s`` or"
1706 b21d488b Christos Stavrakakis
     " ``%s``, ``identifier`` can be a zero-based index number (or -1 to refer"
1707 b21d488b Christos Stavrakakis
     " to the last position), the NIC's UUID of the NIC's name; a"
1708 0fb66bb1 Iustin Pop
     " deprecated version of this parameter used the form ``(op, settings)``,"
1709 0fb66bb1 Iustin Pop
     " where ``op`` can be ``%s`` to add a new NIC with the specified"
1710 0fb66bb1 Iustin Pop
     " settings, ``%s`` to remove the last NIC or a number to modify the"
1711 0fb66bb1 Iustin Pop
     " settings of the NIC with that index" %
1712 e9c3d864 Michael Hanselmann
     (constants.DDM_ADD, constants.DDM_MODIFY, constants.DDM_REMOVE,
1713 e9c3d864 Michael Hanselmann
      constants.DDM_ADD, constants.DDM_REMOVE)),
1714 a2aadb34 Michael Hanselmann
    ("disks", ht.EmptyList, TestDiskModifications,
1715 0fb66bb1 Iustin Pop
     "List of disk changes; see ``nics``"),
1716 45d4c81c Michael Hanselmann
    ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"),
1717 2c9fa1ff Iustin Pop
    ("runtime_mem", None, ht.TMaybePositiveInt, "New runtime memory"),
1718 45d4c81c Michael Hanselmann
    ("hvparams", ht.EmptyDict, ht.TDict,
1719 45d4c81c Michael Hanselmann
     "Per-instance hypervisor parameters, hypervisor-dependent"),
1720 fd9f58fd Iustin Pop
    ("disk_template", None, ht.TMaybe(_BuildDiskTemplateCheck(False)),
1721 45d4c81c Michael Hanselmann
     "Disk template for instance"),
1722 d2204b1a Klaus Aehlig
    ("pnode", None, ht.TMaybeString, "New primary node"),
1723 1c3231aa Thomas Thrainer
    ("pnode_uuid", None, ht.TMaybeString, "New primary node UUID"),
1724 45d4c81c Michael Hanselmann
    ("remote_node", None, ht.TMaybeString,
1725 45d4c81c Michael Hanselmann
     "Secondary node (used when changing disk template)"),
1726 1c3231aa Thomas Thrainer
    ("remote_node_uuid", None, ht.TMaybeString,
1727 1c3231aa Thomas Thrainer
     "Secondary node UUID (used when changing disk template)"),
1728 45d4c81c Michael Hanselmann
    ("os_name", None, ht.TMaybeString,
1729 0fb66bb1 Iustin Pop
     "Change the instance's OS without reinstalling the instance"),
1730 45d4c81c Michael Hanselmann
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1731 93384b8c Guido Trotter
    ("wait_for_sync", True, ht.TBool,
1732 93384b8c Guido Trotter
     "Whether to wait for the disk to synchronize, when changing template"),
1733 3016bc1f Michael Hanselmann
    ("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"),
1734 eaa4c57c Dimitris Aragiorgis
    ("conflicts_check", True, ht.TBool, "Check for conflicting IPs"),
1735 973d7867 Iustin Pop
    ]
1736 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1737 a8083063 Iustin Pop
1738 a8083063 Iustin Pop
1739 60472d29 Iustin Pop
class OpInstanceGrowDisk(OpCode):
1740 8729e0d7 Iustin Pop
  """Grow a disk of an instance."""
1741 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1742 65e183af Michael Hanselmann
  OP_PARAMS = [
1743 65e183af Michael Hanselmann
    _PInstanceName,
1744 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1745 45d4c81c Michael Hanselmann
    _PWaitForSync,
1746 45d4c81c Michael Hanselmann
    ("disk", ht.NoDefault, ht.TInt, "Disk index"),
1747 2c9fa1ff Iustin Pop
    ("amount", ht.NoDefault, ht.TNonNegativeInt,
1748 45d4c81c Michael Hanselmann
     "Amount of disk space to add (megabytes)"),
1749 e7f99087 Iustin Pop
    ("absolute", False, ht.TBool,
1750 e7f99087 Iustin Pop
     "Whether the amount parameter is an absolute target or a relative one"),
1751 4f05fd3b Iustin Pop
    ]
1752 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1753 8729e0d7 Iustin Pop
1754 8729e0d7 Iustin Pop
1755 1aef3df8 Michael Hanselmann
class OpInstanceChangeGroup(OpCode):
1756 1aef3df8 Michael Hanselmann
  """Moves an instance to another node group."""
1757 1aef3df8 Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1758 1aef3df8 Michael Hanselmann
  OP_PARAMS = [
1759 1aef3df8 Michael Hanselmann
    _PInstanceName,
1760 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1761 1aef3df8 Michael Hanselmann
    _PEarlyRelease,
1762 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for computing solution"),
1763 911ee606 Michael Hanselmann
    _PTargetGroups,
1764 1aef3df8 Michael Hanselmann
    ]
1765 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1766 1aef3df8 Michael Hanselmann
1767 1aef3df8 Michael Hanselmann
1768 70a6a926 Adeodato Simo
# Node group opcodes
1769 70a6a926 Adeodato Simo
1770 fabf1731 Iustin Pop
class OpGroupAdd(OpCode):
1771 b1ee5610 Adeodato Simo
  """Add a node group to the cluster."""
1772 b1ee5610 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1773 65e183af Michael Hanselmann
  OP_PARAMS = [
1774 65e183af Michael Hanselmann
    _PGroupName,
1775 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1776 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1777 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1778 e4c03256 René Nussbaumer
    _PHvState,
1779 e4c03256 René Nussbaumer
    _PDiskState,
1780 1b01390b René Nussbaumer
    ("ipolicy", None, ht.TMaybeDict,
1781 1b01390b René Nussbaumer
     "Group-wide :ref:`instance policy <rapi-ipolicy>` specs"),
1782 483be60d Adeodato Simo
    ]
1783 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1784 b1ee5610 Adeodato Simo
1785 b1ee5610 Adeodato Simo
1786 934704ae Iustin Pop
class OpGroupAssignNodes(OpCode):
1787 96276ae7 Adeodato Simo
  """Assign nodes to a node group."""
1788 96276ae7 Adeodato Simo
  OP_DSC_FIELD = "group_name"
1789 96276ae7 Adeodato Simo
  OP_PARAMS = [
1790 96276ae7 Adeodato Simo
    _PGroupName,
1791 96276ae7 Adeodato Simo
    _PForce,
1792 45d4c81c Michael Hanselmann
    ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
1793 45d4c81c Michael Hanselmann
     "List of nodes to assign"),
1794 1c3231aa Thomas Thrainer
    ("node_uuids", None, ht.TMaybeListOf(ht.TNonEmptyString),
1795 1c3231aa Thomas Thrainer
     "List of node UUIDs to assign"),
1796 96276ae7 Adeodato Simo
    ]
1797 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1798 96276ae7 Adeodato Simo
1799 96276ae7 Adeodato Simo
1800 d4d654bd Iustin Pop
class OpGroupQuery(OpCode):
1801 70a6a926 Adeodato Simo
  """Compute the list of node groups."""
1802 65e183af Michael Hanselmann
  OP_PARAMS = [
1803 65e183af Michael Hanselmann
    _POutputFields,
1804 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1805 45d4c81c Michael Hanselmann
     "Empty list to query all groups, group names otherwise"),
1806 65e183af Michael Hanselmann
    ]
1807 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1808 70a6a926 Adeodato Simo
1809 70a6a926 Adeodato Simo
1810 7cbf74f0 Iustin Pop
class OpGroupSetParams(OpCode):
1811 4da7909a Adeodato Simo
  """Change the parameters of a node group."""
1812 4da7909a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1813 65e183af Michael Hanselmann
  OP_PARAMS = [
1814 65e183af Michael Hanselmann
    _PGroupName,
1815 45d4c81c Michael Hanselmann
    _PNodeGroupAllocPolicy,
1816 45d4c81c Michael Hanselmann
    _PGroupNodeParams,
1817 bc5d0215 Andrea Spadaccini
    _PDiskParams,
1818 a8282327 René Nussbaumer
    _PHvState,
1819 a8282327 René Nussbaumer
    _PDiskState,
1820 fb644e77 Agata Murawska
    ("ipolicy", None, ht.TMaybeDict, "Group-wide instance policy specs"),
1821 4da7909a Adeodato Simo
    ]
1822 1456df62 Michael Hanselmann
  OP_RESULT = _TSetParamsResult
1823 4da7909a Adeodato Simo
1824 4da7909a Adeodato Simo
1825 4d1baa51 Iustin Pop
class OpGroupRemove(OpCode):
1826 94bd652a Adeodato Simo
  """Remove a node group from the cluster."""
1827 94bd652a Adeodato Simo
  OP_DSC_FIELD = "group_name"
1828 65e183af Michael Hanselmann
  OP_PARAMS = [
1829 65e183af Michael Hanselmann
    _PGroupName,
1830 65e183af Michael Hanselmann
    ]
1831 c363310d René Nussbaumer
  OP_RESULT = ht.TNone
1832 94bd652a Adeodato Simo
1833 94bd652a Adeodato Simo
1834 a8173e82 Iustin Pop
class OpGroupRename(OpCode):
1835 4fe5cf90 Adeodato Simo
  """Rename a node group in the cluster."""
1836 65e183af Michael Hanselmann
  OP_PARAMS = [
1837 12da663a Michael Hanselmann
    _PGroupName,
1838 12da663a Michael Hanselmann
    ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"),
1839 65e183af Michael Hanselmann
    ]
1840 1456df62 Michael Hanselmann
  OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
1841 4fe5cf90 Adeodato Simo
1842 4fe5cf90 Adeodato Simo
1843 08f8c82c Michael Hanselmann
class OpGroupEvacuate(OpCode):
1844 08f8c82c Michael Hanselmann
  """Evacuate a node group in the cluster."""
1845 08f8c82c Michael Hanselmann
  OP_DSC_FIELD = "group_name"
1846 08f8c82c Michael Hanselmann
  OP_PARAMS = [
1847 08f8c82c Michael Hanselmann
    _PGroupName,
1848 08f8c82c Michael Hanselmann
    _PEarlyRelease,
1849 89514061 Iustin Pop
    _PIAllocFromDesc("Iallocator for computing solution"),
1850 911ee606 Michael Hanselmann
    _PTargetGroups,
1851 08f8c82c Michael Hanselmann
    ]
1852 1456df62 Michael Hanselmann
  OP_RESULT = TJobIdListOnly
1853 08f8c82c Michael Hanselmann
1854 08f8c82c Michael Hanselmann
1855 a8083063 Iustin Pop
# OS opcodes
1856 da2d02e7 Iustin Pop
class OpOsDiagnose(OpCode):
1857 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
1858 65e183af Michael Hanselmann
  OP_PARAMS = [
1859 65e183af Michael Hanselmann
    _POutputFields,
1860 45d4c81c Michael Hanselmann
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1861 45d4c81c Michael Hanselmann
     "Which operating systems to diagnose"),
1862 65e183af Michael Hanselmann
    ]
1863 415feb2e René Nussbaumer
  OP_RESULT = _TOldQueryResult
1864 a8083063 Iustin Pop
1865 7c0d6283 Michael Hanselmann
1866 b954f097 Constantinos Venetsanopoulos
# ExtStorage opcodes
1867 b954f097 Constantinos Venetsanopoulos
class OpExtStorageDiagnose(OpCode):
1868 b954f097 Constantinos Venetsanopoulos
  """Compute the list of external storage providers."""
1869 b954f097 Constantinos Venetsanopoulos
  OP_PARAMS = [
1870 b954f097 Constantinos Venetsanopoulos
    _POutputFields,
1871 b954f097 Constantinos Venetsanopoulos
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1872 b954f097 Constantinos Venetsanopoulos
     "Which ExtStorage Provider to diagnose"),
1873 b954f097 Constantinos Venetsanopoulos
    ]
1874 b954f097 Constantinos Venetsanopoulos
  OP_RESULT = _TOldQueryResult
1875 b954f097 Constantinos Venetsanopoulos
1876 b954f097 Constantinos Venetsanopoulos
1877 a8083063 Iustin Pop
# Exports opcodes
1878 7ca2d4d8 Iustin Pop
class OpBackupQuery(OpCode):
1879 a8083063 Iustin Pop
  """Compute the list of exported images."""
1880 65e183af Michael Hanselmann
  OP_PARAMS = [
1881 45d4c81c Michael Hanselmann
    _PUseLocking,
1882 45d4c81c Michael Hanselmann
    ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
1883 45d4c81c Michael Hanselmann
     "Empty list to query all nodes, node names otherwise"),
1884 65e183af Michael Hanselmann
    ]
1885 202fb4e0 Michael Hanselmann
  OP_RESULT = ht.TDictOf(ht.TNonEmptyString,
1886 202fb4e0 Michael Hanselmann
                         ht.TOr(ht.Comment("False on error")(ht.TBool),
1887 202fb4e0 Michael Hanselmann
                                ht.TListOf(ht.TNonEmptyString)))
1888 a8083063 Iustin Pop
1889 7c0d6283 Michael Hanselmann
1890 71910715 Iustin Pop
class OpBackupPrepare(OpCode):
1891 1410fa8d Michael Hanselmann
  """Prepares an instance export.
1892 1410fa8d Michael Hanselmann

1893 1410fa8d Michael Hanselmann
  @ivar instance_name: Instance name
1894 1410fa8d Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1895 1410fa8d Michael Hanselmann

1896 1410fa8d Michael Hanselmann
  """
1897 1410fa8d Michael Hanselmann
  OP_DSC_FIELD = "instance_name"
1898 65e183af Michael Hanselmann
  OP_PARAMS = [
1899 65e183af Michael Hanselmann
    _PInstanceName,
1900 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1901 45d4c81c Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
1902 45d4c81c Michael Hanselmann
     "Export mode"),
1903 1410fa8d Michael Hanselmann
    ]
1904 fd9f58fd Iustin Pop
  OP_RESULT = ht.TMaybeDict
1905 1410fa8d Michael Hanselmann
1906 1410fa8d Michael Hanselmann
1907 4ff922a2 Iustin Pop
class OpBackupExport(OpCode):
1908 4a96f1d1 Michael Hanselmann
  """Export an instance.
1909 4a96f1d1 Michael Hanselmann

1910 398e9066 Iustin Pop
  For local exports, the export destination is the node name. For
1911 398e9066 Iustin Pop
  remote exports, the export destination is a list of tuples, each
1912 398e9066 Iustin Pop
  consisting of hostname/IP address, port, magic, HMAC and HMAC
1913 398e9066 Iustin Pop
  salt. The HMAC is calculated using the cluster domain secret over
1914 398e9066 Iustin Pop
  the value "${index}:${hostname}:${port}". The destination X509 CA
1915 398e9066 Iustin Pop
  must be a signed certificate.
1916 4a96f1d1 Michael Hanselmann

1917 4a96f1d1 Michael Hanselmann
  @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
1918 4a96f1d1 Michael Hanselmann
  @ivar target_node: Export destination
1919 4a96f1d1 Michael Hanselmann
  @ivar x509_key_name: X509 key to use (remote export only)
1920 4a96f1d1 Michael Hanselmann
  @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
1921 4a96f1d1 Michael Hanselmann
                             only)
1922 4a96f1d1 Michael Hanselmann

1923 4a96f1d1 Michael Hanselmann
  """
1924 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1925 65e183af Michael Hanselmann
  OP_PARAMS = [
1926 65e183af Michael Hanselmann
    _PInstanceName,
1927 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1928 65e183af Michael Hanselmann
    _PShutdownTimeout,
1929 4a96f1d1 Michael Hanselmann
    # TODO: Rename target_node as it changes meaning for different export modes
1930 4a96f1d1 Michael Hanselmann
    # (e.g. "destination")
1931 45d4c81c Michael Hanselmann
    ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
1932 45d4c81c Michael Hanselmann
     "Destination information, depends on export mode"),
1933 1c3231aa Thomas Thrainer
    ("target_node_uuid", None, ht.TMaybeString,
1934 1c3231aa Thomas Thrainer
     "Target node UUID (if local export)"),
1935 45d4c81c Michael Hanselmann
    ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"),
1936 45d4c81c Michael Hanselmann
    ("remove_instance", False, ht.TBool,
1937 45d4c81c Michael Hanselmann
     "Whether to remove instance after export"),
1938 45d4c81c Michael Hanselmann
    ("ignore_remove_failures", False, ht.TBool,
1939 45d4c81c Michael Hanselmann
     "Whether to ignore failures while removing instances"),
1940 45d4c81c Michael Hanselmann
    ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
1941 45d4c81c Michael Hanselmann
     "Export mode"),
1942 fd9f58fd Iustin Pop
    ("x509_key_name", None, ht.TMaybe(ht.TList),
1943 45d4c81c Michael Hanselmann
     "Name of X509 key (remote export only)"),
1944 45d4c81c Michael Hanselmann
    ("destination_x509_ca", None, ht.TMaybeString,
1945 45d4c81c Michael Hanselmann
     "Destination X509 CA (remote export only)"),
1946 17c3f802 Guido Trotter
    ]
1947 202fb4e0 Michael Hanselmann
  OP_RESULT = \
1948 202fb4e0 Michael Hanselmann
    ht.TAnd(ht.TIsLength(2), ht.TItems([
1949 202fb4e0 Michael Hanselmann
      ht.Comment("Finalizing status")(ht.TBool),
1950 202fb4e0 Michael Hanselmann
      ht.Comment("Status for every exported disk")(ht.TListOf(ht.TBool)),
1951 202fb4e0 Michael Hanselmann
      ]))
1952 5c947f38 Iustin Pop
1953 0a7bed64 Michael Hanselmann
1954 ca5890ad Iustin Pop
class OpBackupRemove(OpCode):
1955 9ac99fda Guido Trotter
  """Remove an instance's export."""
1956 60dd1473 Iustin Pop
  OP_DSC_FIELD = "instance_name"
1957 65e183af Michael Hanselmann
  OP_PARAMS = [
1958 65e183af Michael Hanselmann
    _PInstanceName,
1959 da4a52a3 Thomas Thrainer
    _PInstanceUuid,
1960 65e183af Michael Hanselmann
    ]
1961 202fb4e0 Michael Hanselmann
  OP_RESULT = ht.TNone
1962 5c947f38 Iustin Pop
1963 0a7bed64 Michael Hanselmann
1964 5c947f38 Iustin Pop
# Tags opcodes
1965 c6afb1ca Iustin Pop
class OpTagsGet(OpCode):
1966 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
1967 60dd1473 Iustin Pop
  OP_DSC_FIELD = "name"
1968 65e183af Michael Hanselmann
  OP_PARAMS = [
1969 65e183af Michael Hanselmann
    _PTagKind,
1970 cfdf561d Michael Hanselmann
    # Not using _PUseLocking as the default is different for historical reasons
1971 cfdf561d Michael Hanselmann
    ("use_locking", True, ht.TBool, "Whether to use synchronization"),
1972 65e183af Michael Hanselmann
    # Name is only meaningful for nodes and instances
1973 971b3a98 Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString,
1974 971b3a98 Michael Hanselmann
     "Name of object to retrieve tags from"),
1975 65e183af Michael Hanselmann
    ]
1976 48796673 Michael Hanselmann
  OP_RESULT = ht.TListOf(ht.TNonEmptyString)
1977 5c947f38 Iustin Pop
1978 5c947f38 Iustin Pop
1979 715462e7 Iustin Pop
class OpTagsSearch(OpCode):
1980 73415719 Iustin Pop
  """Searches the tags in the cluster for a given pattern."""
1981 60dd1473 Iustin Pop
  OP_DSC_FIELD = "pattern"
1982 65e183af Michael Hanselmann
  OP_PARAMS = [
1983 971b3a98 Michael Hanselmann
    ("pattern", ht.NoDefault, ht.TNonEmptyString,
1984 971b3a98 Michael Hanselmann
     "Search pattern (regular expression)"),
1985 65e183af Michael Hanselmann
    ]
1986 48796673 Michael Hanselmann
  OP_RESULT = ht.TListOf(ht.TAnd(ht.TIsLength(2), ht.TItems([
1987 48796673 Michael Hanselmann
    ht.TNonEmptyString,
1988 48796673 Michael Hanselmann
    ht.TNonEmptyString,
1989 48796673 Michael Hanselmann
    ])))
1990 73415719 Iustin Pop
1991 73415719 Iustin Pop
1992 d1602edc Iustin Pop
class OpTagsSet(OpCode):
1993 f27302fa Iustin Pop
  """Add a list of tags on a given object."""
1994 65e183af Michael Hanselmann
  OP_PARAMS = [
1995 65e183af Michael Hanselmann
    _PTagKind,
1996 65e183af Michael Hanselmann
    _PTags,
1997 bcd35e09 Dato Simó
    # Name is only meaningful for groups, nodes and instances
1998 971b3a98 Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString,
1999 971b3a98 Michael Hanselmann
     "Name of object where tag(s) should be added"),
2000 65e183af Michael Hanselmann
    ]
2001 48796673 Michael Hanselmann
  OP_RESULT = ht.TNone
2002 5c947f38 Iustin Pop
2003 5c947f38 Iustin Pop
2004 3f0ab95f Iustin Pop
class OpTagsDel(OpCode):
2005 f27302fa Iustin Pop
  """Remove a list of tags from a given object."""
2006 65e183af Michael Hanselmann
  OP_PARAMS = [
2007 65e183af Michael Hanselmann
    _PTagKind,
2008 65e183af Michael Hanselmann
    _PTags,
2009 bcd35e09 Dato Simó
    # Name is only meaningful for groups, nodes and instances
2010 971b3a98 Michael Hanselmann
    ("name", ht.NoDefault, ht.TMaybeString,
2011 971b3a98 Michael Hanselmann
     "Name of object where tag(s) should be deleted"),
2012 65e183af Michael Hanselmann
    ]
2013 48796673 Michael Hanselmann
  OP_RESULT = ht.TNone
2014 06009e27 Iustin Pop
2015 e687ec01 Michael Hanselmann
2016 06009e27 Iustin Pop
# Test opcodes
2017 06009e27 Iustin Pop
class OpTestDelay(OpCode):
2018 06009e27 Iustin Pop
  """Sleeps for a configured amount of time.
2019 06009e27 Iustin Pop

2020 06009e27 Iustin Pop
  This is used just for debugging and testing.
2021 06009e27 Iustin Pop

2022 06009e27 Iustin Pop
  Parameters:
2023 aeb6ba44 Dato Simó
    - duration: the time to sleep, in seconds
2024 06009e27 Iustin Pop
    - on_master: if true, sleep on the master
2025 06009e27 Iustin Pop
    - on_nodes: list of nodes in which to sleep
2026 06009e27 Iustin Pop

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

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

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

2037 06009e27 Iustin Pop
  """
2038 60dd1473 Iustin Pop
  OP_DSC_FIELD = "duration"
2039 65e183af Michael Hanselmann
  OP_PARAMS = [
2040 b795a775 Michael Hanselmann
    ("duration", ht.NoDefault, ht.TNumber, None),
2041 197b323b Michael Hanselmann
    ("on_master", True, ht.TBool, None),
2042 197b323b Michael Hanselmann
    ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
2043 1c3231aa Thomas Thrainer
    ("on_node_uuids", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
2044 2c9fa1ff Iustin Pop
    ("repeat", 0, ht.TNonNegativeInt, None),
2045 65e183af Michael Hanselmann
    ]
2046 d61df03e Iustin Pop
2047 8bc17ebb Iustin Pop
  def OP_DSC_FORMATTER(self, value): # pylint: disable=C0103,R0201
2048 8bc17ebb Iustin Pop
    """Custom formatter for duration.
2049 8bc17ebb Iustin Pop

2050 8bc17ebb Iustin Pop
    """
2051 8bc17ebb Iustin Pop
    try:
2052 8bc17ebb Iustin Pop
      v = float(value)
2053 8bc17ebb Iustin Pop
    except TypeError:
2054 8bc17ebb Iustin Pop
      v = value
2055 8bc17ebb Iustin Pop
    return str(v)
2056 8bc17ebb Iustin Pop
2057 d61df03e Iustin Pop
2058 d61df03e Iustin Pop
class OpTestAllocator(OpCode):
2059 d61df03e Iustin Pop
  """Allocator framework testing.
2060 d61df03e Iustin Pop

2061 d61df03e Iustin Pop
  This opcode has two modes:
2062 d61df03e Iustin Pop
    - gather and return allocator input for a given mode (allocate new
2063 d61df03e Iustin Pop
      or replace secondary) and a given instance definition (direction
2064 d61df03e Iustin Pop
      'in')
2065 d61df03e Iustin Pop
    - run a selected allocator for a given operation (as above) and
2066 d61df03e Iustin Pop
      return the allocator output (direction 'out')
2067 d61df03e Iustin Pop

2068 d61df03e Iustin Pop
  """
2069 55b7e783 Iustin Pop
  OP_DSC_FIELD = "iallocator"
2070 65e183af Michael Hanselmann
  OP_PARAMS = [
2071 65e183af Michael Hanselmann
    ("direction", ht.NoDefault,
2072 197b323b Michael Hanselmann
     ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
2073 197b323b Michael Hanselmann
    ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None),
2074 197b323b Michael Hanselmann
    ("name", ht.NoDefault, ht.TNonEmptyString, None),
2075 ff8067cf Michael Hanselmann
    ("nics", ht.NoDefault,
2076 ff8067cf Michael Hanselmann
     ht.TMaybeListOf(ht.TDictOf(ht.TElemOf([constants.INIC_MAC,
2077 ff8067cf Michael Hanselmann
                                            constants.INIC_IP,
2078 ff8067cf Michael Hanselmann
                                            "bridge"]),
2079 fd9f58fd Iustin Pop
                                ht.TMaybeString)),
2080 ff8067cf Michael Hanselmann
     None),
2081 fd9f58fd Iustin Pop
    ("disks", ht.NoDefault, ht.TMaybe(ht.TList), None),
2082 197b323b Michael Hanselmann
    ("hypervisor", None, ht.TMaybeString, None),
2083 55b7e783 Iustin Pop
    _PIAllocFromDesc(None),
2084 197b323b Michael Hanselmann
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None),
2085 fd9f58fd Iustin Pop
    ("memory", None, ht.TMaybe(ht.TNonNegativeInt), None),
2086 fd9f58fd Iustin Pop
    ("vcpus", None, ht.TMaybe(ht.TNonNegativeInt), None),
2087 197b323b Michael Hanselmann
    ("os", None, ht.TMaybeString, None),
2088 197b323b Michael Hanselmann
    ("disk_template", None, ht.TMaybeString, None),
2089 ff8067cf Michael Hanselmann
    ("instances", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
2090 60152bbe Michael Hanselmann
    ("evac_mode", None,
2091 fd9f58fd Iustin Pop
     ht.TMaybe(ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
2092 ff8067cf Michael Hanselmann
    ("target_groups", None, ht.TMaybeListOf(ht.TNonEmptyString), None),
2093 2c9fa1ff Iustin Pop
    ("spindle_use", 1, ht.TNonNegativeInt, None),
2094 2c9fa1ff Iustin Pop
    ("count", 1, ht.TNonNegativeInt, None),
2095 d61df03e Iustin Pop
    ]
2096 363acb1e Iustin Pop
2097 76aef8fc Michael Hanselmann
2098 b469eb4d Iustin Pop
class OpTestJqueue(OpCode):
2099 e58f87a9 Michael Hanselmann
  """Utility opcode to test some aspects of the job queue.
2100 e58f87a9 Michael Hanselmann

2101 e58f87a9 Michael Hanselmann
  """
2102 65e183af Michael Hanselmann
  OP_PARAMS = [
2103 197b323b Michael Hanselmann
    ("notify_waitlock", False, ht.TBool, None),
2104 197b323b Michael Hanselmann
    ("notify_exec", False, ht.TBool, None),
2105 197b323b Michael Hanselmann
    ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None),
2106 197b323b Michael Hanselmann
    ("fail", False, ht.TBool, None),
2107 e58f87a9 Michael Hanselmann
    ]
2108 e58f87a9 Michael Hanselmann
2109 e58f87a9 Michael Hanselmann
2110 be760ba8 Michael Hanselmann
class OpTestDummy(OpCode):
2111 be760ba8 Michael Hanselmann
  """Utility opcode used by unittests.
2112 be760ba8 Michael Hanselmann

2113 be760ba8 Michael Hanselmann
  """
2114 65e183af Michael Hanselmann
  OP_PARAMS = [
2115 197b323b Michael Hanselmann
    ("result", ht.NoDefault, ht.NoType, None),
2116 197b323b Michael Hanselmann
    ("messages", ht.NoDefault, ht.NoType, None),
2117 197b323b Michael Hanselmann
    ("fail", ht.NoDefault, ht.NoType, None),
2118 6a373640 Michael Hanselmann
    ("submit_jobs", None, ht.NoType, None),
2119 be760ba8 Michael Hanselmann
    ]
2120 687c10d9 Iustin Pop
  WITH_LU = False
2121 be760ba8 Michael Hanselmann
2122 be760ba8 Michael Hanselmann
2123 eaa4c57c Dimitris Aragiorgis
# Network opcodes
2124 eaa4c57c Dimitris Aragiorgis
# Add a new network in the cluster
2125 eaa4c57c Dimitris Aragiorgis
class OpNetworkAdd(OpCode):
2126 eaa4c57c Dimitris Aragiorgis
  """Add an IP network to the cluster."""
2127 eaa4c57c Dimitris Aragiorgis
  OP_DSC_FIELD = "network_name"
2128 eaa4c57c Dimitris Aragiorgis
  OP_PARAMS = [
2129 eaa4c57c Dimitris Aragiorgis
    _PNetworkName,
2130 e1494c96 Iustin Pop
    ("network", ht.NoDefault, _TIpNetwork4, "IPv4 subnet"),
2131 e1494c96 Iustin Pop
    ("gateway", None, ht.TMaybe(_TIpAddress4), "IPv4 gateway"),
2132 e1494c96 Iustin Pop
    ("network6", None, ht.TMaybe(_TIpNetwork6), "IPv6 subnet"),
2133 e1494c96 Iustin Pop
    ("gateway6", None, ht.TMaybe(_TIpAddress6), "IPv6 gateway"),
2134 6e8091f9 Dimitris Aragiorgis
    ("mac_prefix", None, ht.TMaybeString,
2135 32e3d8b1 Michael Hanselmann
     "MAC address prefix that overrides cluster one"),
2136 e1494c96 Iustin Pop
    ("add_reserved_ips", None, _TMaybeAddr4List,
2137 32e3d8b1 Michael Hanselmann
     "Which IP addresses to reserve"),
2138 213076fe Dimitris Aragiorgis
    ("conflicts_check", True, ht.TBool,
2139 213076fe Dimitris Aragiorgis
     "Whether to check for conflicting IP addresses"),
2140 8140e24f Dimitris Aragiorgis
    ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Network tags"),
2141 eaa4c57c Dimitris Aragiorgis
    ]
2142 6e8091f9 Dimitris Aragiorgis
  OP_RESULT = ht.TNone
2143 eaa4c57c Dimitris Aragiorgis
2144 3c286190 Dimitris Aragiorgis
2145 eaa4c57c Dimitris Aragiorgis
class OpNetworkRemove(OpCode):
2146 eaa4c57c Dimitris Aragiorgis
  """Remove an existing network from the cluster.
2147 eaa4c57c Dimitris Aragiorgis
     Must not be connected to any nodegroup.
2148 eaa4c57c Dimitris Aragiorgis

2149 eaa4c57c Dimitris Aragiorgis
  """
2150 eaa4c57c Dimitris Aragiorgis
  OP_DSC_FIELD = "network_name"
2151 eaa4c57c Dimitris Aragiorgis
  OP_PARAMS = [
2152 eaa4c57c Dimitris Aragiorgis
    _PNetworkName,
2153 eaa4c57c Dimitris Aragiorgis
    _PForce,
2154 eaa4c57c Dimitris Aragiorgis
    ]
2155 6e8091f9 Dimitris Aragiorgis
  OP_RESULT = ht.TNone
2156 eaa4c57c Dimitris Aragiorgis
2157 3c286190 Dimitris Aragiorgis
2158 eaa4c57c Dimitris Aragiorgis
class OpNetworkSetParams(OpCode):
2159 eaa4c57c Dimitris Aragiorgis
  """Modify Network's parameters except for IPv4 subnet"""
2160 eaa4c57c Dimitris Aragiorgis
  OP_DSC_FIELD = "network_name"
2161 eaa4c57c Dimitris Aragiorgis
  OP_PARAMS = [
2162 eaa4c57c Dimitris Aragiorgis
    _PNetworkName,
2163 e055a2ab Dimitris Aragiorgis
    ("gateway", None, ht.TMaybeValueNone(_TIpAddress4), "IPv4 gateway"),
2164 e055a2ab Dimitris Aragiorgis
    ("network6", None, ht.TMaybeValueNone(_TIpNetwork6), "IPv6 subnet"),
2165 e055a2ab Dimitris Aragiorgis
    ("gateway6", None, ht.TMaybeValueNone(_TIpAddress6), "IPv6 gateway"),
2166 e055a2ab Dimitris Aragiorgis
    ("mac_prefix", None, ht.TMaybeValueNone(ht.TString),
2167 32e3d8b1 Michael Hanselmann
     "MAC address prefix that overrides cluster one"),
2168 e1494c96 Iustin Pop
    ("add_reserved_ips", None, _TMaybeAddr4List,
2169 32e3d8b1 Michael Hanselmann
     "Which external IP addresses to reserve"),
2170 e1494c96 Iustin Pop
    ("remove_reserved_ips", None, _TMaybeAddr4List,
2171 32e3d8b1 Michael Hanselmann
     "Which external IP addresses to release"),
2172 eaa4c57c Dimitris Aragiorgis
    ]
2173 6e8091f9 Dimitris Aragiorgis
  OP_RESULT = ht.TNone
2174 eaa4c57c Dimitris Aragiorgis
2175 3c286190 Dimitris Aragiorgis
2176 eaa4c57c Dimitris Aragiorgis
class OpNetworkConnect(OpCode):
2177 eaa4c57c Dimitris Aragiorgis
  """Connect a Network to a specific Nodegroup with the defined netparams
2178 eaa4c57c Dimitris Aragiorgis
     (mode, link). Nics in this Network will inherit those params.
2179 eaa4c57c Dimitris Aragiorgis
     Produce errors if a NIC (that its not already assigned to a network)
2180 eaa4c57c Dimitris Aragiorgis
     has an IP that is contained in the Network this will produce error unless
2181 eaa4c57c Dimitris Aragiorgis
     --no-conflicts-check is passed.
2182 eaa4c57c Dimitris Aragiorgis

2183 eaa4c57c Dimitris Aragiorgis
  """
2184 eaa4c57c Dimitris Aragiorgis
  OP_DSC_FIELD = "network_name"
2185 eaa4c57c Dimitris Aragiorgis
  OP_PARAMS = [
2186 eaa4c57c Dimitris Aragiorgis
    _PGroupName,
2187 eaa4c57c Dimitris Aragiorgis
    _PNetworkName,
2188 6ef37395 Michael Hanselmann
    ("network_mode", ht.NoDefault, ht.TElemOf(constants.NIC_VALID_MODES),
2189 6ef37395 Michael Hanselmann
     "Connectivity mode"),
2190 e1494c96 Iustin Pop
    ("network_link", ht.NoDefault, ht.TString, "Connectivity link"),
2191 6e8091f9 Dimitris Aragiorgis
    ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"),
2192 eaa4c57c Dimitris Aragiorgis
    ]
2193 6e8091f9 Dimitris Aragiorgis
  OP_RESULT = ht.TNone
2194 eaa4c57c Dimitris Aragiorgis
2195 3c286190 Dimitris Aragiorgis
2196 eaa4c57c Dimitris Aragiorgis
class OpNetworkDisconnect(OpCode):
2197 eaa4c57c Dimitris Aragiorgis
  """Disconnect a Network from a Nodegroup. Produce errors if NICs are
2198 eaa4c57c Dimitris Aragiorgis
     present in the Network unless --no-conficts-check option is passed.
2199 eaa4c57c Dimitris Aragiorgis

2200 eaa4c57c Dimitris Aragiorgis
  """
2201 eaa4c57c Dimitris Aragiorgis
  OP_DSC_FIELD = "network_name"
2202 eaa4c57c Dimitris Aragiorgis
  OP_PARAMS = [
2203 eaa4c57c Dimitris Aragiorgis
    _PGroupName,
2204 eaa4c57c Dimitris Aragiorgis
    _PNetworkName,
2205 eaa4c57c Dimitris Aragiorgis
    ]
2206 6e8091f9 Dimitris Aragiorgis
  OP_RESULT = ht.TNone
2207 eaa4c57c Dimitris Aragiorgis
2208 3c286190 Dimitris Aragiorgis
2209 eaa4c57c Dimitris Aragiorgis
class OpNetworkQuery(OpCode):
2210 eaa4c57c Dimitris Aragiorgis
  """Compute the list of networks."""
2211 eaa4c57c Dimitris Aragiorgis
  OP_PARAMS = [
2212 eaa4c57c Dimitris Aragiorgis
    _POutputFields,
2213 8d459129 Michael Hanselmann
    _PUseLocking,
2214 eaa4c57c Dimitris Aragiorgis
    ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
2215 eaa4c57c Dimitris Aragiorgis
     "Empty list to query all groups, group names otherwise"),
2216 eaa4c57c Dimitris Aragiorgis
    ]
2217 829cfbc5 Dimitris Aragiorgis
  OP_RESULT = _TOldQueryResult
2218 eaa4c57c Dimitris Aragiorgis
2219 eaa4c57c Dimitris Aragiorgis
2220 dbc96028 Michael Hanselmann
def _GetOpList():
2221 dbc96028 Michael Hanselmann
  """Returns list of all defined opcodes.
2222 dbc96028 Michael Hanselmann

2223 dbc96028 Michael Hanselmann
  Does not eliminate duplicates by C{OP_ID}.
2224 dbc96028 Michael Hanselmann

2225 dbc96028 Michael Hanselmann
  """
2226 dbc96028 Michael Hanselmann
  return [v for v in globals().values()
2227 dbc96028 Michael Hanselmann
          if (isinstance(v, type) and issubclass(v, OpCode) and
2228 687c10d9 Iustin Pop
              hasattr(v, "OP_ID") and v is not OpCode)]
2229 dbc96028 Michael Hanselmann
2230 dbc96028 Michael Hanselmann
2231 dbc96028 Michael Hanselmann
OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList())