Skip to content

Commit db695dc

Browse files
committed
Add DataSourceMaaS, a Data Source for Ubuntu Machine as a Service
LP: #942061
2 parents 54b593a + 62623b8 commit db695dc

File tree

10 files changed

+600
-88
lines changed

10 files changed

+600
-88
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- DataSourceConfigDrive: support getting data from openstack config drive (LP: #857378)
2828
- DataSourceNoCloud: support seed from external disk of ISO or vfat (LP: #857378)
2929
- DataSourceNoCloud: support inserting /etc/network/interfaces
30+
- DataSourceMaaS: add data source for Ubuntu Machines as a Service (MaaS) (LP: #942061)
3031
0.6.2:
3132
- fix bug where update was not done unless update was explicitly set.
3233
It would not be run if 'upgrade' or packages were set to be installed

cloudinit/DataSourceEc2.py

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from cloudinit import log
2525
import cloudinit.util as util
2626
import socket
27-
import urllib2
2827
import time
2928
import boto.utils as boto_utils
3029
import os.path
@@ -134,8 +133,8 @@ def wait_for_metadata_service(self):
134133
url2base[cur] = url
135134

136135
starttime = time.time()
137-
url = wait_for_metadata_service(urls=urls, max_wait=max_wait,
138-
timeout=timeout, status_cb=log.warn)
136+
url = util.wait_for_url(urls=urls, max_wait=max_wait,
137+
timeout=timeout, status_cb=log.warn)
139138

140139
if url:
141140
log.debug("Using metadata source: '%s'" % url2base[url])
@@ -208,87 +207,6 @@ def is_vpc(self):
208207
return False
209208

210209

211-
def wait_for_metadata_service(urls, max_wait=None, timeout=None,
212-
status_cb=None):
213-
"""
214-
urls: a list of urls to try
215-
max_wait: roughly the maximum time to wait before giving up
216-
The max time is *actually* len(urls)*timeout as each url will
217-
be tried once and given the timeout provided.
218-
timeout: the timeout provided to urllib2.urlopen
219-
status_cb: call method with string message when a url is not available
220-
221-
the idea of this routine is to wait for the EC2 metdata service to
222-
come up. On both Eucalyptus and EC2 we have seen the case where
223-
the instance hit the MD before the MD service was up. EC2 seems
224-
to have permenantely fixed this, though.
225-
226-
In openstack, the metadata service might be painfully slow, and
227-
unable to avoid hitting a timeout of even up to 10 seconds or more
228-
(LP: #894279) for a simple GET.
229-
230-
Offset those needs with the need to not hang forever (and block boot)
231-
on a system where cloud-init is configured to look for EC2 Metadata
232-
service but is not going to find one. It is possible that the instance
233-
data host (169.254.169.254) may be firewalled off Entirely for a sytem,
234-
meaning that the connection will block forever unless a timeout is set.
235-
"""
236-
starttime = time.time()
237-
238-
sleeptime = 1
239-
240-
def nullstatus_cb(msg):
241-
return
242-
243-
if status_cb == None:
244-
status_cb = nullstatus_cb
245-
246-
def timeup(max_wait, starttime):
247-
return((max_wait <= 0 or max_wait == None) or
248-
(time.time() - starttime > max_wait))
249-
250-
loop_n = 0
251-
while True:
252-
sleeptime = int(loop_n / 5) + 1
253-
for url in urls:
254-
now = time.time()
255-
if loop_n != 0:
256-
if timeup(max_wait, starttime):
257-
break
258-
if timeout and (now + timeout > (starttime + max_wait)):
259-
# shorten timeout to not run way over max_time
260-
timeout = int((starttime + max_wait) - now)
261-
262-
reason = ""
263-
try:
264-
req = urllib2.Request(url)
265-
resp = urllib2.urlopen(req, timeout=timeout)
266-
if resp.read() != "":
267-
return url
268-
reason = "empty data [%s]" % resp.getcode()
269-
except urllib2.HTTPError as e:
270-
reason = "http error [%s]" % e.code
271-
except urllib2.URLError as e:
272-
reason = "url error [%s]" % e.reason
273-
except socket.timeout as e:
274-
reason = "socket timeout [%s]" % e
275-
except Exception as e:
276-
reason = "unexpected error [%s]" % e
277-
278-
if log:
279-
status_cb("'%s' failed [%s/%ss]: %s" %
280-
(url, int(time.time() - starttime), max_wait,
281-
reason))
282-
283-
if timeup(max_wait, starttime):
284-
break
285-
286-
loop_n = loop_n + 1
287-
time.sleep(sleeptime)
288-
289-
return False
290-
291-
292210
datasources = [
293211
(DataSourceEc2, (DataSource.DEP_FILESYSTEM, DataSource.DEP_NETWORK)),
294212
]

0 commit comments

Comments
 (0)