cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #04250
Re: [Merge] ~chad.smith/cloud-init:set-hostname-before-network into cloud-init:master
I've a bit of a quibble with the description. Mostly because cloud-init has _no_ control over how DNS or DHCP servers react to dhcp client requests coming from an instance.
What we (cloud-init) can do is set instance specified hostnames as _soon_ as we know it, which may be of help to some situations where Dynamic DNS via dhcp client hostname value.
This is an environment specific issue and having cloud-init set hostname as soon as possible does not ensure that there won't be issues with DNS, DHCP outside of cloud-init control.
Some inline comments too.
Diff comments:
> diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py
> index d2f1b77..120c3cc 100644
> --- a/cloudinit/cmd/main.py
> +++ b/cloudinit/cmd/main.py
> @@ -354,7 +355,17 @@ def main_init(name, args):
> LOG.debug("[%s] %s will now be targeting instance id: %s. new=%s",
> mode, name, iid, init.is_new_instance())
>
> - init.apply_network_config(bring_up=bool(mode != sources.DSMODE_LOCAL))
> + if mode == sources.DSMODE_LOCAL:
> + # Before network comes up, set any configured hostname to allow
> + # dhcp clients to advertize this hostname to any DDNS services
> + # lp:1746455.
> + cloud = init.cloudify()
> + (hostname, _fqdn) = util.get_hostname_fqdn(
doesn't this sometime return None ? Isn't that going to break your named _fqdn ?
> + init.cfg, cloud, metadata_only=True)
> + if hostname: # Either metadata or user-data provided hostname content
> + cc_set_hostname.handle(
> + 'pre-network-set-hostname', init.cfg, cloud, LOG, None)
> + init.apply_network_config(bring_up=bring_up)
>
> if mode == sources.DSMODE_LOCAL:
> if init.datasource.dsmode != mode:
> 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
hostnames aren't ipv4 or ipv6; the just map to ip addresses.
> + 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
Can't we just return (None, None)?
> # 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.
References