From 0df2864f99559591bb6af44f746c2f1b91ed2255 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Thu, 21 Feb 2013 19:34:57 -0500 Subject: [PATCH] convert ugly camelcase methods to nice, clean underscores --- moto/ec2/responses/__init__.py | 3 ++- moto/ec2/responses/instances.py | 16 ++++++++-------- moto/ec2/responses/tags.py | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/moto/ec2/responses/__init__.py b/moto/ec2/responses/__init__.py index 130902ef0..70fe04388 100644 --- a/moto/ec2/responses/__init__.py +++ b/moto/ec2/responses/__init__.py @@ -1,6 +1,6 @@ from urlparse import parse_qs -from moto.ec2.utils import method_namess_from_class +from moto.ec2.utils import camelcase_to_underscores, method_namess_from_class from .instances import InstanceResponse from .tags import TagResponse @@ -17,6 +17,7 @@ class EC2Response(object): querystring = parse_qs(headers) action = querystring['Action'][0] + action = camelcase_to_underscores(action) for sub_response in self.sub_responses: method_names = method_namess_from_class(sub_response) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index a7ac7213a..d102d79db 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -9,37 +9,37 @@ class InstanceResponse(object): self.querystring = querystring self.instance_ids = instance_ids_from_querystring(querystring) - def DescribeInstances(self): + def describe_instances(self): template = Template(EC2_DESCRIBE_INSTANCES) return template.render(reservations=ec2_backend.all_reservations()) - def RunInstances(self): + def run_instances(self): min_count = int(self.querystring.get('MinCount', ['1'])[0]) new_reservation = ec2_backend.add_instances(min_count) template = Template(EC2_RUN_INSTANCES) return template.render(reservation=new_reservation) - def TerminateInstances(self): + def terminate_instances(self): instances = ec2_backend.terminate_instances(self.instance_ids) template = Template(EC2_TERMINATE_INSTANCES) return template.render(instances=instances) - def RebootInstances(self): + def reboot_instances(self): instances = ec2_backend.reboot_instances(self.instance_ids) template = Template(EC2_REBOOT_INSTANCES) return template.render(instances=instances) - def StopInstances(self): + def stop_instances(self): instances = ec2_backend.stop_instances(self.instance_ids) template = Template(EC2_STOP_INSTANCES) return template.render(instances=instances) - def StartInstances(self): + def start_instances(self): instances = ec2_backend.start_instances(self.instance_ids) template = Template(EC2_START_INSTANCES) return template.render(instances=instances) - def DescribeInstanceAttribute(self): + def describe_instance_attribute(self): # TODO this and modify below should raise IncorrectInstanceState if instance not in stopped state attribute = self.querystring.get("Attribute")[0] normalized_attribute = camelcase_to_underscores(attribute) @@ -49,7 +49,7 @@ class InstanceResponse(object): template = Template(EC2_DESCRIBE_INSTANCE_ATTRIBUTE) return template.render(instance=instance, attribute=attribute, value=value) - def ModifyInstanceAttribute(self): + def modify_instance_attribute(self): for key, value in self.querystring.iteritems(): if '.Value' in key: break diff --git a/moto/ec2/responses/tags.py b/moto/ec2/responses/tags.py index 4914418c2..841d99ab3 100644 --- a/moto/ec2/responses/tags.py +++ b/moto/ec2/responses/tags.py @@ -9,17 +9,17 @@ class TagResponse(object): self.querystring = querystring self.resource_ids = resource_ids_from_querystring(querystring) - def CreateTags(self): + def create_tags(self): for resource_id, tag in self.resource_ids.iteritems(): ec2_backend.create_tag(resource_id, tag[0], tag[1]) return CREATE_RESPONSE - def DeleteTags(self): + def delete_tags(self): ec2_backend.delete_tag() template = Template(DELETE_RESPONSE) return template.render(reservations=ec2_backend.all_reservations()) - def DescribeTags(self): + def describe_tags(self): tags = ec2_backend.describe_tags() template = Template(DESCRIBE_RESPONSE) return template.render(tags=tags)