From 4ba4dd5e2610da6419cbafc5f2b140ddd6ac4428 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 7 May 2014 08:47:25 -0400 Subject: [PATCH] Added subnet_id support to instances --- moto/ec2/models.py | 2 ++ moto/ec2/responses/instances.py | 8 ++++++-- tests/test_ec2/test_instances.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index f1477245..91f16e4c 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -45,6 +45,7 @@ class Instance(BotoInstance): self.user_data = user_data self.security_groups = security_groups self.instance_type = kwargs.get("instance_type", "m1.small") + self.subnet_id = kwargs.get("subnet_id") @classmethod def create_from_cloudformation_json(cls, resource_name, cloudformation_json): @@ -59,6 +60,7 @@ class Instance(BotoInstance): count=1, security_group_names=group_names, instance_type=properties.get("InstanceType", "m1.small"), + subnet_id=properties.get("SubnetId") ) return reservation.instances[0] diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 28047413..a153713c 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -34,7 +34,10 @@ class InstanceResponse(BaseResponse): user_data = self.querystring.get('UserData') security_group_names = self._get_multi_param('SecurityGroup') instance_type = self.querystring.get("InstanceType", ["m1.small"])[0] - new_reservation = ec2_backend.add_instances(image_id, min_count, user_data, security_group_names, instance_type=instance_type) + subnet_id = self.querystring.get("SubnetId", [None])[0] + new_reservation = ec2_backend.add_instances( + image_id, min_count, user_data, security_group_names, + instance_type=instance_type, subnet_id=subnet_id) template = Template(EC2_RUN_INSTANCES) return template.render(reservation=new_reservation) @@ -122,6 +125,7 @@ EC2_RUN_INSTANCES = """