in resources/templates/spot/assets/send_metrics.py [0:0]
def check_interrupt_notice():
global imsv2_token
global interrupt_latch
if interrupt_latch:
print("Already latched interrupt")
return True
if not imsv2_token:
get_imsv2_token()
try:
req = urllib.request.Request(
'http://169.254.169.254/latest/meta-data/spot/instance-action',
headers = {
"X-aws-ec2-metadata-token": imsv2_token
},
method="GET")
res = urllib.request.urlopen(req, timeout=1).read().decode()
print("Received interrupt notification: %s" % str(res))
return True
except Exception as e:
print("No interrupt")
print(e)
return False