Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2: Fix --allow-recreate not recreating terminated spot instances #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions nixops_aws/backends/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ def _reset_state(self):
self.spot_instance_request_id = None
self.spot_instance_price = None

# The `_cached_instance` also contains an instance `.id`;
# reset it just as we reset `vm_id`, otherwise `_get_instance()`
# will incorrectly refer to the old one after resetting.
self._cached_instance = None

def get_ssh_name(self):
retVal = None
if self.use_private_ip_address:
Expand Down Expand Up @@ -907,6 +912,8 @@ def _wait_for_spot_request_fulfillment(self, request_id):
time.sleep(3)
self.log_end("")

assert self._cached_instance is None

instance = self._retry(
lambda: self._get_instance(instance_id=request.instance_id)
)
Expand Down Expand Up @@ -1031,8 +1038,9 @@ def _cancel_spot_request(self):
if request.instance_id is not None and request.instance_id != self.vm_id:
if self.vm_id is not None:
raise Exception(
"spot instance request got fulfilled unexpectedly as instance ‘{0}’".format(
request.instance_id
"spot instance request got fulfilled unexpectedly as instance ‘{0}’; expected ‘{1}’".format(
request.instance_id,
self.vm_id,
)
)
self.vm_id = request.instance_id
Expand Down