Added subnet_id support to instances
This commit is contained in:
parent
5ba2b3cb9a
commit
4ba4dd5e26
@ -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]
|
||||
|
||||
|
@ -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 = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
|
||||
<monitoring>
|
||||
<state>enabled</state>
|
||||
</monitoring>
|
||||
<subnetId>{{ instance.subnet_id }}</subnetId>
|
||||
<sourceDestCheck>true</sourceDestCheck>
|
||||
<groupSet>
|
||||
{% for group in instance.security_groups %}
|
||||
@ -174,7 +178,7 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns='http://ec2.amazona
|
||||
<monitoring>
|
||||
<state>disabled</state>
|
||||
</monitoring>
|
||||
<subnetId>subnet-1a2b3c4d</subnetId>
|
||||
<subnetId>{{ instance.subnet_id }}</subnetId>
|
||||
<vpcId>vpc-1a2b3c4d</vpcId>
|
||||
<privateIpAddress>10.0.0.12</privateIpAddress>
|
||||
<ipAddress>46.51.219.63</ipAddress>
|
||||
|
@ -191,3 +191,13 @@ def test_run_instance_with_instance_type():
|
||||
instance = reservation.instances[0]
|
||||
|
||||
instance.instance_type.should.equal("t1.micro")
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_run_instance_with_subnet():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('ami-1234abcd',
|
||||
subnet_id="subnet-abcd1234")
|
||||
instance = reservation.instances[0]
|
||||
|
||||
instance.subnet_id.should.equal("subnet-abcd1234")
|
||||
|
Loading…
Reference in New Issue
Block a user