From nobody Thu May 2 15:45:33 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.zohomail.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 1507690883240743.8252514667469; Tue, 10 Oct 2017 20:01:23 -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 B4BD2883A5; Wed, 11 Oct 2017 03:01:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FE19189C4; Wed, 11 Oct 2017 03:01:19 +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 CD6B018355D8; Wed, 11 Oct 2017 03:01:16 +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 v9B2WV5v028209 for ; Tue, 10 Oct 2017 22:32:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 688835E279; Wed, 11 Oct 2017 02:32:31 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A70718147; Wed, 11 Oct 2017 02:32:29 +0000 (UTC) Received: from out3140-157.mail.aliyun.com (out3140-157.mail.aliyun.com [42.120.140.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F3A78047E; Wed, 11 Oct 2017 02:32:26 +0000 (UTC) Received: from localhost.localdomain(mailfrom:zhenwei.pi@youruncloud.com ip:112.95.153.98) by smtp.aliyun-inc.com(10.147.44.118); Wed, 11 Oct 2017 10:27:06 +0800 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4BD2883A5 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=youruncloud.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B4BD2883A5 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7F3A78047E Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=youruncloud.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=zhenwei.pi@youruncloud.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7F3A78047E X-Alimail-AntiSpam: AC=CONTINUE; BC=0.05184273|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03308; MF=zhenwei.pi@youruncloud.com; NM=1; PH=DS; RN=3; RT=3; SR=0; TI=SMTPD_---.96-2mvS_1507688824; From: "zhenwei.pi" To: berrange@redhat.com, libvir-list@redhat.com Date: Wed, 11 Oct 2017 10:25:02 +0800 Message-Id: <1507688702-6848-1-git-send-email-zhenwei.pi@youruncloud.com> X-Greylist: Delayed for 00:05:06 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 11 Oct 2017 02:32:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 11 Oct 2017 02:32:28 +0000 (UTC) for IP:'42.120.140.157' DOMAIN:'out3140-157.mail.aliyun.com' HELO:'out3140-157.mail.aliyun.com' FROM:'zhenwei.pi@youruncloud.com' RCPT:'' X-RedHat-Spam-Score: -0.019 (RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, UNPARSEABLE_RELAY) 42.120.140.157 out3140-157.mail.aliyun.com 42.120.140.157 out3140-157.mail.aliyun.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: zhenwei.pi@youruncloud.com Subject: [libvirt] [PATCH go-xml] Add support for memory device element 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.26]); Wed, 11 Oct 2017 03:01:22 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Support model, access and target. Add Marshal/Unmarshal mothed for memory device. Add test code for device list in full domain. Signed-off-by: zhenwei.pi --- domain.go | 29 +++++++++++++++++++++++++++++ domain_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/domain.go b/domain.go index 8c2cc1b..bacab11 100644 --- a/domain.go +++ b/domain.go @@ -436,6 +436,22 @@ type DomainHostdev struct { Address *DomainAddress `xml:"address"` } =20 +type DomainMemorydevTargetNode struct { + Value uint `xml:",chardata"` +} + +type DomainMemorydevTarget struct { + Size *DomainMemory `xml:"size"` + Node *DomainMemorydevTargetNode `xml:"node"` +} + +type DomainMemorydev struct { + XMLName xml.Name `xml:"memory"` + Model string `xml:"model,attr"` + Access string `xml:"access,attr"` + Target *DomainMemorydevTarget `xml:"target"` +} + type DomainDeviceList struct { Emulator string `xml:"emulator,omitempty"` Controllers []DomainController `xml:"controller"` @@ -452,6 +468,7 @@ type DomainDeviceList struct { Sounds []DomainSound `xml:"sound"` RNGs []DomainRNG `xml:"rng"` Hostdevs []DomainHostdev `xml:"hostdev"` + Memorydevs []DomainMemorydev `xml:"memory"` } =20 type DomainMemory struct { @@ -915,6 +932,18 @@ func (d *DomainHostdev) Marshal() (string, error) { return string(doc), nil } =20 +func (d *DomainMemorydev) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainMemorydev) Marshal() (string, error) { + doc, err :=3D xml.MarshalIndent(d, "", " ") + if err !=3D nil { + return "", err + } + return string(doc), nil +} + type HexUint uint =20 func (h *HexUint) UnmarshalXMLAttr(attr xml.Attr) error { diff --git a/domain_test.go b/domain_test.go index 4fe6bfe..dbebe42 100644 --- a/domain_test.go +++ b/domain_test.go @@ -372,6 +372,21 @@ var domainTestData =3D []struct { }, }, }, + Memorydevs: []DomainMemorydev{ + DomainMemorydev{ + Model: "dimm", + Access: "private", + Target: &DomainMemorydevTarget{ + Size: &DomainMemory{ + Value: 1, + Unit: "GiB", + }, + Node: &DomainMemorydevTargetNode{ + Value: 0, + }, + }, + }, + }, }, }, Expected: []string{ @@ -414,6 +429,12 @@ var domainTestData =3D []struct { ` `, ` `, ` `, + ` `, + ` `, + ` 1`, + ` 0`, + ` `, + ` `, ` `, ``, }, @@ -1630,6 +1651,30 @@ var domainTestData =3D []struct { ``, }, }, + { + Object: &DomainMemorydev{ + Model: "dimm", + Access: "private", + Target: &DomainMemorydevTarget{ + Size: &DomainMemory{ + Value: 1, + Unit: "GiB", + }, + Node: &DomainMemorydevTargetNode{ + Value: 0, + }, + }, + }, + + Expected: []string{ + ``, + ` `, + ` 1`, + ` 0`, + ` `, + ``, + }, + }, } =20 func TestDomain(t *testing.T) { --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list