Added key_name support to instances
This commit is contained in:
parent
4ba4dd5e26
commit
b244457c4f
@ -46,6 +46,7 @@ class Instance(BotoInstance):
|
|||||||
self.security_groups = security_groups
|
self.security_groups = security_groups
|
||||||
self.instance_type = kwargs.get("instance_type", "m1.small")
|
self.instance_type = kwargs.get("instance_type", "m1.small")
|
||||||
self.subnet_id = kwargs.get("subnet_id")
|
self.subnet_id = kwargs.get("subnet_id")
|
||||||
|
self.key_name = kwargs.get("key_name")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json):
|
def create_from_cloudformation_json(cls, resource_name, cloudformation_json):
|
||||||
@ -60,7 +61,8 @@ class Instance(BotoInstance):
|
|||||||
count=1,
|
count=1,
|
||||||
security_group_names=group_names,
|
security_group_names=group_names,
|
||||||
instance_type=properties.get("InstanceType", "m1.small"),
|
instance_type=properties.get("InstanceType", "m1.small"),
|
||||||
subnet_id=properties.get("SubnetId")
|
subnet_id=properties.get("SubnetId"),
|
||||||
|
key_name=properties.get("KeyName"),
|
||||||
)
|
)
|
||||||
return reservation.instances[0]
|
return reservation.instances[0]
|
||||||
|
|
||||||
|
@ -35,9 +35,11 @@ class InstanceResponse(BaseResponse):
|
|||||||
security_group_names = self._get_multi_param('SecurityGroup')
|
security_group_names = self._get_multi_param('SecurityGroup')
|
||||||
instance_type = self.querystring.get("InstanceType", ["m1.small"])[0]
|
instance_type = self.querystring.get("InstanceType", ["m1.small"])[0]
|
||||||
subnet_id = self.querystring.get("SubnetId", [None])[0]
|
subnet_id = self.querystring.get("SubnetId", [None])[0]
|
||||||
|
key_name = self.querystring.get("KeyName", [None])[0]
|
||||||
new_reservation = ec2_backend.add_instances(
|
new_reservation = ec2_backend.add_instances(
|
||||||
image_id, min_count, user_data, security_group_names,
|
image_id, min_count, user_data, security_group_names,
|
||||||
instance_type=instance_type, subnet_id=subnet_id)
|
instance_type=instance_type, subnet_id=subnet_id,
|
||||||
|
key_name=key_name)
|
||||||
template = Template(EC2_RUN_INSTANCES)
|
template = Template(EC2_RUN_INSTANCES)
|
||||||
return template.render(reservation=new_reservation)
|
return template.render(reservation=new_reservation)
|
||||||
|
|
||||||
@ -114,6 +116,7 @@ EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
|
|||||||
<privateDnsName/>
|
<privateDnsName/>
|
||||||
<dnsName/>
|
<dnsName/>
|
||||||
<reason/>
|
<reason/>
|
||||||
|
<keyName>{{ instance.key_name }}</keyName>
|
||||||
<amiLaunchIndex>0</amiLaunchIndex>
|
<amiLaunchIndex>0</amiLaunchIndex>
|
||||||
<instanceType>{{ instance.instance_type }}</instanceType>
|
<instanceType>{{ instance.instance_type }}</instanceType>
|
||||||
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
||||||
@ -164,7 +167,7 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns='http://ec2.amazona
|
|||||||
<privateDnsName>ip-10.0.0.12.ec2.internal</privateDnsName>
|
<privateDnsName>ip-10.0.0.12.ec2.internal</privateDnsName>
|
||||||
<dnsName>ec2-46.51.219.63.compute-1.amazonaws.com</dnsName>
|
<dnsName>ec2-46.51.219.63.compute-1.amazonaws.com</dnsName>
|
||||||
<reason/>
|
<reason/>
|
||||||
<keyName>gsg-keypair</keyName>
|
<keyName>{{ instance.key_name }}</keyName>
|
||||||
<amiLaunchIndex>0</amiLaunchIndex>
|
<amiLaunchIndex>0</amiLaunchIndex>
|
||||||
<productCodes/>
|
<productCodes/>
|
||||||
<instanceType>{{ instance.instance_type }}</instanceType>
|
<instanceType>{{ instance.instance_type }}</instanceType>
|
||||||
|
@ -201,3 +201,12 @@ def test_run_instance_with_subnet():
|
|||||||
instance = reservation.instances[0]
|
instance = reservation.instances[0]
|
||||||
|
|
||||||
instance.subnet_id.should.equal("subnet-abcd1234")
|
instance.subnet_id.should.equal("subnet-abcd1234")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_run_instance_with_keypair():
|
||||||
|
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||||
|
reservation = conn.run_instances('ami-1234abcd', key_name="keypair_name")
|
||||||
|
instance = reservation.instances[0]
|
||||||
|
|
||||||
|
instance.key_name.should.equal("keypair_name")
|
||||||
|
Loading…
Reference in New Issue
Block a user