diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_grub_dpkg.py | 3 | ||||
-rw-r--r-- | cloudinit/CloudConfig/cc_timezone.py | 1 | ||||
-rw-r--r-- | cloudinit/DataSourceEc2.py | 61 | ||||
-rw-r--r-- | cloudinit/UserDataHandler.py | 1 | ||||
-rw-r--r-- | cloudinit/__init__.py | 22 | ||||
-rw-r--r-- | cloudinit/util.py | 6 | ||||
-rw-r--r-- | doc/examples/seed/README | 4 |
8 files changed, 54 insertions, 50 deletions
@@ -5,6 +5,12 @@ (LP: #739694) - fix bug in resizefs cloud-config that would cause trace based on failure of 'blkid /dev/root' (LP: #726938) + - convert dos formated files to unix for user-scripts, boothooks, + and upstart jobs (LP: #744965) + - fix bug in seeding of grub dpkg configuration (LP: #752361) due + to renamed devices in newer (natty) kernels (/dev/sda1 -> /dev/xvda1) + - make metadata urls configurable, to support eucalyptus in + STATIC or SYSTEM modes (LP: #761847) 0.6.1: - fix bug in fixing permission on /var/log/cloud-init.log (LP: #704509) - improve comment strings in rsyslog file tools/21-cloudinit.conf diff --git a/cloudinit/CloudConfig/cc_grub_dpkg.py b/cloudinit/CloudConfig/cc_grub_dpkg.py index dafb43cf..b26e90e8 100644 --- a/cloudinit/CloudConfig/cc_grub_dpkg.py +++ b/cloudinit/CloudConfig/cc_grub_dpkg.py @@ -31,7 +31,8 @@ def handle(name,cfg,cloud,log,args): idevs_empty=util.get_cfg_option_str(cfg["grub-dpkg"], "grub-pc/install_devices_empty",None) - if os.path.exists("/dev/sda1") and not os.path.exists("/dev/sda"): + if (( os.path.exists("/dev/sda1") and not os.path.exists("/dev/sda") ) or + ( os.path.exists("/dev/xvda1") and not os.path.exists("/dev/xvda") )): if idevs == None: idevs="" if idevs_empty == None: idevs_empty="true" else: diff --git a/cloudinit/CloudConfig/cc_timezone.py b/cloudinit/CloudConfig/cc_timezone.py index f221819e..a26df8f9 100644 --- a/cloudinit/CloudConfig/cc_timezone.py +++ b/cloudinit/CloudConfig/cc_timezone.py @@ -25,7 +25,6 @@ frequency = per_instance tz_base = "/usr/share/zoneinfo" def handle(name,cfg,cloud,log,args): - print args if len(args) != 0: timezone = args[0] else: diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index 00d882aa..18c1ed50 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -27,11 +27,12 @@ import sys import boto_utils import os.path import errno +import urlparse class DataSourceEc2(DataSource.DataSource): api_ver = '2009-04-04' seeddir = seeddir + '/ec2' - metadata_address = "http://169.254.169.254:80/" + metadata_address = "http://169.254.169.254" def __str__(self): return("DataSourceEc2") @@ -80,14 +81,6 @@ class DataSourceEc2(DataSource.DataSource): except: return fallback - def try_to_resolve_metadata(self, address): - log.warning("Trying %s" % address) - try: - socket.getaddrinfo(address.split(":")[1][2:], address.split(":")[2]) - return True - except Exception as e: - log.warning("%s failed with %s" % (address, e)) - return False def wait_for_metadata_service(self, sleeps = None): mcfg = self.ds_cfg @@ -110,43 +103,45 @@ class DataSourceEc2(DataSource.DataSource): sleeptime = 1 - addresslist = ["http://169.254.169.254:80", "http://instance-data:8773"] + def_mdurls = ["http://169.254.169.254", "http://instance-data:8773"] try: - addresslist = mcfg.get("metadata_urls", addresslist) + mdurls = mcfg.get("metadata_urls", def_mdurls) except Exception as e: + mdurls = def_mdurls util.logexc(log) - log.warning("Failed to get metadata URLs, using defaults") + log.warn("Failed to get metadata URLs, using defaults") starttime = time.time() - log.warning("Attempting to resolve metadata services") - #for addr in addresslist: - # log.warning("\t%s/meta-data/instance-id" % addr) - # Remove addresses from the list that wont resolve. - addresslist[:] = [x for x in addresslist if self.try_to_resolve_metadata(x)] + filtered = [x for x in mdurls if try_to_resolve_metadata(x)] - log.warning("The following metadata service addresses resolved:") - for addr in addresslist: - log.warning("\t%s/meta-data/instance-id" % addr) + if set(filtered) != set(mdurls): + log.debug("removed the following from metadata urls: %s" % + list((set(mdurls) - set(filtered)))) + if len(filtered): + mdurls = filtered + else: + log.warn("Empty metadata url list! using default list") + mdurls = def_mdurls + + log.debug("Searching the following metadata urls: %s" % mdurls) for x in range(sleeps): - log.warning("[%02s/%s] Trying Metadata Services:" % (x+1, sleeps)) - for address in addresslist: - url="%s/%s/meta-data/instance-id" % (address, self.api_ver) + for url in mdurls: + iurl="%s/%s/meta-data/instance-id" % (url, self.api_ver) # given 100 sleeps, this ends up total sleep time of 1050 sec sleeptime=int(x/5)+1 reason = "" try: - #log.warning("\t - Trying %s" % url) req = urllib2.Request(url) resp = urllib2.urlopen(req, timeout=timeout) if resp.read() != "": - self.metadata_address = address - log.warning("Success! Using %s for metadata" % self.metadata_address) + self.metadata_address = url + log.debug("Using metadata source: '%s'" % url) return True reason = "empty data [%s]" % resp.getcode() except urllib2.HTTPError as e: @@ -156,10 +151,9 @@ class DataSourceEc2(DataSource.DataSource): #not needed? Addresses being checked are displayed above #if x == 0: - # log.warning("waiting for metadata service at %s" % url) + # log.warn("waiting for metadata service at %s" % url) - log.warning("\t%s - Failed With : %s" % (address, reason)) - log.warning("Sleeping for %d seconds\n" % sleeptime) + log.warn("'%s' failed: %s" % (url, reason)) time.sleep(sleeptime) log.critical("giving up on md after %i seconds\n" % @@ -217,6 +211,15 @@ class DataSourceEc2(DataSource.DataSource): return True return False +def try_to_resolve_metadata(url): + try: + addr = urlparse.urlsplit(url).netloc.split(":")[0] + socket.getaddrinfo(addr, None) + return True + except Exception as e: + return False + + datasources = [ ( DataSourceEc2, ( DataSource.DEP_FILESYSTEM , DataSource.DEP_NETWORK ) ), ] diff --git a/cloudinit/UserDataHandler.py b/cloudinit/UserDataHandler.py index fbb000fc..83377dab 100644 --- a/cloudinit/UserDataHandler.py +++ b/cloudinit/UserDataHandler.py @@ -74,7 +74,6 @@ def explode_cc_archive(archive,parts): if mtype == None: mtype = type_from_startswith(payload,def_type) - print "adding %s,%s" % (filename, mtype) parts['content'].append(content) parts['names'].append(filename) parts['types'].append(mtype) diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 24e12d08..ab0a834a 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -393,14 +393,15 @@ class CloudInit: filename=filename.replace(os.sep,'_') scriptsdir = get_ipath_cur('scripts') util.write_file("%s/%s" % - (scriptsdir,filename), payload, 0700) + (scriptsdir,filename), util.dos2unix(payload), 0700) def handle_upstart_job(self,data,ctype,filename,payload): if ctype == "__end__" or ctype == "__begin__": return if not filename.endswith(".conf"): filename=filename+".conf" - util.write_file("%s/%s" % ("/etc/init",filename), payload, 0644) + util.write_file("%s/%s" % ("/etc/init",filename), + util.dos2unix(payload), 0644) def handle_cloud_config(self,data,ctype,filename,payload): if ctype == "__begin__": @@ -427,26 +428,15 @@ class CloudInit: if ctype == "__begin__": return filename=filename.replace(os.sep,'_') + payload = util.dos2unix(payload) prefix="#cloud-boothook" - dos=False start = 0 if payload.startswith(prefix): - start = len(prefix) - if payload[start] == '\r': - start=start+1 - dos = True - else: - if payload.find('\r\n',0,100) >= 0: - dos = True - - if dos: - payload=payload[start:].replace('\r\n','\n') - elif start != 0: - payload=payload[start:] + start = len(prefix) + 1 boothooks_dir = self.get_ipath("boothooks") filepath = "%s/%s" % (boothooks_dir,filename) - util.write_file(filepath, payload, 0700) + util.write_file(filepath, payload[start:], 0700) try: env=os.environ.copy() env['INSTANCE_ID']= self.datasource.get_instance_id() diff --git a/cloudinit/util.py b/cloudinit/util.py index fc4233de..8f6a6b0d 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -389,3 +389,9 @@ def shellify(cmdlist): else: content="%s%s\n" % ( content, str(args) ) return content + +def dos2unix(input): + # find first end of line + pos = input.find('\n') + if pos <= 0 or input[pos-1] != '\r': return(input) + return(input.replace('\r\n','\n')) diff --git a/doc/examples/seed/README b/doc/examples/seed/README index 927768f8..cc15839e 100644 --- a/doc/examples/seed/README +++ b/doc/examples/seed/README @@ -2,9 +2,9 @@ This directory is an example of a 'seed' directory. copying these files inside an instance's - /var/lib/cloud/data/cache/nocloud + /var/lib/cloud/seed/nocloud or - /var/lib/cloud/data/cache/nocloud-net + /var/lib/cloud/seed/nocloud-net will cause the 'DataSourceNoCloud' and 'DataSourceNoCloudNet' modules to enable and read the given data. |