root / lib / opcodes.py @ 57de31c0
History | View | Annotate | Download (51.5 kB)
1 | 2f31098c | Iustin Pop | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | 687c10d9 | Iustin Pop | # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc.
|
5 | a8083063 | Iustin Pop | #
|
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | a8083063 | Iustin Pop | # (at your option) any later version.
|
10 | a8083063 | Iustin Pop | #
|
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | a8083063 | Iustin Pop | # General Public License for more details.
|
15 | a8083063 | Iustin Pop | #
|
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | a8083063 | Iustin Pop | # 02110-1301, USA.
|
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | """OpCodes module
|
23 | a8083063 | Iustin Pop |
|
24 | a8083063 | Iustin Pop | This module implements the data structures which define the cluster
|
25 | a8083063 | Iustin Pop | operations - the so-called opcodes.
|
26 | a8083063 | Iustin Pop |
|
27 | 0e46916d | Iustin Pop | Every operation which modifies the cluster state is expressed via
|
28 | 0e46916d | Iustin Pop | opcodes.
|
29 | a8083063 | Iustin Pop |
|
30 | a8083063 | Iustin Pop | """
|
31 | a8083063 | Iustin Pop | |
32 | a8083063 | Iustin Pop | # this are practically structures, so disable the message about too
|
33 | a8083063 | Iustin Pop | # few public methods:
|
34 | b459a848 | Andrea Spadaccini | # pylint: disable=R0903
|
35 | a8083063 | Iustin Pop | |
36 | 1cbef6d8 | Michael Hanselmann | import logging |
37 | ff0d18e6 | Iustin Pop | import re |
38 | 1cbef6d8 | Michael Hanselmann | |
39 | eb62069e | Iustin Pop | from ganeti import compat |
40 | 65e183af | Michael Hanselmann | from ganeti import constants |
41 | 65e183af | Michael Hanselmann | from ganeti import errors |
42 | 65e183af | Michael Hanselmann | from ganeti import ht |
43 | 65e183af | Michael Hanselmann | |
44 | 65e183af | Michael Hanselmann | |
45 | 65e183af | Michael Hanselmann | # Common opcode attributes
|
46 | 65e183af | Michael Hanselmann | |
47 | 65e183af | Michael Hanselmann | #: output fields for a query operation
|
48 | 197b323b | Michael Hanselmann | _POutputFields = ("output_fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
|
49 | 45d4c81c | Michael Hanselmann | "Selected output fields")
|
50 | 65e183af | Michael Hanselmann | |
51 | 65e183af | Michael Hanselmann | #: the shutdown timeout
|
52 | 45d4c81c | Michael Hanselmann | _PShutdownTimeout = \ |
53 | 45d4c81c | Michael Hanselmann | ("shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
|
54 | 45d4c81c | Michael Hanselmann | "How long to wait for instance to shut down")
|
55 | 65e183af | Michael Hanselmann | |
56 | 65e183af | Michael Hanselmann | #: the force parameter
|
57 | 45d4c81c | Michael Hanselmann | _PForce = ("force", False, ht.TBool, "Whether to force the operation") |
58 | 65e183af | Michael Hanselmann | |
59 | 65e183af | Michael Hanselmann | #: a required instance name (for single-instance LUs)
|
60 | 45d4c81c | Michael Hanselmann | _PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString,
|
61 | 45d4c81c | Michael Hanselmann | "Instance name")
|
62 | 65e183af | Michael Hanselmann | |
63 | 65e183af | Michael Hanselmann | #: Whether to ignore offline nodes
|
64 | 45d4c81c | Michael Hanselmann | _PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool, |
65 | 45d4c81c | Michael Hanselmann | "Whether to ignore offline nodes")
|
66 | 65e183af | Michael Hanselmann | |
67 | 65e183af | Michael Hanselmann | #: a required node name (for single-node LUs)
|
68 | 45d4c81c | Michael Hanselmann | _PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString, "Node name") |
69 | 65e183af | Michael Hanselmann | |
70 | 65e183af | Michael Hanselmann | #: a required node group name (for single-group LUs)
|
71 | 45d4c81c | Michael Hanselmann | _PGroupName = ("group_name", ht.NoDefault, ht.TNonEmptyString, "Group name") |
72 | 65e183af | Michael Hanselmann | |
73 | 65e183af | Michael Hanselmann | #: Migration type (live/non-live)
|
74 | 65e183af | Michael Hanselmann | _PMigrationMode = ("mode", None, |
75 | 197b323b | Michael Hanselmann | ht.TOr(ht.TNone, ht.TElemOf(constants.HT_MIGRATION_MODES)), |
76 | 45d4c81c | Michael Hanselmann | "Migration mode")
|
77 | 65e183af | Michael Hanselmann | |
78 | 65e183af | Michael Hanselmann | #: Obsolete 'live' migration mode (boolean)
|
79 | 45d4c81c | Michael Hanselmann | _PMigrationLive = ("live", None, ht.TMaybeBool, |
80 | 45d4c81c | Michael Hanselmann | "Legacy setting for live migration, do not use")
|
81 | 65e183af | Michael Hanselmann | |
82 | 65e183af | Michael Hanselmann | #: Tag type
|
83 | 197b323b | Michael Hanselmann | _PTagKind = ("kind", ht.NoDefault, ht.TElemOf(constants.VALID_TAG_TYPES), None) |
84 | 65e183af | Michael Hanselmann | |
85 | 65e183af | Michael Hanselmann | #: List of tag strings
|
86 | 197b323b | Michael Hanselmann | _PTags = ("tags", ht.NoDefault, ht.TListOf(ht.TNonEmptyString), None) |
87 | 65e183af | Michael Hanselmann | |
88 | 45d4c81c | Michael Hanselmann | _PForceVariant = ("force_variant", False, ht.TBool, |
89 | 45d4c81c | Michael Hanselmann | "Whether to force an unknown OS variant")
|
90 | 45d4c81c | Michael Hanselmann | |
91 | 45d4c81c | Michael Hanselmann | _PWaitForSync = ("wait_for_sync", True, ht.TBool, |
92 | 45d4c81c | Michael Hanselmann | "Whether to wait for the disk to synchronize")
|
93 | 45d4c81c | Michael Hanselmann | |
94 | 45d4c81c | Michael Hanselmann | _PIgnoreConsistency = ("ignore_consistency", False, ht.TBool, |
95 | 45d4c81c | Michael Hanselmann | "Whether to ignore disk consistency")
|
96 | 45d4c81c | Michael Hanselmann | |
97 | 45d4c81c | Michael Hanselmann | _PStorageName = ("name", ht.NoDefault, ht.TMaybeString, "Storage name") |
98 | 45d4c81c | Michael Hanselmann | |
99 | 45d4c81c | Michael Hanselmann | _PUseLocking = ("use_locking", False, ht.TBool, |
100 | 45d4c81c | Michael Hanselmann | "Whether to use synchronization")
|
101 | 45d4c81c | Michael Hanselmann | |
102 | 45d4c81c | Michael Hanselmann | _PNameCheck = ("name_check", True, ht.TBool, "Whether to check name") |
103 | 45d4c81c | Michael Hanselmann | |
104 | 45d4c81c | Michael Hanselmann | _PNodeGroupAllocPolicy = \ |
105 | 45d4c81c | Michael Hanselmann | ("alloc_policy", None, |
106 | 45d4c81c | Michael Hanselmann | ht.TOr(ht.TNone, ht.TElemOf(constants.VALID_ALLOC_POLICIES)), |
107 | 45d4c81c | Michael Hanselmann | "Instance allocation policy")
|
108 | 45d4c81c | Michael Hanselmann | |
109 | 45d4c81c | Michael Hanselmann | _PGroupNodeParams = ("ndparams", None, ht.TMaybeDict, |
110 | 45d4c81c | Michael Hanselmann | "Default node parameters for group")
|
111 | 45d4c81c | Michael Hanselmann | |
112 | abd66bf8 | Michael Hanselmann | _PQueryWhat = ("what", ht.NoDefault, ht.TElemOf(constants.QR_VIA_OP),
|
113 | 8e7078e0 | Michael Hanselmann | "Resource(s) to query for")
|
114 | 8e7078e0 | Michael Hanselmann | |
115 | e1f23243 | Michael Hanselmann | _PEarlyRelease = ("early_release", False, ht.TBool, |
116 | e1f23243 | Michael Hanselmann | "Whether to release locks as soon as possible")
|
117 | e1f23243 | Michael Hanselmann | |
118 | 45d4c81c | Michael Hanselmann | _PIpCheckDoc = "Whether to ensure instance's IP address is inactive"
|
119 | 45d4c81c | Michael Hanselmann | |
120 | 9b64e486 | Iustin Pop | #: Do not remember instance state changes
|
121 | 6aac5aef | Iustin Pop | _PNoRemember = ("no_remember", False, ht.TBool, |
122 | 6aac5aef | Iustin Pop | "Do not remember the state change")
|
123 | 9b64e486 | Iustin Pop | |
124 | f8fa4175 | Michael Hanselmann | #: Target node for instance migration/failover
|
125 | f8fa4175 | Michael Hanselmann | _PMigrationTargetNode = ("target_node", None, ht.TMaybeString, |
126 | f8fa4175 | Michael Hanselmann | "Target node for shared-storage instances")
|
127 | f8fa4175 | Michael Hanselmann | |
128 | 323f9095 | Stephen Shirley | _PStartupPaused = ("startup_paused", False, ht.TBool, |
129 | 323f9095 | Stephen Shirley | "Pause instance at startup")
|
130 | 323f9095 | Stephen Shirley | |
131 | 57106b74 | Michael Hanselmann | _PVerbose = ("verbose", False, ht.TBool, "Verbose mode") |
132 | 57106b74 | Michael Hanselmann | |
133 | 57106b74 | Michael Hanselmann | # Parameters for cluster verification
|
134 | 57106b74 | Michael Hanselmann | _PDebugSimulateErrors = ("debug_simulate_errors", False, ht.TBool, |
135 | 57106b74 | Michael Hanselmann | "Whether to simulate errors (useful for debugging)")
|
136 | 57106b74 | Michael Hanselmann | _PErrorCodes = ("error_codes", False, ht.TBool, "Error codes") |
137 | 57106b74 | Michael Hanselmann | _PSkipChecks = ("skip_checks", ht.EmptyList,
|
138 | 57106b74 | Michael Hanselmann | ht.TListOf(ht.TElemOf(constants.VERIFY_OPTIONAL_CHECKS)), |
139 | 57106b74 | Michael Hanselmann | "Which checks to skip")
|
140 | 93f2399e | Andrea Spadaccini | _PIgnoreErrors = ("ignore_errors", ht.EmptyList,
|
141 | 93f2399e | Andrea Spadaccini | ht.TListOf(ht.TElemOf(constants.CV_ALL_ECODES_STRINGS)), |
142 | 93f2399e | Andrea Spadaccini | "List of error codes that should be treated as warnings")
|
143 | 323f9095 | Stephen Shirley | |
144 | ff0d18e6 | Iustin Pop | #: OP_ID conversion regular expression
|
145 | ff0d18e6 | Iustin Pop | _OPID_RE = re.compile("([a-z])([A-Z])")
|
146 | ff0d18e6 | Iustin Pop | |
147 | 8c9ee749 | Michael Hanselmann | #: Utility function for L{OpClusterSetParams}
|
148 | 8c9ee749 | Michael Hanselmann | _TestClusterOsList = ht.TOr(ht.TNone, |
149 | 8c9ee749 | Michael Hanselmann | ht.TListOf(ht.TAnd(ht.TList, ht.TIsLength(2),
|
150 | eb62069e | Iustin Pop | ht.TMap(ht.WithDesc("GetFirstItem")(compat.fst),
|
151 | 8c9ee749 | Michael Hanselmann | ht.TElemOf(constants.DDMS_VALUES))))) |
152 | 8c9ee749 | Michael Hanselmann | |
153 | ff0d18e6 | Iustin Pop | |
154 | 526a662a | Michael Hanselmann | # TODO: Generate check from constants.INIC_PARAMS_TYPES
|
155 | 526a662a | Michael Hanselmann | #: Utility function for testing NIC definitions
|
156 | 526a662a | Michael Hanselmann | _TestNicDef = ht.TDictOf(ht.TElemOf(constants.INIC_PARAMS), |
157 | 526a662a | Michael Hanselmann | ht.TOr(ht.TNone, ht.TNonEmptyString)) |
158 | 526a662a | Michael Hanselmann | |
159 | 1456df62 | Michael Hanselmann | _TSetParamsResultItemItems = [ |
160 | 1456df62 | Michael Hanselmann | ht.Comment("name of changed parameter")(ht.TNonEmptyString),
|
161 | b3d2ee31 | Michael Hanselmann | ht.Comment("new value")(ht.TAny),
|
162 | 1456df62 | Michael Hanselmann | ] |
163 | 1456df62 | Michael Hanselmann | |
164 | 1456df62 | Michael Hanselmann | _TSetParamsResult = \ |
165 | 1456df62 | Michael Hanselmann | ht.TListOf(ht.TAnd(ht.TIsLength(len(_TSetParamsResultItemItems)),
|
166 | 1456df62 | Michael Hanselmann | ht.TItems(_TSetParamsResultItemItems))) |
167 | 1456df62 | Michael Hanselmann | |
168 | 3ce9a5e7 | Michael Hanselmann | _SUMMARY_PREFIX = { |
169 | 3ce9a5e7 | Michael Hanselmann | "CLUSTER_": "C_", |
170 | 3ce9a5e7 | Michael Hanselmann | "GROUP_": "G_", |
171 | 3ce9a5e7 | Michael Hanselmann | "NODE_": "N_", |
172 | 3ce9a5e7 | Michael Hanselmann | "INSTANCE_": "I_", |
173 | 3ce9a5e7 | Michael Hanselmann | } |
174 | 3ce9a5e7 | Michael Hanselmann | |
175 | b95479a5 | Michael Hanselmann | #: Attribute name for dependencies
|
176 | b95479a5 | Michael Hanselmann | DEPEND_ATTR = "depends"
|
177 | b95479a5 | Michael Hanselmann | |
178 | 018ae30b | Michael Hanselmann | #: Attribute name for comment
|
179 | 018ae30b | Michael Hanselmann | COMMENT_ATTR = "comment"
|
180 | 018ae30b | Michael Hanselmann | |
181 | 526a662a | Michael Hanselmann | |
182 | ff0d18e6 | Iustin Pop | def _NameToId(name): |
183 | ff0d18e6 | Iustin Pop | """Convert an opcode class name to an OP_ID.
|
184 | ff0d18e6 | Iustin Pop |
|
185 | ff0d18e6 | Iustin Pop | @type name: string
|
186 | ff0d18e6 | Iustin Pop | @param name: the class name, as OpXxxYyy
|
187 | ff0d18e6 | Iustin Pop | @rtype: string
|
188 | ff0d18e6 | Iustin Pop | @return: the name in the OP_XXXX_YYYY format
|
189 | ff0d18e6 | Iustin Pop |
|
190 | ff0d18e6 | Iustin Pop | """
|
191 | ff0d18e6 | Iustin Pop | if not name.startswith("Op"): |
192 | ff0d18e6 | Iustin Pop | return None |
193 | ff0d18e6 | Iustin Pop | # Note: (?<=[a-z])(?=[A-Z]) would be ideal, since it wouldn't
|
194 | ff0d18e6 | Iustin Pop | # consume any input, and hence we would just have all the elements
|
195 | ff0d18e6 | Iustin Pop | # in the list, one by one; but it seems that split doesn't work on
|
196 | ff0d18e6 | Iustin Pop | # non-consuming input, hence we have to process the input string a
|
197 | ff0d18e6 | Iustin Pop | # bit
|
198 | ff0d18e6 | Iustin Pop | name = _OPID_RE.sub(r"\1,\2", name)
|
199 | ff0d18e6 | Iustin Pop | elems = name.split(",")
|
200 | ff0d18e6 | Iustin Pop | return "_".join(n.upper() for n in elems) |
201 | ff0d18e6 | Iustin Pop | |
202 | 65e183af | Michael Hanselmann | |
203 | 65e183af | Michael Hanselmann | def RequireFileStorage(): |
204 | 65e183af | Michael Hanselmann | """Checks that file storage is enabled.
|
205 | 65e183af | Michael Hanselmann |
|
206 | 65e183af | Michael Hanselmann | While it doesn't really fit into this module, L{utils} was deemed too large
|
207 | 65e183af | Michael Hanselmann | of a dependency to be imported for just one or two functions.
|
208 | 65e183af | Michael Hanselmann |
|
209 | 65e183af | Michael Hanselmann | @raise errors.OpPrereqError: when file storage is disabled
|
210 | 65e183af | Michael Hanselmann |
|
211 | 65e183af | Michael Hanselmann | """
|
212 | 65e183af | Michael Hanselmann | if not constants.ENABLE_FILE_STORAGE: |
213 | 65e183af | Michael Hanselmann | raise errors.OpPrereqError("File storage disabled at configure time", |
214 | 65e183af | Michael Hanselmann | errors.ECODE_INVAL) |
215 | 65e183af | Michael Hanselmann | |
216 | 65e183af | Michael Hanselmann | |
217 | 4b97f902 | Apollon Oikonomopoulos | def RequireSharedFileStorage(): |
218 | 4b97f902 | Apollon Oikonomopoulos | """Checks that shared file storage is enabled.
|
219 | 4b97f902 | Apollon Oikonomopoulos |
|
220 | 4b97f902 | Apollon Oikonomopoulos | While it doesn't really fit into this module, L{utils} was deemed too large
|
221 | 4b97f902 | Apollon Oikonomopoulos | of a dependency to be imported for just one or two functions.
|
222 | 4b97f902 | Apollon Oikonomopoulos |
|
223 | 4b97f902 | Apollon Oikonomopoulos | @raise errors.OpPrereqError: when shared file storage is disabled
|
224 | 4b97f902 | Apollon Oikonomopoulos |
|
225 | 4b97f902 | Apollon Oikonomopoulos | """
|
226 | 4b97f902 | Apollon Oikonomopoulos | if not constants.ENABLE_SHARED_FILE_STORAGE: |
227 | 4b97f902 | Apollon Oikonomopoulos | raise errors.OpPrereqError("Shared file storage disabled at" |
228 | 4b97f902 | Apollon Oikonomopoulos | " configure time", errors.ECODE_INVAL)
|
229 | 4b97f902 | Apollon Oikonomopoulos | |
230 | 4b97f902 | Apollon Oikonomopoulos | |
231 | 8c9ee749 | Michael Hanselmann | @ht.WithDesc("CheckFileStorage") |
232 | 8c9ee749 | Michael Hanselmann | def _CheckFileStorage(value): |
233 | 8c9ee749 | Michael Hanselmann | """Ensures file storage is enabled if used.
|
234 | 65e183af | Michael Hanselmann |
|
235 | 65e183af | Michael Hanselmann | """
|
236 | 8c9ee749 | Michael Hanselmann | if value == constants.DT_FILE:
|
237 | 65e183af | Michael Hanselmann | RequireFileStorage() |
238 | 4b97f902 | Apollon Oikonomopoulos | elif value == constants.DT_SHARED_FILE:
|
239 | 4b97f902 | Apollon Oikonomopoulos | RequireSharedFileStorage() |
240 | 65e183af | Michael Hanselmann | return True |
241 | 65e183af | Michael Hanselmann | |
242 | 65e183af | Michael Hanselmann | |
243 | 45fe090b | Michael Hanselmann | def _BuildDiskTemplateCheck(accept_none): |
244 | 45fe090b | Michael Hanselmann | """Builds check for disk template.
|
245 | 45fe090b | Michael Hanselmann |
|
246 | 45fe090b | Michael Hanselmann | @type accept_none: bool
|
247 | 45fe090b | Michael Hanselmann | @param accept_none: whether to accept None as a correct value
|
248 | 45fe090b | Michael Hanselmann | @rtype: callable
|
249 | 45fe090b | Michael Hanselmann |
|
250 | 45fe090b | Michael Hanselmann | """
|
251 | 45fe090b | Michael Hanselmann | template_check = ht.TElemOf(constants.DISK_TEMPLATES) |
252 | 45fe090b | Michael Hanselmann | |
253 | 45fe090b | Michael Hanselmann | if accept_none:
|
254 | 45fe090b | Michael Hanselmann | template_check = ht.TOr(template_check, ht.TNone) |
255 | 45fe090b | Michael Hanselmann | |
256 | 45fe090b | Michael Hanselmann | return ht.TAnd(template_check, _CheckFileStorage)
|
257 | 8c9ee749 | Michael Hanselmann | |
258 | 8c9ee749 | Michael Hanselmann | |
259 | 65e183af | Michael Hanselmann | def _CheckStorageType(storage_type): |
260 | 65e183af | Michael Hanselmann | """Ensure a given storage type is valid.
|
261 | 65e183af | Michael Hanselmann |
|
262 | 65e183af | Michael Hanselmann | """
|
263 | 65e183af | Michael Hanselmann | if storage_type not in constants.VALID_STORAGE_TYPES: |
264 | 65e183af | Michael Hanselmann | raise errors.OpPrereqError("Unknown storage type: %s" % storage_type, |
265 | 65e183af | Michael Hanselmann | errors.ECODE_INVAL) |
266 | 65e183af | Michael Hanselmann | if storage_type == constants.ST_FILE:
|
267 | 65e183af | Michael Hanselmann | RequireFileStorage() |
268 | 65e183af | Michael Hanselmann | return True |
269 | 65e183af | Michael Hanselmann | |
270 | 65e183af | Michael Hanselmann | |
271 | 65e183af | Michael Hanselmann | #: Storage type parameter
|
272 | 45d4c81c | Michael Hanselmann | _PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
|
273 | 45d4c81c | Michael Hanselmann | "Storage type")
|
274 | 65e183af | Michael Hanselmann | |
275 | 65e183af | Michael Hanselmann | |
276 | 65e183af | Michael Hanselmann | class _AutoOpParamSlots(type): |
277 | 65e183af | Michael Hanselmann | """Meta class for opcode definitions.
|
278 | 65e183af | Michael Hanselmann |
|
279 | 65e183af | Michael Hanselmann | """
|
280 | 65e183af | Michael Hanselmann | def __new__(mcs, name, bases, attrs): |
281 | 65e183af | Michael Hanselmann | """Called when a class should be created.
|
282 | 65e183af | Michael Hanselmann |
|
283 | 65e183af | Michael Hanselmann | @param mcs: The meta class
|
284 | 65e183af | Michael Hanselmann | @param name: Name of created class
|
285 | 65e183af | Michael Hanselmann | @param bases: Base classes
|
286 | 65e183af | Michael Hanselmann | @type attrs: dict
|
287 | 65e183af | Michael Hanselmann | @param attrs: Class attributes
|
288 | 65e183af | Michael Hanselmann |
|
289 | 65e183af | Michael Hanselmann | """
|
290 | 65e183af | Michael Hanselmann | assert "__slots__" not in attrs, \ |
291 | 65e183af | Michael Hanselmann | "Class '%s' defines __slots__ when it should use OP_PARAMS" % name
|
292 | e89a9021 | Iustin Pop | assert "OP_ID" not in attrs, "Class '%s' defining OP_ID" % name |
293 | ff0d18e6 | Iustin Pop | |
294 | e89a9021 | Iustin Pop | attrs["OP_ID"] = _NameToId(name)
|
295 | 65e183af | Michael Hanselmann | |
296 | 65e183af | Michael Hanselmann | # Always set OP_PARAMS to avoid duplicates in BaseOpCode.GetAllParams
|
297 | 65e183af | Michael Hanselmann | params = attrs.setdefault("OP_PARAMS", [])
|
298 | 65e183af | Michael Hanselmann | |
299 | 65e183af | Michael Hanselmann | # Use parameter names as slots
|
300 | 197b323b | Michael Hanselmann | slots = [pname for (pname, _, _, _) in params] |
301 | 65e183af | Michael Hanselmann | |
302 | 65e183af | Michael Hanselmann | assert "OP_DSC_FIELD" not in attrs or attrs["OP_DSC_FIELD"] in slots, \ |
303 | 65e183af | Michael Hanselmann | "Class '%s' uses unknown field in OP_DSC_FIELD" % name
|
304 | 65e183af | Michael Hanselmann | |
305 | 65e183af | Michael Hanselmann | attrs["__slots__"] = slots
|
306 | 65e183af | Michael Hanselmann | |
307 | 65e183af | Michael Hanselmann | return type.__new__(mcs, name, bases, attrs) |
308 | 65e183af | Michael Hanselmann | |
309 | df458e0b | Iustin Pop | |
310 | 0e46916d | Iustin Pop | class BaseOpCode(object): |
311 | df458e0b | Iustin Pop | """A simple serializable object.
|
312 | df458e0b | Iustin Pop |
|
313 | 0e46916d | Iustin Pop | This object serves as a parent class for OpCode without any custom
|
314 | 0e46916d | Iustin Pop | field handling.
|
315 | 0e46916d | Iustin Pop |
|
316 | df458e0b | Iustin Pop | """
|
317 | b459a848 | Andrea Spadaccini | # pylint: disable=E1101
|
318 | e89a9021 | Iustin Pop | # as OP_ID is dynamically defined
|
319 | 65e183af | Michael Hanselmann | __metaclass__ = _AutoOpParamSlots |
320 | 65e183af | Michael Hanselmann | |
321 | a8083063 | Iustin Pop | def __init__(self, **kwargs): |
322 | a7399f66 | Iustin Pop | """Constructor for BaseOpCode.
|
323 | a7399f66 | Iustin Pop |
|
324 | a7399f66 | Iustin Pop | The constructor takes only keyword arguments and will set
|
325 | a7399f66 | Iustin Pop | attributes on this object based on the passed arguments. As such,
|
326 | a7399f66 | Iustin Pop | it means that you should not pass arguments which are not in the
|
327 | a7399f66 | Iustin Pop | __slots__ attribute for this class.
|
328 | a7399f66 | Iustin Pop |
|
329 | a7399f66 | Iustin Pop | """
|
330 | adf385c7 | Iustin Pop | slots = self._all_slots()
|
331 | a8083063 | Iustin Pop | for key in kwargs: |
332 | adf385c7 | Iustin Pop | if key not in slots: |
333 | df458e0b | Iustin Pop | raise TypeError("Object %s doesn't support the parameter '%s'" % |
334 | 3ecf6786 | Iustin Pop | (self.__class__.__name__, key))
|
335 | a8083063 | Iustin Pop | setattr(self, key, kwargs[key]) |
336 | a8083063 | Iustin Pop | |
337 | df458e0b | Iustin Pop | def __getstate__(self): |
338 | a7399f66 | Iustin Pop | """Generic serializer.
|
339 | a7399f66 | Iustin Pop |
|
340 | a7399f66 | Iustin Pop | This method just returns the contents of the instance as a
|
341 | a7399f66 | Iustin Pop | dictionary.
|
342 | a7399f66 | Iustin Pop |
|
343 | a7399f66 | Iustin Pop | @rtype: C{dict}
|
344 | a7399f66 | Iustin Pop | @return: the instance attributes and their values
|
345 | a7399f66 | Iustin Pop |
|
346 | a7399f66 | Iustin Pop | """
|
347 | df458e0b | Iustin Pop | state = {} |
348 | adf385c7 | Iustin Pop | for name in self._all_slots(): |
349 | df458e0b | Iustin Pop | if hasattr(self, name): |
350 | df458e0b | Iustin Pop | state[name] = getattr(self, name) |
351 | df458e0b | Iustin Pop | return state
|
352 | df458e0b | Iustin Pop | |
353 | df458e0b | Iustin Pop | def __setstate__(self, state): |
354 | a7399f66 | Iustin Pop | """Generic unserializer.
|
355 | a7399f66 | Iustin Pop |
|
356 | a7399f66 | Iustin Pop | This method just restores from the serialized state the attributes
|
357 | a7399f66 | Iustin Pop | of the current instance.
|
358 | a7399f66 | Iustin Pop |
|
359 | a7399f66 | Iustin Pop | @param state: the serialized opcode data
|
360 | a7399f66 | Iustin Pop | @type state: C{dict}
|
361 | a7399f66 | Iustin Pop |
|
362 | a7399f66 | Iustin Pop | """
|
363 | df458e0b | Iustin Pop | if not isinstance(state, dict): |
364 | df458e0b | Iustin Pop | raise ValueError("Invalid data to __setstate__: expected dict, got %s" % |
365 | df458e0b | Iustin Pop | type(state))
|
366 | df458e0b | Iustin Pop | |
367 | adf385c7 | Iustin Pop | for name in self._all_slots(): |
368 | 44db3a6f | Iustin Pop | if name not in state and hasattr(self, name): |
369 | df458e0b | Iustin Pop | delattr(self, name) |
370 | df458e0b | Iustin Pop | |
371 | df458e0b | Iustin Pop | for name in state: |
372 | df458e0b | Iustin Pop | setattr(self, name, state[name]) |
373 | df458e0b | Iustin Pop | |
374 | adf385c7 | Iustin Pop | @classmethod
|
375 | adf385c7 | Iustin Pop | def _all_slots(cls): |
376 | adf385c7 | Iustin Pop | """Compute the list of all declared slots for a class.
|
377 | adf385c7 | Iustin Pop |
|
378 | adf385c7 | Iustin Pop | """
|
379 | adf385c7 | Iustin Pop | slots = [] |
380 | adf385c7 | Iustin Pop | for parent in cls.__mro__: |
381 | adf385c7 | Iustin Pop | slots.extend(getattr(parent, "__slots__", [])) |
382 | adf385c7 | Iustin Pop | return slots
|
383 | adf385c7 | Iustin Pop | |
384 | 65e183af | Michael Hanselmann | @classmethod
|
385 | 65e183af | Michael Hanselmann | def GetAllParams(cls): |
386 | 65e183af | Michael Hanselmann | """Compute list of all parameters for an opcode.
|
387 | 65e183af | Michael Hanselmann |
|
388 | 65e183af | Michael Hanselmann | """
|
389 | 65e183af | Michael Hanselmann | slots = [] |
390 | 65e183af | Michael Hanselmann | for parent in cls.__mro__: |
391 | 65e183af | Michael Hanselmann | slots.extend(getattr(parent, "OP_PARAMS", [])) |
392 | 65e183af | Michael Hanselmann | return slots
|
393 | 65e183af | Michael Hanselmann | |
394 | 1cbef6d8 | Michael Hanselmann | def Validate(self, set_defaults): |
395 | 1cbef6d8 | Michael Hanselmann | """Validate opcode parameters, optionally setting default values.
|
396 | 1cbef6d8 | Michael Hanselmann |
|
397 | 1cbef6d8 | Michael Hanselmann | @type set_defaults: bool
|
398 | 1cbef6d8 | Michael Hanselmann | @param set_defaults: Whether to set default values
|
399 | 1cbef6d8 | Michael Hanselmann | @raise errors.OpPrereqError: When a parameter value doesn't match
|
400 | 1cbef6d8 | Michael Hanselmann | requirements
|
401 | 1cbef6d8 | Michael Hanselmann |
|
402 | 1cbef6d8 | Michael Hanselmann | """
|
403 | 197b323b | Michael Hanselmann | for (attr_name, default, test, _) in self.GetAllParams(): |
404 | 1cbef6d8 | Michael Hanselmann | assert test == ht.NoType or callable(test) |
405 | 1cbef6d8 | Michael Hanselmann | |
406 | 1cbef6d8 | Michael Hanselmann | if not hasattr(self, attr_name): |
407 | 1cbef6d8 | Michael Hanselmann | if default == ht.NoDefault:
|
408 | 1cbef6d8 | Michael Hanselmann | raise errors.OpPrereqError("Required parameter '%s.%s' missing" % |
409 | 1cbef6d8 | Michael Hanselmann | (self.OP_ID, attr_name),
|
410 | 1cbef6d8 | Michael Hanselmann | errors.ECODE_INVAL) |
411 | 1cbef6d8 | Michael Hanselmann | elif set_defaults:
|
412 | 1cbef6d8 | Michael Hanselmann | if callable(default): |
413 | 1cbef6d8 | Michael Hanselmann | dval = default() |
414 | 1cbef6d8 | Michael Hanselmann | else:
|
415 | 1cbef6d8 | Michael Hanselmann | dval = default |
416 | 1cbef6d8 | Michael Hanselmann | setattr(self, attr_name, dval) |
417 | 1cbef6d8 | Michael Hanselmann | |
418 | 1cbef6d8 | Michael Hanselmann | if test == ht.NoType:
|
419 | 1cbef6d8 | Michael Hanselmann | # no tests here
|
420 | 1cbef6d8 | Michael Hanselmann | continue
|
421 | 1cbef6d8 | Michael Hanselmann | |
422 | 1cbef6d8 | Michael Hanselmann | if set_defaults or hasattr(self, attr_name): |
423 | 1cbef6d8 | Michael Hanselmann | attr_val = getattr(self, attr_name) |
424 | 1cbef6d8 | Michael Hanselmann | if not test(attr_val): |
425 | 1cbef6d8 | Michael Hanselmann | logging.error("OpCode %s, parameter %s, has invalid type %s/value %s",
|
426 | 1cbef6d8 | Michael Hanselmann | self.OP_ID, attr_name, type(attr_val), attr_val) |
427 | 1cbef6d8 | Michael Hanselmann | raise errors.OpPrereqError("Parameter '%s.%s' fails validation" % |
428 | 1cbef6d8 | Michael Hanselmann | (self.OP_ID, attr_name),
|
429 | 1cbef6d8 | Michael Hanselmann | errors.ECODE_INVAL) |
430 | 1cbef6d8 | Michael Hanselmann | |
431 | df458e0b | Iustin Pop | |
432 | b247c6fc | Michael Hanselmann | def _BuildJobDepCheck(relative): |
433 | b247c6fc | Michael Hanselmann | """Builds check for job dependencies (L{DEPEND_ATTR}).
|
434 | b247c6fc | Michael Hanselmann |
|
435 | b247c6fc | Michael Hanselmann | @type relative: bool
|
436 | b247c6fc | Michael Hanselmann | @param relative: Whether to accept relative job IDs (negative)
|
437 | b247c6fc | Michael Hanselmann | @rtype: callable
|
438 | b247c6fc | Michael Hanselmann |
|
439 | b247c6fc | Michael Hanselmann | """
|
440 | b247c6fc | Michael Hanselmann | if relative:
|
441 | b247c6fc | Michael Hanselmann | job_id = ht.TOr(ht.TJobId, ht.TRelativeJobId) |
442 | b247c6fc | Michael Hanselmann | else:
|
443 | b247c6fc | Michael Hanselmann | job_id = ht.TJobId |
444 | b247c6fc | Michael Hanselmann | |
445 | b247c6fc | Michael Hanselmann | job_dep = \ |
446 | b247c6fc | Michael Hanselmann | ht.TAnd(ht.TIsLength(2),
|
447 | b247c6fc | Michael Hanselmann | ht.TItems([job_id, |
448 | b247c6fc | Michael Hanselmann | ht.TListOf(ht.TElemOf(constants.JOBS_FINALIZED))])) |
449 | b247c6fc | Michael Hanselmann | |
450 | b247c6fc | Michael Hanselmann | return ht.TOr(ht.TNone, ht.TListOf(job_dep))
|
451 | b247c6fc | Michael Hanselmann | |
452 | b247c6fc | Michael Hanselmann | |
453 | b247c6fc | Michael Hanselmann | TNoRelativeJobDependencies = _BuildJobDepCheck(False)
|
454 | b247c6fc | Michael Hanselmann | |
455 | 1ce03fb1 | Michael Hanselmann | #: List of submission status and job ID as returned by C{SubmitManyJobs}
|
456 | 1456df62 | Michael Hanselmann | _TJobIdListItem = \ |
457 | 1456df62 | Michael Hanselmann | ht.TAnd(ht.TIsLength(2),
|
458 | 1456df62 | Michael Hanselmann | ht.TItems([ht.Comment("success")(ht.TBool),
|
459 | 1456df62 | Michael Hanselmann | ht.Comment("Job ID if successful, error message"
|
460 | 1456df62 | Michael Hanselmann | " otherwise")(ht.TOr(ht.TString,
|
461 | 1456df62 | Michael Hanselmann | ht.TJobId))])) |
462 | 1456df62 | Michael Hanselmann | TJobIdList = ht.TListOf(_TJobIdListItem) |
463 | 1ce03fb1 | Michael Hanselmann | |
464 | f7686867 | Michael Hanselmann | #: Result containing only list of submitted jobs
|
465 | f7686867 | Michael Hanselmann | TJobIdListOnly = ht.TStrictDict(True, True, { |
466 | 1456df62 | Michael Hanselmann | constants.JOB_IDS_KEY: ht.Comment("List of submitted jobs")(TJobIdList),
|
467 | f7686867 | Michael Hanselmann | }) |
468 | f7686867 | Michael Hanselmann | |
469 | b247c6fc | Michael Hanselmann | |
470 | 0e46916d | Iustin Pop | class OpCode(BaseOpCode): |
471 | a7399f66 | Iustin Pop | """Abstract OpCode.
|
472 | a7399f66 | Iustin Pop |
|
473 | a7399f66 | Iustin Pop | This is the root of the actual OpCode hierarchy. All clases derived
|
474 | a7399f66 | Iustin Pop | from this class should override OP_ID.
|
475 | a7399f66 | Iustin Pop |
|
476 | a7399f66 | Iustin Pop | @cvar OP_ID: The ID of this opcode. This should be unique amongst all
|
477 | 20777413 | Iustin Pop | children of this class.
|
478 | bde8f481 | Adeodato Simo | @cvar OP_DSC_FIELD: The name of a field whose value will be included in the
|
479 | bde8f481 | Adeodato Simo | string returned by Summary(); see the docstring of that
|
480 | bde8f481 | Adeodato Simo | method for details).
|
481 | 65e183af | Michael Hanselmann | @cvar OP_PARAMS: List of opcode attributes, the default values they should
|
482 | 65e183af | Michael Hanselmann | get if not already defined, and types they must match.
|
483 | 1ce03fb1 | Michael Hanselmann | @cvar OP_RESULT: Callable to verify opcode result
|
484 | 687c10d9 | Iustin Pop | @cvar WITH_LU: Boolean that specifies whether this should be included in
|
485 | 687c10d9 | Iustin Pop | mcpu's dispatch table
|
486 | 20777413 | Iustin Pop | @ivar dry_run: Whether the LU should be run in dry-run mode, i.e. just
|
487 | 20777413 | Iustin Pop | the check steps
|
488 | 8f5c488d | Michael Hanselmann | @ivar priority: Opcode priority for queue
|
489 | a7399f66 | Iustin Pop |
|
490 | a7399f66 | Iustin Pop | """
|
491 | b459a848 | Andrea Spadaccini | # pylint: disable=E1101
|
492 | e89a9021 | Iustin Pop | # as OP_ID is dynamically defined
|
493 | 687c10d9 | Iustin Pop | WITH_LU = True
|
494 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
495 | 45d4c81c | Michael Hanselmann | ("dry_run", None, ht.TMaybeBool, "Run checks only, don't execute"), |
496 | 45d4c81c | Michael Hanselmann | ("debug_level", None, ht.TOr(ht.TNone, ht.TPositiveInt), "Debug level"), |
497 | 65e183af | Michael Hanselmann | ("priority", constants.OP_PRIO_DEFAULT,
|
498 | 45d4c81c | Michael Hanselmann | ht.TElemOf(constants.OP_PRIO_SUBMIT_VALID), "Opcode priority"),
|
499 | b247c6fc | Michael Hanselmann | (DEPEND_ATTR, None, _BuildJobDepCheck(True), |
500 | b247c6fc | Michael Hanselmann | "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
|
501 | b247c6fc | Michael Hanselmann | " job IDs can be used"),
|
502 | 018ae30b | Michael Hanselmann | (COMMENT_ATTR, None, ht.TMaybeString,
|
503 | 018ae30b | Michael Hanselmann | "Comment describing the purpose of the opcode"),
|
504 | 65e183af | Michael Hanselmann | ] |
505 | 1ce03fb1 | Michael Hanselmann | OP_RESULT = None
|
506 | df458e0b | Iustin Pop | |
507 | df458e0b | Iustin Pop | def __getstate__(self): |
508 | df458e0b | Iustin Pop | """Specialized getstate for opcodes.
|
509 | df458e0b | Iustin Pop |
|
510 | a7399f66 | Iustin Pop | This method adds to the state dictionary the OP_ID of the class,
|
511 | a7399f66 | Iustin Pop | so that on unload we can identify the correct class for
|
512 | a7399f66 | Iustin Pop | instantiating the opcode.
|
513 | a7399f66 | Iustin Pop |
|
514 | a7399f66 | Iustin Pop | @rtype: C{dict}
|
515 | a7399f66 | Iustin Pop | @return: the state as a dictionary
|
516 | a7399f66 | Iustin Pop |
|
517 | df458e0b | Iustin Pop | """
|
518 | 0e46916d | Iustin Pop | data = BaseOpCode.__getstate__(self)
|
519 | df458e0b | Iustin Pop | data["OP_ID"] = self.OP_ID |
520 | df458e0b | Iustin Pop | return data
|
521 | df458e0b | Iustin Pop | |
522 | df458e0b | Iustin Pop | @classmethod
|
523 | 00abdc96 | Iustin Pop | def LoadOpCode(cls, data): |
524 | df458e0b | Iustin Pop | """Generic load opcode method.
|
525 | df458e0b | Iustin Pop |
|
526 | a7399f66 | Iustin Pop | The method identifies the correct opcode class from the dict-form
|
527 | a7399f66 | Iustin Pop | by looking for a OP_ID key, if this is not found, or its value is
|
528 | a7399f66 | Iustin Pop | not available in this module as a child of this class, we fail.
|
529 | a7399f66 | Iustin Pop |
|
530 | a7399f66 | Iustin Pop | @type data: C{dict}
|
531 | a7399f66 | Iustin Pop | @param data: the serialized opcode
|
532 | a7399f66 | Iustin Pop |
|
533 | df458e0b | Iustin Pop | """
|
534 | df458e0b | Iustin Pop | if not isinstance(data, dict): |
535 | df458e0b | Iustin Pop | raise ValueError("Invalid data to LoadOpCode (%s)" % type(data)) |
536 | df458e0b | Iustin Pop | if "OP_ID" not in data: |
537 | df458e0b | Iustin Pop | raise ValueError("Invalid data to LoadOpcode, missing OP_ID") |
538 | df458e0b | Iustin Pop | op_id = data["OP_ID"]
|
539 | df458e0b | Iustin Pop | op_class = None
|
540 | 363acb1e | Iustin Pop | if op_id in OP_MAPPING: |
541 | 363acb1e | Iustin Pop | op_class = OP_MAPPING[op_id] |
542 | 363acb1e | Iustin Pop | else:
|
543 | df458e0b | Iustin Pop | raise ValueError("Invalid data to LoadOpCode: OP_ID %s unsupported" % |
544 | df458e0b | Iustin Pop | op_id) |
545 | df458e0b | Iustin Pop | op = op_class() |
546 | df458e0b | Iustin Pop | new_data = data.copy() |
547 | df458e0b | Iustin Pop | del new_data["OP_ID"] |
548 | df458e0b | Iustin Pop | op.__setstate__(new_data) |
549 | df458e0b | Iustin Pop | return op
|
550 | df458e0b | Iustin Pop | |
551 | 60dd1473 | Iustin Pop | def Summary(self): |
552 | 60dd1473 | Iustin Pop | """Generates a summary description of this opcode.
|
553 | 60dd1473 | Iustin Pop |
|
554 | ff0d18e6 | Iustin Pop | The summary is the value of the OP_ID attribute (without the "OP_"
|
555 | ff0d18e6 | Iustin Pop | prefix), plus the value of the OP_DSC_FIELD attribute, if one was
|
556 | ff0d18e6 | Iustin Pop | defined; this field should allow to easily identify the operation
|
557 | ff0d18e6 | Iustin Pop | (for an instance creation job, e.g., it would be the instance
|
558 | ff0d18e6 | Iustin Pop | name).
|
559 | bde8f481 | Adeodato Simo |
|
560 | 60dd1473 | Iustin Pop | """
|
561 | ff0d18e6 | Iustin Pop | assert self.OP_ID is not None and len(self.OP_ID) > 3 |
562 | 60dd1473 | Iustin Pop | # all OP_ID start with OP_, we remove that
|
563 | 60dd1473 | Iustin Pop | txt = self.OP_ID[3:] |
564 | 60dd1473 | Iustin Pop | field_name = getattr(self, "OP_DSC_FIELD", None) |
565 | 60dd1473 | Iustin Pop | if field_name:
|
566 | 60dd1473 | Iustin Pop | field_value = getattr(self, field_name, None) |
567 | bc8bbda1 | Iustin Pop | if isinstance(field_value, (list, tuple)): |
568 | bc8bbda1 | Iustin Pop | field_value = ",".join(str(i) for i in field_value) |
569 | 60dd1473 | Iustin Pop | txt = "%s(%s)" % (txt, field_value)
|
570 | 60dd1473 | Iustin Pop | return txt
|
571 | 60dd1473 | Iustin Pop | |
572 | 3ce9a5e7 | Michael Hanselmann | def TinySummary(self): |
573 | 3ce9a5e7 | Michael Hanselmann | """Generates a compact summary description of the opcode.
|
574 | 3ce9a5e7 | Michael Hanselmann |
|
575 | 3ce9a5e7 | Michael Hanselmann | """
|
576 | 3ce9a5e7 | Michael Hanselmann | assert self.OP_ID.startswith("OP_") |
577 | 3ce9a5e7 | Michael Hanselmann | |
578 | 3ce9a5e7 | Michael Hanselmann | text = self.OP_ID[3:] |
579 | 3ce9a5e7 | Michael Hanselmann | |
580 | 3ce9a5e7 | Michael Hanselmann | for (prefix, supplement) in _SUMMARY_PREFIX.items(): |
581 | 3ce9a5e7 | Michael Hanselmann | if text.startswith(prefix):
|
582 | 3ce9a5e7 | Michael Hanselmann | return supplement + text[len(prefix):] |
583 | 3ce9a5e7 | Michael Hanselmann | |
584 | 3ce9a5e7 | Michael Hanselmann | return text
|
585 | 3ce9a5e7 | Michael Hanselmann | |
586 | a8083063 | Iustin Pop | |
587 | afee0879 | Iustin Pop | # cluster opcodes
|
588 | afee0879 | Iustin Pop | |
589 | bc84ffa7 | Iustin Pop | class OpClusterPostInit(OpCode): |
590 | b5f5fae9 | Luca Bigliardi | """Post cluster initialization.
|
591 | b5f5fae9 | Luca Bigliardi |
|
592 | b5f5fae9 | Luca Bigliardi | This opcode does not touch the cluster at all. Its purpose is to run hooks
|
593 | b5f5fae9 | Luca Bigliardi | after the cluster has been initialized.
|
594 | b5f5fae9 | Luca Bigliardi |
|
595 | b5f5fae9 | Luca Bigliardi | """
|
596 | b5f5fae9 | Luca Bigliardi | |
597 | b5f5fae9 | Luca Bigliardi | |
598 | c6d43e9e | Iustin Pop | class OpClusterDestroy(OpCode): |
599 | a7399f66 | Iustin Pop | """Destroy the cluster.
|
600 | a7399f66 | Iustin Pop |
|
601 | a7399f66 | Iustin Pop | This opcode has no other parameters. All the state is irreversibly
|
602 | a7399f66 | Iustin Pop | lost after the execution of this opcode.
|
603 | a7399f66 | Iustin Pop |
|
604 | a7399f66 | Iustin Pop | """
|
605 | a8083063 | Iustin Pop | |
606 | a8083063 | Iustin Pop | |
607 | a2f7ab92 | Iustin Pop | class OpClusterQuery(OpCode): |
608 | fdc267f4 | Iustin Pop | """Query cluster information."""
|
609 | a8083063 | Iustin Pop | |
610 | a8083063 | Iustin Pop | |
611 | fcad7225 | Michael Hanselmann | class OpClusterVerify(OpCode): |
612 | fcad7225 | Michael Hanselmann | """Submits all jobs necessary to verify the cluster.
|
613 | fcad7225 | Michael Hanselmann |
|
614 | fcad7225 | Michael Hanselmann | """
|
615 | fcad7225 | Michael Hanselmann | OP_PARAMS = [ |
616 | fcad7225 | Michael Hanselmann | _PDebugSimulateErrors, |
617 | fcad7225 | Michael Hanselmann | _PErrorCodes, |
618 | fcad7225 | Michael Hanselmann | _PSkipChecks, |
619 | 93f2399e | Andrea Spadaccini | _PIgnoreErrors, |
620 | fcad7225 | Michael Hanselmann | _PVerbose, |
621 | fcad7225 | Michael Hanselmann | ("group_name", None, ht.TMaybeString, "Group to verify") |
622 | fcad7225 | Michael Hanselmann | ] |
623 | f7686867 | Michael Hanselmann | OP_RESULT = TJobIdListOnly |
624 | fcad7225 | Michael Hanselmann | |
625 | fcad7225 | Michael Hanselmann | |
626 | bf93ae69 | Adeodato Simo | class OpClusterVerifyConfig(OpCode): |
627 | bf93ae69 | Adeodato Simo | """Verify the cluster config.
|
628 | bf93ae69 | Adeodato Simo |
|
629 | bf93ae69 | Adeodato Simo | """
|
630 | bf93ae69 | Adeodato Simo | OP_PARAMS = [ |
631 | 57106b74 | Michael Hanselmann | _PDebugSimulateErrors, |
632 | 57106b74 | Michael Hanselmann | _PErrorCodes, |
633 | 93f2399e | Andrea Spadaccini | _PIgnoreErrors, |
634 | 57106b74 | Michael Hanselmann | _PVerbose, |
635 | bf93ae69 | Adeodato Simo | ] |
636 | f7686867 | Michael Hanselmann | OP_RESULT = ht.TBool |
637 | bf93ae69 | Adeodato Simo | |
638 | bf93ae69 | Adeodato Simo | |
639 | bf93ae69 | Adeodato Simo | class OpClusterVerifyGroup(OpCode): |
640 | bf93ae69 | Adeodato Simo | """Run verify on a node group from the cluster.
|
641 | a7399f66 | Iustin Pop |
|
642 | a7399f66 | Iustin Pop | @type skip_checks: C{list}
|
643 | a7399f66 | Iustin Pop | @ivar skip_checks: steps to be skipped from the verify process; this
|
644 | a7399f66 | Iustin Pop | needs to be a subset of
|
645 | a7399f66 | Iustin Pop | L{constants.VERIFY_OPTIONAL_CHECKS}; currently
|
646 | a7399f66 | Iustin Pop | only L{constants.VERIFY_NPLUSONE_MEM} can be passed
|
647 | a7399f66 | Iustin Pop |
|
648 | a7399f66 | Iustin Pop | """
|
649 | bf93ae69 | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
650 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
651 | 57106b74 | Michael Hanselmann | _PGroupName, |
652 | 57106b74 | Michael Hanselmann | _PDebugSimulateErrors, |
653 | 57106b74 | Michael Hanselmann | _PErrorCodes, |
654 | 57106b74 | Michael Hanselmann | _PSkipChecks, |
655 | 93f2399e | Andrea Spadaccini | _PIgnoreErrors, |
656 | 57106b74 | Michael Hanselmann | _PVerbose, |
657 | 65e183af | Michael Hanselmann | ] |
658 | f7686867 | Michael Hanselmann | OP_RESULT = ht.TBool |
659 | a8083063 | Iustin Pop | |
660 | a8083063 | Iustin Pop | |
661 | bd8210a7 | Iustin Pop | class OpClusterVerifyDisks(OpCode): |
662 | 150e978f | Iustin Pop | """Verify the cluster disks.
|
663 | 150e978f | Iustin Pop |
|
664 | ae1a845c | Michael Hanselmann | """
|
665 | f7686867 | Michael Hanselmann | OP_RESULT = TJobIdListOnly |
666 | ae1a845c | Michael Hanselmann | |
667 | ae1a845c | Michael Hanselmann | |
668 | ae1a845c | Michael Hanselmann | class OpGroupVerifyDisks(OpCode): |
669 | ae1a845c | Michael Hanselmann | """Verifies the status of all disks in a node group.
|
670 | 150e978f | Iustin Pop |
|
671 | ae1a845c | Michael Hanselmann | Result: a tuple of three elements:
|
672 | ae1a845c | Michael Hanselmann | - dict of node names with issues (values: error msg)
|
673 | 150e978f | Iustin Pop | - list of instances with degraded disks (that should be activated)
|
674 | b63ed789 | Iustin Pop | - dict of instances with missing logical volumes (values: (node, vol)
|
675 | b63ed789 | Iustin Pop | pairs with details about the missing volumes)
|
676 | 150e978f | Iustin Pop |
|
677 | b63ed789 | Iustin Pop | In normal operation, all lists should be empty. A non-empty instance
|
678 | b63ed789 | Iustin Pop | list (3rd element of the result) is still ok (errors were fixed) but
|
679 | b63ed789 | Iustin Pop | non-empty node list means some node is down, and probably there are
|
680 | b63ed789 | Iustin Pop | unfixable drbd errors.
|
681 | 150e978f | Iustin Pop |
|
682 | 150e978f | Iustin Pop | Note that only instances that are drbd-based are taken into
|
683 | 150e978f | Iustin Pop | consideration. This might need to be revisited in the future.
|
684 | 150e978f | Iustin Pop |
|
685 | 150e978f | Iustin Pop | """
|
686 | ae1a845c | Michael Hanselmann | OP_DSC_FIELD = "group_name"
|
687 | ae1a845c | Michael Hanselmann | OP_PARAMS = [ |
688 | ae1a845c | Michael Hanselmann | _PGroupName, |
689 | ae1a845c | Michael Hanselmann | ] |
690 | 1ce03fb1 | Michael Hanselmann | OP_RESULT = \ |
691 | 1ce03fb1 | Michael Hanselmann | ht.TAnd(ht.TIsLength(3),
|
692 | 1ce03fb1 | Michael Hanselmann | ht.TItems([ht.TDictOf(ht.TString, ht.TString), |
693 | 1ce03fb1 | Michael Hanselmann | ht.TListOf(ht.TString), |
694 | 6973587f | Michael Hanselmann | ht.TDictOf(ht.TString, |
695 | 6973587f | Michael Hanselmann | ht.TListOf(ht.TListOf(ht.TString)))])) |
696 | 150e978f | Iustin Pop | |
697 | 150e978f | Iustin Pop | |
698 | 5d01aca3 | Iustin Pop | class OpClusterRepairDiskSizes(OpCode): |
699 | 60975797 | Iustin Pop | """Verify the disk sizes of the instances and fixes configuration
|
700 | 60975797 | Iustin Pop | mimatches.
|
701 | 60975797 | Iustin Pop |
|
702 | 60975797 | Iustin Pop | Parameters: optional instances list, in case we want to restrict the
|
703 | 60975797 | Iustin Pop | checks to only a subset of the instances.
|
704 | 60975797 | Iustin Pop |
|
705 | 60975797 | Iustin Pop | Result: a list of tuples, (instance, disk, new-size) for changed
|
706 | 60975797 | Iustin Pop | configurations.
|
707 | 60975797 | Iustin Pop |
|
708 | 60975797 | Iustin Pop | In normal operation, the list should be empty.
|
709 | 60975797 | Iustin Pop |
|
710 | 60975797 | Iustin Pop | @type instances: list
|
711 | 60975797 | Iustin Pop | @ivar instances: the list of instances to check, or empty for all instances
|
712 | 60975797 | Iustin Pop |
|
713 | 60975797 | Iustin Pop | """
|
714 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
715 | 197b323b | Michael Hanselmann | ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), |
716 | 65e183af | Michael Hanselmann | ] |
717 | 60975797 | Iustin Pop | |
718 | 60975797 | Iustin Pop | |
719 | 2f093ea0 | Iustin Pop | class OpClusterConfigQuery(OpCode): |
720 | ae5849b5 | Michael Hanselmann | """Query cluster configuration values."""
|
721 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
722 | 65e183af | Michael Hanselmann | _POutputFields |
723 | 65e183af | Michael Hanselmann | ] |
724 | a8083063 | Iustin Pop | |
725 | a8083063 | Iustin Pop | |
726 | e126df25 | Iustin Pop | class OpClusterRename(OpCode): |
727 | a7399f66 | Iustin Pop | """Rename the cluster.
|
728 | a7399f66 | Iustin Pop |
|
729 | a7399f66 | Iustin Pop | @type name: C{str}
|
730 | a7399f66 | Iustin Pop | @ivar name: The new name of the cluster. The name and/or the master IP
|
731 | a7399f66 | Iustin Pop | address will be changed to match the new name and its IP
|
732 | a7399f66 | Iustin Pop | address.
|
733 | a7399f66 | Iustin Pop |
|
734 | a7399f66 | Iustin Pop | """
|
735 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "name"
|
736 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
737 | 197b323b | Michael Hanselmann | ("name", ht.NoDefault, ht.TNonEmptyString, None), |
738 | 65e183af | Michael Hanselmann | ] |
739 | 07bd8a51 | Iustin Pop | |
740 | 07bd8a51 | Iustin Pop | |
741 | a6682fdc | Iustin Pop | class OpClusterSetParams(OpCode): |
742 | a7399f66 | Iustin Pop | """Change the parameters of the cluster.
|
743 | a7399f66 | Iustin Pop |
|
744 | a7399f66 | Iustin Pop | @type vg_name: C{str} or C{None}
|
745 | a7399f66 | Iustin Pop | @ivar vg_name: The new volume group name or None to disable LVM usage.
|
746 | a7399f66 | Iustin Pop |
|
747 | a7399f66 | Iustin Pop | """
|
748 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
749 | 45d4c81c | Michael Hanselmann | ("vg_name", None, ht.TMaybeString, "Volume group name"), |
750 | 65e183af | Michael Hanselmann | ("enabled_hypervisors", None, |
751 | 65e183af | Michael Hanselmann | ht.TOr(ht.TAnd(ht.TListOf(ht.TElemOf(constants.HYPER_TYPES)), ht.TTrue), |
752 | 45d4c81c | Michael Hanselmann | ht.TNone), |
753 | 45d4c81c | Michael Hanselmann | "List of enabled hypervisors"),
|
754 | 65e183af | Michael Hanselmann | ("hvparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
755 | 45d4c81c | Michael Hanselmann | ht.TNone), |
756 | 45d4c81c | Michael Hanselmann | "Cluster-wide hypervisor parameter defaults, hypervisor-dependent"),
|
757 | 45d4c81c | Michael Hanselmann | ("beparams", None, ht.TOr(ht.TDict, ht.TNone), |
758 | 45d4c81c | Michael Hanselmann | "Cluster-wide backend parameter defaults"),
|
759 | 65e183af | Michael Hanselmann | ("os_hvp", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
760 | 45d4c81c | Michael Hanselmann | ht.TNone), |
761 | 45d4c81c | Michael Hanselmann | "Cluster-wide per-OS hypervisor parameter defaults"),
|
762 | 65e183af | Michael Hanselmann | ("osparams", None, ht.TOr(ht.TDictOf(ht.TNonEmptyString, ht.TDict), |
763 | 45d4c81c | Michael Hanselmann | ht.TNone), |
764 | 45d4c81c | Michael Hanselmann | "Cluster-wide OS parameter defaults"),
|
765 | 197b323b | Michael Hanselmann | ("candidate_pool_size", None, ht.TOr(ht.TStrictPositiveInt, ht.TNone), |
766 | 45d4c81c | Michael Hanselmann | "Master candidate pool size"),
|
767 | 45d4c81c | Michael Hanselmann | ("uid_pool", None, ht.NoType, |
768 | 45d4c81c | Michael Hanselmann | "Set UID pool, must be list of lists describing UID ranges (two items,"
|
769 | 45d4c81c | Michael Hanselmann | " start and end inclusive)"),
|
770 | 45d4c81c | Michael Hanselmann | ("add_uids", None, ht.NoType, |
771 | 45d4c81c | Michael Hanselmann | "Extend UID pool, must be list of lists describing UID ranges (two"
|
772 | 45d4c81c | Michael Hanselmann | " items, start and end inclusive) to be added"),
|
773 | 45d4c81c | Michael Hanselmann | ("remove_uids", None, ht.NoType, |
774 | 45d4c81c | Michael Hanselmann | "Shrink UID pool, must be list of lists describing UID ranges (two"
|
775 | 45d4c81c | Michael Hanselmann | " items, start and end inclusive) to be removed"),
|
776 | 45d4c81c | Michael Hanselmann | ("maintain_node_health", None, ht.TMaybeBool, |
777 | 45d4c81c | Michael Hanselmann | "Whether to automatically maintain node health"),
|
778 | 45d4c81c | Michael Hanselmann | ("prealloc_wipe_disks", None, ht.TMaybeBool, |
779 | 45d4c81c | Michael Hanselmann | "Whether to wipe disks before allocating them to instances"),
|
780 | 45d4c81c | Michael Hanselmann | ("nicparams", None, ht.TMaybeDict, "Cluster-wide NIC parameter defaults"), |
781 | 45d4c81c | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict, "Cluster-wide node parameter defaults"), |
782 | 45d4c81c | Michael Hanselmann | ("drbd_helper", None, ht.TOr(ht.TString, ht.TNone), "DRBD helper program"), |
783 | 45d4c81c | Michael Hanselmann | ("default_iallocator", None, ht.TOr(ht.TString, ht.TNone), |
784 | 45d4c81c | Michael Hanselmann | "Default iallocator for cluster"),
|
785 | 45d4c81c | Michael Hanselmann | ("master_netdev", None, ht.TOr(ht.TString, ht.TNone), |
786 | 45d4c81c | Michael Hanselmann | "Master network device"),
|
787 | 5a8648eb | Andrea Spadaccini | ("master_netmask", None, ht.TOr(ht.TInt, ht.TNone), |
788 | 5a8648eb | Andrea Spadaccini | "Netmask of the master IP"),
|
789 | 45d4c81c | Michael Hanselmann | ("reserved_lvs", None, ht.TOr(ht.TListOf(ht.TNonEmptyString), ht.TNone), |
790 | 45d4c81c | Michael Hanselmann | "List of reserved LVs"),
|
791 | 45d4c81c | Michael Hanselmann | ("hidden_os", None, _TestClusterOsList, |
792 | 45d4c81c | Michael Hanselmann | "Modify list of hidden operating systems. Each modification must have"
|
793 | 45d4c81c | Michael Hanselmann | " two items, the operation and the OS name. The operation can be"
|
794 | 45d4c81c | Michael Hanselmann | " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
|
795 | 45d4c81c | Michael Hanselmann | ("blacklisted_os", None, _TestClusterOsList, |
796 | 45d4c81c | Michael Hanselmann | "Modify list of blacklisted operating systems. Each modification must have"
|
797 | 45d4c81c | Michael Hanselmann | " two items, the operation and the OS name. The operation can be"
|
798 | 45d4c81c | Michael Hanselmann | " ``%s`` or ``%s``." % (constants.DDM_ADD, constants.DDM_REMOVE)),
|
799 | bf689b7a | Andrea Spadaccini | ("use_external_mip_script", None, ht.TMaybeBool, |
800 | bf689b7a | Andrea Spadaccini | "Whether to use an external master IP address setup script"),
|
801 | 4b7735f9 | Iustin Pop | ] |
802 | 12515db7 | Manuel Franceschini | |
803 | 12515db7 | Manuel Franceschini | |
804 | d1240007 | Iustin Pop | class OpClusterRedistConf(OpCode): |
805 | afee0879 | Iustin Pop | """Force a full push of the cluster configuration.
|
806 | afee0879 | Iustin Pop |
|
807 | afee0879 | Iustin Pop | """
|
808 | afee0879 | Iustin Pop | |
809 | 83f72637 | Michael Hanselmann | |
810 | fb926117 | Andrea Spadaccini | class OpClusterActivateMasterIp(OpCode): |
811 | fb926117 | Andrea Spadaccini | """Activate the master IP on the master node.
|
812 | fb926117 | Andrea Spadaccini |
|
813 | fb926117 | Andrea Spadaccini | """
|
814 | fb926117 | Andrea Spadaccini | |
815 | fb926117 | Andrea Spadaccini | |
816 | fb926117 | Andrea Spadaccini | class OpClusterDeactivateMasterIp(OpCode): |
817 | fb926117 | Andrea Spadaccini | """Deactivate the master IP on the master node.
|
818 | fb926117 | Andrea Spadaccini |
|
819 | fb926117 | Andrea Spadaccini | """
|
820 | fb926117 | Andrea Spadaccini | |
821 | fb926117 | Andrea Spadaccini | |
822 | 83f72637 | Michael Hanselmann | class OpQuery(OpCode): |
823 | 83f72637 | Michael Hanselmann | """Query for resources/items.
|
824 | 83f72637 | Michael Hanselmann |
|
825 | abd66bf8 | Michael Hanselmann | @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
|
826 | 83f72637 | Michael Hanselmann | @ivar fields: List of fields to retrieve
|
827 | 2e5c33db | Iustin Pop | @ivar qfilter: Query filter
|
828 | 83f72637 | Michael Hanselmann |
|
829 | 83f72637 | Michael Hanselmann | """
|
830 | e50d8412 | Michael Hanselmann | OP_DSC_FIELD = "what"
|
831 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
832 | 8e7078e0 | Michael Hanselmann | _PQueryWhat, |
833 | ee13764f | Michael Hanselmann | _PUseLocking, |
834 | 45d4c81c | Michael Hanselmann | ("fields", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
|
835 | 45d4c81c | Michael Hanselmann | "Requested fields"),
|
836 | 2e5c33db | Iustin Pop | ("qfilter", None, ht.TOr(ht.TNone, ht.TListOf), |
837 | 45d4c81c | Michael Hanselmann | "Query filter"),
|
838 | 83f72637 | Michael Hanselmann | ] |
839 | 83f72637 | Michael Hanselmann | |
840 | 83f72637 | Michael Hanselmann | |
841 | 83f72637 | Michael Hanselmann | class OpQueryFields(OpCode): |
842 | 83f72637 | Michael Hanselmann | """Query for available resource/item fields.
|
843 | 83f72637 | Michael Hanselmann |
|
844 | abd66bf8 | Michael Hanselmann | @ivar what: Resources to query for, must be one of L{constants.QR_VIA_OP}
|
845 | 83f72637 | Michael Hanselmann | @ivar fields: List of fields to retrieve
|
846 | 83f72637 | Michael Hanselmann |
|
847 | 83f72637 | Michael Hanselmann | """
|
848 | e50d8412 | Michael Hanselmann | OP_DSC_FIELD = "what"
|
849 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
850 | 8e7078e0 | Michael Hanselmann | _PQueryWhat, |
851 | 8e7078e0 | Michael Hanselmann | ("fields", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), |
852 | 8e7078e0 | Michael Hanselmann | "Requested fields; if not given, all are returned"),
|
853 | 83f72637 | Michael Hanselmann | ] |
854 | 83f72637 | Michael Hanselmann | |
855 | 83f72637 | Michael Hanselmann | |
856 | 792af3ad | Renรฉ Nussbaumer | class OpOobCommand(OpCode): |
857 | eb64da59 | Renรฉ Nussbaumer | """Interact with OOB."""
|
858 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
859 | c4ec0755 | Renรฉ Nussbaumer | ("node_names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
860 | c4ec0755 | Renรฉ Nussbaumer | "List of nodes to run the OOB command against"),
|
861 | c4ec0755 | Renรฉ Nussbaumer | ("command", None, ht.TElemOf(constants.OOB_COMMANDS), |
862 | c4ec0755 | Renรฉ Nussbaumer | "OOB command to be run"),
|
863 | c4ec0755 | Renรฉ Nussbaumer | ("timeout", constants.OOB_TIMEOUT, ht.TInt,
|
864 | c4ec0755 | Renรฉ Nussbaumer | "Timeout before the OOB helper will be terminated"),
|
865 | c4ec0755 | Renรฉ Nussbaumer | ("ignore_status", False, ht.TBool, |
866 | c4ec0755 | Renรฉ Nussbaumer | "Ignores the node offline status for power off"),
|
867 | beff3779 | Renรฉ Nussbaumer | ("power_delay", constants.OOB_POWER_DELAY, ht.TPositiveFloat,
|
868 | beff3779 | Renรฉ Nussbaumer | "Time in seconds to wait between powering on nodes"),
|
869 | eb64da59 | Renรฉ Nussbaumer | ] |
870 | eb64da59 | Renรฉ Nussbaumer | |
871 | eb64da59 | Renรฉ Nussbaumer | |
872 | 07bd8a51 | Iustin Pop | # node opcodes
|
873 | 07bd8a51 | Iustin Pop | |
874 | 73d565a3 | Iustin Pop | class OpNodeRemove(OpCode): |
875 | a7399f66 | Iustin Pop | """Remove a node.
|
876 | a7399f66 | Iustin Pop |
|
877 | a7399f66 | Iustin Pop | @type node_name: C{str}
|
878 | a7399f66 | Iustin Pop | @ivar node_name: The name of the node to remove. If the node still has
|
879 | a7399f66 | Iustin Pop | instances on it, the operation will fail.
|
880 | a7399f66 | Iustin Pop |
|
881 | a7399f66 | Iustin Pop | """
|
882 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "node_name"
|
883 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
884 | 65e183af | Michael Hanselmann | _PNodeName, |
885 | 65e183af | Michael Hanselmann | ] |
886 | a8083063 | Iustin Pop | |
887 | a8083063 | Iustin Pop | |
888 | d817d49f | Iustin Pop | class OpNodeAdd(OpCode): |
889 | a7399f66 | Iustin Pop | """Add a node to the cluster.
|
890 | a7399f66 | Iustin Pop |
|
891 | a7399f66 | Iustin Pop | @type node_name: C{str}
|
892 | a7399f66 | Iustin Pop | @ivar node_name: The name of the node to add. This can be a short name,
|
893 | a7399f66 | Iustin Pop | but it will be expanded to the FQDN.
|
894 | a7399f66 | Iustin Pop | @type primary_ip: IP address
|
895 | a7399f66 | Iustin Pop | @ivar primary_ip: The primary IP of the node. This will be ignored when the
|
896 | a7399f66 | Iustin Pop | opcode is submitted, but will be filled during the node
|
897 | a7399f66 | Iustin Pop | add (so it will be visible in the job query).
|
898 | a7399f66 | Iustin Pop | @type secondary_ip: IP address
|
899 | a7399f66 | Iustin Pop | @ivar secondary_ip: The secondary IP of the node. This needs to be passed
|
900 | a7399f66 | Iustin Pop | if the cluster has been initialized in 'dual-network'
|
901 | a7399f66 | Iustin Pop | mode, otherwise it must not be given.
|
902 | a7399f66 | Iustin Pop | @type readd: C{bool}
|
903 | a7399f66 | Iustin Pop | @ivar readd: Whether to re-add an existing node to the cluster. If
|
904 | a7399f66 | Iustin Pop | this is not passed, then the operation will abort if the node
|
905 | a7399f66 | Iustin Pop | name is already in the cluster; use this parameter to 'repair'
|
906 | a7399f66 | Iustin Pop | a node that had its configuration broken, or was reinstalled
|
907 | a7399f66 | Iustin Pop | without removal from the cluster.
|
908 | f936c153 | Iustin Pop | @type group: C{str}
|
909 | f936c153 | Iustin Pop | @ivar group: The node group to which this node will belong.
|
910 | fd3d37b6 | Iustin Pop | @type vm_capable: C{bool}
|
911 | fd3d37b6 | Iustin Pop | @ivar vm_capable: The vm_capable node attribute
|
912 | fd3d37b6 | Iustin Pop | @type master_capable: C{bool}
|
913 | fd3d37b6 | Iustin Pop | @ivar master_capable: The master_capable node attribute
|
914 | a7399f66 | Iustin Pop |
|
915 | a7399f66 | Iustin Pop | """
|
916 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "node_name"
|
917 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
918 | 65e183af | Michael Hanselmann | _PNodeName, |
919 | 45d4c81c | Michael Hanselmann | ("primary_ip", None, ht.NoType, "Primary IP address"), |
920 | 45d4c81c | Michael Hanselmann | ("secondary_ip", None, ht.TMaybeString, "Secondary IP address"), |
921 | 45d4c81c | Michael Hanselmann | ("readd", False, ht.TBool, "Whether node is re-added to cluster"), |
922 | 45d4c81c | Michael Hanselmann | ("group", None, ht.TMaybeString, "Initial node group"), |
923 | 45d4c81c | Michael Hanselmann | ("master_capable", None, ht.TMaybeBool, |
924 | 45d4c81c | Michael Hanselmann | "Whether node can become master or master candidate"),
|
925 | 45d4c81c | Michael Hanselmann | ("vm_capable", None, ht.TMaybeBool, |
926 | 45d4c81c | Michael Hanselmann | "Whether node can host instances"),
|
927 | 45d4c81c | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict, "Node parameters"), |
928 | 65e183af | Michael Hanselmann | ] |
929 | a8083063 | Iustin Pop | |
930 | a8083063 | Iustin Pop | |
931 | 2237687b | Iustin Pop | class OpNodeQuery(OpCode): |
932 | a8083063 | Iustin Pop | """Compute the list of nodes."""
|
933 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
934 | 65e183af | Michael Hanselmann | _POutputFields, |
935 | 45d4c81c | Michael Hanselmann | _PUseLocking, |
936 | 45d4c81c | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
937 | 45d4c81c | Michael Hanselmann | "Empty list to query all nodes, node names otherwise"),
|
938 | 65e183af | Michael Hanselmann | ] |
939 | a8083063 | Iustin Pop | |
940 | a8083063 | Iustin Pop | |
941 | 8ed55bfd | Iustin Pop | class OpNodeQueryvols(OpCode): |
942 | dcb93971 | Michael Hanselmann | """Get list of volumes on node."""
|
943 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
944 | 65e183af | Michael Hanselmann | _POutputFields, |
945 | 45d4c81c | Michael Hanselmann | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
946 | 45d4c81c | Michael Hanselmann | "Empty list to query all nodes, node names otherwise"),
|
947 | 65e183af | Michael Hanselmann | ] |
948 | dcb93971 | Michael Hanselmann | |
949 | dcb93971 | Michael Hanselmann | |
950 | ad8d0595 | Iustin Pop | class OpNodeQueryStorage(OpCode): |
951 | 9e5442ce | Michael Hanselmann | """Get information on storage for node(s)."""
|
952 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
953 | 65e183af | Michael Hanselmann | _POutputFields, |
954 | 65e183af | Michael Hanselmann | _PStorageType, |
955 | 45d4c81c | Michael Hanselmann | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "List of nodes"), |
956 | 45d4c81c | Michael Hanselmann | ("name", None, ht.TMaybeString, "Storage name"), |
957 | 9e5442ce | Michael Hanselmann | ] |
958 | 9e5442ce | Michael Hanselmann | |
959 | 9e5442ce | Michael Hanselmann | |
960 | 2cee4077 | Iustin Pop | class OpNodeModifyStorage(OpCode): |
961 | 099c52ad | Iustin Pop | """Modifies the properies of a storage unit"""
|
962 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
963 | 65e183af | Michael Hanselmann | _PNodeName, |
964 | 65e183af | Michael Hanselmann | _PStorageType, |
965 | 45d4c81c | Michael Hanselmann | _PStorageName, |
966 | 45d4c81c | Michael Hanselmann | ("changes", ht.NoDefault, ht.TDict, "Requested changes"), |
967 | efb8da02 | Michael Hanselmann | ] |
968 | efb8da02 | Michael Hanselmann | |
969 | efb8da02 | Michael Hanselmann | |
970 | 76aef8fc | Michael Hanselmann | class OpRepairNodeStorage(OpCode): |
971 | 76aef8fc | Michael Hanselmann | """Repairs the volume group on a node."""
|
972 | 76aef8fc | Michael Hanselmann | OP_DSC_FIELD = "node_name"
|
973 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
974 | 65e183af | Michael Hanselmann | _PNodeName, |
975 | 65e183af | Michael Hanselmann | _PStorageType, |
976 | 45d4c81c | Michael Hanselmann | _PStorageName, |
977 | 45d4c81c | Michael Hanselmann | _PIgnoreConsistency, |
978 | 76aef8fc | Michael Hanselmann | ] |
979 | 76aef8fc | Michael Hanselmann | |
980 | 76aef8fc | Michael Hanselmann | |
981 | f13973c4 | Iustin Pop | class OpNodeSetParams(OpCode): |
982 | b31c8676 | Iustin Pop | """Change the parameters of a node."""
|
983 | b31c8676 | Iustin Pop | OP_DSC_FIELD = "node_name"
|
984 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
985 | 65e183af | Michael Hanselmann | _PNodeName, |
986 | 65e183af | Michael Hanselmann | _PForce, |
987 | 45d4c81c | Michael Hanselmann | ("master_candidate", None, ht.TMaybeBool, |
988 | 45d4c81c | Michael Hanselmann | "Whether the node should become a master candidate"),
|
989 | 45d4c81c | Michael Hanselmann | ("offline", None, ht.TMaybeBool, |
990 | 45d4c81c | Michael Hanselmann | "Whether the node should be marked as offline"),
|
991 | 45d4c81c | Michael Hanselmann | ("drained", None, ht.TMaybeBool, |
992 | 45d4c81c | Michael Hanselmann | "Whether the node should be marked as drained"),
|
993 | 45d4c81c | Michael Hanselmann | ("auto_promote", False, ht.TBool, |
994 | 45d4c81c | Michael Hanselmann | "Whether node(s) should be promoted to master candidate if necessary"),
|
995 | 45d4c81c | Michael Hanselmann | ("master_capable", None, ht.TMaybeBool, |
996 | 45d4c81c | Michael Hanselmann | "Denote whether node can become master or master candidate"),
|
997 | 45d4c81c | Michael Hanselmann | ("vm_capable", None, ht.TMaybeBool, |
998 | 45d4c81c | Michael Hanselmann | "Denote whether node can host instances"),
|
999 | 45d4c81c | Michael Hanselmann | ("secondary_ip", None, ht.TMaybeString, |
1000 | 45d4c81c | Michael Hanselmann | "Change node's secondary IP address"),
|
1001 | 45d4c81c | Michael Hanselmann | ("ndparams", None, ht.TMaybeDict, "Set node parameters"), |
1002 | 45d4c81c | Michael Hanselmann | ("powered", None, ht.TMaybeBool, |
1003 | 45d4c81c | Michael Hanselmann | "Whether the node should be marked as powered"),
|
1004 | b31c8676 | Iustin Pop | ] |
1005 | 1456df62 | Michael Hanselmann | OP_RESULT = _TSetParamsResult |
1006 | b31c8676 | Iustin Pop | |
1007 | f5118ade | Iustin Pop | |
1008 | e0d4735f | Iustin Pop | class OpNodePowercycle(OpCode): |
1009 | f5118ade | Iustin Pop | """Tries to powercycle a node."""
|
1010 | f5118ade | Iustin Pop | OP_DSC_FIELD = "node_name"
|
1011 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1012 | 65e183af | Michael Hanselmann | _PNodeName, |
1013 | 65e183af | Michael Hanselmann | _PForce, |
1014 | f5118ade | Iustin Pop | ] |
1015 | f5118ade | Iustin Pop | |
1016 | 7ffc5a86 | Michael Hanselmann | |
1017 | 5b14a488 | Iustin Pop | class OpNodeMigrate(OpCode): |
1018 | 80cb875c | Michael Hanselmann | """Migrate all instances from a node."""
|
1019 | 80cb875c | Michael Hanselmann | OP_DSC_FIELD = "node_name"
|
1020 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1021 | 65e183af | Michael Hanselmann | _PNodeName, |
1022 | 65e183af | Michael Hanselmann | _PMigrationMode, |
1023 | 65e183af | Michael Hanselmann | _PMigrationLive, |
1024 | f8fa4175 | Michael Hanselmann | _PMigrationTargetNode, |
1025 | 8eb34306 | Apollon Oikonomopoulos | ("iallocator", None, ht.TMaybeString, |
1026 | 8eb34306 | Apollon Oikonomopoulos | "Iallocator for deciding the target node for shared-storage instances"),
|
1027 | 80cb875c | Michael Hanselmann | ] |
1028 | 80cb875c | Michael Hanselmann | |
1029 | 80cb875c | Michael Hanselmann | |
1030 | e1f23243 | Michael Hanselmann | class OpNodeEvacuate(OpCode): |
1031 | e1f23243 | Michael Hanselmann | """Evacuate instances off a number of nodes."""
|
1032 | e1f23243 | Michael Hanselmann | OP_DSC_FIELD = "node_name"
|
1033 | e1f23243 | Michael Hanselmann | OP_PARAMS = [ |
1034 | e1f23243 | Michael Hanselmann | _PEarlyRelease, |
1035 | e1f23243 | Michael Hanselmann | _PNodeName, |
1036 | e1f23243 | Michael Hanselmann | ("remote_node", None, ht.TMaybeString, "New secondary node"), |
1037 | e1f23243 | Michael Hanselmann | ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), |
1038 | e1f23243 | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES),
|
1039 | e1f23243 | Michael Hanselmann | "Node evacuation mode"),
|
1040 | e1f23243 | Michael Hanselmann | ] |
1041 | 1456df62 | Michael Hanselmann | OP_RESULT = TJobIdListOnly |
1042 | e1f23243 | Michael Hanselmann | |
1043 | e1f23243 | Michael Hanselmann | |
1044 | a8083063 | Iustin Pop | # instance opcodes
|
1045 | a8083063 | Iustin Pop | |
1046 | e1530b10 | Iustin Pop | class OpInstanceCreate(OpCode): |
1047 | 9bf56d77 | Michael Hanselmann | """Create an instance.
|
1048 | 9bf56d77 | Michael Hanselmann |
|
1049 | 9bf56d77 | Michael Hanselmann | @ivar instance_name: Instance name
|
1050 | 9bf56d77 | Michael Hanselmann | @ivar mode: Instance creation mode (one of L{constants.INSTANCE_CREATE_MODES})
|
1051 | 9bf56d77 | Michael Hanselmann | @ivar source_handshake: Signed handshake from source (remote import only)
|
1052 | 9bf56d77 | Michael Hanselmann | @ivar source_x509_ca: Source X509 CA in PEM format (remote import only)
|
1053 | 9bf56d77 | Michael Hanselmann | @ivar source_instance_name: Previous name of instance (remote import only)
|
1054 | dae91d02 | Michael Hanselmann | @ivar source_shutdown_timeout: Shutdown timeout used for source instance
|
1055 | dae91d02 | Michael Hanselmann | (remote import only)
|
1056 | 9bf56d77 | Michael Hanselmann |
|
1057 | 9bf56d77 | Michael Hanselmann | """
|
1058 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1059 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1060 | 65e183af | Michael Hanselmann | _PInstanceName, |
1061 | 45d4c81c | Michael Hanselmann | _PForceVariant, |
1062 | 45d4c81c | Michael Hanselmann | _PWaitForSync, |
1063 | 45d4c81c | Michael Hanselmann | _PNameCheck, |
1064 | 45d4c81c | Michael Hanselmann | ("beparams", ht.EmptyDict, ht.TDict, "Backend parameters for instance"), |
1065 | 526a662a | Michael Hanselmann | ("disks", ht.NoDefault,
|
1066 | 526a662a | Michael Hanselmann | # TODO: Generate check from constants.IDISK_PARAMS_TYPES
|
1067 | 526a662a | Michael Hanselmann | ht.TListOf(ht.TDictOf(ht.TElemOf(constants.IDISK_PARAMS), |
1068 | 526a662a | Michael Hanselmann | ht.TOr(ht.TNonEmptyString, ht.TInt))), |
1069 | 526a662a | Michael Hanselmann | "Disk descriptions, for example ``[{\"%s\": 100}, {\"%s\": 5}]``;"
|
1070 | 526a662a | Michael Hanselmann | " each disk definition must contain a ``%s`` value and"
|
1071 | 526a662a | Michael Hanselmann | " can contain an optional ``%s`` value denoting the disk access mode"
|
1072 | 526a662a | Michael Hanselmann | " (%s)" %
|
1073 | 526a662a | Michael Hanselmann | (constants.IDISK_SIZE, constants.IDISK_SIZE, constants.IDISK_SIZE, |
1074 | 526a662a | Michael Hanselmann | constants.IDISK_MODE, |
1075 | 526a662a | Michael Hanselmann | " or ".join("``%s``" % i for i in sorted(constants.DISK_ACCESS_SET)))), |
1076 | 45fe090b | Michael Hanselmann | ("disk_template", ht.NoDefault, _BuildDiskTemplateCheck(True), |
1077 | 45fe090b | Michael Hanselmann | "Disk template"),
|
1078 | 45d4c81c | Michael Hanselmann | ("file_driver", None, ht.TOr(ht.TNone, ht.TElemOf(constants.FILE_DRIVER)), |
1079 | 45d4c81c | Michael Hanselmann | "Driver for file-backed disks"),
|
1080 | 45d4c81c | Michael Hanselmann | ("file_storage_dir", None, ht.TMaybeString, |
1081 | 45d4c81c | Michael Hanselmann | "Directory for storing file-backed disks"),
|
1082 | 45d4c81c | Michael Hanselmann | ("hvparams", ht.EmptyDict, ht.TDict,
|
1083 | 45d4c81c | Michael Hanselmann | "Hypervisor parameters for instance, hypervisor-dependent"),
|
1084 | 45d4c81c | Michael Hanselmann | ("hypervisor", None, ht.TMaybeString, "Hypervisor"), |
1085 | 45d4c81c | Michael Hanselmann | ("iallocator", None, ht.TMaybeString, |
1086 | 45d4c81c | Michael Hanselmann | "Iallocator for deciding which node(s) to use"),
|
1087 | 45d4c81c | Michael Hanselmann | ("identify_defaults", False, ht.TBool, |
1088 | 45d4c81c | Michael Hanselmann | "Reset instance parameters to default if equal"),
|
1089 | 45d4c81c | Michael Hanselmann | ("ip_check", True, ht.TBool, _PIpCheckDoc), |
1090 | 45d4c81c | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES),
|
1091 | 45d4c81c | Michael Hanselmann | "Instance creation mode"),
|
1092 | 526a662a | Michael Hanselmann | ("nics", ht.NoDefault, ht.TListOf(_TestNicDef),
|
1093 | 526a662a | Michael Hanselmann | "List of NIC (network interface) definitions, for example"
|
1094 | 526a662a | Michael Hanselmann | " ``[{}, {}, {\"%s\": \"198.51.100.4\"}]``; each NIC definition can"
|
1095 | 526a662a | Michael Hanselmann | " contain the optional values %s" %
|
1096 | 526a662a | Michael Hanselmann | (constants.INIC_IP, |
1097 | 526a662a | Michael Hanselmann | ", ".join("``%s``" % i for i in sorted(constants.INIC_PARAMS)))), |
1098 | 45d4c81c | Michael Hanselmann | ("no_install", None, ht.TMaybeBool, |
1099 | 45d4c81c | Michael Hanselmann | "Do not install the OS (will disable automatic start)"),
|
1100 | 45d4c81c | Michael Hanselmann | ("osparams", ht.EmptyDict, ht.TDict, "OS parameters for instance"), |
1101 | 45d4c81c | Michael Hanselmann | ("os_type", None, ht.TMaybeString, "Operating system"), |
1102 | 45d4c81c | Michael Hanselmann | ("pnode", None, ht.TMaybeString, "Primary node"), |
1103 | 45d4c81c | Michael Hanselmann | ("snode", None, ht.TMaybeString, "Secondary node"), |
1104 | 45d4c81c | Michael Hanselmann | ("source_handshake", None, ht.TOr(ht.TList, ht.TNone), |
1105 | 45d4c81c | Michael Hanselmann | "Signed handshake from source (remote import only)"),
|
1106 | 45d4c81c | Michael Hanselmann | ("source_instance_name", None, ht.TMaybeString, |
1107 | 45d4c81c | Michael Hanselmann | "Source instance name (remote import only)"),
|
1108 | 65e183af | Michael Hanselmann | ("source_shutdown_timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT,
|
1109 | 526a662a | Michael Hanselmann | ht.TPositiveInt, |
1110 | 526a662a | Michael Hanselmann | "How long source instance was given to shut down (remote import only)"),
|
1111 | 45d4c81c | Michael Hanselmann | ("source_x509_ca", None, ht.TMaybeString, |
1112 | 45d4c81c | Michael Hanselmann | "Source X509 CA in PEM format (remote import only)"),
|
1113 | 45d4c81c | Michael Hanselmann | ("src_node", None, ht.TMaybeString, "Source node for import"), |
1114 | 45d4c81c | Michael Hanselmann | ("src_path", None, ht.TMaybeString, "Source directory for import"), |
1115 | 45d4c81c | Michael Hanselmann | ("start", True, ht.TBool, "Whether to start instance after creation"), |
1116 | 720f56c8 | Apollon Oikonomopoulos | ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Instance tags"), |
1117 | 3b6d8c9b | Iustin Pop | ] |
1118 | 1456df62 | Michael Hanselmann | OP_RESULT = ht.Comment("instance nodes")(ht.TListOf(ht.TNonEmptyString))
|
1119 | a8083063 | Iustin Pop | |
1120 | a8083063 | Iustin Pop | |
1121 | 5073fd8f | Iustin Pop | class OpInstanceReinstall(OpCode): |
1122 | fdc267f4 | Iustin Pop | """Reinstall an instance's OS."""
|
1123 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1124 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1125 | 65e183af | Michael Hanselmann | _PInstanceName, |
1126 | 45d4c81c | Michael Hanselmann | _PForceVariant, |
1127 | 45d4c81c | Michael Hanselmann | ("os_type", None, ht.TMaybeString, "Instance operating system"), |
1128 | 45d4c81c | Michael Hanselmann | ("osparams", None, ht.TMaybeDict, "Temporary OS parameters"), |
1129 | 65e183af | Michael Hanselmann | ] |
1130 | fe7b0351 | Michael Hanselmann | |
1131 | fe7b0351 | Michael Hanselmann | |
1132 | 3cd2d4b1 | Iustin Pop | class OpInstanceRemove(OpCode): |
1133 | a8083063 | Iustin Pop | """Remove an instance."""
|
1134 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1135 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1136 | 65e183af | Michael Hanselmann | _PInstanceName, |
1137 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
1138 | 45d4c81c | Michael Hanselmann | ("ignore_failures", False, ht.TBool, |
1139 | 45d4c81c | Michael Hanselmann | "Whether to ignore failures during removal"),
|
1140 | fc1baca9 | Michael Hanselmann | ] |
1141 | a8083063 | Iustin Pop | |
1142 | a8083063 | Iustin Pop | |
1143 | 5659e2e2 | Iustin Pop | class OpInstanceRename(OpCode): |
1144 | decd5f45 | Iustin Pop | """Rename an instance."""
|
1145 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1146 | 65e183af | Michael Hanselmann | _PInstanceName, |
1147 | 45d4c81c | Michael Hanselmann | _PNameCheck, |
1148 | 45d4c81c | Michael Hanselmann | ("new_name", ht.NoDefault, ht.TNonEmptyString, "New instance name"), |
1149 | 45d4c81c | Michael Hanselmann | ("ip_check", False, ht.TBool, _PIpCheckDoc), |
1150 | 4f05fd3b | Iustin Pop | ] |
1151 | 1456df62 | Michael Hanselmann | OP_RESULT = ht.Comment("New instance name")(ht.TNonEmptyString)
|
1152 | decd5f45 | Iustin Pop | |
1153 | decd5f45 | Iustin Pop | |
1154 | c873d91c | Iustin Pop | class OpInstanceStartup(OpCode): |
1155 | fdc267f4 | Iustin Pop | """Startup an instance."""
|
1156 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1157 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1158 | 65e183af | Michael Hanselmann | _PInstanceName, |
1159 | 65e183af | Michael Hanselmann | _PForce, |
1160 | 65e183af | Michael Hanselmann | _PIgnoreOfflineNodes, |
1161 | 45d4c81c | Michael Hanselmann | ("hvparams", ht.EmptyDict, ht.TDict,
|
1162 | 45d4c81c | Michael Hanselmann | "Temporary hypervisor parameters, hypervisor-dependent"),
|
1163 | 45d4c81c | Michael Hanselmann | ("beparams", ht.EmptyDict, ht.TDict, "Temporary backend parameters"), |
1164 | 9b64e486 | Iustin Pop | _PNoRemember, |
1165 | 323f9095 | Stephen Shirley | _PStartupPaused, |
1166 | 4f05fd3b | Iustin Pop | ] |
1167 | a8083063 | Iustin Pop | |
1168 | a8083063 | Iustin Pop | |
1169 | ee3e37a7 | Iustin Pop | class OpInstanceShutdown(OpCode): |
1170 | fdc267f4 | Iustin Pop | """Shutdown an instance."""
|
1171 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1172 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1173 | 65e183af | Michael Hanselmann | _PInstanceName, |
1174 | 65e183af | Michael Hanselmann | _PIgnoreOfflineNodes, |
1175 | 45d4c81c | Michael Hanselmann | ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt,
|
1176 | 45d4c81c | Michael Hanselmann | "How long to wait for instance to shut down"),
|
1177 | 9b64e486 | Iustin Pop | _PNoRemember, |
1178 | b44bd844 | Michael Hanselmann | ] |
1179 | a8083063 | Iustin Pop | |
1180 | a8083063 | Iustin Pop | |
1181 | 90ab1a95 | Iustin Pop | class OpInstanceReboot(OpCode): |
1182 | bf6929a2 | Alexander Schreiber | """Reboot an instance."""
|
1183 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1184 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1185 | 65e183af | Michael Hanselmann | _PInstanceName, |
1186 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
1187 | 45d4c81c | Michael Hanselmann | ("ignore_secondaries", False, ht.TBool, |
1188 | 45d4c81c | Michael Hanselmann | "Whether to start the instance even if secondary disks are failing"),
|
1189 | 45d4c81c | Michael Hanselmann | ("reboot_type", ht.NoDefault, ht.TElemOf(constants.REBOOT_TYPES),
|
1190 | 45d4c81c | Michael Hanselmann | "How to reboot instance"),
|
1191 | 4f05fd3b | Iustin Pop | ] |
1192 | bf6929a2 | Alexander Schreiber | |
1193 | bf6929a2 | Alexander Schreiber | |
1194 | 668f755d | Iustin Pop | class OpInstanceReplaceDisks(OpCode): |
1195 | fdc267f4 | Iustin Pop | """Replace the disks of an instance."""
|
1196 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1197 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1198 | 65e183af | Michael Hanselmann | _PInstanceName, |
1199 | e1f23243 | Michael Hanselmann | _PEarlyRelease, |
1200 | 45d4c81c | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.REPLACE_MODES),
|
1201 | 45d4c81c | Michael Hanselmann | "Replacement mode"),
|
1202 | 45d4c81c | Michael Hanselmann | ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
|
1203 | 45d4c81c | Michael Hanselmann | "Disk indexes"),
|
1204 | 45d4c81c | Michael Hanselmann | ("remote_node", None, ht.TMaybeString, "New secondary node"), |
1205 | 45d4c81c | Michael Hanselmann | ("iallocator", None, ht.TMaybeString, |
1206 | 45d4c81c | Michael Hanselmann | "Iallocator for deciding new secondary node"),
|
1207 | 4f05fd3b | Iustin Pop | ] |
1208 | a8083063 | Iustin Pop | |
1209 | a8083063 | Iustin Pop | |
1210 | 019dbee1 | Iustin Pop | class OpInstanceFailover(OpCode): |
1211 | a8083063 | Iustin Pop | """Failover an instance."""
|
1212 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1213 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1214 | 65e183af | Michael Hanselmann | _PInstanceName, |
1215 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
1216 | 45d4c81c | Michael Hanselmann | _PIgnoreConsistency, |
1217 | f8fa4175 | Michael Hanselmann | _PMigrationTargetNode, |
1218 | 8eb34306 | Apollon Oikonomopoulos | ("iallocator", None, ht.TMaybeString, |
1219 | 8eb34306 | Apollon Oikonomopoulos | "Iallocator for deciding the target node for shared-storage instances"),
|
1220 | 17c3f802 | Guido Trotter | ] |
1221 | a8083063 | Iustin Pop | |
1222 | a8083063 | Iustin Pop | |
1223 | 75c866c2 | Iustin Pop | class OpInstanceMigrate(OpCode): |
1224 | 53c776b5 | Iustin Pop | """Migrate an instance.
|
1225 | 53c776b5 | Iustin Pop |
|
1226 | 53c776b5 | Iustin Pop | This migrates (without shutting down an instance) to its secondary
|
1227 | 53c776b5 | Iustin Pop | node.
|
1228 | 53c776b5 | Iustin Pop |
|
1229 | 2f907a8c | Iustin Pop | @ivar instance_name: the name of the instance
|
1230 | 8c35561f | Iustin Pop | @ivar mode: the migration mode (live, non-live or None for auto)
|
1231 | 53c776b5 | Iustin Pop |
|
1232 | 53c776b5 | Iustin Pop | """
|
1233 | ee69c97f | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1234 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1235 | 65e183af | Michael Hanselmann | _PInstanceName, |
1236 | 65e183af | Michael Hanselmann | _PMigrationMode, |
1237 | 65e183af | Michael Hanselmann | _PMigrationLive, |
1238 | f8fa4175 | Michael Hanselmann | _PMigrationTargetNode, |
1239 | 45d4c81c | Michael Hanselmann | ("cleanup", False, ht.TBool, |
1240 | 45d4c81c | Michael Hanselmann | "Whether a previously failed migration should be cleaned up"),
|
1241 | 8eb34306 | Apollon Oikonomopoulos | ("iallocator", None, ht.TMaybeString, |
1242 | 8eb34306 | Apollon Oikonomopoulos | "Iallocator for deciding the target node for shared-storage instances"),
|
1243 | d5cafd31 | Renรฉ Nussbaumer | ("allow_failover", False, ht.TBool, |
1244 | d5cafd31 | Renรฉ Nussbaumer | "Whether we can fallback to failover if migration is not possible"),
|
1245 | 65e183af | Michael Hanselmann | ] |
1246 | 53c776b5 | Iustin Pop | |
1247 | 53c776b5 | Iustin Pop | |
1248 | 0091b480 | Iustin Pop | class OpInstanceMove(OpCode): |
1249 | 313bcead | Iustin Pop | """Move an instance.
|
1250 | 313bcead | Iustin Pop |
|
1251 | 313bcead | Iustin Pop | This move (with shutting down an instance and data copying) to an
|
1252 | 313bcead | Iustin Pop | arbitrary node.
|
1253 | 313bcead | Iustin Pop |
|
1254 | 313bcead | Iustin Pop | @ivar instance_name: the name of the instance
|
1255 | 313bcead | Iustin Pop | @ivar target_node: the destination node
|
1256 | 313bcead | Iustin Pop |
|
1257 | 313bcead | Iustin Pop | """
|
1258 | 313bcead | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1259 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1260 | 65e183af | Michael Hanselmann | _PInstanceName, |
1261 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
1262 | 45d4c81c | Michael Hanselmann | ("target_node", ht.NoDefault, ht.TNonEmptyString, "Target node"), |
1263 | bb851c63 | Iustin Pop | _PIgnoreConsistency, |
1264 | 154b9580 | Balazs Lecz | ] |
1265 | 313bcead | Iustin Pop | |
1266 | 313bcead | Iustin Pop | |
1267 | cc0dec7b | Iustin Pop | class OpInstanceConsole(OpCode): |
1268 | fdc267f4 | Iustin Pop | """Connect to an instance's console."""
|
1269 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1270 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1271 | 65e183af | Michael Hanselmann | _PInstanceName |
1272 | 65e183af | Michael Hanselmann | ] |
1273 | a8083063 | Iustin Pop | |
1274 | a8083063 | Iustin Pop | |
1275 | 83f5d475 | Iustin Pop | class OpInstanceActivateDisks(OpCode): |
1276 | fdc267f4 | Iustin Pop | """Activate an instance's disks."""
|
1277 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1278 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1279 | 65e183af | Michael Hanselmann | _PInstanceName, |
1280 | 45d4c81c | Michael Hanselmann | ("ignore_size", False, ht.TBool, "Whether to ignore recorded size"), |
1281 | 65e183af | Michael Hanselmann | ] |
1282 | a8083063 | Iustin Pop | |
1283 | a8083063 | Iustin Pop | |
1284 | e176281f | Iustin Pop | class OpInstanceDeactivateDisks(OpCode): |
1285 | fdc267f4 | Iustin Pop | """Deactivate an instance's disks."""
|
1286 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1287 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1288 | c9c41373 | Iustin Pop | _PInstanceName, |
1289 | c9c41373 | Iustin Pop | _PForce, |
1290 | 65e183af | Michael Hanselmann | ] |
1291 | a8083063 | Iustin Pop | |
1292 | a8083063 | Iustin Pop | |
1293 | 6b273e78 | Iustin Pop | class OpInstanceRecreateDisks(OpCode): |
1294 | a52978c7 | Michael Hanselmann | """Recreate an instance's disks."""
|
1295 | bd315bfa | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1296 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1297 | 65e183af | Michael Hanselmann | _PInstanceName, |
1298 | 45d4c81c | Michael Hanselmann | ("disks", ht.EmptyList, ht.TListOf(ht.TPositiveInt),
|
1299 | 45d4c81c | Michael Hanselmann | "List of disk indexes"),
|
1300 | 93384b8c | Guido Trotter | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1301 | 93384b8c | Guido Trotter | "New instance nodes, if relocation is desired"),
|
1302 | 65e183af | Michael Hanselmann | ] |
1303 | bd315bfa | Iustin Pop | |
1304 | bd315bfa | Iustin Pop | |
1305 | f2af0bec | Iustin Pop | class OpInstanceQuery(OpCode): |
1306 | a8083063 | Iustin Pop | """Compute the list of instances."""
|
1307 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1308 | 65e183af | Michael Hanselmann | _POutputFields, |
1309 | 45d4c81c | Michael Hanselmann | _PUseLocking, |
1310 | 45d4c81c | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1311 | 45d4c81c | Michael Hanselmann | "Empty list to query all instances, instance names otherwise"),
|
1312 | 65e183af | Michael Hanselmann | ] |
1313 | a8083063 | Iustin Pop | |
1314 | a8083063 | Iustin Pop | |
1315 | dc28c4e4 | Iustin Pop | class OpInstanceQueryData(OpCode): |
1316 | a8083063 | Iustin Pop | """Compute the run-time status of instances."""
|
1317 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1318 | af7b6689 | Michael Hanselmann | _PUseLocking, |
1319 | af7b6689 | Michael Hanselmann | ("instances", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1320 | af7b6689 | Michael Hanselmann | "Instance names"),
|
1321 | af7b6689 | Michael Hanselmann | ("static", False, ht.TBool, |
1322 | af7b6689 | Michael Hanselmann | "Whether to only return configuration data without querying"
|
1323 | af7b6689 | Michael Hanselmann | " nodes"),
|
1324 | 65e183af | Michael Hanselmann | ] |
1325 | a8083063 | Iustin Pop | |
1326 | a8083063 | Iustin Pop | |
1327 | 9a3cc7ae | Iustin Pop | class OpInstanceSetParams(OpCode): |
1328 | a8083063 | Iustin Pop | """Change the parameters of an instance."""
|
1329 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1330 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1331 | 65e183af | Michael Hanselmann | _PInstanceName, |
1332 | 65e183af | Michael Hanselmann | _PForce, |
1333 | 45d4c81c | Michael Hanselmann | _PForceVariant, |
1334 | 526a662a | Michael Hanselmann | # TODO: Use _TestNicDef
|
1335 | 45d4c81c | Michael Hanselmann | ("nics", ht.EmptyList, ht.TList,
|
1336 | 45d4c81c | Michael Hanselmann | "List of NIC changes. Each item is of the form ``(op, settings)``."
|
1337 | 45d4c81c | Michael Hanselmann | " ``op`` can be ``%s`` to add a new NIC with the specified settings,"
|
1338 | 45d4c81c | Michael Hanselmann | " ``%s`` to remove the last NIC or a number to modify the settings"
|
1339 | 45d4c81c | Michael Hanselmann | " of the NIC with that index." %
|
1340 | 45d4c81c | Michael Hanselmann | (constants.DDM_ADD, constants.DDM_REMOVE)), |
1341 | 45d4c81c | Michael Hanselmann | ("disks", ht.EmptyList, ht.TList, "List of disk changes. See ``nics``."), |
1342 | 45d4c81c | Michael Hanselmann | ("beparams", ht.EmptyDict, ht.TDict, "Per-instance backend parameters"), |
1343 | 45d4c81c | Michael Hanselmann | ("hvparams", ht.EmptyDict, ht.TDict,
|
1344 | 45d4c81c | Michael Hanselmann | "Per-instance hypervisor parameters, hypervisor-dependent"),
|
1345 | 45fe090b | Michael Hanselmann | ("disk_template", None, ht.TOr(ht.TNone, _BuildDiskTemplateCheck(False)), |
1346 | 45d4c81c | Michael Hanselmann | "Disk template for instance"),
|
1347 | 45d4c81c | Michael Hanselmann | ("remote_node", None, ht.TMaybeString, |
1348 | 45d4c81c | Michael Hanselmann | "Secondary node (used when changing disk template)"),
|
1349 | 45d4c81c | Michael Hanselmann | ("os_name", None, ht.TMaybeString, |
1350 | 45d4c81c | Michael Hanselmann | "Change instance's OS name. Does not reinstall the instance."),
|
1351 | 45d4c81c | Michael Hanselmann | ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"), |
1352 | 93384b8c | Guido Trotter | ("wait_for_sync", True, ht.TBool, |
1353 | 93384b8c | Guido Trotter | "Whether to wait for the disk to synchronize, when changing template"),
|
1354 | 57de31c0 | Agata Murawska | ("offline_inst", False, ht.TBool, |
1355 | 57de31c0 | Agata Murawska | "Whether to turn off the down instance completely"),
|
1356 | 57de31c0 | Agata Murawska | ("online_inst", False, ht.TBool, |
1357 | 57de31c0 | Agata Murawska | "Whether to enable the offline instance"),
|
1358 | 973d7867 | Iustin Pop | ] |
1359 | 1456df62 | Michael Hanselmann | OP_RESULT = _TSetParamsResult |
1360 | a8083063 | Iustin Pop | |
1361 | a8083063 | Iustin Pop | |
1362 | 60472d29 | Iustin Pop | class OpInstanceGrowDisk(OpCode): |
1363 | 8729e0d7 | Iustin Pop | """Grow a disk of an instance."""
|
1364 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1365 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1366 | 65e183af | Michael Hanselmann | _PInstanceName, |
1367 | 45d4c81c | Michael Hanselmann | _PWaitForSync, |
1368 | 45d4c81c | Michael Hanselmann | ("disk", ht.NoDefault, ht.TInt, "Disk index"), |
1369 | 45d4c81c | Michael Hanselmann | ("amount", ht.NoDefault, ht.TInt,
|
1370 | 45d4c81c | Michael Hanselmann | "Amount of disk space to add (megabytes)"),
|
1371 | 4f05fd3b | Iustin Pop | ] |
1372 | 8729e0d7 | Iustin Pop | |
1373 | 8729e0d7 | Iustin Pop | |
1374 | 1aef3df8 | Michael Hanselmann | class OpInstanceChangeGroup(OpCode): |
1375 | 1aef3df8 | Michael Hanselmann | """Moves an instance to another node group."""
|
1376 | 1aef3df8 | Michael Hanselmann | OP_DSC_FIELD = "instance_name"
|
1377 | 1aef3df8 | Michael Hanselmann | OP_PARAMS = [ |
1378 | 1aef3df8 | Michael Hanselmann | _PInstanceName, |
1379 | 1aef3df8 | Michael Hanselmann | _PEarlyRelease, |
1380 | 1aef3df8 | Michael Hanselmann | ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), |
1381 | 1aef3df8 | Michael Hanselmann | ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), |
1382 | 1aef3df8 | Michael Hanselmann | "Destination group names or UUIDs (defaults to \"all but current group\""),
|
1383 | 1aef3df8 | Michael Hanselmann | ] |
1384 | 1456df62 | Michael Hanselmann | OP_RESULT = TJobIdListOnly |
1385 | 1aef3df8 | Michael Hanselmann | |
1386 | 1aef3df8 | Michael Hanselmann | |
1387 | 70a6a926 | Adeodato Simo | # Node group opcodes
|
1388 | 70a6a926 | Adeodato Simo | |
1389 | fabf1731 | Iustin Pop | class OpGroupAdd(OpCode): |
1390 | b1ee5610 | Adeodato Simo | """Add a node group to the cluster."""
|
1391 | b1ee5610 | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1392 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1393 | 65e183af | Michael Hanselmann | _PGroupName, |
1394 | 45d4c81c | Michael Hanselmann | _PNodeGroupAllocPolicy, |
1395 | 45d4c81c | Michael Hanselmann | _PGroupNodeParams, |
1396 | 483be60d | Adeodato Simo | ] |
1397 | b1ee5610 | Adeodato Simo | |
1398 | b1ee5610 | Adeodato Simo | |
1399 | 934704ae | Iustin Pop | class OpGroupAssignNodes(OpCode): |
1400 | 96276ae7 | Adeodato Simo | """Assign nodes to a node group."""
|
1401 | 96276ae7 | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1402 | 96276ae7 | Adeodato Simo | OP_PARAMS = [ |
1403 | 96276ae7 | Adeodato Simo | _PGroupName, |
1404 | 96276ae7 | Adeodato Simo | _PForce, |
1405 | 45d4c81c | Michael Hanselmann | ("nodes", ht.NoDefault, ht.TListOf(ht.TNonEmptyString),
|
1406 | 45d4c81c | Michael Hanselmann | "List of nodes to assign"),
|
1407 | 96276ae7 | Adeodato Simo | ] |
1408 | 96276ae7 | Adeodato Simo | |
1409 | 96276ae7 | Adeodato Simo | |
1410 | d4d654bd | Iustin Pop | class OpGroupQuery(OpCode): |
1411 | 70a6a926 | Adeodato Simo | """Compute the list of node groups."""
|
1412 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1413 | 65e183af | Michael Hanselmann | _POutputFields, |
1414 | 45d4c81c | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1415 | 45d4c81c | Michael Hanselmann | "Empty list to query all groups, group names otherwise"),
|
1416 | 65e183af | Michael Hanselmann | ] |
1417 | 70a6a926 | Adeodato Simo | |
1418 | 70a6a926 | Adeodato Simo | |
1419 | 7cbf74f0 | Iustin Pop | class OpGroupSetParams(OpCode): |
1420 | 4da7909a | Adeodato Simo | """Change the parameters of a node group."""
|
1421 | 4da7909a | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1422 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1423 | 65e183af | Michael Hanselmann | _PGroupName, |
1424 | 45d4c81c | Michael Hanselmann | _PNodeGroupAllocPolicy, |
1425 | 45d4c81c | Michael Hanselmann | _PGroupNodeParams, |
1426 | 4da7909a | Adeodato Simo | ] |
1427 | 1456df62 | Michael Hanselmann | OP_RESULT = _TSetParamsResult |
1428 | 4da7909a | Adeodato Simo | |
1429 | 4da7909a | Adeodato Simo | |
1430 | 4d1baa51 | Iustin Pop | class OpGroupRemove(OpCode): |
1431 | 94bd652a | Adeodato Simo | """Remove a node group from the cluster."""
|
1432 | 94bd652a | Adeodato Simo | OP_DSC_FIELD = "group_name"
|
1433 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1434 | 65e183af | Michael Hanselmann | _PGroupName, |
1435 | 65e183af | Michael Hanselmann | ] |
1436 | 94bd652a | Adeodato Simo | |
1437 | 94bd652a | Adeodato Simo | |
1438 | a8173e82 | Iustin Pop | class OpGroupRename(OpCode): |
1439 | 4fe5cf90 | Adeodato Simo | """Rename a node group in the cluster."""
|
1440 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1441 | 12da663a | Michael Hanselmann | _PGroupName, |
1442 | 12da663a | Michael Hanselmann | ("new_name", ht.NoDefault, ht.TNonEmptyString, "New group name"), |
1443 | 65e183af | Michael Hanselmann | ] |
1444 | 1456df62 | Michael Hanselmann | OP_RESULT = ht.Comment("New group name")(ht.TNonEmptyString)
|
1445 | 4fe5cf90 | Adeodato Simo | |
1446 | 4fe5cf90 | Adeodato Simo | |
1447 | 08f8c82c | Michael Hanselmann | class OpGroupEvacuate(OpCode): |
1448 | 08f8c82c | Michael Hanselmann | """Evacuate a node group in the cluster."""
|
1449 | 08f8c82c | Michael Hanselmann | OP_DSC_FIELD = "group_name"
|
1450 | 08f8c82c | Michael Hanselmann | OP_PARAMS = [ |
1451 | 08f8c82c | Michael Hanselmann | _PGroupName, |
1452 | 08f8c82c | Michael Hanselmann | _PEarlyRelease, |
1453 | 08f8c82c | Michael Hanselmann | ("iallocator", None, ht.TMaybeString, "Iallocator for computing solution"), |
1454 | 08f8c82c | Michael Hanselmann | ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), |
1455 | 08f8c82c | Michael Hanselmann | "Destination group names or UUIDs"),
|
1456 | 08f8c82c | Michael Hanselmann | ] |
1457 | 1456df62 | Michael Hanselmann | OP_RESULT = TJobIdListOnly |
1458 | 08f8c82c | Michael Hanselmann | |
1459 | 08f8c82c | Michael Hanselmann | |
1460 | a8083063 | Iustin Pop | # OS opcodes
|
1461 | da2d02e7 | Iustin Pop | class OpOsDiagnose(OpCode): |
1462 | a8083063 | Iustin Pop | """Compute the list of guest operating systems."""
|
1463 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1464 | 65e183af | Michael Hanselmann | _POutputFields, |
1465 | 45d4c81c | Michael Hanselmann | ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1466 | 45d4c81c | Michael Hanselmann | "Which operating systems to diagnose"),
|
1467 | 65e183af | Michael Hanselmann | ] |
1468 | a8083063 | Iustin Pop | |
1469 | 7c0d6283 | Michael Hanselmann | |
1470 | a8083063 | Iustin Pop | # Exports opcodes
|
1471 | 7ca2d4d8 | Iustin Pop | class OpBackupQuery(OpCode): |
1472 | a8083063 | Iustin Pop | """Compute the list of exported images."""
|
1473 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1474 | 45d4c81c | Michael Hanselmann | _PUseLocking, |
1475 | 45d4c81c | Michael Hanselmann | ("nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
|
1476 | 45d4c81c | Michael Hanselmann | "Empty list to query all nodes, node names otherwise"),
|
1477 | 65e183af | Michael Hanselmann | ] |
1478 | a8083063 | Iustin Pop | |
1479 | 7c0d6283 | Michael Hanselmann | |
1480 | 71910715 | Iustin Pop | class OpBackupPrepare(OpCode): |
1481 | 1410fa8d | Michael Hanselmann | """Prepares an instance export.
|
1482 | 1410fa8d | Michael Hanselmann |
|
1483 | 1410fa8d | Michael Hanselmann | @ivar instance_name: Instance name
|
1484 | 1410fa8d | Michael Hanselmann | @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
1485 | 1410fa8d | Michael Hanselmann |
|
1486 | 1410fa8d | Michael Hanselmann | """
|
1487 | 1410fa8d | Michael Hanselmann | OP_DSC_FIELD = "instance_name"
|
1488 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1489 | 65e183af | Michael Hanselmann | _PInstanceName, |
1490 | 45d4c81c | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.EXPORT_MODES),
|
1491 | 45d4c81c | Michael Hanselmann | "Export mode"),
|
1492 | 1410fa8d | Michael Hanselmann | ] |
1493 | 1410fa8d | Michael Hanselmann | |
1494 | 1410fa8d | Michael Hanselmann | |
1495 | 4ff922a2 | Iustin Pop | class OpBackupExport(OpCode): |
1496 | 4a96f1d1 | Michael Hanselmann | """Export an instance.
|
1497 | 4a96f1d1 | Michael Hanselmann |
|
1498 | 4a96f1d1 | Michael Hanselmann | For local exports, the export destination is the node name. For remote
|
1499 | 4a96f1d1 | Michael Hanselmann | exports, the export destination is a list of tuples, each consisting of
|
1500 | 4a96f1d1 | Michael Hanselmann | hostname/IP address, port, HMAC and HMAC salt. The HMAC is calculated using
|
1501 | 4a96f1d1 | Michael Hanselmann | the cluster domain secret over the value "${index}:${hostname}:${port}". The
|
1502 | 4a96f1d1 | Michael Hanselmann | destination X509 CA must be a signed certificate.
|
1503 | 4a96f1d1 | Michael Hanselmann |
|
1504 | 4a96f1d1 | Michael Hanselmann | @ivar mode: Export mode (one of L{constants.EXPORT_MODES})
|
1505 | 4a96f1d1 | Michael Hanselmann | @ivar target_node: Export destination
|
1506 | 4a96f1d1 | Michael Hanselmann | @ivar x509_key_name: X509 key to use (remote export only)
|
1507 | 4a96f1d1 | Michael Hanselmann | @ivar destination_x509_ca: Destination X509 CA in PEM format (remote export
|
1508 | 4a96f1d1 | Michael Hanselmann | only)
|
1509 | 4a96f1d1 | Michael Hanselmann |
|
1510 | 4a96f1d1 | Michael Hanselmann | """
|
1511 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1512 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1513 | 65e183af | Michael Hanselmann | _PInstanceName, |
1514 | 65e183af | Michael Hanselmann | _PShutdownTimeout, |
1515 | 4a96f1d1 | Michael Hanselmann | # TODO: Rename target_node as it changes meaning for different export modes
|
1516 | 4a96f1d1 | Michael Hanselmann | # (e.g. "destination")
|
1517 | 45d4c81c | Michael Hanselmann | ("target_node", ht.NoDefault, ht.TOr(ht.TNonEmptyString, ht.TList),
|
1518 | 45d4c81c | Michael Hanselmann | "Destination information, depends on export mode"),
|
1519 | 45d4c81c | Michael Hanselmann | ("shutdown", True, ht.TBool, "Whether to shutdown instance before export"), |
1520 | 45d4c81c | Michael Hanselmann | ("remove_instance", False, ht.TBool, |
1521 | 45d4c81c | Michael Hanselmann | "Whether to remove instance after export"),
|
1522 | 45d4c81c | Michael Hanselmann | ("ignore_remove_failures", False, ht.TBool, |
1523 | 45d4c81c | Michael Hanselmann | "Whether to ignore failures while removing instances"),
|
1524 | 45d4c81c | Michael Hanselmann | ("mode", constants.EXPORT_MODE_LOCAL, ht.TElemOf(constants.EXPORT_MODES),
|
1525 | 45d4c81c | Michael Hanselmann | "Export mode"),
|
1526 | 45d4c81c | Michael Hanselmann | ("x509_key_name", None, ht.TOr(ht.TList, ht.TNone), |
1527 | 45d4c81c | Michael Hanselmann | "Name of X509 key (remote export only)"),
|
1528 | 45d4c81c | Michael Hanselmann | ("destination_x509_ca", None, ht.TMaybeString, |
1529 | 45d4c81c | Michael Hanselmann | "Destination X509 CA (remote export only)"),
|
1530 | 17c3f802 | Guido Trotter | ] |
1531 | 5c947f38 | Iustin Pop | |
1532 | 0a7bed64 | Michael Hanselmann | |
1533 | ca5890ad | Iustin Pop | class OpBackupRemove(OpCode): |
1534 | 9ac99fda | Guido Trotter | """Remove an instance's export."""
|
1535 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "instance_name"
|
1536 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1537 | 65e183af | Michael Hanselmann | _PInstanceName, |
1538 | 65e183af | Michael Hanselmann | ] |
1539 | 5c947f38 | Iustin Pop | |
1540 | 0a7bed64 | Michael Hanselmann | |
1541 | 5c947f38 | Iustin Pop | # Tags opcodes
|
1542 | c6afb1ca | Iustin Pop | class OpTagsGet(OpCode): |
1543 | 5c947f38 | Iustin Pop | """Returns the tags of the given object."""
|
1544 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "name"
|
1545 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1546 | 65e183af | Michael Hanselmann | _PTagKind, |
1547 | 65e183af | Michael Hanselmann | # Name is only meaningful for nodes and instances
|
1548 | 197b323b | Michael Hanselmann | ("name", ht.NoDefault, ht.TMaybeString, None), |
1549 | 65e183af | Michael Hanselmann | ] |
1550 | 5c947f38 | Iustin Pop | |
1551 | 5c947f38 | Iustin Pop | |
1552 | 715462e7 | Iustin Pop | class OpTagsSearch(OpCode): |
1553 | 73415719 | Iustin Pop | """Searches the tags in the cluster for a given pattern."""
|
1554 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "pattern"
|
1555 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1556 | 197b323b | Michael Hanselmann | ("pattern", ht.NoDefault, ht.TNonEmptyString, None), |
1557 | 65e183af | Michael Hanselmann | ] |
1558 | 73415719 | Iustin Pop | |
1559 | 73415719 | Iustin Pop | |
1560 | d1602edc | Iustin Pop | class OpTagsSet(OpCode): |
1561 | f27302fa | Iustin Pop | """Add a list of tags on a given object."""
|
1562 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1563 | 65e183af | Michael Hanselmann | _PTagKind, |
1564 | 65e183af | Michael Hanselmann | _PTags, |
1565 | 65e183af | Michael Hanselmann | # Name is only meaningful for nodes and instances
|
1566 | 197b323b | Michael Hanselmann | ("name", ht.NoDefault, ht.TMaybeString, None), |
1567 | 65e183af | Michael Hanselmann | ] |
1568 | 5c947f38 | Iustin Pop | |
1569 | 5c947f38 | Iustin Pop | |
1570 | 3f0ab95f | Iustin Pop | class OpTagsDel(OpCode): |
1571 | f27302fa | Iustin Pop | """Remove a list of tags from a given object."""
|
1572 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1573 | 65e183af | Michael Hanselmann | _PTagKind, |
1574 | 65e183af | Michael Hanselmann | _PTags, |
1575 | 65e183af | Michael Hanselmann | # Name is only meaningful for nodes and instances
|
1576 | 197b323b | Michael Hanselmann | ("name", ht.NoDefault, ht.TMaybeString, None), |
1577 | 65e183af | Michael Hanselmann | ] |
1578 | 06009e27 | Iustin Pop | |
1579 | e687ec01 | Michael Hanselmann | |
1580 | 06009e27 | Iustin Pop | # Test opcodes
|
1581 | 06009e27 | Iustin Pop | class OpTestDelay(OpCode): |
1582 | 06009e27 | Iustin Pop | """Sleeps for a configured amount of time.
|
1583 | 06009e27 | Iustin Pop |
|
1584 | 06009e27 | Iustin Pop | This is used just for debugging and testing.
|
1585 | 06009e27 | Iustin Pop |
|
1586 | 06009e27 | Iustin Pop | Parameters:
|
1587 | 06009e27 | Iustin Pop | - duration: the time to sleep
|
1588 | 06009e27 | Iustin Pop | - on_master: if true, sleep on the master
|
1589 | 06009e27 | Iustin Pop | - on_nodes: list of nodes in which to sleep
|
1590 | 06009e27 | Iustin Pop |
|
1591 | 06009e27 | Iustin Pop | If the on_master parameter is true, it will execute a sleep on the
|
1592 | 06009e27 | Iustin Pop | master (before any node sleep).
|
1593 | 06009e27 | Iustin Pop |
|
1594 | 06009e27 | Iustin Pop | If the on_nodes list is not empty, it will sleep on those nodes
|
1595 | 06009e27 | Iustin Pop | (after the sleep on the master, if that is enabled).
|
1596 | 06009e27 | Iustin Pop |
|
1597 | 06009e27 | Iustin Pop | As an additional feature, the case of duration < 0 will be reported
|
1598 | 06009e27 | Iustin Pop | as an execution error, so this opcode can be used as a failure
|
1599 | 06009e27 | Iustin Pop | generator. The case of duration == 0 will not be treated specially.
|
1600 | 06009e27 | Iustin Pop |
|
1601 | 06009e27 | Iustin Pop | """
|
1602 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "duration"
|
1603 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1604 | b795a775 | Michael Hanselmann | ("duration", ht.NoDefault, ht.TNumber, None), |
1605 | 197b323b | Michael Hanselmann | ("on_master", True, ht.TBool, None), |
1606 | 197b323b | Michael Hanselmann | ("on_nodes", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), |
1607 | 197b323b | Michael Hanselmann | ("repeat", 0, ht.TPositiveInt, None), |
1608 | 65e183af | Michael Hanselmann | ] |
1609 | d61df03e | Iustin Pop | |
1610 | d61df03e | Iustin Pop | |
1611 | d61df03e | Iustin Pop | class OpTestAllocator(OpCode): |
1612 | d61df03e | Iustin Pop | """Allocator framework testing.
|
1613 | d61df03e | Iustin Pop |
|
1614 | d61df03e | Iustin Pop | This opcode has two modes:
|
1615 | d61df03e | Iustin Pop | - gather and return allocator input for a given mode (allocate new
|
1616 | d61df03e | Iustin Pop | or replace secondary) and a given instance definition (direction
|
1617 | d61df03e | Iustin Pop | 'in')
|
1618 | d61df03e | Iustin Pop | - run a selected allocator for a given operation (as above) and
|
1619 | d61df03e | Iustin Pop | return the allocator output (direction 'out')
|
1620 | d61df03e | Iustin Pop |
|
1621 | d61df03e | Iustin Pop | """
|
1622 | 60dd1473 | Iustin Pop | OP_DSC_FIELD = "allocator"
|
1623 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1624 | 65e183af | Michael Hanselmann | ("direction", ht.NoDefault,
|
1625 | 197b323b | Michael Hanselmann | ht.TElemOf(constants.VALID_IALLOCATOR_DIRECTIONS), None),
|
1626 | 197b323b | Michael Hanselmann | ("mode", ht.NoDefault, ht.TElemOf(constants.VALID_IALLOCATOR_MODES), None), |
1627 | 197b323b | Michael Hanselmann | ("name", ht.NoDefault, ht.TNonEmptyString, None), |
1628 | 65e183af | Michael Hanselmann | ("nics", ht.NoDefault, ht.TOr(ht.TNone, ht.TListOf(
|
1629 | fdbe29ee | Michael Hanselmann | ht.TDictOf(ht.TElemOf([constants.INIC_MAC, constants.INIC_IP, "bridge"]),
|
1630 | 45d4c81c | Michael Hanselmann | ht.TOr(ht.TNone, ht.TNonEmptyString)))), None),
|
1631 | 197b323b | Michael Hanselmann | ("disks", ht.NoDefault, ht.TOr(ht.TNone, ht.TList), None), |
1632 | 197b323b | Michael Hanselmann | ("hypervisor", None, ht.TMaybeString, None), |
1633 | 197b323b | Michael Hanselmann | ("allocator", None, ht.TMaybeString, None), |
1634 | 197b323b | Michael Hanselmann | ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), None), |
1635 | dd47a0f0 | Iustin Pop | ("memory", None, ht.TOr(ht.TNone, ht.TPositiveInt), None), |
1636 | 197b323b | Michael Hanselmann | ("vcpus", None, ht.TOr(ht.TNone, ht.TPositiveInt), None), |
1637 | 197b323b | Michael Hanselmann | ("os", None, ht.TMaybeString, None), |
1638 | 197b323b | Michael Hanselmann | ("disk_template", None, ht.TMaybeString, None), |
1639 | bee581e2 | Michael Hanselmann | ("instances", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), |
1640 | bee581e2 | Michael Hanselmann | None),
|
1641 | 60152bbe | Michael Hanselmann | ("evac_mode", None, |
1642 | 60152bbe | Michael Hanselmann | ht.TOr(ht.TNone, ht.TElemOf(constants.IALLOCATOR_NEVAC_MODES)), None),
|
1643 | bee581e2 | Michael Hanselmann | ("target_groups", None, ht.TOr(ht.TNone, ht.TListOf(ht.TNonEmptyString)), |
1644 | bee581e2 | Michael Hanselmann | None),
|
1645 | d61df03e | Iustin Pop | ] |
1646 | 363acb1e | Iustin Pop | |
1647 | 76aef8fc | Michael Hanselmann | |
1648 | b469eb4d | Iustin Pop | class OpTestJqueue(OpCode): |
1649 | e58f87a9 | Michael Hanselmann | """Utility opcode to test some aspects of the job queue.
|
1650 | e58f87a9 | Michael Hanselmann |
|
1651 | e58f87a9 | Michael Hanselmann | """
|
1652 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1653 | 197b323b | Michael Hanselmann | ("notify_waitlock", False, ht.TBool, None), |
1654 | 197b323b | Michael Hanselmann | ("notify_exec", False, ht.TBool, None), |
1655 | 197b323b | Michael Hanselmann | ("log_messages", ht.EmptyList, ht.TListOf(ht.TString), None), |
1656 | 197b323b | Michael Hanselmann | ("fail", False, ht.TBool, None), |
1657 | e58f87a9 | Michael Hanselmann | ] |
1658 | e58f87a9 | Michael Hanselmann | |
1659 | e58f87a9 | Michael Hanselmann | |
1660 | be760ba8 | Michael Hanselmann | class OpTestDummy(OpCode): |
1661 | be760ba8 | Michael Hanselmann | """Utility opcode used by unittests.
|
1662 | be760ba8 | Michael Hanselmann |
|
1663 | be760ba8 | Michael Hanselmann | """
|
1664 | 65e183af | Michael Hanselmann | OP_PARAMS = [ |
1665 | 197b323b | Michael Hanselmann | ("result", ht.NoDefault, ht.NoType, None), |
1666 | 197b323b | Michael Hanselmann | ("messages", ht.NoDefault, ht.NoType, None), |
1667 | 197b323b | Michael Hanselmann | ("fail", ht.NoDefault, ht.NoType, None), |
1668 | 6a373640 | Michael Hanselmann | ("submit_jobs", None, ht.NoType, None), |
1669 | be760ba8 | Michael Hanselmann | ] |
1670 | 687c10d9 | Iustin Pop | WITH_LU = False
|
1671 | be760ba8 | Michael Hanselmann | |
1672 | be760ba8 | Michael Hanselmann | |
1673 | dbc96028 | Michael Hanselmann | def _GetOpList(): |
1674 | dbc96028 | Michael Hanselmann | """Returns list of all defined opcodes.
|
1675 | dbc96028 | Michael Hanselmann |
|
1676 | dbc96028 | Michael Hanselmann | Does not eliminate duplicates by C{OP_ID}.
|
1677 | dbc96028 | Michael Hanselmann |
|
1678 | dbc96028 | Michael Hanselmann | """
|
1679 | dbc96028 | Michael Hanselmann | return [v for v in globals().values() |
1680 | dbc96028 | Michael Hanselmann | if (isinstance(v, type) and issubclass(v, OpCode) and |
1681 | 687c10d9 | Iustin Pop | hasattr(v, "OP_ID") and v is not OpCode)] |
1682 | dbc96028 | Michael Hanselmann | |
1683 | dbc96028 | Michael Hanselmann | |
1684 | dbc96028 | Michael Hanselmann | OP_MAPPING = dict((v.OP_ID, v) for v in _GetOpList()) |