EC2: describe_hosts() now returns the AllocationTime-attribute (#7012)

This commit is contained in:
Bert Blommers 2023-11-09 22:24:06 -01:00 committed by GitHub
parent 90e8bb1313
commit 0b84eec6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 0 deletions

View File

@ -1,5 +1,6 @@
from .core import TaggedEC2Resource
from ..utils import generic_filter, random_dedicated_host_id
from moto.core.utils import unix_time
from typing import Any, Dict, List, Optional
@ -21,6 +22,7 @@ class Host(TaggedEC2Resource):
self.instance_family: Optional[str] = instance_family
self.auto_placement = auto_placement or "on"
self.ec2_backend = backend
self.allocation_time = unix_time()
def release(self) -> None:
self.state = "released"

View File

@ -66,6 +66,7 @@ EC2_DESCRIBE_HOSTS = """<DescribeHostsResult xmlns="http://ec2.amazonaws.com/doc
<hostSet>
{% for host in hosts %}
<item>
<allocationTime>{{ host.allocation_time }}</allocationTime>
<autoPlacement>{{ host.auto_placement }}</autoPlacement>
<availabilityZone>{{ host.zone }}</availabilityZone>
<availableCapacity></availableCapacity>

View File

@ -26,6 +26,7 @@ def test_describe_hosts_with_instancefamily():
host = client.describe_hosts(HostIds=host_ids)["Hosts"][0]
assert "AllocationTime" in host
assert host["HostProperties"]["InstanceFamily"] == "c5"