Commit da5ccf7f authored by Davanum Srinivas's avatar Davanum Srinivas

Specify DHCP domain for hostname

In 9a8c6db4, 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"
parent 5ae7bba4
...@@ -121,6 +121,7 @@ type RouterOpts struct { ...@@ -121,6 +121,7 @@ type RouterOpts struct {
type MetadataOpts struct { type MetadataOpts struct {
SearchOrder string `gcfg:"search-order"` SearchOrder string `gcfg:"search-order"`
RequestTimeout MyDuration `gcfg:"request-timeout"` RequestTimeout MyDuration `gcfg:"request-timeout"`
DHCPDomain string `gcfg:"dhcp-domain"`
} }
// OpenStack is an implementation of cloud provider Interface for OpenStack. // OpenStack is an implementation of cloud provider Interface for OpenStack.
...@@ -233,6 +234,7 @@ func configFromEnv() (cfg Config, ok bool) { ...@@ -233,6 +234,7 @@ func configFromEnv() (cfg Config, ok bool) {
cfg.Global.TrustID != "") cfg.Global.TrustID != "")
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID) cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.Metadata.DHCPDomain = "novalocal"
cfg.BlockStorage.BSVersion = "auto" cfg.BlockStorage.BSVersion = "auto"
return return
...@@ -250,6 +252,7 @@ func readConfig(config io.Reader) (Config, error) { ...@@ -250,6 +252,7 @@ func readConfig(config io.Reader) (Config, error) {
cfg.BlockStorage.TrustDevicePath = false cfg.BlockStorage.TrustDevicePath = false
cfg.BlockStorage.IgnoreVolumeAZ = false cfg.BlockStorage.IgnoreVolumeAZ = false
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID) cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.Metadata.DHCPDomain = "novalocal"
err := gcfg.ReadInto(&cfg, config) err := gcfg.ReadInto(&cfg, config)
return cfg, err return cfg, err
......
...@@ -61,6 +61,10 @@ func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types ...@@ -61,6 +61,10 @@ func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types
if err != nil { if err != nil {
return "", err 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 return types.NodeName(strings.Split(md.Hostname, ".")[0]), nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment