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