summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-05-05 10:48:48 -0400
committerScott Moser <smoser@ubuntu.com>2010-05-05 10:48:48 -0400
commitbec9d097ebcbc5e8d595990d8cbcbb30f433e2fb (patch)
treeca4445ec465d57a7151f83efea0a8869626350b4
parentbc0a5f24f95a47a7f846233e1fdda65bdb3d607e (diff)
downloadvyos-cloud-init-bec9d097ebcbc5e8d595990d8cbcbb30f433e2fb.tar.gz
vyos-cloud-init-bec9d097ebcbc5e8d595990d8cbcbb30f433e2fb.zip
wait considerably longer (1050 seconds) for metadata service to come up
Also - adds some debugging information when its waiting - add 'uptime' printout on initial cloud-init invocation
-rwxr-xr-xcloud-init.py15
-rw-r--r--cloudinit/DataSourceEc2.py40
2 files changed, 43 insertions, 12 deletions
diff --git a/cloud-init.py b/cloud-init.py
index c92f07cd..68cc30bc 100755
--- a/cloud-init.py
+++ b/cloud-init.py
@@ -21,11 +21,24 @@ import sys
import cloudinit
import cloudinit.util as util
+import time
def warn(str):
sys.stderr.write(str)
def main():
+ now = time.strftime("%a, %d %b %Y %H:%M:%S %z")
+ try:
+ uptimef=open("/proc/uptime")
+ uptime=uptimef.read().split(" ")[0]
+ uptimef.close()
+ except IOError as e:
+ warn("unable to open /proc/uptime\n")
+ uptime = "na"
+
+ sys.stderr.write("cloud-init running: %s. up %s seconds\n" % (now, uptime))
+ sys.stderr.flush()
+
# cache is not instance specific, so it has to be purged
cloudinit.purge_cache()
@@ -35,7 +48,7 @@ def main():
cloud.get_data_source()
except Exception as e:
print e
- sys.stderr.write("Failed to get instance data")
+ sys.stderr.write("Failed to get instance data\n")
sys.exit(1)
# store the metadata
diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py
index aeab7d5a..750baab3 100644
--- a/cloudinit/DataSourceEc2.py
+++ b/cloudinit/DataSourceEc2.py
@@ -20,6 +20,7 @@ import cloudinit
import socket
import urllib2
import time
+import sys
import boto_utils
class DataSourceEc2(DataSource.DataSource):
@@ -100,20 +101,37 @@ class DataSourceEc2(DataSource.DataSource):
except:
return 'http://archive.ubuntu.com/ubuntu/'
- def wait_for_metadata_service(self, sleeps = 10):
+
+ def wait_for_metadata_service(self, sleeps = 100):
sleeptime = 1
+ address = '169.254.169.254'
+ starttime = time.time()
+
+ url="http://%s/%s/meta-data/instance-id" % (address,self.api_ver)
for x in range(sleeps):
- s = socket.socket()
+ # given 100 sleeps, this ends up total sleep time of 1050 sec
+ sleeptime=int(x/5)+1
+
+ reason = ""
try:
- address = '169.254.169.254'
- port = 80
- s.connect((address,port))
- s.close()
- return True
- except socket.error, e:
- print "sleeping %s" % sleeptime
- time.sleep(sleeptime)
- #timeout = timeout * 2
+ req = urllib2.Request(url)
+ resp = urllib2.urlopen(req, timeout=2)
+ if resp.read() != "": return True
+ reason = "empty data [%s]" % resp.getcode()
+ except urllib2.HTTPError, e:
+ reason = "http error [%s]" % e.code
+ except urllib2.URLError, e:
+ reason = "url error [%s]" % e.reason
+
+ if x == 0:
+ sys.stderr.write("waiting for metadata service at %s\n" % url)
+
+ sys.stderr.write(" %s [%02s/%s]: %s\n" %
+ (time.strftime("%H:%M:%S"), x+1, sleeps, reason))
+ time.sleep(sleeptime)
+
+ sys.stderr.write("giving up on md after %i seconds\n" %
+ int(time.time()-starttime))
return False
def get_public_ssh_keys(self):