From nobody Fri Apr 26 03:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499156202151847.5367551708688; Tue, 4 Jul 2017 01:16:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C499080469; Tue, 4 Jul 2017 08:16:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1042963F60; Tue, 4 Jul 2017 08:16:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D554B41F50; Tue, 4 Jul 2017 08:16:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v648GVGd015499 for ; Tue, 4 Jul 2017 04:16:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id D36DD5D981; Tue, 4 Jul 2017 08:16:31 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE0C15D96A for ; Tue, 4 Jul 2017 08:16:30 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A712AC0587D4 for ; Tue, 4 Jul 2017 08:16:28 +0000 (UTC) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3472AAAF2 for ; Tue, 4 Jul 2017 08:16:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C499080469 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C499080469 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A712AC0587D4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=thipp@suse.de DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A712AC0587D4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Thomas Hipp To: libvir-list@redhat.com Date: Tue, 4 Jul 2017 10:16:07 +0200 Message-Id: <20170704081607.687-1-thipp@suse.de> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 04 Jul 2017 08:16:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 04 Jul 2017 08:16:29 +0000 (UTC) for IP:'195.135.220.15' DOMAIN:'mx2.suse.de' HELO:'mx1.suse.de' FROM:'thipp@suse.de' RCPT:'' X-RedHat-Spam-Score: -1.502 (BAYES_50, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, SPF_PASS) 195.135.220.15 mx2.suse.de 195.135.220.15 mx2.suse.de X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Thomas Hipp Subject: [libvirt] [PATCH go-xml] Add support for device RNG X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 04 Jul 2017 08:16:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add support for device RNG (random number generator), and add test code. Signed-off-by: Thomas Hipp Reviewed-by: Daniel P. Berrange --- 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"` } =20 type DomainInterfaceTarget struct { @@ -384,6 +386,25 @@ type DomainSound struct { Address *DomainAddress `xml:"address"` } =20 +type DomainRNGRate struct { + Bytes uint `xml:"bytes,attr"` + Period uint `xml:"period,attr,omitempty"` +} + +type DomainRNGBackend struct { + Backend string `xml:",chardata"` + 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"` } =20 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 :=3D xml.MarshalIndent(d, "", " ") + if err !=3D 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 =3D []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 =3D []struct { ` `, `
`, ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, ` `, ``, }, @@ -1334,6 +1365,60 @@ var domainTestData =3D []struct { ``, }, }, + { + Object: &DomainRNG{ + Model: "virtio", + Rate: &DomainRNGRate{ + Period: 2000, + Bytes: 1234, + }, + Backend: &DomainRNGBackend{ + Backend: "/dev/random", + Model: "random", + }, + }, + + Expected: []string{ + ``, + ` `, + ` /dev/random`, + ``, + }, + }, + { + 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{ + ``, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, } =20 func TestDomain(t *testing.T) { --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list