Revision debac808
b/daemons/ganeti-masterd | ||
---|---|---|
256 | 256 |
(names, fields, use_locking) = args |
257 | 257 |
logging.info("Received instance query request for %s", names) |
258 | 258 |
if use_locking: |
259 |
raise errors.OpPrereqError("Sync queries are not allowed") |
|
259 |
raise errors.OpPrereqError("Sync queries are not allowed", |
|
260 |
errors.ECODE_INVAL) |
|
260 | 261 |
op = opcodes.OpQueryInstances(names=names, output_fields=fields, |
261 | 262 |
use_locking=use_locking) |
262 | 263 |
return self._Query(op) |
... | ... | |
265 | 266 |
(names, fields, use_locking) = args |
266 | 267 |
logging.info("Received node query request for %s", names) |
267 | 268 |
if use_locking: |
268 |
raise errors.OpPrereqError("Sync queries are not allowed") |
|
269 |
raise errors.OpPrereqError("Sync queries are not allowed", |
|
270 |
errors.ECODE_INVAL) |
|
269 | 271 |
op = opcodes.OpQueryNodes(names=names, output_fields=fields, |
270 | 272 |
use_locking=use_locking) |
271 | 273 |
return self._Query(op) |
... | ... | |
273 | 275 |
elif method == luxi.REQ_QUERY_EXPORTS: |
274 | 276 |
nodes, use_locking = args |
275 | 277 |
if use_locking: |
276 |
raise errors.OpPrereqError("Sync queries are not allowed") |
|
278 |
raise errors.OpPrereqError("Sync queries are not allowed", |
|
279 |
errors.ECODE_INVAL) |
|
277 | 280 |
logging.info("Received exports query request") |
278 | 281 |
op = opcodes.OpQueryExports(nodes=nodes, use_locking=use_locking) |
279 | 282 |
return self._Query(op) |
b/lib/bootstrap.py | ||
---|---|---|
160 | 160 |
""" |
161 | 161 |
# TODO: complete the docstring |
162 | 162 |
if config.ConfigWriter.IsCluster(): |
163 |
raise errors.OpPrereqError("Cluster is already initialised") |
|
163 |
raise errors.OpPrereqError("Cluster is already initialised", |
|
164 |
errors.ECODE_STATE) |
|
164 | 165 |
|
165 | 166 |
if not enabled_hypervisors: |
166 | 167 |
raise errors.OpPrereqError("Enabled hypervisors list must contain at" |
167 |
" least one member") |
|
168 |
" least one member", errors.ECODE_INVAL)
|
|
168 | 169 |
invalid_hvs = set(enabled_hypervisors) - constants.HYPER_TYPES |
169 | 170 |
if invalid_hvs: |
170 | 171 |
raise errors.OpPrereqError("Enabled hypervisors contains invalid" |
171 |
" entries: %s" % invalid_hvs) |
|
172 |
" entries: %s" % invalid_hvs, |
|
173 |
errors.ECODE_INVAL) |
|
172 | 174 |
|
173 | 175 |
hostname = utils.HostInfo() |
174 | 176 |
|
175 | 177 |
if hostname.ip.startswith("127."): |
176 | 178 |
raise errors.OpPrereqError("This host's IP resolves to the private" |
177 | 179 |
" range (%s). Please fix DNS or %s." % |
178 |
(hostname.ip, constants.ETC_HOSTS)) |
|
180 |
(hostname.ip, constants.ETC_HOSTS), |
|
181 |
errors.ECODE_ENVIRON) |
|
179 | 182 |
|
180 | 183 |
if not utils.OwnIpAddress(hostname.ip): |
181 | 184 |
raise errors.OpPrereqError("Inconsistency: this host's name resolves" |
182 | 185 |
" to %s,\nbut this ip address does not" |
183 |
" belong to this host."
|
|
184 |
" Aborting." % hostname.ip)
|
|
186 |
" belong to this host. Aborting." %
|
|
187 |
hostname.ip, errors.ECODE_ENVIRON)
|
|
185 | 188 |
|
186 | 189 |
clustername = utils.HostInfo(cluster_name) |
187 | 190 |
|
188 | 191 |
if utils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT, |
189 | 192 |
timeout=5): |
190 |
raise errors.OpPrereqError("Cluster IP already active. Aborting.") |
|
193 |
raise errors.OpPrereqError("Cluster IP already active. Aborting.", |
|
194 |
errors.ECODE_NOTUNIQUE) |
|
191 | 195 |
|
192 | 196 |
if secondary_ip: |
193 | 197 |
if not utils.IsValidIP(secondary_ip): |
194 |
raise errors.OpPrereqError("Invalid secondary ip given") |
|
198 |
raise errors.OpPrereqError("Invalid secondary ip given", |
|
199 |
errors.ECODE_INVAL) |
|
195 | 200 |
if (secondary_ip != hostname.ip and |
196 | 201 |
not utils.OwnIpAddress(secondary_ip)): |
197 | 202 |
raise errors.OpPrereqError("You gave %s as secondary IP," |
198 | 203 |
" but it does not belong to this host." % |
199 |
secondary_ip) |
|
204 |
secondary_ip, errors.ECODE_ENVIRON)
|
|
200 | 205 |
else: |
201 | 206 |
secondary_ip = hostname.ip |
202 | 207 |
|
... | ... | |
206 | 211 |
constants.MIN_VG_SIZE) |
207 | 212 |
if vgstatus: |
208 | 213 |
raise errors.OpPrereqError("Error: %s\nspecify --no-lvm-storage if" |
209 |
" you are not using lvm" % vgstatus) |
|
214 |
" you are not using lvm" % vgstatus, |
|
215 |
errors.ECODE_INVAL) |
|
210 | 216 |
|
211 | 217 |
file_storage_dir = os.path.normpath(file_storage_dir) |
212 | 218 |
|
213 | 219 |
if not os.path.isabs(file_storage_dir): |
214 | 220 |
raise errors.OpPrereqError("The file storage directory you passed is" |
215 |
" not an absolute path.") |
|
221 |
" not an absolute path.", errors.ECODE_INVAL)
|
|
216 | 222 |
|
217 | 223 |
if not os.path.exists(file_storage_dir): |
218 | 224 |
try: |
219 | 225 |
os.makedirs(file_storage_dir, 0750) |
220 | 226 |
except OSError, err: |
221 | 227 |
raise errors.OpPrereqError("Cannot create file storage directory" |
222 |
" '%s': %s" % |
|
223 |
(file_storage_dir, err))
|
|
228 |
" '%s': %s" % (file_storage_dir, err),
|
|
229 |
errors.ECODE_ENVIRON)
|
|
224 | 230 |
|
225 | 231 |
if not os.path.isdir(file_storage_dir): |
226 | 232 |
raise errors.OpPrereqError("The file storage directory '%s' is not" |
227 |
" a directory." % file_storage_dir) |
|
233 |
" a directory." % file_storage_dir, |
|
234 |
errors.ECODE_ENVIRON) |
|
228 | 235 |
|
229 | 236 |
if not re.match("^[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}$", mac_prefix): |
230 |
raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix) |
|
237 |
raise errors.OpPrereqError("Invalid mac prefix given '%s'" % mac_prefix, |
|
238 |
errors.ECODE_INVAL) |
|
231 | 239 |
|
232 | 240 |
result = utils.RunCmd(["ip", "link", "show", "dev", master_netdev]) |
233 | 241 |
if result.failed: |
234 | 242 |
raise errors.OpPrereqError("Invalid master netdev given (%s): '%s'" % |
235 | 243 |
(master_netdev, |
236 |
result.output.strip())) |
|
244 |
result.output.strip()), errors.ECODE_INVAL)
|
|
237 | 245 |
|
238 | 246 |
if not (os.path.isfile(constants.NODE_INITD_SCRIPT) and |
239 | 247 |
os.access(constants.NODE_INITD_SCRIPT, os.X_OK)): |
240 | 248 |
raise errors.OpPrereqError("Init.d script '%s' missing or not" |
241 |
" executable." % constants.NODE_INITD_SCRIPT) |
|
249 |
" executable." % constants.NODE_INITD_SCRIPT, |
|
250 |
errors.ECODE_ENVIRON) |
|
242 | 251 |
|
243 | 252 |
dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE)] |
244 | 253 |
utils.EnsureDirs(dirs) |
... | ... | |
449 | 458 |
raise errors.OpPrereqError("This commands must be run on the node" |
450 | 459 |
" where you want the new master to be." |
451 | 460 |
" %s is already the master" % |
452 |
old_master) |
|
461 |
old_master, errors.ECODE_INVAL)
|
|
453 | 462 |
|
454 | 463 |
if new_master not in mc_list: |
455 | 464 |
mc_no_master = [name for name in mc_list if name != old_master] |
... | ... | |
457 | 466 |
" as master candidates. Only these nodes" |
458 | 467 |
" can become masters. Current list of" |
459 | 468 |
" master candidates is:\n" |
460 |
"%s" % ('\n'.join(mc_no_master))) |
|
469 |
"%s" % ('\n'.join(mc_no_master)), |
|
470 |
errors.ECODE_STATE) |
|
461 | 471 |
|
462 | 472 |
if not no_voting: |
463 | 473 |
vote_list = GatherMasterVotes(node_list) |
... | ... | |
466 | 476 |
voted_master = vote_list[0][0] |
467 | 477 |
if voted_master is None: |
468 | 478 |
raise errors.OpPrereqError("Cluster is inconsistent, most nodes did" |
469 |
" not respond.") |
|
479 |
" not respond.", errors.ECODE_ENVIRON)
|
|
470 | 480 |
elif voted_master != old_master: |
471 | 481 |
raise errors.OpPrereqError("I have a wrong configuration, I believe" |
472 | 482 |
" the master is %s but the other nodes" |
473 | 483 |
" voted %s. Please resync the configuration" |
474 | 484 |
" of this node." % |
475 |
(old_master, voted_master)) |
|
485 |
(old_master, voted_master), |
|
486 |
errors.ECODE_STATE) |
|
476 | 487 |
# end checks |
477 | 488 |
|
478 | 489 |
rcode = 0 |
b/lib/mcpu.py | ||
---|---|---|
387 | 387 |
except errors.LockError: |
388 | 388 |
raise errors.OpPrereqError( |
389 | 389 |
"Couldn't add locks (%s), probably because of a race condition" |
390 |
" with another job, who added them first" % add_locks) |
|
390 |
" with another job, who added them first" % add_locks, |
|
391 |
errors.ECODE_FAULT) |
|
391 | 392 |
|
392 | 393 |
acquired = add_locks |
393 | 394 |
|
b/lib/objects.py | ||
---|---|---|
734 | 734 |
idx = int(idx) |
735 | 735 |
return self.disks[idx] |
736 | 736 |
except ValueError, err: |
737 |
raise errors.OpPrereqError("Invalid disk index: '%s'" % str(err)) |
|
737 |
raise errors.OpPrereqError("Invalid disk index: '%s'" % str(err), |
|
738 |
errors.ECODE_INVAL) |
|
738 | 739 |
except IndexError: |
739 | 740 |
raise errors.OpPrereqError("Invalid disk index: %d (instace has disks" |
740 |
" 0 to %d" % (idx, len(self.disks))) |
|
741 |
" 0 to %d" % (idx, len(self.disks)), |
|
742 |
errors.ECODE_INVAL) |
|
741 | 743 |
|
742 | 744 |
def ToDict(self): |
743 | 745 |
"""Instance-specific conversion to standard python types. |
b/scripts/gnt-cluster | ||
---|---|---|
280 | 280 |
""" |
281 | 281 |
filename = args[0] |
282 | 282 |
if not os.path.exists(filename): |
283 |
raise errors.OpPrereqError("No such filename '%s'" % filename) |
|
283 |
raise errors.OpPrereqError("No such filename '%s'" % filename, |
|
284 |
errors.ECODE_INVAL) |
|
284 | 285 |
|
285 | 286 |
cl = GetClient() |
286 | 287 |
|
... | ... | |
550 | 551 |
val = "unset" |
551 | 552 |
ToStdout("The drain flag is %s" % val) |
552 | 553 |
else: |
553 |
raise errors.OpPrereqError("Command '%s' is not valid." % command) |
|
554 |
raise errors.OpPrereqError("Command '%s' is not valid." % command, |
|
555 |
errors.ECODE_INVAL) |
|
554 | 556 |
|
555 | 557 |
return 0 |
556 | 558 |
|
... | ... | |
581 | 583 |
|
582 | 584 |
elif command == "pause": |
583 | 585 |
if len(args) < 2: |
584 |
raise errors.OpPrereqError("Missing pause duration") |
|
586 |
raise errors.OpPrereqError("Missing pause duration", errors.ECODE_INVAL)
|
|
585 | 587 |
|
586 | 588 |
result = client.SetWatcherPause(time.time() + ParseTimespec(args[1])) |
587 | 589 |
_ShowWatcherPause(result) |
... | ... | |
591 | 593 |
_ShowWatcherPause(result) |
592 | 594 |
|
593 | 595 |
else: |
594 |
raise errors.OpPrereqError("Command '%s' is not valid." % command) |
|
596 |
raise errors.OpPrereqError("Command '%s' is not valid." % command, |
|
597 |
errors.ECODE_INVAL) |
|
595 | 598 |
|
596 | 599 |
return 0 |
597 | 600 |
|
b/scripts/gnt-instance | ||
---|---|---|
79 | 79 |
client = GetClient() |
80 | 80 |
if mode == _SHUTDOWN_CLUSTER: |
81 | 81 |
if names: |
82 |
raise errors.OpPrereqError("Cluster filter mode takes no arguments") |
|
82 |
raise errors.OpPrereqError("Cluster filter mode takes no arguments", |
|
83 |
errors.ECODE_INVAL) |
|
83 | 84 |
idata = client.QueryInstances([], ["name"], False) |
84 | 85 |
inames = [row[0] for row in idata] |
85 | 86 |
|
... | ... | |
87 | 88 |
_SHUTDOWN_NODES_PRI, |
88 | 89 |
_SHUTDOWN_NODES_SEC): |
89 | 90 |
if not names: |
90 |
raise errors.OpPrereqError("No node names passed") |
|
91 |
raise errors.OpPrereqError("No node names passed", errors.ECODE_INVAL)
|
|
91 | 92 |
ndata = client.QueryNodes(names, ["name", "pinst_list", "sinst_list"], |
92 | 93 |
False) |
93 | 94 |
ipri = [row[1] for row in ndata] |
... | ... | |
105 | 106 |
|
106 | 107 |
elif mode == _SHUTDOWN_INSTANCES: |
107 | 108 |
if not names: |
108 |
raise errors.OpPrereqError("No instance names passed") |
|
109 |
raise errors.OpPrereqError("No instance names passed", |
|
110 |
errors.ECODE_INVAL) |
|
109 | 111 |
idata = client.QueryInstances(names, ["name"], False) |
110 | 112 |
inames = [row[0] for row in idata] |
111 | 113 |
|
112 | 114 |
else: |
113 |
raise errors.OpPrereqError("Unknown mode '%s'" % mode) |
|
115 |
raise errors.OpPrereqError("Unknown mode '%s'" % mode, errors.ECODE_INVAL)
|
|
114 | 116 |
|
115 | 117 |
return inames |
116 | 118 |
|
... | ... | |
171 | 173 |
result = client.QueryInstances(names, ["name"], False) |
172 | 174 |
for orig_name, row in zip(names, result): |
173 | 175 |
if row[0] is None: |
174 |
raise errors.OpPrereqError("Instance '%s' does not exist" % orig_name) |
|
176 |
raise errors.OpPrereqError("Instance '%s' does not exist" % orig_name, |
|
177 |
errors.ECODE_NOENT) |
|
175 | 178 |
|
176 | 179 |
|
177 | 180 |
def GenericManyOps(operation, fn): |
... | ... | |
190 | 193 |
inames = _ExpandMultiNames(opts.multi_mode, args, client=cl) |
191 | 194 |
if not inames: |
192 | 195 |
raise errors.OpPrereqError("Selection filter does not match" |
193 |
" any instances") |
|
196 |
" any instances", errors.ECODE_INVAL)
|
|
194 | 197 |
multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1 |
195 | 198 |
if not (opts.force_multi or not multi_on |
196 | 199 |
or _ConfirmOperation(inames, operation)): |
... | ... | |
371 | 374 |
for required_field in ('os', 'template'): |
372 | 375 |
if required_field not in spec: |
373 | 376 |
raise errors.OpPrereqError('Required field "%s" is missing.' % |
374 |
required_field) |
|
377 |
required_field, errors.ECODE_INVAL)
|
|
375 | 378 |
# Validate special fields |
376 | 379 |
if spec['primary_node'] is not None: |
377 | 380 |
if (spec['template'] in constants.DTS_NET_MIRROR and |
378 | 381 |
spec['secondary_node'] is None): |
379 | 382 |
raise errors.OpPrereqError('Template requires secondary node, but' |
380 |
' there was no secondary provided.') |
|
383 |
' there was no secondary provided.', |
|
384 |
errors.ECODE_INVAL) |
|
381 | 385 |
elif spec['iallocator'] is None: |
382 | 386 |
raise errors.OpPrereqError('You have to provide at least a primary_node' |
383 |
' or an iallocator.') |
|
387 |
' or an iallocator.', |
|
388 |
errors.ECODE_INVAL) |
|
384 | 389 |
|
385 | 390 |
if (spec['hvparams'] and |
386 | 391 |
not isinstance(spec['hvparams'], dict)): |
387 |
raise errors.OpPrereqError('Hypervisor parameters must be a dict.') |
|
392 |
raise errors.OpPrereqError('Hypervisor parameters must be a dict.', |
|
393 |
errors.ECODE_INVAL) |
|
388 | 394 |
|
389 | 395 |
json_filename = args[0] |
390 | 396 |
try: |
... | ... | |
414 | 420 |
except ValueError, err: |
415 | 421 |
raise errors.OpPrereqError("Invalid disk size '%s' for" |
416 | 422 |
" instance %s: %s" % |
417 |
(elem, name, err)) |
|
423 |
(elem, name, err), errors.ECODE_INVAL)
|
|
418 | 424 |
disks.append({"size": size}) |
419 | 425 |
|
420 | 426 |
utils.ForceDictType(specs['backend'], constants.BES_PARAMETER_TYPES) |
... | ... | |
429 | 435 |
|
430 | 436 |
if specs['nics'] is not None and tmp_nics: |
431 | 437 |
raise errors.OpPrereqError("'nics' list incompatible with using" |
432 |
" individual nic fields as well") |
|
438 |
" individual nic fields as well", |
|
439 |
errors.ECODE_INVAL) |
|
433 | 440 |
elif specs['nics'] is not None: |
434 | 441 |
tmp_nics = specs['nics'] |
435 | 442 |
elif not tmp_nics: |
... | ... | |
478 | 485 |
|
479 | 486 |
inames = _ExpandMultiNames(opts.multi_mode, args) |
480 | 487 |
if not inames: |
481 |
raise errors.OpPrereqError("Selection filter does not match any instances") |
|
488 |
raise errors.OpPrereqError("Selection filter does not match any instances", |
|
489 |
errors.ECODE_INVAL) |
|
482 | 490 |
|
483 | 491 |
# second, if requested, ask for an OS |
484 | 492 |
if opts.select_os is True: |
... | ... | |
672 | 680 |
try: |
673 | 681 |
disk = int(disk) |
674 | 682 |
except ValueError, err: |
675 |
raise errors.OpPrereqError("Invalid disk index: %s" % str(err)) |
|
683 |
raise errors.OpPrereqError("Invalid disk index: %s" % str(err), |
|
684 |
errors.ECODE_INVAL) |
|
676 | 685 |
amount = utils.ParseUnit(args[2]) |
677 | 686 |
op = opcodes.OpGrowDisk(instance_name=instance, disk=disk, amount=amount, |
678 | 687 |
wait_for_sync=opts.wait_for_sync) |
... | ... | |
752 | 761 |
try: |
753 | 762 |
disks = [int(i) for i in opts.disks.split(",")] |
754 | 763 |
except ValueError, err: |
755 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
764 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err), |
|
765 |
errors.ECODE_INVAL) |
|
756 | 766 |
cnt = [opts.on_primary, opts.on_secondary, opts.auto, |
757 | 767 |
new_2ndary is not None, iallocator is not None].count(True) |
758 | 768 |
if cnt != 1: |
759 | 769 |
raise errors.OpPrereqError("One and only one of the -p, -s, -a, -n and -i" |
760 |
" options must be passed") |
|
770 |
" options must be passed", errors.ECODE_INVAL)
|
|
761 | 771 |
elif opts.on_primary: |
762 | 772 |
mode = constants.REPLACE_DISK_PRI |
763 | 773 |
elif opts.on_secondary: |
... | ... | |
766 | 776 |
mode = constants.REPLACE_DISK_AUTO |
767 | 777 |
if disks: |
768 | 778 |
raise errors.OpPrereqError("Cannot specify disks when using automatic" |
769 |
" mode") |
|
779 |
" mode", errors.ECODE_INVAL)
|
|
770 | 780 |
elif new_2ndary is not None or iallocator is not None: |
771 | 781 |
# replace secondary |
772 | 782 |
mode = constants.REPLACE_DISK_CHG |
... | ... | |
1208 | 1218 |
pass |
1209 | 1219 |
if disk_op == constants.DDM_ADD: |
1210 | 1220 |
if 'size' not in disk_dict: |
1211 |
raise errors.OpPrereqError("Missing required parameter 'size'") |
|
1221 |
raise errors.OpPrereqError("Missing required parameter 'size'", |
|
1222 |
errors.ECODE_INVAL) |
|
1212 | 1223 |
disk_dict['size'] = utils.ParseUnit(disk_dict['size']) |
1213 | 1224 |
|
1214 | 1225 |
op = opcodes.OpSetInstanceParams(instance_name=args[0], |
b/scripts/gnt-node | ||
---|---|---|
114 | 114 |
try: |
115 | 115 |
return _USER_STORAGE_TYPE[user_storage_type] |
116 | 116 |
except KeyError: |
117 |
raise errors.OpPrereqError("Unknown storage type: %s" % user_storage_type) |
|
117 |
raise errors.OpPrereqError("Unknown storage type: %s" % user_storage_type, |
|
118 |
errors.ECODE_INVAL) |
|
118 | 119 |
|
119 | 120 |
|
120 | 121 |
@UsesRPC |
... | ... | |
249 | 250 |
cnt = [dst_node, iallocator].count(None) |
250 | 251 |
if cnt != 1: |
251 | 252 |
raise errors.OpPrereqError("One and only one of the -n and -I" |
252 |
" options must be passed") |
|
253 |
" options must be passed", errors.ECODE_INVAL)
|
|
253 | 254 |
|
254 | 255 |
selected_fields = ["name", "sinst_list"] |
255 | 256 |
src_node = args[0] |
... | ... | |
270 | 271 |
if src_node == dst_node: |
271 | 272 |
raise errors.OpPrereqError("Evacuate node needs different source and" |
272 | 273 |
" target nodes (node %s given twice)" % |
273 |
src_node) |
|
274 |
src_node, errors.ECODE_INVAL)
|
|
274 | 275 |
txt_msg = "to node %s" % dst_node |
275 | 276 |
else: |
276 | 277 |
txt_msg = "using iallocator %s" % iallocator |
Also available in: Unified diff