We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 2e5f947 + 83332c3 commit 12b2e18Copy full SHA for 12b2e18
agent.py
@@ -18,6 +18,7 @@
18
import sched
19
import sys
20
import time
21
+import urllib
22
23
# Check we're not using an old version of Python. We need 2.4 above because some modules (like subprocess)
24
# were only introduced in 2.4.
@@ -42,12 +43,12 @@ def get_ec2_instance_id():
42
43
"""Fetch EC2 instance ID if possible. If not on EC2 returns None"""
44
try:
45
url = urllib.urlopen(agent.EC2_URL)
- if url.getcode() == 200:
46
- instanceId = url.read()
47
- return instanceId
+ instanceId = url.read()
+ assert instanceId.startswith("i-"), "Malformed instance-id: %s" % instanceId
48
+ return instanceId
49
50
except Exception, e:
- pass
51
+ logging.getLogger('agent').exception('Cannot determine instance-id. Is this machine on EC2?')
52
53
return None
54
0 commit comments