From nobody Sun May 5 10:35:09 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560881932; cv=none; d=zoho.com; s=zohoarc; b=NmX+Nf3E/Gbun9i5pJRK9T8iz+qVWvyMoFHish24dsw6ngBpDIQbiabEpmUAw5jjho8GdETFH/F84Rybe3rjkpUNrtyb4empAnAWu02g7oswWgl9Fv+1mxK9MQVGtPesZbzpS3SlWkFSKTR8f1sbnuaUzBa3XMMqdstto29RBFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560881932; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=+WvADYGL5viCqz+d574qveFV0EfSgfb9MglSnM+slDI=; b=Q4RxEminpLn+QKJEvcOn48wtjVIL8nHQLMXMFFhtcT5Qn8Ey4Akd6zUBm9/Xcj551ITlpFf/m9nsceKB3QBaf7VucR5cKNszHqgESI8GqXSftSKg4hxzzIa25n0S9Vdj6byedhRNtFvdREEeK3lwb1227f3cMydKy3RbP/B0b2A= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560881932553591.3198082917851; Tue, 18 Jun 2019 11:18:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF5B5285B4; Tue, 18 Jun 2019 18:17:56 +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 1AB4A19492; Tue, 18 Jun 2019 18:17:52 +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 8B1E3C596; Tue, 18 Jun 2019 18:17:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5IHO428006884 for ; Tue, 18 Jun 2019 13:24:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id A0D00851A; Tue, 18 Jun 2019 17:24:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFB6C60FDE; Tue, 18 Jun 2019 17:24:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 18 Jun 2019 18:23:59 +0100 Message-Id: <20190618172359.8090-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [go-xml PATCH] Add support for network filter binding XML schema 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Jun 2019 18:18:42 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 --- nwfilter_binding.go | 73 +++++++++++++++++++++++++++++++++++++++++++++ xml_test.go | 3 ++ 2 files changed, 76 insertions(+) create mode 100644 nwfilter_binding.go diff --git a/nwfilter_binding.go b/nwfilter_binding.go new file mode 100644 index 0000000..918ab71 --- /dev/null +++ b/nwfilter_binding.go @@ -0,0 +1,73 @@ +/* + * This file is part of the libvirt-go-xml project + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL= THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + * + * Copyright (C) 2017 Lian Duan + * + */ + +package libvirtxml + +import ( + "encoding/xml" +) + +type NWFilterBinding struct { + XMLName xml.Name `xml:"filterbinding"` + Owner *NWFilterBindingOwner `xml:"owner"` + PortDev *NWFilterBindingPortDev `xml:"portdev"` + MAC *NWFilterBindingMAC `xml:"mac"` + FilterRef *NWFilterBindingFilterRef `xml:"filterref"` +} + +type NWFilterBindingOwner struct { + UUID string `xml:"uuid,omitempty"` + Name string `xml:"name,omitempty"` +} + +type NWFilterBindingPortDev struct { + Name string `xml:"name,attr"` +} + +type NWFilterBindingMAC struct { + Address string `xml:"address,attr"` +} + +type NWFilterBindingFilterRef struct { + Filter string `xml:"filter,attr"` + Parameters []NWFilterBindingFilterParam `xml:"parameter"` +} + +type NWFilterBindingFilterParam struct { + Name string `xml:"name,attr"` + Value string `xml:"value,attr"` +} + +func (s *NWFilterBinding) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), s) +} + +func (s *NWFilterBinding) Marshal() (string, error) { + doc, err :=3D xml.MarshalIndent(s, "", " ") + if err !=3D nil { + return "", err + } + return string(doc), nil +} diff --git a/xml_test.go b/xml_test.go index 320c248..d1da879 100644 --- a/xml_test.go +++ b/xml_test.go @@ -83,6 +83,7 @@ var xmldirs =3D []string{ "testdata/libvirt/tests/storagevolxml2xmlin", "testdata/libvirt/tests/storagevolxml2xmlout", "testdata/libvirt/tests/vircaps2xmldata", + "testdata/libvirt/tests/virnwfilterbindingxml2xmldata", "testdata/libvirt/tests/virstorageutildata", "testdata/libvirt/tests/vmx2xmldata", "testdata/libvirt/tests/xlconfigdata", @@ -325,6 +326,8 @@ func testRoundTrip(t *testing.T, xml string, filename s= tring) { } else { doc =3D &CapsHostCPU{} } + } else if strings.HasPrefix(xml, "