summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorChuck Short <chuck.short@canonical.com>2013-01-03 09:04:58 -0600
committerChuck Short <chuck.short@canonical.com>2013-01-18 14:08:57 -0600
commit5cce71baaa13fc651d76b6b26a29effbf879f1b1 (patch)
tree37bf0ca16344390b1bb3af24558751919595de19 /nova/api
parent7d20f1fe553b0db5883e787992413e7a0ca4f099 (diff)
downloadnova-5cce71baaa13fc651d76b6b26a29effbf879f1b1.tar.gz
nova-5cce71baaa13fc651d76b6b26a29effbf879f1b1.tar.xz
nova-5cce71baaa13fc651d76b6b26a29effbf879f1b1.zip
Refactor EC2 keypairs exception
According to the following document: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/api-error-codes.html The EC2 API sends specific error codes when keypair listing or keypair generation fails, specifically the error codes are InvalidKeyPair.Duplicate - duplicate keypair InvalidKeyPair.Format - keypair format invalid InvalidKeyPair.NotFound - keypair not found ResourceLimitExceeded - keypair quota exceeded Refactored create_key_pair and describe_key_pair so that it throws the correct EC2 error codes according to the public EC2 API specs. Also removed some duplicate exceptions as well. Fixes LP: 1072318 DocImpact Change-Id: Ib7045e49211d9300e9cb6ca0bfe80e569d635c9b Signed-off-by: Chuck Short <chuck.short@canonical.com>
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/__init__.py8
-rw-r--r--nova/api/ec2/cloud.py14
2 files changed, 10 insertions, 12 deletions
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py
index 7cd7e1c7d..85b87e3e5 100644
--- a/nova/api/ec2/__init__.py
+++ b/nova/api/ec2/__init__.py
@@ -511,7 +511,13 @@ class Executor(wsgi.Application):
except exception.KeyPairExists as ex:
LOG.debug(_('KeyPairExists raised: %s'), unicode(ex),
context=context)
- return ec2_error(req, request_id, type(ex).__name__, unicode(ex))
+ code = 'InvalidKeyPair.Duplicate'
+ return ec2_error(req, request_id, code, unicode(ex))
+ except exception.InvalidKeypair as ex:
+ LOG.debug(_('InvalidKeypair raised: %s'), unicode(ex),
+ context)
+ code = 'InvalidKeyPair.Format'
+ return ec2_error(req, request_id, code, unicode(ex))
except exception.InvalidParameterValue as ex:
LOG.debug(_('InvalidParameterValue raised: %s'), unicode(ex),
context=context)
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index 414b2e969..31f486b81 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -434,7 +434,8 @@ class CloudController(object):
#If looking for non existent key pair
if key_name is not None and not key_pairs:
msg = _('Could not find key pair(s): %s') % ','.join(key_name)
- raise exception.EC2APIError(msg)
+ raise exception.KeypairNotFound(msg,
+ code="InvalidKeyPair.Duplicate")
result = []
for key_pair in key_pairs:
@@ -457,13 +458,7 @@ class CloudController(object):
key_name)
except exception.KeypairLimitExceeded:
msg = _("Quota exceeded, too many key pairs.")
- raise exception.EC2APIError(msg)
- except exception.InvalidKeypair:
- msg = _("Keypair data is invalid")
- raise exception.EC2APIError(msg)
- except exception.KeyPairExists:
- msg = _("Key pair '%s' already exists.") % key_name
- raise exception.KeyPairExists(msg)
+ raise exception.EC2APIError(msg, code='ResourceLimitExceeded')
return {'keyName': key_name,
'keyFingerprint': keypair['fingerprint'],
'keyMaterial': keypair['private_key']}
@@ -486,9 +481,6 @@ class CloudController(object):
except exception.InvalidKeypair:
msg = _("Keypair data is invalid")
raise exception.EC2APIError(msg)
- except exception.KeyPairExists:
- msg = _("Key pair '%s' already exists.") % key_name
- raise exception.EC2APIError(msg)
return {'keyName': key_name,
'keyFingerprint': keypair['fingerprint']}