Implemented raising error if the attribute is invalid.
This commit is contained in:
parent
7215b00466
commit
9623e8a10c
@ -332,6 +332,15 @@ class InvalidParameterValueErrorTagNull(EC2ClientError):
|
|||||||
"Tag value cannot be null. Use empty string instead.")
|
"Tag value cannot be null. Use empty string instead.")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidParameterValueErrorUnknownAttribute(EC2ClientError):
|
||||||
|
|
||||||
|
def __init__(self, parameter_value):
|
||||||
|
super(InvalidParameterValueErrorUnknownAttribute, self).__init__(
|
||||||
|
"InvalidParameterValue",
|
||||||
|
"Value ({0}) for parameter attribute is invalid. Unknown attribute."
|
||||||
|
.format(parameter_value))
|
||||||
|
|
||||||
|
|
||||||
class InvalidInternetGatewayIdError(EC2ClientError):
|
class InvalidInternetGatewayIdError(EC2ClientError):
|
||||||
|
|
||||||
def __init__(self, internet_gateway_id):
|
def __init__(self, internet_gateway_id):
|
||||||
|
@ -54,6 +54,7 @@ from .exceptions import (
|
|||||||
InvalidNetworkInterfaceIdError,
|
InvalidNetworkInterfaceIdError,
|
||||||
InvalidParameterValueError,
|
InvalidParameterValueError,
|
||||||
InvalidParameterValueErrorTagNull,
|
InvalidParameterValueErrorTagNull,
|
||||||
|
InvalidParameterValueErrorUnknownAttribute,
|
||||||
InvalidPermissionNotFoundError,
|
InvalidPermissionNotFoundError,
|
||||||
InvalidPermissionDuplicateError,
|
InvalidPermissionDuplicateError,
|
||||||
InvalidRouteTableIdError,
|
InvalidRouteTableIdError,
|
||||||
@ -383,6 +384,10 @@ class NetworkInterfaceBackend(object):
|
|||||||
|
|
||||||
|
|
||||||
class Instance(TaggedEC2Resource, BotoInstance):
|
class Instance(TaggedEC2Resource, BotoInstance):
|
||||||
|
VALID_ATTRIBUTES = {'instanceType', 'kernel', 'ramdisk', 'userData', 'disableApiTermination',
|
||||||
|
'instanceInitiatedShutdownBehavior', 'rootDeviceName', 'blockDeviceMapping',
|
||||||
|
'productCodes', 'sourceDestCheck', 'groupSet', 'ebsOptimized', 'sriovNetSupport'}
|
||||||
|
|
||||||
def __init__(self, ec2_backend, image_id, user_data, security_groups, **kwargs):
|
def __init__(self, ec2_backend, image_id, user_data, security_groups, **kwargs):
|
||||||
super(Instance, self).__init__()
|
super(Instance, self).__init__()
|
||||||
self.ec2_backend = ec2_backend
|
self.ec2_backend = ec2_backend
|
||||||
@ -793,9 +798,14 @@ class InstanceBackend(object):
|
|||||||
setattr(instance, 'security_groups', new_group_list)
|
setattr(instance, 'security_groups', new_group_list)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def describe_instance_attribute(self, instance_id, key):
|
def describe_instance_attribute(self, instance_id, attribute):
|
||||||
if key == 'group_set':
|
if attribute not in Instance.VALID_ATTRIBUTES:
|
||||||
|
raise InvalidParameterValueErrorUnknownAttribute(attribute)
|
||||||
|
|
||||||
|
if attribute == 'groupSet':
|
||||||
key = 'security_groups'
|
key = 'security_groups'
|
||||||
|
else:
|
||||||
|
key = camelcase_to_underscores(attribute)
|
||||||
instance = self.get_instance(instance_id)
|
instance = self.get_instance(instance_id)
|
||||||
value = getattr(instance, key)
|
value = getattr(instance, key)
|
||||||
return instance, value
|
return instance, value
|
||||||
|
@ -113,12 +113,11 @@ class InstanceResponse(BaseResponse):
|
|||||||
# TODO this and modify below should raise IncorrectInstanceState if
|
# TODO this and modify below should raise IncorrectInstanceState if
|
||||||
# instance not in stopped state
|
# instance not in stopped state
|
||||||
attribute = self._get_param('Attribute')
|
attribute = self._get_param('Attribute')
|
||||||
key = camelcase_to_underscores(attribute)
|
|
||||||
instance_id = self._get_param('InstanceId')
|
instance_id = self._get_param('InstanceId')
|
||||||
instance, value = self.ec2_backend.describe_instance_attribute(
|
instance, value = self.ec2_backend.describe_instance_attribute(
|
||||||
instance_id, key)
|
instance_id, attribute)
|
||||||
|
|
||||||
if key == "group_set":
|
if attribute == "groupSet":
|
||||||
template = self.response_template(
|
template = self.response_template(
|
||||||
EC2_DESCRIBE_INSTANCE_GROUPSET_ATTRIBUTE)
|
EC2_DESCRIBE_INSTANCE_GROUPSET_ATTRIBUTE)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user