Could someone please review this? Cheers, Thomas On 07/12/2017 03:28 PM, Thomas Hipp wrote: > Add support for DNS in network, and add test code. > > Signed-off-by: Thomas Hipp <thipp@xxxxxxx> > --- > network.go | 39 ++++++++++++++++++++++++++++++++++ > network_test.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- > 2 files changed, 99 insertions(+), 5 deletions(-) > > diff --git a/network.go b/network.go > index cc850a1..e0baa96 100644 > --- a/network.go > +++ b/network.go > @@ -84,6 +84,44 @@ type NetworkRoute struct { > Gateway string `xml:"gateway,attr,omitempty"` > } > > +type NetworkDNSForwarder struct { > + Domain string `xml:"domain,attr,omitempty"` > + Addr string `xml:"addr,attr,omitempty"` > +} > + > +type NetworkDNSTXT struct { > + Name string `xml:"name,attr"` > + Value string `xml:"value,attr"` > +} > + > +type NetworkDNSHostHostname struct { > + Hostname string `xml:",chardata"` > +} > + > +type NetworkDNSHost struct { > + IP string `xml:"ip,attr"` > + Hostnames []NetworkDNSHostHostname `xml:"hostname"` > +} > + > +type NetworkDNSSRV struct { > + Service string `xml:"service,attr"` > + Protocol string `xml:"protocol,attr"` > + Target string `xml:"target,attr,omitempty"` > + Port uint `xml:"port,attr,omitempty"` > + Priority uint `xml:"priority,attr,omitempty"` > + Weight uint `xml:"weight,attr,omitempty"` > + Domain string `xml:"domain,attr,omitempty"` > +} > + > +type NetworkDNS struct { > + Enable string `xml:"enable,attr,omitempty"` > + ForwardPlainNames string `xml:"forwardPlainNames,attr,omitempty"` > + Forwarders []NetworkDNSForwarder `xml:"forwarder"` > + TXTs []NetworkDNSTXT `xml:"txt"` > + Host *NetworkDNSHost `xml:"host"` > + SRVs []NetworkDNSSRV `xml:"srv"` > +} > + > type Network struct { > XMLName xml.Name `xml:"network"` > IPv6 string `xml:"ipv6,attr,omitempty"` > @@ -96,6 +134,7 @@ type Network struct { > Domain *NetworkDomain `xml:"domain"` > IPs []NetworkIP `xml:"ip"` > Routes []NetworkRoute `xml:"route"` > + DNS *NetworkDNS `xml:"dns"` > } > > func (s *Network) Unmarshal(doc string) error { > diff --git a/network_test.go b/network_test.go > index 5269398..2eb81ab 100644 > --- a/network_test.go > +++ b/network_test.go > @@ -89,9 +89,9 @@ var networkTestData = []struct { > }, > }, > NetworkIP{ > - Family: "ipv6", > - Address:"2001:db8:ca2:2::1", > - Prefix: "64", > + Family: "ipv6", > + Address: "2001:db8:ca2:2::1", > + Prefix: "64", > DHCP: &NetworkDHCP{ > Hosts: []NetworkDHCPHost{ > NetworkDHCPHost{ > @@ -99,13 +99,57 @@ var networkTestData = []struct { > Name: "paul", > }, > NetworkDHCPHost{ > - ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66", > - IP: "2001:db8:ca2:2:3::2", > + ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66", > + IP: "2001:db8:ca2:2:3::2", > }, > }, > }, > }, > }, > + DNS: &NetworkDNS{ > + Enable: "yes", > + ForwardPlainNames: "no", > + Forwarders: []NetworkDNSForwarder{ > + NetworkDNSForwarder{ > + Addr: "8.8.8.8", > + }, > + NetworkDNSForwarder{ > + Domain: "example.com", > + Addr: "8.8.4.4", > + }, > + NetworkDNSForwarder{ > + Domain: "www.example.com", > + }, > + }, > + TXTs: []NetworkDNSTXT{ > + NetworkDNSTXT{ > + Name: "example", > + Value: "example value", > + }, > + }, > + Host: &NetworkDNSHost{ > + IP: "192.168.122.2", > + Hostnames: []NetworkDNSHostHostname{ > + NetworkDNSHostHostname{ > + Hostname: "myhost", > + }, > + NetworkDNSHostHostname{ > + Hostname: "myhostalias", > + }, > + }, > + }, > + SRVs: []NetworkDNSSRV{ > + NetworkDNSSRV{ > + Service: "name", > + Protocol: "tcp", > + Domain: "test-domain-name", > + Target: ".", > + Port: 1024, > + Priority: 10, > + Weight: 10, > + }, > + }, > + }, > }, > Expected: []string{ > `<network>`, > @@ -124,6 +168,17 @@ var networkTestData = []struct { > ` <host id="0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66" ip="2001:db8:ca2:2:3::2"></host>`, > ` </dhcp>`, > ` </ip>`, > + ` <dns enable="yes" forwardPlainNames="no">`, > + ` <forwarder addr="8.8.8.8"></forwarder>`, > + ` <forwarder domain="example.com" addr="8.8.4.4"></forwarder>`, > + ` <forwarder domain="www.example.com"></forwarder>`, > + ` <txt name="example" value="example value"></txt>`, > + ` <host ip="192.168.122.2">`, > + ` <hostname>myhost</hostname>`, > + ` <hostname>myhostalias</hostname>`, > + ` </host>`, > + ` <srv service="name" protocol="tcp" target="." port="1024" priority="10" weight="10" domain="test-domain-name"></srv>`, > + ` </dns>`, > `</network>`, > }, > }, > -- Thomas Hipp Software Developer — k8s core SUSE Linux GmbH, Maxfeldstr. 5, D-90409 Nürnberg Tel: +49 (0) 911 74053 0 — Fax: +49 (0) 911 7417755 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) PGP fingerprint: 48D6 A5F4 2D60 57BF 9A37 8004 5DE8 949A 899C 8D99
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list