Diff comments:
> diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py > index a05ca2f..d1a213f 100644 > --- a/cloudinit/sources/__init__.py > +++ b/cloudinit/sources/__init__.py > @@ -276,21 +276,34 @@ class DataSource(object): > return "iid-datasource" > return str(self.metadata['instance-id']) > > - def get_hostname(self, fqdn=False, resolve_ip=False): > + def get_hostname(self, fqdn=False, resolve_ip=False, > metadata_only=False): > + """Get hostname or fqdn from the datasource. Look it up if desired. > + > + @param fqdn: Boolean, set True to return hostname with domain. > + @param resolve_ip: Boolean, set True to attempt to resolve an ipv4 Yes, but I was just documenting current behavior, which only(perhaps incorrectly) uses util.is_ipv4 to check whether a string is an ipv4 address before attempting to resolve it. Maybe it's worth fixing the logic of this function to check for ipv6 too and attempt resolution in that case? > + address provided in local-hostname metadata. > + @param metadata_only: Boolean, set True to avoid looking up hostname > + if metadata doesn't have local-hostname present. > + > + @return: hostname or qualified hostname. Optionally return None when > + metadata_only is True and local-hostname data is not available. > + """ > defdomain = "localdomain" > defhost = "localhost" > domain = defdomain > > if not self.metadata or 'local-hostname' not in self.metadata: > + if metadata_only: > + return None The method is wrapped in cloud.get_hostname and expects to return the value of a single property, either the fully qualified hostname or the unqualified hostname. Returning None, None here causes us to add significantly more logic up in util.get_hostname_fqdn unless you also think we should refactor Datasource.get_hostname to return a tuple of <hostname>, <qualified_hostname> in general. > # this is somewhat questionable really. > # the cloud datasource was asked for a hostname > # and didn't have one. raising error might be more appropriate > # but instead, basically look up the existing hostname > toks = [] > hostname = util.get_hostname() > - fqdn = util.get_fqdn_from_hosts(hostname) > - if fqdn and fqdn.find(".") > 0: > - toks = str(fqdn).split(".") > + hosts_fqdn = util.get_fqdn_from_hosts(hostname) > + if hosts_fqdn and hosts_fqdn.find(".") > 0: > + toks = str(hosts_fqdn).split(".") > elif hostname and hostname.find(".") > 0: > toks = str(hostname).split(".") > elif hostname: -- https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/339720 Your team cloud-init commiters is requested to review the proposed merge of ~chad.smith/cloud-init:set-hostname-before-network into cloud-init:master. _______________________________________________ Mailing list: https://launchpad.net/~cloud-init-dev Post to : cloud-init-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~cloud-init-dev More help : https://help.launchpad.net/ListHelp