On Tue, Jul 04, 2017 at 10:16:07AM +0200, Thomas Hipp wrote: > Add support for device RNG (random number generator), and add test code. > > Signed-off-by: Thomas Hipp <thipp@xxxxxxx> > --- > domain.go | 34 +++++++++++++++++++++++ > domain_test.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 119 insertions(+) > > diff --git a/domain.go b/domain.go > index f9e3a80..b4f56bf 100644 > --- a/domain.go > +++ b/domain.go > @@ -184,6 +184,8 @@ type DomainInterfaceSource struct { > Path string `xml:"path,attr,omitempty"` > Mode string `xml:"mode,attr,omitempty"` > Port uint `xml:"port,attr,omitempty"` > + Service string `xml:"service,attr,omitempty"` > + Host string `xml:"host,attr,omitempty"` > } > > type DomainInterfaceTarget struct { > @@ -384,6 +386,25 @@ type DomainSound struct { > Address *DomainAddress `xml:"address"` > } > > +type DomainRNGRate struct { > + Bytes uint `xml:"bytes,attr"` > + Period uint `xml:"period,attr,omitempty"` > +} > + > +type DomainRNGBackend struct { > + Backend string `xml:",chardata"` Nitpick, I'll rename this to 'Device' to make it more obvious what it is. > + Model string `xml:"model,attr"` > + Type string `xml:"type,attr,omitempty"` > + Sources []DomainInterfaceSource `xml:"source"` > +} > + > +type DomainRNG struct { > + XMLName xml.Name `xml:"rng"` > + Model string `xml:"model,attr"` > + Rate *DomainRNGRate `xml:"rate"` > + Backend *DomainRNGBackend `xml:"backend"` > +} > + > type DomainDeviceList struct { > Emulator string `xml:"emulator,omitempty"` > Controllers []DomainController `xml:"controller"` > @@ -398,6 +419,7 @@ type DomainDeviceList struct { > Channels []DomainChannel `xml:"channel"` > MemBalloon *DomainMemBalloon `xml:"memballoon"` > Sounds []DomainSound `xml:"sound"` > + RNGs []DomainRNG `xml:"rng"` > } > > type DomainMemory struct { > @@ -734,3 +756,15 @@ func (d *DomainSound) Marshal() (string, error) { > } > return string(doc), nil > } > + > +func (d *DomainRNG) Unmarshal(doc string) error { > + return xml.Unmarshal([]byte(doc), d) > +} > + > +func (d *DomainRNG) Marshal() (string, error) { > + doc, err := xml.MarshalIndent(d, "", " ") > + if err != nil { > + return "", err > + } > + return string(doc), nil > +} > diff --git a/domain_test.go b/domain_test.go > index 0ce908b..aac23fe 100644 > --- a/domain_test.go > +++ b/domain_test.go > @@ -333,6 +333,30 @@ var domainTestData = []struct { > }, > }, > }, > + RNGs: []DomainRNG{ > + DomainRNG{ > + Model: "virtio", > + Rate: &DomainRNGRate{ > + Period: 2000, > + Bytes: 1234, > + }, > + Backend: &DomainRNGBackend{ > + Model: "egd", > + Type: "udp", > + Sources: []DomainInterfaceSource{ > + DomainInterfaceSource{ > + Mode: "bind", > + Service: "1234", > + }, > + DomainInterfaceSource{ > + Mode: "connect", > + Host: "1.2.3.4", > + Service: "1234", > + }, > + }, > + }, > + }, > + }, > }, > }, > Expected: []string{ > @@ -368,6 +392,13 @@ var domainTestData = []struct { > ` <codec type="duplex"></codec>`, > ` <address type="pci" domain="0" bus="0" slot="8" function="0"></address>`, > ` </sound>`, > + ` <rng model="virtio">`, > + ` <rate bytes="1234" period="2000"></rate>`, > + ` <backend model="egd" type="udp">`, > + ` <source mode="bind" service="1234"></source>`, > + ` <source mode="connect" service="1234" host="1.2.3.4"></source>`, > + ` </backend>`, > + ` </rng>`, > ` </devices>`, > `</domain>`, > }, > @@ -1334,6 +1365,60 @@ var domainTestData = []struct { > `</sound>`, > }, > }, > + { > + Object: &DomainRNG{ > + Model: "virtio", > + Rate: &DomainRNGRate{ > + Period: 2000, > + Bytes: 1234, > + }, > + Backend: &DomainRNGBackend{ > + Backend: "/dev/random", > + Model: "random", > + }, > + }, > + > + Expected: []string{ > + `<rng model="virtio">`, > + ` <rate bytes="1234" period="2000"></rate>`, > + ` <backend model="random">/dev/random</backend>`, > + `</rng>`, > + }, > + }, > + { > + Object: &DomainRNG{ > + Model: "virtio", > + Rate: &DomainRNGRate{ > + Period: 2000, > + Bytes: 1234, > + }, > + Backend: &DomainRNGBackend{ > + Model: "egd", > + Type: "udp", > + Sources: []DomainInterfaceSource{ > + DomainInterfaceSource{ > + Mode: "bind", > + Service: "1234", > + }, > + DomainInterfaceSource{ > + Mode: "connect", > + Host: "1.2.3.4", > + Service: "1234", > + }, > + }, > + }, > + }, > + > + Expected: []string{ > + `<rng model="virtio">`, > + ` <rate bytes="1234" period="2000"></rate>`, > + ` <backend model="egd" type="udp">`, > + ` <source mode="bind" service="1234"></source>`, > + ` <source mode="connect" service="1234" host="1.2.3.4"></source>`, > + ` </backend>`, > + `</rng>`, > + }, > + }, > } Reviewed-by: Daniel P. Berrange <berrange@xxxxxxxxxx> THanks, I'll merge this Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list