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