Specify DHCP domain for hostname

In 9a8c6db448, we looked at the hostname
in the metadata service and used '.' as the delimiter to chop off the
dhcp_domain (specified in nova.conf). However administrators need to
better control the dhcp domain better as there may be a '.' in the host
name itself. So let's introduce a config option that we can use and
default it to what nova uses when dhcp_domain is not specified which is
"novalocal"
This commit is contained in:
Davanum Srinivas 2018-03-29 06:56:30 -04:00
parent 5ae7bba496
commit da5ccf7fb7
2 changed files with 7 additions and 0 deletions

View File

@ -121,6 +121,7 @@ type RouterOpts struct {
type MetadataOpts struct {
SearchOrder string `gcfg:"search-order"`
RequestTimeout MyDuration `gcfg:"request-timeout"`
DHCPDomain string `gcfg:"dhcp-domain"`
}
// OpenStack is an implementation of cloud provider Interface for OpenStack.
@ -233,6 +234,7 @@ func configFromEnv() (cfg Config, ok bool) {
cfg.Global.TrustID != "")
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.Metadata.DHCPDomain = "novalocal"
cfg.BlockStorage.BSVersion = "auto"
return
@ -250,6 +252,7 @@ func readConfig(config io.Reader) (Config, error) {
cfg.BlockStorage.TrustDevicePath = false
cfg.BlockStorage.IgnoreVolumeAZ = false
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.Metadata.DHCPDomain = "novalocal"
err := gcfg.ReadInto(&cfg, config)
return cfg, err

View File

@ -61,6 +61,10 @@ func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types
if err != nil {
return "", err
}
domain := "." + i.opts.DHCPDomain
if i.opts.DHCPDomain != "" && strings.HasSuffix(md.Hostname, domain) {
return types.NodeName(strings.TrimSuffix(md.Hostname, domain)), nil
}
return types.NodeName(strings.Split(md.Hostname, ".")[0]), nil
}