EC2: run_instances() now returns the Placement.HostId attribute (#6885)
This commit is contained in:
parent
309d5eb3bc
commit
36f006c32a
@ -111,6 +111,7 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel):
|
||||
self.instance_type: str = kwargs.get("instance_type", "m1.small")
|
||||
self.region_name = kwargs.get("region_name", "us-east-1")
|
||||
placement = kwargs.get("placement", None)
|
||||
self.placement_hostid = kwargs.get("placement_hostid")
|
||||
self.subnet_id = kwargs.get("subnet_id")
|
||||
if not self.subnet_id:
|
||||
self.subnet_id = next(
|
||||
|
@ -61,6 +61,7 @@ class InstanceResponse(EC2BaseResponse):
|
||||
"instance_type": self._get_param("InstanceType", if_none="m1.small"),
|
||||
"is_instance_type_default": not self._get_param("InstanceType"),
|
||||
"placement": self._get_param("Placement.AvailabilityZone"),
|
||||
"placement_hostid": self._get_param("Placement.HostId"),
|
||||
"region_name": self.region,
|
||||
"subnet_id": self._get_param("SubnetId"),
|
||||
"owner_id": owner_id,
|
||||
@ -470,6 +471,7 @@ EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
|
||||
<instanceLifecycle>{{ instance.lifecycle }}</instanceLifecycle>
|
||||
{% endif %}
|
||||
<placement>
|
||||
{% if instance.placement_hostid %}<hostId>{{ instance.placement_hostid }}</hostId>{% endif %}
|
||||
<availabilityZone>{{ instance.placement}}</availabilityZone>
|
||||
<groupName/>
|
||||
<tenancy>default</tenancy>
|
||||
@ -627,6 +629,7 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns="http://ec2.amazona
|
||||
<instanceLifecycle>{{ instance.lifecycle }}</instanceLifecycle>
|
||||
{% endif %}
|
||||
<placement>
|
||||
{% if instance.placement_hostid %}<hostId>{{ instance.placement_hostid }}</hostId>{% endif %}
|
||||
<availabilityZone>{{ instance.placement }}</availabilityZone>
|
||||
<groupName/>
|
||||
<tenancy>default</tenancy>
|
||||
|
@ -1326,6 +1326,23 @@ def test_run_instance_with_specified_private_ipv4():
|
||||
assert instance["PrivateIpAddress"] == "192.168.42.5"
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_run_instance_with_placement():
|
||||
client = boto3.client("ec2", region_name="eu-central-1")
|
||||
host_id = "h-asdfasdfasdf"
|
||||
|
||||
instance = client.run_instances(
|
||||
ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, Placement={"HostId": host_id}
|
||||
)["Instances"][0]
|
||||
instance_id = instance["InstanceId"]
|
||||
assert instance["Placement"]["HostId"] == host_id
|
||||
|
||||
resp = client.describe_instances(InstanceIds=[instance_id])["Reservations"][0][
|
||||
"Instances"
|
||||
][0]
|
||||
assert resp["Placement"]["HostId"] == host_id
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_run_instance_mapped_public_ipv4():
|
||||
client = boto3.client("ec2", region_name="eu-central-1")
|
||||
|
Loading…
Reference in New Issue
Block a user