Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

When requesting spot instances, looping untils SIR are returned by amazo... #163

Closed
wants to merge 2 commits into from

1 participant

Commits on Nov 13, 2012
  1. @FinchPowers
Commits on Jul 17, 2013
  1. @FinchPowers

    cleaning commit

    FinchPowers authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 1 deletion.
  1. +24 −1 starcluster/awsutils.py
View
25 starcluster/awsutils.py
@@ -349,13 +349,36 @@ def request_spot_instances(self, price, image_id, instance_type='m1.small',
availability_zone_group=None,
security_groups=None, placement=None,
placement_group=None, user_data=None):
- return self.conn.request_spot_instances(
+ requests = self.conn.request_spot_instances(
price, image_id, instance_type=instance_type, count=count,
launch_group=launch_group, key_name=key_name,
security_groups=security_groups,
availability_zone_group=availability_zone_group,
placement=placement, placement_group=placement_group,
user_data=user_data)
+ requests_ids = []
+ for request in requests:
+ requests_ids.append(request.id)
+
+ #Make sure the spot instance request has been ingested by EC2
+ #before proceeding. Wait at most 10 sec.
+ counter = 0
+ while True:
+ all_requests = self.conn.get_all_spot_instance_requests()
+ all_requests.reverse() # start from the end as our request will
+ # usually be the last
+ for request in all_requests:
+ if request.id in requests_ids:
+ del requests_ids[requests_ids.index(request.id)]
+ if len(requests_ids) == 0:
+ #done
+ return requests
+
+ if counter % 10 == 0:
+ log.info("Still waiting for instances " + str(requests_ids))
+ log.debug(str(counter) + ": Instance not propagated, sleeping")
+ time.sleep(1)
+ counter += 1
def run_instances(self, image_id, instance_type='m1.small', min_count=1,
max_count=1, key_name=None, security_groups=None,
Something went wrong with that request. Please try again.