Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print("Canceling spot instance requests...", file=sys.stderr)
client.cancel_spot_instance_requests(
SpotInstanceRequestIds=request_ids)
# Make sure we have the latest information on any launched spot instances.
spot_requests = client.describe_spot_instance_requests(
SpotInstanceRequestIds=request_ids)['SpotInstanceRequests']
instance_ids = [
r['InstanceId'] for r in spot_requests
if 'InstanceId' in r]
if instance_ids:
cluster_instances = list(
ec2.instances.filter(
Filters=[
{'Name': 'instance-id', 'Values': instance_ids}
]))
raise InterruptedEC2Operation(instances=cluster_instances) from e
])
.create_tags(Tags=slave_tags))
existing_slaves = {i.public_ip_address for i in self.slave_instances}
self.slave_instances += new_slave_instances
self.wait_for_state('running')
new_slaves = {i.public_ip_address for i in self.slave_instances} - existing_slaves
super().add_slaves(
user=user,
identity_file=identity_file,
new_hosts=new_slaves)
except (Exception, KeyboardInterrupt) as e:
if isinstance(e, InterruptedEC2Operation):
cleanup_instances = e.instances
else:
cleanup_instances = new_slave_instances
_cleanup_instances(
instances=cleanup_instances,
assume_yes=assume_yes,
region=self.region,
)
raise