Skip to content

Commit

Permalink
Optionally tag spot requests (resolves #237)
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ committed Oct 26, 2016
1 parent ec97c3e commit a84310d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/cgcloud/lib/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,24 @@ def spot_request_not_found( e ):


def create_spot_instances( ec2, price, image_id, spec,
num_instances=1, timeout=None, tentative=False ):
num_instances=1, timeout=None, tentative=False, tag=''):
"""
:rtype: Iterator[list[Instance]]
"""
def spotRequestNotFound(e):
return e.error_code == "InvalidSpotInstanceRequestID.NotFound"

for attempt in retry_ec2( retry_for=a_long_time,
retry_while=inconsistencies_detected ):
with attempt:
requests = ec2.request_spot_instances( price, image_id, count=num_instances, **spec )

if tag:
for requestID in (request.id for request in requests):
for attempt in retry_ec2(retry_while=spotRequestNotFound):
with attempt:
ec2.create_tags([requestID], {'clusterName': tag})

num_active, num_other = 0, 0
# noinspection PyUnboundLocalVariable,PyTypeChecker
# request_spot_instances's type annotation is wrong
Expand Down

0 comments on commit a84310d

Please sign in to comment.