Revision 2cfbc784
b/lib/bootstrap.py | ||
---|---|---|
318 | 318 |
ipcls = netutils.IPAddress.GetClassFromIpVersion(primary_ip_version) |
319 | 319 |
except errors.ProgrammerError: |
320 | 320 |
raise errors.OpPrereqError("Invalid primary ip version: %d." % |
321 |
primary_ip_version) |
|
321 |
primary_ip_version, errors.ECODE_INVAL)
|
|
322 | 322 |
|
323 | 323 |
hostname = netutils.GetHostname(family=ipcls.family) |
324 | 324 |
if not ipcls.IsValid(hostname.ip): |
325 | 325 |
raise errors.OpPrereqError("This host's IP (%s) is not a valid IPv%d" |
326 |
" address." % (hostname.ip, primary_ip_version)) |
|
326 |
" address." % (hostname.ip, primary_ip_version), |
|
327 |
errors.ECODE_INVAL) |
|
327 | 328 |
|
328 | 329 |
if ipcls.IsLoopback(hostname.ip): |
329 | 330 |
raise errors.OpPrereqError("This host's IP (%s) resolves to a loopback" |
... | ... | |
363 | 364 |
if master_netmask is not None: |
364 | 365 |
if not ipcls.ValidateNetmask(master_netmask): |
365 | 366 |
raise errors.OpPrereqError("CIDR netmask (%s) not valid for IPv%s " % |
366 |
(master_netmask, primary_ip_version)) |
|
367 |
(master_netmask, primary_ip_version), |
|
368 |
errors.ECODE_INVAL) |
|
367 | 369 |
else: |
368 | 370 |
master_netmask = ipcls.iplen |
369 | 371 |
|
... | ... | |
461 | 463 |
unknown_params = param_keys - default_param_keys |
462 | 464 |
raise errors.OpPrereqError("Invalid parameters for disk template %s:" |
463 | 465 |
" %s" % (template, |
464 |
utils.CommaJoin(unknown_params))) |
|
466 |
utils.CommaJoin(unknown_params)), |
|
467 |
errors.ECODE_INVAL) |
|
465 | 468 |
utils.ForceDictType(dt_params, constants.DISK_DT_TYPES) |
466 | 469 |
try: |
467 | 470 |
utils.VerifyDictOptions(diskparams, constants.DISK_DT_DEFAULTS) |
b/lib/cli.py | ||
---|---|---|
416 | 416 |
constants.TAG_NODE, |
417 | 417 |
constants.TAG_INSTANCE): |
418 | 418 |
if not args: |
419 |
raise errors.OpPrereqError("no arguments passed to the command") |
|
419 |
raise errors.OpPrereqError("no arguments passed to the command", |
|
420 |
errors.ECODE_INVAL) |
|
420 | 421 |
name = args.pop(0) |
421 | 422 |
retval = kind, name |
422 | 423 |
else: |
... | ... | |
483 | 484 |
kind, name = _ExtractTagsObject(opts, args) |
484 | 485 |
_ExtendTags(opts, args) |
485 | 486 |
if not args: |
486 |
raise errors.OpPrereqError("No tags to be added") |
|
487 |
raise errors.OpPrereqError("No tags to be added", errors.ECODE_INVAL)
|
|
487 | 488 |
op = opcodes.OpTagsSet(kind=kind, name=name, tags=args) |
488 | 489 |
SubmitOrSend(op, opts) |
489 | 490 |
|
... | ... | |
500 | 501 |
kind, name = _ExtractTagsObject(opts, args) |
501 | 502 |
_ExtendTags(opts, args) |
502 | 503 |
if not args: |
503 |
raise errors.OpPrereqError("No tags to be removed") |
|
504 |
raise errors.OpPrereqError("No tags to be removed", errors.ECODE_INVAL)
|
|
504 | 505 |
op = opcodes.OpTagsDel(kind=kind, name=name, tags=args) |
505 | 506 |
SubmitOrSend(op, opts) |
506 | 507 |
|
... | ... | |
2091 | 2092 |
ss.GetMasterNode() |
2092 | 2093 |
except errors.ConfigurationError: |
2093 | 2094 |
raise errors.OpPrereqError("Cluster not initialized or this machine is" |
2094 |
" not part of a cluster") |
|
2095 |
" not part of a cluster", |
|
2096 |
errors.ECODE_INVAL) |
|
2095 | 2097 |
|
2096 | 2098 |
master, myself = ssconf.GetMasterAndMyself(ss=ss) |
2097 | 2099 |
if master != myself: |
2098 | 2100 |
raise errors.OpPrereqError("This is not the master node, please connect" |
2099 | 2101 |
" to node '%s' and rerun the command" % |
2100 |
master) |
|
2102 |
master, errors.ECODE_INVAL)
|
|
2101 | 2103 |
raise |
2102 | 2104 |
return client |
2103 | 2105 |
|
... | ... | |
2271 | 2273 |
try: |
2272 | 2274 |
nic_max = max(int(nidx[0]) + 1 for nidx in optvalue) |
2273 | 2275 |
except (TypeError, ValueError), err: |
2274 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) |
|
2276 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err), |
|
2277 |
errors.ECODE_INVAL) |
|
2275 | 2278 |
|
2276 | 2279 |
nics = [{}] * nic_max |
2277 | 2280 |
for nidx, ndict in optvalue: |
... | ... | |
2279 | 2282 |
|
2280 | 2283 |
if not isinstance(ndict, dict): |
2281 | 2284 |
raise errors.OpPrereqError("Invalid nic/%d value: expected dict," |
2282 |
" got %s" % (nidx, ndict)) |
|
2285 |
" got %s" % (nidx, ndict), errors.ECODE_INVAL)
|
|
2283 | 2286 |
|
2284 | 2287 |
utils.ForceDictType(ndict, constants.INIC_PARAMS_TYPES) |
2285 | 2288 |
|
... | ... | |
2323 | 2326 |
if opts.disk_template == constants.DT_DISKLESS: |
2324 | 2327 |
if opts.disks or opts.sd_size is not None: |
2325 | 2328 |
raise errors.OpPrereqError("Diskless instance but disk" |
2326 |
" information passed") |
|
2329 |
" information passed", errors.ECODE_INVAL)
|
|
2327 | 2330 |
disks = [] |
2328 | 2331 |
else: |
2329 | 2332 |
if (not opts.disks and not opts.sd_size |
2330 | 2333 |
and mode == constants.INSTANCE_CREATE): |
2331 |
raise errors.OpPrereqError("No disk information specified") |
|
2334 |
raise errors.OpPrereqError("No disk information specified", |
|
2335 |
errors.ECODE_INVAL) |
|
2332 | 2336 |
if opts.disks and opts.sd_size is not None: |
2333 | 2337 |
raise errors.OpPrereqError("Please use either the '--disk' or" |
2334 |
" '-s' option") |
|
2338 |
" '-s' option", errors.ECODE_INVAL)
|
|
2335 | 2339 |
if opts.sd_size is not None: |
2336 | 2340 |
opts.disks = [(0, {constants.IDISK_SIZE: opts.sd_size})] |
2337 | 2341 |
|
... | ... | |
2339 | 2343 |
try: |
2340 | 2344 |
disk_max = max(int(didx[0]) + 1 for didx in opts.disks) |
2341 | 2345 |
except ValueError, err: |
2342 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
2346 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err), |
|
2347 |
errors.ECODE_INVAL) |
|
2343 | 2348 |
disks = [{}] * disk_max |
2344 | 2349 |
else: |
2345 | 2350 |
disks = [] |
... | ... | |
2347 | 2352 |
didx = int(didx) |
2348 | 2353 |
if not isinstance(ddict, dict): |
2349 | 2354 |
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) |
2350 |
raise errors.OpPrereqError(msg) |
|
2355 |
raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
|
2351 | 2356 |
elif constants.IDISK_SIZE in ddict: |
2352 | 2357 |
if constants.IDISK_ADOPT in ddict: |
2353 | 2358 |
raise errors.OpPrereqError("Only one of 'size' and 'adopt' allowed" |
2354 |
" (disk %d)" % didx) |
|
2359 |
" (disk %d)" % didx, errors.ECODE_INVAL)
|
|
2355 | 2360 |
try: |
2356 | 2361 |
ddict[constants.IDISK_SIZE] = \ |
2357 | 2362 |
utils.ParseUnit(ddict[constants.IDISK_SIZE]) |
2358 | 2363 |
except ValueError, err: |
2359 | 2364 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
2360 |
(didx, err)) |
|
2365 |
(didx, err), errors.ECODE_INVAL)
|
|
2361 | 2366 |
elif constants.IDISK_ADOPT in ddict: |
2362 | 2367 |
if mode == constants.INSTANCE_IMPORT: |
2363 | 2368 |
raise errors.OpPrereqError("Disk adoption not allowed for instance" |
2364 |
" import") |
|
2369 |
" import", errors.ECODE_INVAL)
|
|
2365 | 2370 |
ddict[constants.IDISK_SIZE] = 0 |
2366 | 2371 |
else: |
2367 | 2372 |
raise errors.OpPrereqError("Missing size or adoption source for" |
2368 |
" disk %d" % didx) |
|
2373 |
" disk %d" % didx, errors.ECODE_INVAL)
|
|
2369 | 2374 |
disks[didx] = ddict |
2370 | 2375 |
|
2371 | 2376 |
if opts.tags is not None: |
... | ... | |
3074 | 3079 |
""" |
3075 | 3080 |
value = str(value) |
3076 | 3081 |
if not value: |
3077 |
raise errors.OpPrereqError("Empty time specification passed") |
|
3082 |
raise errors.OpPrereqError("Empty time specification passed", |
|
3083 |
errors.ECODE_INVAL) |
|
3078 | 3084 |
suffix_map = { |
3079 | 3085 |
"s": 1, |
3080 | 3086 |
"m": 60, |
... | ... | |
3086 | 3092 |
try: |
3087 | 3093 |
value = int(value) |
3088 | 3094 |
except (TypeError, ValueError): |
3089 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value) |
|
3095 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value, |
|
3096 |
errors.ECODE_INVAL) |
|
3090 | 3097 |
else: |
3091 | 3098 |
multiplier = suffix_map[value[-1]] |
3092 | 3099 |
value = value[:-1] |
3093 | 3100 |
if not value: # no data left after stripping the suffix |
3094 | 3101 |
raise errors.OpPrereqError("Invalid time specification (only" |
3095 |
" suffix passed)") |
|
3102 |
" suffix passed)", errors.ECODE_INVAL)
|
|
3096 | 3103 |
try: |
3097 | 3104 |
value = int(value) * multiplier |
3098 | 3105 |
except (TypeError, ValueError): |
3099 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value) |
|
3106 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value, |
|
3107 |
errors.ECODE_INVAL) |
|
3100 | 3108 |
return value |
3101 | 3109 |
|
3102 | 3110 |
|
b/lib/client/gnt_instance.py | ||
---|---|---|
614 | 614 |
|
615 | 615 |
if not ht.TDict(ddict): |
616 | 616 |
msg = "Invalid disk/%d value: expected dict, got %s" % (didx, ddict) |
617 |
raise errors.OpPrereqError(msg) |
|
617 |
raise errors.OpPrereqError(msg, errors.ECODE_INVAL)
|
|
618 | 618 |
|
619 | 619 |
if constants.IDISK_SIZE in ddict: |
620 | 620 |
try: |
... | ... | |
622 | 622 |
utils.ParseUnit(ddict[constants.IDISK_SIZE]) |
623 | 623 |
except ValueError, err: |
624 | 624 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
625 |
(didx, err)) |
|
625 |
(didx, err), errors.ECODE_INVAL)
|
|
626 | 626 |
|
627 | 627 |
disks.append((didx, ddict)) |
628 | 628 |
|
b/lib/cmdlib.py | ||
---|---|---|
1655 | 1655 |
" cluster-wide default iallocator found;" |
1656 | 1656 |
" please specify either an iallocator or a" |
1657 | 1657 |
" node, or set a cluster-wide default" |
1658 |
" iallocator") |
|
1658 |
" iallocator", errors.ECODE_INVAL)
|
|
1659 | 1659 |
|
1660 | 1660 |
|
1661 | 1661 |
def _GetDefaultIAllocator(cfg, iallocator): |
... | ... | |
3827 | 3827 |
ipcls = netutils.IPAddress.GetClassFromIpFamily(ip_family) |
3828 | 3828 |
except errors.ProgrammerError: |
3829 | 3829 |
raise errors.OpPrereqError("Invalid primary ip family: %s." % |
3830 |
ip_family) |
|
3830 |
ip_family, errors.ECODE_INVAL)
|
|
3831 | 3831 |
if not ipcls.ValidateNetmask(netmask): |
3832 | 3832 |
raise errors.OpPrereqError("CIDR netmask (%s) not valid" % |
3833 |
(netmask)) |
|
3833 |
(netmask), errors.ECODE_INVAL)
|
|
3834 | 3834 |
|
3835 | 3835 |
|
3836 | 3836 |
class LUClusterSetParams(LogicalUnit): |
... | ... | |
4029 | 4029 |
" address" % (instance.name, nic_idx)) |
4030 | 4030 |
if nic_errors: |
4031 | 4031 |
raise errors.OpPrereqError("Cannot apply the change, errors:\n%s" % |
4032 |
"\n".join(nic_errors)) |
|
4032 |
"\n".join(nic_errors), errors.ECODE_INVAL)
|
|
4033 | 4033 |
|
4034 | 4034 |
# hypervisor list/parameters |
4035 | 4035 |
self.new_hvparams = new_hvp = objects.FillDict(cluster.hvparams, {}) |
... | ... | |
5957 | 5957 |
self.op.powered == True): |
5958 | 5958 |
raise errors.OpPrereqError(("Node %s needs to be turned on before its" |
5959 | 5959 |
" offline status can be reset") % |
5960 |
self.op.node_name) |
|
5960 |
self.op.node_name, errors.ECODE_STATE)
|
|
5961 | 5961 |
elif self.op.powered is not None: |
5962 | 5962 |
raise errors.OpPrereqError(("Unable to change powered state for node %s" |
5963 | 5963 |
" as it does not support out-of-band" |
5964 |
" handling") % self.op.node_name) |
|
5964 |
" handling") % self.op.node_name, |
|
5965 |
errors.ECODE_STATE) |
|
5965 | 5966 |
|
5966 | 5967 |
# If we're being deofflined/drained, we'll MC ourself if needed |
5967 | 5968 |
if (self.op.drained == False or self.op.offline == False or |
... | ... | |
6038 | 6039 |
|
6039 | 6040 |
if node.offline: |
6040 | 6041 |
if affected_instances: |
6041 |
raise errors.OpPrereqError("Cannot change secondary IP address:"
|
|
6042 |
" offline node has instances (%s)"
|
|
6043 |
" configured to use it" %
|
|
6044 |
utils.CommaJoin(affected_instances.keys()))
|
|
6042 |
msg = ("Cannot change secondary IP address: offline node has"
|
|
6043 |
" instances (%s) configured to use it" %
|
|
6044 |
utils.CommaJoin(affected_instances.keys()))
|
|
6045 |
raise errors.OpPrereqError(msg, errors.ECODE_STATE)
|
|
6045 | 6046 |
else: |
6046 | 6047 |
# On online nodes, check that no instances are running, and that |
6047 | 6048 |
# the node has the new ip and we can reach it. |
... | ... | |
8142 | 8143 |
if self.target_node == instance.primary_node: |
8143 | 8144 |
raise errors.OpPrereqError("Cannot migrate instance %s" |
8144 | 8145 |
" to its primary (%s)" % |
8145 |
(instance.name, instance.primary_node)) |
|
8146 |
(instance.name, instance.primary_node), |
|
8147 |
errors.ECODE_STATE) |
|
8146 | 8148 |
|
8147 | 8149 |
if len(self.lu.tasklets) == 1: |
8148 | 8150 |
# It is safe to release locks only when we're the only tasklet |
... | ... | |
9670 | 9672 |
if self.op.disk_template not in constants.DISK_TEMPLATES: |
9671 | 9673 |
raise errors.OpPrereqError("Disk template specified in configuration" |
9672 | 9674 |
" file is not one of the allowed values:" |
9673 |
" %s" % " ".join(constants.DISK_TEMPLATES)) |
|
9675 |
" %s" % |
|
9676 |
" ".join(constants.DISK_TEMPLATES), |
|
9677 |
errors.ECODE_INVAL) |
|
9674 | 9678 |
else: |
9675 | 9679 |
raise errors.OpPrereqError("No disk template specified and the export" |
9676 | 9680 |
" is missing the disk_template information", |
... | ... | |
9783 | 9787 |
|
9784 | 9788 |
cfg_storagedir = get_fsd_fn() |
9785 | 9789 |
if not cfg_storagedir: |
9786 |
raise errors.OpPrereqError("Cluster file storage dir not defined") |
|
9790 |
raise errors.OpPrereqError("Cluster file storage dir not defined", |
|
9791 |
errors.ECODE_STATE) |
|
9787 | 9792 |
joinargs.append(cfg_storagedir) |
9788 | 9793 |
|
9789 | 9794 |
if self.op.file_storage_dir is not None: |
... | ... | |
12654 | 12659 |
raise errors.OpPrereqError("This change will prevent the instance" |
12655 | 12660 |
" from starting, due to %d MB of memory" |
12656 | 12661 |
" missing on its primary node" % |
12657 |
miss_mem, |
|
12658 |
errors.ECODE_NORES) |
|
12662 |
miss_mem, errors.ECODE_NORES) |
|
12659 | 12663 |
|
12660 | 12664 |
if be_new[constants.BE_AUTO_BALANCE]: |
12661 | 12665 |
for node, nres in nodeinfo.items(): |
... | ... | |
12681 | 12685 |
instance.hypervisor) |
12682 | 12686 |
remote_info.Raise("Error checking node %s" % instance.primary_node) |
12683 | 12687 |
if not remote_info.payload: # not running already |
12684 |
raise errors.OpPrereqError("Instance %s is not running" % instance.name,
|
|
12685 |
errors.ECODE_STATE) |
|
12688 |
raise errors.OpPrereqError("Instance %s is not running" % |
|
12689 |
instance.name, errors.ECODE_STATE)
|
|
12686 | 12690 |
|
12687 | 12691 |
current_memory = remote_info.payload["memory"] |
12688 | 12692 |
if (not self.op.force and |
... | ... | |
12704 | 12708 |
|
12705 | 12709 |
if self.op.disks and instance.disk_template == constants.DT_DISKLESS: |
12706 | 12710 |
raise errors.OpPrereqError("Disk operations not supported for" |
12707 |
" diskless instances", |
|
12708 |
errors.ECODE_INVAL) |
|
12711 |
" diskless instances", errors.ECODE_INVAL) |
|
12709 | 12712 |
|
12710 | 12713 |
def _PrepareNicCreate(_, params, private): |
12711 | 12714 |
self._PrepareNicModification(params, private, None, {}, cluster, pnode) |
... | ... | |
13212 | 13215 |
raise errors.OpPrereqError("Can't compute solution for changing group of" |
13213 | 13216 |
" instance '%s' using iallocator '%s': %s" % |
13214 | 13217 |
(self.op.instance_name, self.op.iallocator, |
13215 |
ial.info), |
|
13216 |
errors.ECODE_NORES) |
|
13218 |
ial.info), errors.ECODE_NORES) |
|
13217 | 13219 |
|
13218 | 13220 |
jobs = _LoadNodeEvacResult(self, ial.result, self.op.early_release, False) |
13219 | 13221 |
|
... | ... | |
13442 | 13444 |
self.instance.admin_state == constants.ADMINST_UP and |
13443 | 13445 |
not self.op.shutdown): |
13444 | 13446 |
raise errors.OpPrereqError("Can not remove instance without shutting it" |
13445 |
" down before") |
|
13447 |
" down before", errors.ECODE_STATE)
|
|
13446 | 13448 |
|
13447 | 13449 |
if self.op.mode == constants.EXPORT_MODE_LOCAL: |
13448 | 13450 |
self.op.target_node = _ExpandNodeName(self.cfg, self.op.target_node) |
... | ... | |
13472 | 13474 |
try: |
13473 | 13475 |
(key_name, hmac_digest, hmac_salt) = self.x509_key_name |
13474 | 13476 |
except (TypeError, ValueError), err: |
13475 |
raise errors.OpPrereqError("Invalid data for X509 key name: %s" % err) |
|
13477 |
raise errors.OpPrereqError("Invalid data for X509 key name: %s" % err, |
|
13478 |
errors.ECODE_INVAL) |
|
13476 | 13479 |
|
13477 | 13480 |
if not utils.VerifySha1Hmac(cds, key_name, hmac_digest, salt=hmac_salt): |
13478 | 13481 |
raise errors.OpPrereqError("HMAC for X509 key name is wrong", |
... | ... | |
14227 | 14230 |
|
14228 | 14231 |
# Verify the cluster would not be left group-less. |
14229 | 14232 |
if len(self.cfg.GetNodeGroupList()) == 1: |
14230 |
raise errors.OpPrereqError("Group '%s' is the only group," |
|
14231 |
" cannot be removed" % |
|
14232 |
self.op.group_name, |
|
14233 |
raise errors.OpPrereqError("Group '%s' is the only group, cannot be" |
|
14234 |
" removed" % self.op.group_name, |
|
14233 | 14235 |
errors.ECODE_STATE) |
14234 | 14236 |
|
14235 | 14237 |
def BuildHooksEnv(self): |
b/lib/ovf.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2011 Google Inc. |
|
4 |
# Copyright (C) 2011, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
152 | 152 |
""" |
153 | 153 |
if not constants.QEMUIMG_PATH: |
154 | 154 |
raise errors.OpPrereqError("qemu-img not found at build time, unable" |
155 |
" to continue") |
|
155 |
" to continue", errors.ECODE_STATE)
|
|
156 | 156 |
|
157 | 157 |
|
158 | 158 |
def LinkFile(old_path, prefix=None, suffix=None, directory=None): |
... | ... | |
191 | 191 |
counter += 1 |
192 | 192 |
else: |
193 | 193 |
raise errors.OpPrereqError("Error moving the file %s to %s location:" |
194 |
" %s" % (old_path, new_path, err)) |
|
194 |
" %s" % (old_path, new_path, err), |
|
195 |
errors.ECODE_ENVIRON) |
|
195 | 196 |
return new_path |
196 | 197 |
|
197 | 198 |
|
... | ... | |
228 | 229 |
self.tree.parse(input_path) |
229 | 230 |
except (ParseError, xml.parsers.expat.ExpatError), err: |
230 | 231 |
raise errors.OpPrereqError("Error while reading %s file: %s" % |
231 |
(OVF_EXT, err)) |
|
232 |
(OVF_EXT, err), errors.ECODE_ENVIRON)
|
|
232 | 233 |
|
233 | 234 |
# Create a list of all files in the OVF package |
234 | 235 |
(input_dir, input_file) = os.path.split(input_path) |
... | ... | |
245 | 246 |
for file_name in files_list: |
246 | 247 |
file_path = utils.PathJoin(input_dir, file_name) |
247 | 248 |
if not os.path.exists(file_path): |
248 |
raise errors.OpPrereqError("File does not exist: %s" % file_path) |
|
249 |
raise errors.OpPrereqError("File does not exist: %s" % file_path, |
|
250 |
errors.ECODE_ENVIRON) |
|
249 | 251 |
logging.info("Files in the OVF package: %s", " ".join(files_list)) |
250 | 252 |
self.files_list = files_list |
251 | 253 |
self.input_dir = input_dir |
... | ... | |
360 | 362 |
for file_name, value in manifest_files.iteritems(): |
361 | 363 |
if sha1_sums.get(utils.PathJoin(self.input_dir, file_name)) != value: |
362 | 364 |
raise errors.OpPrereqError("SHA1 checksum of %s does not match the" |
363 |
" value in manifest file" % file_name) |
|
365 |
" value in manifest file" % file_name, |
|
366 |
errors.ECODE_ENVIRON) |
|
364 | 367 |
logging.info("SHA1 checksums verified") |
365 | 368 |
|
366 | 369 |
def GetInstanceName(self): |
... | ... | |
451 | 454 |
matching_units = [units for units, variants in |
452 | 455 |
ALLOCATION_UNITS.iteritems() if alloc_units.lower() in variants] |
453 | 456 |
if matching_units == []: |
454 |
raise errors.OpPrereqError("Unit %s for RAM memory unknown",
|
|
455 |
alloc_units)
|
|
457 |
raise errors.OpPrereqError("Unit %s for RAM memory unknown" %
|
|
458 |
alloc_units, errors.ECODE_INVAL)
|
|
456 | 459 |
units = matching_units[0] |
457 | 460 |
memory_raw = int(memory.findtext("{%s}VirtualQuantity" % RASD_SCHEMA, |
458 | 461 |
default=constants.VALUE_AUTO)) |
... | ... | |
579 | 582 |
disk_elem = self._GetElementMatchingAttr(disk_search, disk_match) |
580 | 583 |
if disk_elem is None: |
581 | 584 |
raise errors.OpPrereqError("%s file corrupted - disk %s not found in" |
582 |
" references" % (OVF_EXT, disk)) |
|
585 |
" references" % (OVF_EXT, disk), |
|
586 |
errors.ECODE_ENVIRON) |
|
583 | 587 |
disk_name = disk_elem.get("{%s}href" % OVF_SCHEMA) |
584 | 588 |
disk_compression = disk_elem.get("{%s}compression" % OVF_SCHEMA) |
585 | 589 |
results.append((disk_name, disk_compression)) |
... | ... | |
860 | 864 |
""" |
861 | 865 |
input_path = os.path.abspath(input_path) |
862 | 866 |
if not os.path.isfile(input_path): |
863 |
raise errors.OpPrereqError("File does not exist: %s" % input_path) |
|
867 |
raise errors.OpPrereqError("File does not exist: %s" % input_path, |
|
868 |
errors.ECODE_ENVIRON) |
|
864 | 869 |
self.options = options |
865 | 870 |
self.temp_file_manager = utils.TemporaryFileManager() |
866 | 871 |
self.temp_dir = None |
... | ... | |
896 | 901 |
# For now we only support gzip, as it is used in ovftool |
897 | 902 |
if compression != COMPRESSION_TYPE: |
898 | 903 |
raise errors.OpPrereqError("Unsupported compression type: %s" |
899 |
% compression) |
|
904 |
% compression, errors.ECODE_INVAL)
|
|
900 | 905 |
disk_file = os.path.basename(disk_path) |
901 | 906 |
if action == DECOMPRESS: |
902 | 907 |
(disk_name, _) = os.path.splitext(disk_file) |
... | ... | |
910 | 915 |
run_result = utils.RunCmd(args, output=new_path) |
911 | 916 |
if run_result.failed: |
912 | 917 |
raise errors.OpPrereqError("Disk %s failed with output: %s" |
913 |
% (action, run_result.stderr)) |
|
918 |
% (action, run_result.stderr), |
|
919 |
errors.ECODE_ENVIRON) |
|
914 | 920 |
logging.info("The %s of the disk is completed", action) |
915 | 921 |
return (COMPRESSION_EXT, new_path) |
916 | 922 |
|
... | ... | |
948 | 954 |
run_result = utils.RunCmd(args, cwd=os.getcwd()) |
949 | 955 |
if run_result.failed: |
950 | 956 |
raise errors.OpPrereqError("Convertion to %s failed, qemu-img output was" |
951 |
": %s" % (disk_format, run_result.stderr)) |
|
957 |
": %s" % (disk_format, run_result.stderr), |
|
958 |
errors.ECODE_ENVIRON) |
|
952 | 959 |
return (".%s" % disk_format, new_disk_path) |
953 | 960 |
|
954 | 961 |
@staticmethod |
... | ... | |
970 | 977 |
run_result = utils.RunCmd(args, cwd=os.getcwd()) |
971 | 978 |
if run_result.failed: |
972 | 979 |
raise errors.OpPrereqError("Gathering info about the disk using qemu-img" |
973 |
" failed, output was: %s" % run_result.stderr) |
|
980 |
" failed, output was: %s" % run_result.stderr, |
|
981 |
errors.ECODE_ENVIRON) |
|
974 | 982 |
result = run_result.output |
975 | 983 |
regexp = r"%s" % regexp |
976 | 984 |
match = re.search(regexp, result) |
... | ... | |
978 | 986 |
disk_format = match.group(1) |
979 | 987 |
else: |
980 | 988 |
raise errors.OpPrereqError("No file information matching %s found in:" |
981 |
" %s" % (regexp, result)) |
|
989 |
" %s" % (regexp, result), |
|
990 |
errors.ECODE_ENVIRON) |
|
982 | 991 |
return disk_format |
983 | 992 |
|
984 | 993 |
def Parse(self): |
... | ... | |
1063 | 1072 |
self._UnpackOVA(input_path) |
1064 | 1073 |
else: |
1065 | 1074 |
raise errors.OpPrereqError("Unknown file extension; expected %s or %s" |
1066 |
" file" % (OVA_EXT, OVF_EXT)) |
|
1075 |
" file" % (OVA_EXT, OVF_EXT), |
|
1076 |
errors.ECODE_INVAL) |
|
1067 | 1077 |
assert ((input_extension == OVA_EXT and self.temp_dir) or |
1068 | 1078 |
(input_extension == OVF_EXT and not self.temp_dir)) |
1069 | 1079 |
assert self.input_dir in self.input_path |
... | ... | |
1095 | 1105 |
input_name = None |
1096 | 1106 |
if not tarfile.is_tarfile(input_path): |
1097 | 1107 |
raise errors.OpPrereqError("The provided %s file is not a proper tar" |
1098 |
" archive", OVA_EXT)
|
|
1108 |
" archive" % OVA_EXT, errors.ECODE_ENVIRON)
|
|
1099 | 1109 |
ova_content = tarfile.open(input_path) |
1100 | 1110 |
temp_dir = tempfile.mkdtemp() |
1101 | 1111 |
self.temp_dir = temp_dir |
... | ... | |
1105 | 1115 |
utils.PathJoin(temp_dir, file_normname) |
1106 | 1116 |
except ValueError, err: |
1107 | 1117 |
raise errors.OpPrereqError("File %s inside %s package is not safe" % |
1108 |
(file_name, OVA_EXT)) |
|
1118 |
(file_name, OVA_EXT), errors.ECODE_ENVIRON)
|
|
1109 | 1119 |
if file_name.endswith(OVF_EXT): |
1110 | 1120 |
input_name = file_name |
1111 | 1121 |
if not input_name: |
1112 | 1122 |
raise errors.OpPrereqError("No %s file in %s package found" % |
1113 |
(OVF_EXT, OVA_EXT)) |
|
1123 |
(OVF_EXT, OVA_EXT), errors.ECODE_ENVIRON)
|
|
1114 | 1124 |
logging.warning("Unpacking the %s archive, this may take a while", |
1115 | 1125 |
input_path) |
1116 | 1126 |
self.input_dir = temp_dir |
... | ... | |
1126 | 1136 |
extract(self.temp_dir) |
1127 | 1137 |
except tarfile.TarError, err: |
1128 | 1138 |
raise errors.OpPrereqError("Error while extracting %s archive: %s" % |
1129 |
(OVA_EXT, err)) |
|
1139 |
(OVA_EXT, err), errors.ECODE_ENVIRON)
|
|
1130 | 1140 |
logging.info("OVA package extracted to %s directory", self.temp_dir) |
1131 | 1141 |
|
1132 | 1142 |
def Parse(self): |
... | ... | |
1142 | 1152 |
self.results_name = self._GetInfo("instance name", self.options.name, |
1143 | 1153 |
self._ParseNameOptions, self.ovf_reader.GetInstanceName) |
1144 | 1154 |
if not self.results_name: |
1145 |
raise errors.OpPrereqError("Name of instance not provided") |
|
1155 |
raise errors.OpPrereqError("Name of instance not provided", |
|
1156 |
errors.ECODE_INVAL) |
|
1146 | 1157 |
|
1147 | 1158 |
self.output_dir = utils.PathJoin(self.output_dir, self.results_name) |
1148 | 1159 |
try: |
1149 | 1160 |
utils.Makedirs(self.output_dir) |
1150 | 1161 |
except OSError, err: |
1151 | 1162 |
raise errors.OpPrereqError("Failed to create directory %s: %s" % |
1152 |
(self.output_dir, err)) |
|
1163 |
(self.output_dir, err), errors.ECODE_ENVIRON)
|
|
1153 | 1164 |
|
1154 | 1165 |
self.results_template = self._GetInfo("disk template", |
1155 | 1166 |
self.options.disk_template, self._ParseTemplateOptions, |
... | ... | |
1167 | 1178 |
self.results_os = self._GetInfo("OS", self.options.os, |
1168 | 1179 |
self._ParseOSOptions, self.ovf_reader.GetOSData) |
1169 | 1180 |
if not self.results_os.get("os_name"): |
1170 |
raise errors.OpPrereqError("OS name must be provided") |
|
1181 |
raise errors.OpPrereqError("OS name must be provided", |
|
1182 |
errors.ECODE_INVAL) |
|
1171 | 1183 |
|
1172 | 1184 |
self.results_backend = self._GetInfo("backend", self.options.beparams, |
1173 | 1185 |
self._ParseBackendOptions, self.ovf_reader.GetBackendData) |
... | ... | |
1194 | 1206 |
|
1195 | 1207 |
if not self.results_disk and not self.results_network: |
1196 | 1208 |
raise errors.OpPrereqError("Either disk specification or network" |
1197 |
" description must be present") |
|
1209 |
" description must be present", |
|
1210 |
errors.ECODE_STATE) |
|
1198 | 1211 |
|
1199 | 1212 |
@staticmethod |
1200 | 1213 |
def _GetInfo(name, cmd_arg, cmd_function, nocmd_function, |
... | ... | |
1340 | 1353 |
disk_size = utils.ParseUnit(disk_desc["size"]) |
1341 | 1354 |
except ValueError: |
1342 | 1355 |
raise errors.OpPrereqError("Invalid disk size for disk %s: %s" % |
1343 |
(disk_id, disk_desc["size"])) |
|
1356 |
(disk_id, disk_desc["size"]), |
|
1357 |
errors.ECODE_INVAL) |
|
1344 | 1358 |
new_path = utils.PathJoin(self.output_dir, str(disk_id)) |
1345 | 1359 |
args = [ |
1346 | 1360 |
constants.QEMUIMG_PATH, |
... | ... | |
1353 | 1367 |
run_result = utils.RunCmd(args) |
1354 | 1368 |
if run_result.failed: |
1355 | 1369 |
raise errors.OpPrereqError("Creation of disk %s failed, output was:" |
1356 |
" %s" % (new_path, run_result.stderr)) |
|
1370 |
" %s" % (new_path, run_result.stderr), |
|
1371 |
errors.ECODE_ENVIRON) |
|
1357 | 1372 |
results["disk%s_size" % disk_id] = str(disk_size) |
1358 | 1373 |
results["disk%s_dump" % disk_id] = "disk%s.raw" % disk_id |
1359 | 1374 |
else: |
1360 | 1375 |
raise errors.OpPrereqError("Disks created for import must have their" |
1361 |
" size specified") |
|
1376 |
" size specified", |
|
1377 |
errors.ECODE_INVAL) |
|
1362 | 1378 |
results["disk_count"] = str(len(self.options.disks)) |
1363 | 1379 |
return results |
1364 | 1380 |
|
... | ... | |
1376 | 1392 |
for (counter, (disk_name, disk_compression)) in enumerate(disks_list): |
1377 | 1393 |
if os.path.dirname(disk_name): |
1378 | 1394 |
raise errors.OpPrereqError("Disks are not allowed to have absolute" |
1379 |
" paths or paths outside main OVF directory") |
|
1395 |
" paths or paths outside main OVF" |
|
1396 |
" directory", errors.ECODE_ENVIRON) |
|
1380 | 1397 |
disk, _ = os.path.splitext(disk_name) |
1381 | 1398 |
disk_path = utils.PathJoin(self.input_dir, disk_name) |
1382 | 1399 |
if disk_compression not in NO_COMPRESSION: |
... | ... | |
1451 | 1468 |
try: |
1452 | 1469 |
utils.WriteFile(output_file_name, data=output_contents) |
1453 | 1470 |
except errors.ProgrammerError, err: |
1454 |
raise errors.OpPrereqError("Saving the config file failed: %s" % err) |
|
1471 |
raise errors.OpPrereqError("Saving the config file failed: %s" % err, |
|
1472 |
errors.ECODE_ENVIRON) |
|
1455 | 1473 |
|
1456 | 1474 |
self.Cleanup() |
1457 | 1475 |
|
... | ... | |
1531 | 1549 |
self.config_parser.read(input_path) |
1532 | 1550 |
except ConfigParser.MissingSectionHeaderError, err: |
1533 | 1551 |
raise errors.OpPrereqError("Error when trying to read %s: %s" % |
1534 |
(input_path, err)) |
|
1552 |
(input_path, err), errors.ECODE_ENVIRON)
|
|
1535 | 1553 |
if self.options.ova_package: |
1536 | 1554 |
self.temp_dir = tempfile.mkdtemp() |
1537 | 1555 |
self.packed_dir = self.output_dir |
... | ... | |
1553 | 1571 |
else: |
1554 | 1572 |
name = self.config_parser.get(constants.INISECT_INS, NAME) |
1555 | 1573 |
if name is None: |
1556 |
raise errors.OpPrereqError("No instance name found") |
|
1574 |
raise errors.OpPrereqError("No instance name found", |
|
1575 |
errors.ECODE_ENVIRON) |
|
1557 | 1576 |
return name |
1558 | 1577 |
|
1559 | 1578 |
def _ParseVCPUs(self): |
... | ... | |
1567 | 1586 |
""" |
1568 | 1587 |
vcpus = self.config_parser.getint(constants.INISECT_BEP, VCPUS) |
1569 | 1588 |
if vcpus == 0: |
1570 |
raise errors.OpPrereqError("No CPU information found") |
|
1589 |
raise errors.OpPrereqError("No CPU information found", |
|
1590 |
errors.ECODE_ENVIRON) |
|
1571 | 1591 |
return vcpus |
1572 | 1592 |
|
1573 | 1593 |
def _ParseMemory(self): |
... | ... | |
1581 | 1601 |
""" |
1582 | 1602 |
memory = self.config_parser.getint(constants.INISECT_BEP, MEMORY) |
1583 | 1603 |
if memory == 0: |
1584 |
raise errors.OpPrereqError("No memory information found") |
|
1604 |
raise errors.OpPrereqError("No memory information found", |
|
1605 |
errors.ECODE_ENVIRON) |
|
1585 | 1606 |
return memory |
1586 | 1607 |
|
1587 | 1608 |
def _ParseGaneti(self): |
... | ... | |
1596 | 1617 |
results["hypervisor"] = {} |
1597 | 1618 |
hyp_name = self.config_parser.get(constants.INISECT_INS, HYPERV) |
1598 | 1619 |
if hyp_name is None: |
1599 |
raise errors.OpPrereqError("No hypervisor information found") |
|
1620 |
raise errors.OpPrereqError("No hypervisor information found", |
|
1621 |
errors.ECODE_ENVIRON) |
|
1600 | 1622 |
results["hypervisor"]["name"] = hyp_name |
1601 | 1623 |
pairs = self.config_parser.items(constants.INISECT_HYP) |
1602 | 1624 |
for (name, value) in pairs: |
... | ... | |
1605 | 1627 |
results["os"] = {} |
1606 | 1628 |
os_name = self.config_parser.get(constants.INISECT_EXP, OS) |
1607 | 1629 |
if os_name is None: |
1608 |
raise errors.OpPrereqError("No operating system information found") |
|
1630 |
raise errors.OpPrereqError("No operating system information found", |
|
1631 |
errors.ECODE_ENVIRON) |
|
1609 | 1632 |
results["os"]["name"] = os_name |
1610 | 1633 |
pairs = self.config_parser.items(constants.INISECT_OSP) |
1611 | 1634 |
for (name, value) in pairs: |
... | ... | |
1648 | 1671 |
}) |
1649 | 1672 |
if results[counter]["mode"] not in constants.NIC_VALID_MODES: |
1650 | 1673 |
raise errors.OpPrereqError("Network mode %s not recognized" |
1651 |
% results[counter]["mode"]) |
|
1674 |
% results[counter]["mode"], |
|
1675 |
errors.ECODE_INVAL) |
|
1652 | 1676 |
counter += 1 |
1653 | 1677 |
return results |
1654 | 1678 |
|
... | ... | |
1666 | 1690 |
disk_path = utils.PathJoin(self.input_dir, disk_file) |
1667 | 1691 |
results = {} |
1668 | 1692 |
if not os.path.isfile(disk_path): |
1669 |
raise errors.OpPrereqError("Disk image does not exist: %s" % disk_path) |
|
1693 |
raise errors.OpPrereqError("Disk image does not exist: %s" % disk_path, |
|
1694 |
errors.ECODE_ENVIRON) |
|
1670 | 1695 |
if os.path.dirname(disk_file): |
1671 | 1696 |
raise errors.OpPrereqError("Path for the disk: %s contains a directory" |
1672 |
" name" % disk_path) |
|
1697 |
" name" % disk_path, errors.ECODE_ENVIRON)
|
|
1673 | 1698 |
disk_name, _ = os.path.splitext(disk_file) |
1674 | 1699 |
ext, new_disk_path = self._ConvertDisk(self.options.disk_format, disk_path) |
1675 | 1700 |
results["format"] = self.options.disk_format |
... | ... | |
1715 | 1740 |
utils.Makedirs(self.output_dir) |
1716 | 1741 |
except OSError, err: |
1717 | 1742 |
raise errors.OpPrereqError("Failed to create directory %s: %s" % |
1718 |
(self.output_dir, err)) |
|
1743 |
(self.output_dir, err), errors.ECODE_ENVIRON)
|
|
1719 | 1744 |
|
1720 | 1745 |
self.references_files = [] |
1721 | 1746 |
self.results_name = self._ParseName() |
... | ... | |
1749 | 1774 |
try: |
1750 | 1775 |
utils.WriteFile(path, data=data) |
1751 | 1776 |
except errors.ProgrammerError, err: |
1752 |
raise errors.OpPrereqError("Saving the manifest file failed: %s" % err) |
|
1777 |
raise errors.OpPrereqError("Saving the manifest file failed: %s" % err, |
|
1778 |
errors.ECODE_ENVIRON) |
|
1753 | 1779 |
|
1754 | 1780 |
@staticmethod |
1755 | 1781 |
def _PrepareTarFile(tar_path, files_list): |
... | ... | |
1808 | 1834 |
utils.Makedirs(self.packed_dir) |
1809 | 1835 |
except OSError, err: |
1810 | 1836 |
raise errors.OpPrereqError("Failed to create directory %s: %s" % |
1811 |
(self.packed_dir, err)) |
|
1837 |
(self.packed_dir, err), |
|
1838 |
errors.ECODE_ENVIRON) |
|
1812 | 1839 |
self._PrepareTarFile(packed_path, files_list) |
1813 | 1840 |
logging.info("Creation of the OVF package was successfull") |
1814 | 1841 |
self.Cleanup() |
b/lib/qlang.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2010, 2011 Google Inc. |
|
4 |
# Copyright (C) 2010, 2011, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
327 | 327 |
(filter_text, ) = args |
328 | 328 |
except (TypeError, ValueError): |
329 | 329 |
raise errors.OpPrereqError("Exactly one argument must be given as a" |
330 |
" filter") |
|
330 |
" filter", errors.ECODE_INVAL)
|
|
331 | 331 |
|
332 | 332 |
result = ParseFilter(filter_text) |
333 | 333 |
elif args: |
b/lib/server/masterd.py | ||
---|---|---|
310 | 310 |
qfilter=qfilter)) |
311 | 311 |
elif what == constants.QR_LOCK: |
312 | 312 |
if qfilter is not None: |
313 |
raise errors.OpPrereqError("Lock queries can't be filtered") |
|
313 |
raise errors.OpPrereqError("Lock queries can't be filtered", |
|
314 |
errors.ECODE_INVAL) |
|
314 | 315 |
return context.glm.QueryLocks(fields) |
315 | 316 |
elif what == constants.QR_JOB: |
316 | 317 |
return queue.QueryJobs(fields, qfilter) |
b/lib/uidpool.py | ||
---|---|---|
1 | 1 |
# |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2010 Google Inc. |
|
4 |
# Copyright (C) 2010, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
65 | 65 |
if n_elements > 2: |
66 | 66 |
raise errors.OpPrereqError( |
67 | 67 |
"Invalid user-id range definition. Only one hyphen allowed: %s" |
68 |
% boundaries) |
|
68 |
% boundaries, errors.ECODE_INVAL)
|
|
69 | 69 |
try: |
70 | 70 |
lower = int(boundaries[0]) |
71 | 71 |
except (ValueError, TypeError), err: |
Also available in: Unified diff