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