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