=== modified file 'cloudinit/CloudConfig/cc_update_etc_hosts.py' --- cloudinit/CloudConfig/cc_update_etc_hosts.py 2011-06-30 17:35:12 +0000 +++ cloudinit/CloudConfig/cc_update_etc_hosts.py 2011-07-18 20:20:16 +0000 @@ -17,7 +17,6 @@ # along with this program. If not, see . import cloudinit.util as util from cloudinit.CloudConfig import per_always -import platform import StringIO frequency = per_always @@ -26,8 +25,9 @@ if not util.get_cfg_option_bool(cfg,"manage_etc_hosts",False): log.debug("manage_etc_hosts is not set, checking sanity of /etc/hosts") with open('/etc/hosts', 'r') as etchosts: - current_hostname = platform.node() - hosts_line = "# Added by cloud-init\n127.0.1.1\t%s.localdomain %s\n" % (current_hostname, current_hostname) + current_hostname = cloud.get_hostname() + fqdn = cloud.get_hostname(fqdn=True) + hosts_line = "# Added by cloud-init\n127.0.1.1\t%s %s\n" % (fqdn, current_hostname) need_write = False need_change = True new_etchosts = StringIO.StringIO() @@ -59,14 +59,19 @@ try: hostname = util.get_cfg_option_str(cfg,"hostname",cloud.get_hostname()) + fqdn = util.get_cfg_option_str(cfg,"fqdn",cloud.get_hostname(fqdn=True)) + if not hostname: hostname = cloud.get_hostname() + if not fqdn: + fqdn = cloud.get_hostname(fqdn=True) if not hostname: log.info("manage_etc_hosts was set, but no hostname found") return - util.render_to_file('hosts', '/etc/hosts', { 'hostname' : hostname }) + util.render_to_file('hosts', '/etc/hosts', \ + { 'hostname' : hostname, 'fqdn' : fqdn }) except Exception as e: log.warn("failed to update /etc/hosts") === modified file 'cloudinit/DataSource.py' --- cloudinit/DataSource.py 2011-02-07 18:05:34 +0000 +++ cloudinit/DataSource.py 2011-07-18 19:46:55 +0000 @@ -96,10 +96,13 @@ return "ubuntuhost" return(self.metadata['instance-id']) - def get_hostname(self): + def get_hostname(self, fqdn=False): if not 'local-hostname' in self.metadata: return None + if fqdn: + return self.metadata['local-hostname'] + toks = self.metadata['local-hostname'].split('.') # if there is an ipv4 address in 'local-hostname', then # make up a hostname (LP: #475354) === modified file 'cloudinit/__init__.py' --- cloudinit/__init__.py 2011-06-17 15:03:49 +0000 +++ cloudinit/__init__.py 2011-07-18 19:46:49 +0000 @@ -452,8 +452,8 @@ def get_mirror(self): return(self.datasource.get_local_mirror()) - def get_hostname(self): - return(self.datasource.get_hostname()) + def get_hostname(self, fqdn=False): + return(self.datasource.get_hostname(fqdn=fqdn)) def device_name_to_device(self,name): return(self.datasource.device_name_to_device(name)) === modified file 'templates/hosts.tmpl' --- templates/hosts.tmpl 2011-02-17 21:22:53 +0000 +++ templates/hosts.tmpl 2011-07-18 20:21:09 +0000 @@ -13,7 +13,7 @@ # /etc/cloud/cloud.cfg or cloud-config from user-data # ## The value '$hostname' will be replaced with the local-hostname -127.0.1.1 $hostname +127.0.1.1 $fqdn $hostname 127.0.0.1 localhost # The following lines are desirable for IPv6 capable hosts