Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 5ba7046

Browse files
authored
Merge pull request #429 from JrCs/dns-search-domain
Add dns search domain
2 parents 4b5daf6 + 4d2b59d commit 5ba7046

File tree

7 files changed

+30
-2
lines changed

7 files changed

+30
-2
lines changed

Documentation/vmware-guestinfo.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ property names are prefixed with `guestinfo.` in the VMX, e.g., `guestinfo.hostn
2121
| `interface.<n>.route.<l>.gateway` | `IP address` |
2222
| `interface.<n>.route.<l>.destination` | `CIDR IP address` |
2323
| `dns.server.<x>` | `IP address` |
24+
| `dns.domain.<y>` | `DNS search domain` |
2425
| `coreos.config.data` | `string` |
2526
| `coreos.config.data.encoding` | `{"", "base64", "gzip+base64"}` |
2627
| `coreos.config.url` | `URL` |
2728

28-
Note: "n", "m", "l", and "x" are 0-indexed, incrementing integers. The
29+
Note: "n", "m", "l", "x" and "y" are 0-indexed, incrementing integers. The
2930
identifier for an `interface` does not correspond to anything outside of this
3031
configuration; it serves only to distinguish between multiple `interface`s.
3132

datasource/vmware/vmware.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ func (v vmware) FetchMetadata() (metadata datasource.Metadata, err error) {
5858
}
5959
}
6060

61+
for i := 0; ; i++ {
62+
if domain := saveConfig("dns.domain.%d", i); domain == "" {
63+
break
64+
}
65+
}
66+
6167
found := true
6268
for i := 0; found; i++ {
6369
found = false

network/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ func (i *logicalInterface) Network() string {
7171

7272
switch conf := i.config.(type) {
7373
case configMethodStatic:
74+
if len(conf.domains) > 0 {
75+
config += fmt.Sprintf("Domains=%s\n", strings.Join(conf.domains, " "))
76+
}
7477
for _, nameserver := range conf.nameservers {
7578
config += fmt.Sprintf("DNS=%s\n", nameserver)
7679
}

network/interface_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ func TestInterfaceGenerators(t *testing.T) {
8989
{
9090
name: "testname",
9191
netdev: "[NetDev]\nKind=vlan\nName=testname\n\n[VLAN]\nId=0\n",
92-
network: "[Match]\nName=testname\n\n[Network]\nDNS=8.8.8.8\n\n[Address]\nAddress=192.168.1.100/24\n\n[Route]\nDestination=0.0.0.0/0\nGateway=1.2.3.4\n",
92+
network: "[Match]\nName=testname\n\n[Network]\nDomains=coreos.com example.com\nDNS=8.8.8.8\n\n[Address]\nAddress=192.168.1.100/24\n\n[Route]\nDestination=0.0.0.0/0\nGateway=1.2.3.4\n",
9393
kind: "vlan",
9494
iface: &vlanInterface{logicalInterface: logicalInterface{
9595
name: "testname",
9696
config: configMethodStatic{
9797
addresses: []net.IPNet{{IP: []byte{192, 168, 1, 100}, Mask: []byte{255, 255, 255, 0}}},
9898
nameservers: []net.IP{[]byte{8, 8, 8, 8}},
99+
domains: []string{"coreos.com", "example.com"},
99100
routes: []route{{destination: net.IPNet{IP: []byte{0, 0, 0, 0}, Mask: []byte{0, 0, 0, 0}}, gateway: []byte{1, 2, 3, 4}}},
100101
},
101102
}},

network/stanza.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type configMethod interface{}
5353
type configMethodStatic struct {
5454
addresses []net.IPNet
5555
nameservers []net.IP
56+
domains []string
5657
routes []route
5758
hwaddress net.HardwareAddr
5859
}

network/vmware.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ func ProcessVMwareNetconf(config map[string]string) ([]InterfaceGenerator, error
3838
}
3939
log.Printf("Parsed %d nameservers", len(nameservers))
4040

41+
log.Println("Parsing search domains")
42+
var domains []string
43+
for i := 0; ; i++ {
44+
if domain, ok := config[fmt.Sprintf("dns.domain.%d", i)]; ok {
45+
domains = append(domains, domain)
46+
} else {
47+
break
48+
}
49+
}
50+
log.Printf("Parsed %d search domains", len(domains))
51+
4152
var interfaces []InterfaceGenerator
4253
for i := 0; ; i++ {
4354
var addresses []net.IPNet
@@ -86,6 +97,7 @@ func ProcessVMwareNetconf(config map[string]string) ([]InterfaceGenerator, error
8697
hwaddress: iface.hwaddr,
8798
addresses: addresses,
8899
nameservers: nameservers,
100+
domains: domains,
89101
routes: routes,
90102
}
91103
} else if dhcp {

network/vmware_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ func TestProcessVMwareNetconf(t *testing.T) {
9898
config: map[string]string{
9999
"dns.server.0": "1.2.3.4",
100100
"dns.server.1": "5.6.7.8",
101+
"dns.domain.0": "coreos.com",
102+
"dns.domain.1": "example.com",
101103
"interface.0.mac": "00:11:22:33:44:55",
102104
"interface.0.ip.0.address": "10.0.0.100/24",
103105
"interface.0.ip.1.address": "10.0.0.101/24",
@@ -124,6 +126,7 @@ func TestProcessVMwareNetconf(t *testing.T) {
124126
gateway: net.ParseIP("10.0.0.1")},
125127
},
126128
nameservers: []net.IP{net.ParseIP("1.2.3.4"), net.ParseIP("5.6.7.8")},
129+
domains: []string{"coreos.com", "example.com"},
127130
},
128131
}},
129132
&physicalInterface{logicalInterface{
@@ -135,6 +138,7 @@ func TestProcessVMwareNetconf(t *testing.T) {
135138
gateway: net.ParseIP("10.0.1.1")},
136139
},
137140
nameservers: []net.IP{net.ParseIP("1.2.3.4"), net.ParseIP("5.6.7.8")},
141+
domains: []string{"coreos.com", "example.com"},
138142
},
139143
}},
140144
&physicalInterface{logicalInterface{

0 commit comments

Comments
 (0)