Improve parameter related EC2 error codes

This patch replaces parameter/attribute related raises of EC2APIError
with specific exceptions.

 * Introduce new MissingParameter exception with 'MissingParameter'
   ec2_code.
 * Introduce new InvalidAttribute exception which isn't a valid EC2
   error code but it's needed nonetheless as the nova EC2 API isn't
   fully compatible.
 * Add 'InvalidParameterValue' ec2_code to existing
   InvalidParameterValue exception and use it where appropriate. Also
   add it to existing InvalidPortRange exception.

Implements: blueprint ec2-error-codes

Change-Id: I7820edfd9045fdc817a8538a754c9add20b68cf4
This commit is contained in:
Jakub Ruzicka
2013-08-12 12:26:27 -04:00
parent 6e1be8905b
commit 0f449e06df

View File

@@ -245,6 +245,10 @@ class InvalidBDMForLegacy(InvalidBDM):
"be converted to legacy format. ")
class InvalidAttribute(Invalid):
msg_fmt = _("Attribute not supported: %(attr)s")
class VolumeUnattached(Invalid):
msg_fmt = _("Volume %(volume_id)s is not attached to anything")
@@ -280,6 +284,7 @@ class InvalidMetadataSize(Invalid):
class InvalidPortRange(Invalid):
ec2_code = 'InvalidParameterValue'
msg_fmt = _("Invalid port range %(from_port)s:%(to_port)s. %(msg)s")
@@ -303,6 +308,7 @@ class InvalidUnicodeParameter(Invalid):
# Cannot be templated as the error syntax varies.
# msg needs to be constructed when raised.
class InvalidParameterValue(Invalid):
ec2_code = 'InvalidParameterValue'
msg_fmt = _("%(err)s")
@@ -1407,3 +1413,9 @@ class PciInvalidAlias(NovaException):
class PciRequestAliasNotDefined(NovaException):
msg_fmt = _("PCI alias %(alias)s is not defined")
class MissingParameter(NovaException):
ec2_code = 'MissingParameter'
msg_fmt = _("Not enough parameters: %(reason)s")
code = 400