Created
May 3, 2021 18:27
-
-
Save tonyhutter/47173e2f2e810920b5ee264cabb5e171 to your computer and use it in GitHub Desktop.
partially completed moto changes for describe_spot_price_history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ru ./lib/python3.6/site-packages/moto.orig/ec2/models.py ./lib/python3.6/site-packages/moto/ec2/models.py | |
--- ./lib/python3.6/site-packages/moto.orig/ec2/models.py 2021-01-12 22:15:05.958727781 +0000 | |
+++ ./lib/python3.6/site-packages/moto/ec2/models.py 2021-05-03 18:23:48.524026897 +0000 | |
@@ -4041,6 +4041,7 @@ | |
class SpotInstanceRequest(BotoSpotRequest, TaggedEC2Resource): | |
+ test_request_state = "" | |
def __init__( | |
self, | |
ec2_backend, | |
@@ -4100,6 +4101,7 @@ | |
ls.groups.append(default_group) | |
self.instance = self.launch_instance() | |
+ self.last_request_state = "" | |
def get_filter_value(self, filter_name): | |
if filter_name == "state": | |
@@ -4184,12 +4186,21 @@ | |
) | |
self.spot_instance_requests[spot_request_id] = request | |
requests.append(request) | |
+ | |
return requests | |
@Model.prop("SpotInstanceRequest") | |
def describe_spot_instance_requests(self, filters=None): | |
requests = self.spot_instance_requests.values() | |
+ # Toggle out status between "pending-evaluation" and "fulfilled" (initially its | |
+ # "pending-evaluation". | |
+ for request in requests: | |
+ if request.test_request_state == "pending-evaluation": | |
+ request.test_request_state = "fulfilled" | |
+ else: | |
+ request.test_request_state = "pending-evaluation" | |
+ | |
return generic_filter(filters, requests) | |
def cancel_spot_instance_requests(self, request_ids): | |
Binary files ./lib/python3.6/site-packages/moto.orig/ec2/responses/__pycache__/spot_instances.cpython-36.pyc and ./lib/python3.6/site-packages/moto/ec2/responses/__pycache__/spot_instances.cpython-36.pyc differ | |
diff -ru ./lib/python3.6/site-packages/moto.orig/ec2/responses/spot_instances.py ./lib/python3.6/site-packages/moto/ec2/responses/spot_instances.py | |
--- ./lib/python3.6/site-packages/moto.orig/ec2/responses/spot_instances.py 2021-01-13 00:17:42.027718486 +0000 | |
+++ ./lib/python3.6/site-packages/moto/ec2/responses/spot_instances.py 2021-05-03 18:24:50.521022348 +0000 | |
@@ -2,6 +2,8 @@ | |
from moto.core.responses import BaseResponse | |
from moto.ec2.utils import filters_from_querystring | |
+from twisted.python import log | |
+ | |
class SpotInstances(BaseResponse): | |
def cancel_spot_instance_requests(self): | |
@@ -32,12 +34,14 @@ | |
filters = filters_from_querystring(self.querystring) | |
requests = self.ec2_backend.describe_spot_instance_requests(filters=filters) | |
template = self.response_template(DESCRIBE_SPOT_INSTANCES_TEMPLATE) | |
+ | |
return template.render(requests=requests) | |
def describe_spot_price_history(self): | |
- raise NotImplementedError( | |
- "SpotInstances.describe_spot_price_history is not yet implemented" | |
- ) | |
+ filters = filters_from_querystring(self.querystring) | |
+ requests = self.ec2_backend.describe_spot_instance_requests(filters=filters) | |
+ template = self.response_template(DESCRIBE_SPOT_PRICE_HISTORY_TEMPLATE) | |
+ return template.render(requests=requests) | |
def request_spot_instances(self): | |
price = self._get_param("SpotPrice") | |
@@ -148,7 +152,7 @@ | |
<type>{{ request.type }}</type> | |
<state>{{ request.state }}</state> | |
<status> | |
- <code>pending-evaluation</code> | |
+ <code>fulfilled</code> | |
<updateTime>2015-01-01T00:00:00.000Z</updateTime> | |
<message>Your Spot request has been submitted for review, and is pending evaluation.</message> | |
</status> | |
@@ -228,3 +232,18 @@ | |
{% endfor %} | |
</spotInstanceRequestSet> | |
</CancelSpotInstanceRequestsResponse>""" | |
+ | |
+DESCRIBE_SPOT_PRICE_HISTORY_TEMPLATE = """<DescribeSpotPriceHistoryResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/"> | |
+ <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> | |
+ <spotPriceHistorySet> | |
+ {% for request in requests %} | |
+ <item> | |
+ <spotInstanceRequestId>{{ request.id }}</spotInstanceRequestId> | |
+ <productDescription>Linux/UNIX (Amazon VPC)</productDescription> | |
+ <instanceType>m1.large</instanceType> | |
+ <spotPrice>0.080000</spotPrice> | |
+ <availabilityZone>us-west-1a</availabilityZone> | |
+ </item> | |
+ {% endfor %} | |
+ </spotPriceHistorySet> | |
+</DescribeSpotPriceHistoryResponse>""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment