diff options
author | Thomas Hipp <thipp@suse.de> | 2017-07-20 12:17:18 +0200 |
---|---|---|
committer | Flavio Castelli <flavio@castelli.me> | 2017-07-27 14:59:30 +0200 |
commit | ed3000f4d3b2ee5eeab855f32e9fde80193944df (patch) | |
tree | 506a894bf1ceb7b12a6c0239c19b262d8fdd58bd | |
parent | 9754465f2e30381186621695e499b55c151f75f9 (diff) | |
download | terraform-provider-libvirt-ed3000f4d3b2ee5eeab855f32e9fde80193944df.tar terraform-provider-libvirt-ed3000f4d3b2ee5eeab855f32e9fde80193944df.tar.gz |
vendor: add libvirt-go-xml
Signed-off-by: Thomas Hipp <thipp@suse.de>
24 files changed, 4247 insertions, 5 deletions
@@ -1,5 +1,5 @@ -hash: 68e2acca116bc7eb7f8cd0958665c47cbddeda84005fafb9d90bf781563c0ca9 -updated: 2017-06-07T10:38:02.706155214+02:00 +hash: 2ab777ab6ba80c757dcf4940680b896243b0842787d991bfca6c18efd3f496dd +updated: 2017-07-20T12:15:39.378349689+02:00 imports: - name: github.com/apparentlymart/go-cidr version: f74186abdf0be1c9f8bfa7a5f97afcd3e598ff5e @@ -115,7 +115,9 @@ imports: - name: github.com/jmespath/go-jmespath version: 0b12d6b521d83fc7f755e7cfc1b1fbdd35a01a74 - name: github.com/libvirt/libvirt-go - version: 5ba8227244c30438609adcec6ea84dc1e688dfbd + version: 664b6d217e029ce5ad3094a8c2202c202b213d06 +- name: github.com/libvirt/libvirt-go-xml + version: 83a754119fc7239caffd1f50e08cb13b1b3825ef - name: github.com/mitchellh/copystructure version: d23ffcb85de31694d6ccaa23ccb4a03e55c1303f - name: github.com/mitchellh/go-homedir @@ -18,3 +18,4 @@ import: - package: gopkg.in/yaml.v2 - package: github.com/libvirt/libvirt-go version: ^3.4.0 +- package: github.com/libvirt/libvirt-go-xml diff --git a/vendor/github.com/libvirt/libvirt-go-xml/.gitignore b/vendor/github.com/libvirt/libvirt-go-xml/.gitignore new file mode 100644 index 00000000..00862030 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/.gitignore @@ -0,0 +1,3 @@ +*~ +*.bak +.\#* diff --git a/vendor/github.com/libvirt/libvirt-go-xml/.travis.yml b/vendor/github.com/libvirt/libvirt-go-xml/.travis.yml new file mode 100644 index 00000000..5e6be774 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/.travis.yml @@ -0,0 +1,11 @@ +language: go +os: linux +dist: trusty + +go: + - 1.5 + - 1.6 + - 1.7 + +script: + go test -timeout 1m -v diff --git a/vendor/github.com/libvirt/libvirt-go-xml/LICENSE b/vendor/github.com/libvirt/libvirt-go-xml/LICENSE new file mode 100644 index 00000000..8e49eed0 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/LICENSE @@ -0,0 +1,19 @@ +The MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +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.
\ No newline at end of file diff --git a/vendor/github.com/libvirt/libvirt-go-xml/README.md b/vendor/github.com/libvirt/libvirt-go-xml/README.md new file mode 100644 index 00000000..79f42f42 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/README.md @@ -0,0 +1,67 @@ +# libvirt-go-xml [![Build Status](https://travis-ci.org/libvirt/libvirt-go-xml.svg?branch=master)](https://travis-ci.org/libvirt/libvirt-go-xml) [![GoDoc](https://godoc.org/github.com/libvirt/libvirt-go-xml?status.svg)](https://godoc.org/github.com/libvirt/libvirt-go-xml) + +Go API for manipulating libvirt XML documents + +This package provides a Go API that defines a set of structs, annotated for use +with "encoding/xml", that can represent libvirt XML documents. There is no +dependancy on the libvirt library itself, so this can be used regardless of +the way in which the application talks to libvirt. + +## Documentation + +* [API documentation for the bindings](https://godoc.org/github.com/libvirt/libvirt-go-xml) +* [Libvirt XML schema documentation](https://libvirt.org/format.html): + * [capabilities](https://libvirt.org/formatcaps.html) + * [domain](https://libvirt.org/formatdomain.html) + * [domain capabilities](https://libvirt.org/formatdomaincaps.html) + * [domain snapshot](https://libvirt.org/formatsnapshot.html) + * [network](https://libvirt.org/formatnetwork.html) + * [node device](https://libvirt.org/formatnode.html) + * [nwfilter](https://libvirt.org/formatnwfilter.html) + * [secret](https://libvirt.org/formatsecret.html) + * [storage](https://libvirt.org/formatstorage.html) + * [storage encryption](https://libvirt.org/formatstorageencryption.html) + +## Contributing + +The libvirt project aims to add support for new APIs to libvirt-go +as soon as they are added to the main libvirt C library. If you +are submitting changes to the libvirt C library API, please submit +a libvirt-go change at the same time. + +Bug fixes and other improvements to the libvirt-go library are +welcome at any time. The preferred submission method is to use +git send-email to submit patches to the libvir-list@redhat.com +mailing list. eg. to send a single patch + +``` + # git send-email --to libvir-list@redhat.com --subject-prefix "PATCH go-xml" \ + --smtp-server=$HOSTNAME -1 +``` + +Or to send all patches on the current branch, against master + +``` + $ git send-email --to libvir-list@redhat.com --subject-prefix "PATCH go-xml" \ + --smtp-server=$HOSTNAME --no-chain-reply-to --cover-letter --annotate \ + master.. +``` + +Note the master GIT repository is at + +``` + http://libvirt.org/git/?p=libvirt-go.git;a=summary +``` + +The following automatic read-only mirrors are available as a +convenience to allow contributors to "fork" the repository: + +``` + https://gitlab.com/libvirt/libvirt-go + https://github.com/libvirt/libvirt-go +``` + +While you can send pull-requests to these mirrors, they will be +re-submitted via emai to the mailing list for review before +being merged, unless they are trivial/obvious bug fixes. + diff --git a/vendor/github.com/libvirt/libvirt-go-xml/capabilities.go b/vendor/github.com/libvirt/libvirt-go-xml/capabilities.go new file mode 100644 index 00000000..d27e1f70 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/capabilities.go @@ -0,0 +1,156 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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) 2016 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "encoding/xml" +) + +type CapsHostCPUTopology struct { + Sockets int `xml:"sockets,attr"` + Cores int `xml:"cores,attr"` + Threads int `xml:"threads,attr"` +} + +type CapsHostCPUFeature struct { + Name string `xml:"name,attr"` +} + +type CapsHostCPUPageSize struct { + Size int `xml:"size,attr"` + Unit string `xml:"unit,attr"` +} + +type CapsHostCPU struct { + Arch string `xml:"arch"` + Model string `xml:"model"` + Vendor string `xml:"vendor"` + Topology CapsHostCPUTopology `xml:"topology"` + Features []CapsHostCPUFeature `xml:"feature"` + PageSizes []CapsHostCPUPageSize `xml:"pages"` +} + +type CapsHostNUMAMemory struct { + Size uint64 `xml:"size,attr"` + Unit string `xml:"unit,attr"` +} + +type CapsHostNUMAPageInfo struct { + Size int `xml:"size,attr"` + Unit string `xml:"unit,attr"` + Count uint64 `xml:",chardata"` +} + +type CapsHostNUMACPU struct { + ID int `xml:"id,attr"` + SocketID int `xml:"socket_id,attr"` + CoreID int `xml:"core_id,attr"` + Siblings string `xml:"siblings,attr"` +} + +type CapsHostNUMADistance struct { + ID int `xml:"id,attr"` + Value int `xml:"value,attr"` +} + +type CapsHostNUMACell struct { + ID int `xml:"id,attr"` + Memory CapsHostNUMAMemory `xml:"memory"` + PageInfo []CapsHostNUMAPageInfo `xml:"pages"` + Distances []CapsHostNUMADistance `xml:"distances>sibling"` + CPUS []CapsHostNUMACPU `xml:"cpus>cpu"` +} + +type CapsHostNUMATopology struct { + Cells []CapsHostNUMACell `xml:"cells>cell"` +} + +type CapsHostSecModelLabel struct { + Type string `xml:"type,attr"` + Value string `xml:",chardata"` +} + +type CapsHostSecModel struct { + Name string `xml:"model"` + DOI string `xml:"doi"` + Labels []CapsHostSecModelLabel `xml:"baselabel"` +} + +type CapsHost struct { + UUID string `xml:"uuid"` + CPU *CapsHostCPU `xml:"cpu"` + NUMA *CapsHostNUMATopology `xml:"topology"` + SecModel []CapsHostSecModel `xml:"secmodel"` +} + +type CapsGuestMachine struct { + Name string `xml:",chardata"` + MaxCPUs int `xml:"maxCpus,attr"` + Canonical *string `xml:"canonical,attr"` +} + +type CapsGuestDomain struct { + Type string `xml:"type,attr"` + Emulator string `xml:"emulator"` + Machines []CapsGuestMachine `xml:"machine"` +} + +type CapsGuestArch struct { + Name string `xml:"name,attr"` + WordSize string `xml:"wordsize"` + Emulator string `xml:"emulator"` + Machines []CapsGuestMachine `xml:"machine"` + Domains []CapsGuestDomain `xml:"domain"` +} + +type CapsGuestFeatures struct { + CPUSelection *struct{} `xml:"cpuselection"` + DeviceBoot *struct{} `xml:"deviceboot"` +} + +type CapsGuest struct { + OSType string `xml:"os_type"` + Arch CapsGuestArch `xml:"arch"` + Features *CapsGuestFeatures `xml:"features"` +} + +type Caps struct { + XMLName xml.Name `xml:"capabilities"` + Host CapsHost `xml:"host"` + Guests []CapsGuest `xml:"guest"` +} + +func (c *Caps) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), c) +} + +func (c *Caps) Marshal() (string, error) { + doc, err := xml.MarshalIndent(c, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/doc.go b/vendor/github.com/libvirt/libvirt-go-xml/doc.go new file mode 100644 index 00000000..2886c792 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/doc.go @@ -0,0 +1,62 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +// Package libvirt-go-xml defines structs for parsing libvirt XML schemas +// +// The libvirt API uses XML schemas/documents to describe the configuration +// of many of its managed objects. Thus when using the libvirt-go package, +// it is often neccessary to either parse or format XML documents. This +// package defines a set of Go structs which have been annotated for use +// with the encoding/xml API to manage libvirt XML documents. +// +// Example creating a domain XML document from configuration: +// +// import ( +// "github.com/libvirt/libvirt-go-xml" +// ) +// +// domcfg := &libvirtxml.Domain{Type: "kvm", Name: "demo", +// UUID: "8f99e332-06c4-463a-9099-330fb244e1b3", +// ....} +// xmldoc, err := domcfg.Marshal() +// +// Example parsing a domainXML document, in combination with libvirt-go +// +// import ( +// "github.com/libvirt/libvirt-go" +// "github.com/libvirt/libvirt-go-xml" +// "fmt" +// ) +// +// conn, err := libvirt.NewConnect("qemu:///system") +// dom := conn.LookupDomainByName("demo") +// xmldoc, err := dom.GetXMLDesc(0) +// +// domcfg := &libvirtxml.Domain{} +// err := domcfg.Unmarshal(xmldoc) +// +// fmt.Printf("Virt type %s", domcfg.Type) +// +package libvirtxml diff --git a/vendor/github.com/libvirt/libvirt-go-xml/document.go b/vendor/github.com/libvirt/libvirt-go-xml/document.go new file mode 100644 index 00000000..9b4cf36d --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/document.go @@ -0,0 +1,6 @@ +package libvirtxml + +type Document interface { + Unmarshal(doc string) error + Marshal() (string, error) +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/domain.go b/vendor/github.com/libvirt/libvirt-go-xml/domain.go new file mode 100644 index 00000000..a5d32037 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/domain.go @@ -0,0 +1,794 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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) 2016 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "encoding/xml" +) + +type DomainController struct { + XMLName xml.Name `xml:"controller"` + Type string `xml:"type,attr"` + Index *uint `xml:"index,attr"` + Model string `xml:"model,attr,omitempty"` + Address *DomainAddress `xml:"address"` +} + +type DomainDiskSecret struct { + Type string `xml:"type,attr,omitempty"` + Usage string `xml:"usage,attr,omitempty"` + UUID string `xml:"uuid,attr,omitempty"` +} + +type DomainDiskAuth struct { + Username string `xml:"username,attr,omitempty"` + Secret *DomainDiskSecret `xml:"secret"` +} + +type DomainDiskSourceHost struct { + Transport string `xml:"transport,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` + Port string `xml:"port,attr,omitempty"` + Socket string `xml:"socket,attr,omitempty"` +} + +type DomainDiskSource struct { + File string `xml:"file,attr,omitempty"` + Device string `xml:"dev,attr,omitempty"` + Protocol string `xml:"protocol,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` + Pool string `xml:"pool,attr,omitempty"` + Volume string `xml:"volume,attr,omitempty"` + Hosts []DomainDiskSourceHost `xml:"host"` + StartupPolicy string `xml:"startupPolicy,attr,omitempty"` +} + +type DomainDiskDriver struct { + Name string `xml:"name,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + Cache string `xml:"cache,attr,omitempty"` + IO string `xml:"io,attr,omitempty"` + ErrorPolicy string `xml:"error_policy,attr,omitempty"` + Discard string `xml:"discard,attr,omitempty"` +} + +type DomainDiskTarget struct { + Dev string `xml:"dev,attr,omitempty"` + Bus string `xml:"bus,attr,omitempty"` +} + +type DomainDiskReadOnly struct { +} + +type DomainDiskShareable struct { +} + +type DomainDiskIOTune struct { + TotalBytesSec uint64 `xml:"total_bytes_sec"` + ReadBytesSec uint64 `xml:"read_bytes_sec"` + WriteBytesSec uint64 `xml:"write_bytes_sec"` + TotalIopsSec uint64 `xml:"total_iops_sec"` + ReadIopsSec uint64 `xml:"read_iops_sec"` + WriteIopsSec uint64 `xml:"write_iops_sec"` + TotalBytesSecMax uint64 `xml:"total_bytes_sec_max"` + ReadBytesSecMax uint64 `xml:"read_bytes_sec_max"` + WriteBytesSecMax uint64 `xml:"write_bytes_sec_max"` + TotalIopsSecMax uint64 `xml:"total_iops_sec_max"` + ReadIopsSecMax uint64 `xml:"read_iops_sec_max"` + WriteIopsSecMax uint64 `xml:"write_iops_sec_max"` + TotalBytesSecMaxLength uint64 `xml:"total_bytes_sec_max_length"` + ReadBytesSecMaxLength uint64 `xml:"read_bytes_sec_max_length"` + WriteBytesSecMaxLength uint64 `xml:"write_bytes_sec_max_length"` + TotalIopsSecMaxLength uint64 `xml:"total_iops_sec_max_length"` + ReadIopsSecMaxLength uint64 `xml:"read_iops_sec_max_length"` + WriteIopsSecMaxLength uint64 `xml:"write_iops_sec_max_length"` + SizeIopsSec uint64 `xml:"size_iops_sec"` + GroupName string `xml:"group_name"` +} + +type DomainDisk struct { + XMLName xml.Name `xml:"disk"` + Type string `xml:"type,attr"` + Device string `xml:"device,attr"` + Snapshot string `xml:"snapshot,attr,omitempty"` + Driver *DomainDiskDriver `xml:"driver"` + Auth *DomainDiskAuth `xml:"auth"` + Source *DomainDiskSource `xml:"source"` + Target *DomainDiskTarget `xml:"target"` + IOTune *DomainDiskIOTune `xml:"iotune"` + Serial string `xml:"serial,omitempty"` + ReadOnly *DomainDiskReadOnly `xml:"readonly"` + Shareable *DomainDiskShareable `xml:"shareable"` + Address *DomainAddress `xml:"address"` + Boot *DomainDeviceBoot `xml:"boot"` + WWN string `xml:"wwn,omitempty"` +} + +type DomainFilesystemDriver struct { + Type string `xml:"type,attr"` + Name string `xml:"name,attr,omitempty"` + WRPolicy string `xml:"wrpolicy,attr,omitempty"` +} + +type DomainFilesystemSource struct { + Dir string `xml:"dir,attr,omitempty"` + File string `xml:"file,attr,omitempty"` +} + +type DomainFilesystemTarget struct { + Dir string `xml:"dir,attr"` +} + +type DomainFilesystemReadOnly struct { +} + +type DomainFilesystemSpaceHardLimit struct { + Value uint `xml:",chardata"` + Unit string `xml:"unit,attr,omitempty"` +} + +type DomainFilesystemSpaceSoftLimit struct { + Value uint `xml:",chardata"` + Unit string `xml:"unit,attr,omitempty"` +} + +type DomainFilesystem struct { + XMLName xml.Name `xml:"filesystem"` + Type string `xml:"type,attr"` + AccessMode string `xml:"accessmode,attr"` + Driver *DomainFilesystemDriver `xml:"driver"` + Source *DomainFilesystemSource `xml:"source"` + Target *DomainFilesystemTarget `xml:"target"` + ReadOnly *DomainFilesystemReadOnly `xml:"readonly"` + SpaceHardLimit *DomainFilesystemSpaceHardLimit `xml:"space_hard_limit"` + SpaceSoftLimit *DomainFilesystemSpaceSoftLimit `xml:"space_soft_limit"` + Address *DomainAddress `xml:"address"` +} + +type DomainInterfaceMAC struct { + Address string `xml:"address,attr"` +} + +type DomainInterfaceModel struct { + Type string `xml:"type,attr"` +} + +type DomainInterfaceSource struct { + Bridge string `xml:"bridge,attr,omitempty"` + Dev string `xml:"dev,attr,omitempty"` + Network string `xml:"network,attr,omitempty"` + Address string `xml:"address,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` + 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 { + Dev string `xml:"dev,attr"` +} + +type DomainInterfaceAlias struct { + Name string `xml:"name,attr"` +} + +type DomainInterfaceLink struct { + State string `xml:"state,attr"` +} + +type DomainDeviceBoot struct { + Order uint `xml:"order,attr"` +} + +type DomainInterfaceScript struct { + Path string `xml:"path,attr"` +} + +type DomainInterfaceDriver struct { + Name string `xml:"name,attr"` + Queues uint `xml:"queues,attr,omitempty"` +} + +type DomainInterfaceVirtualport struct { + Type string `xml:"type,attr"` +} + +type DomainInterfaceBandwidthParams struct { + Average *int `xml:"average,attr,omitempty"` + Peak *int `xml:"peak,attr,omitempty"` + Burst *int `xml:"burst,attr,omitempty"` + Floor *int `xml:"floor,attr,omitempty"` +} + +type DomainInterfaceBandwidth struct { + Inbound *DomainInterfaceBandwidthParams `xml:"inbound"` + Outbound *DomainInterfaceBandwidthParams `xml:"outbound"` +} + +type DomainInterface struct { + XMLName xml.Name `xml:"interface"` + Type string `xml:"type,attr"` + MAC *DomainInterfaceMAC `xml:"mac"` + Model *DomainInterfaceModel `xml:"model"` + Source *DomainInterfaceSource `xml:"source"` + Target *DomainInterfaceTarget `xml:"target"` + Alias *DomainInterfaceAlias `xml:"alias"` + Link *DomainInterfaceLink `xml:"link"` + Boot *DomainDeviceBoot `xml:"boot"` + Script *DomainInterfaceScript `xml:"script"` + Driver *DomainInterfaceDriver `xml:"driver"` + Virtualport *DomainInterfaceVirtualport `xml:"virtualport"` + Bandwidth *DomainInterfaceBandwidth `xml:"bandwidth"` + Address *DomainAddress `xml:"address"` +} + +type DomainChardevSource struct { + Mode string `xml:"mode,attr,omitempty"` + Path string `xml:"path,attr"` + Append string `xml:"append,attr,omitempty"` +} + +type DomainChardevTarget struct { + Type string `xml:"type,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` + State string `xml:"state,attr,omitempty"` // is guest agent connected? + Port *uint `xml:"port,attr"` +} + +type DomainConsoleTarget struct { + Type string `xml:"type,attr,omitempty"` + Port *uint `xml:"port,attr"` +} + +type DomainSerialTarget struct { + Type string `xml:"type,attr,omitempty"` + Port *uint `xml:"port,attr"` +} + +type DomainChannelTarget struct { + Type string `xml:"type,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` + State string `xml:"state,attr,omitempty"` // is guest agent connected? +} + +type DomainAlias struct { + Name string `xml:"name,attr"` +} + +type DomainAddress struct { + Type string `xml:"type,attr"` + Controller *uint `xml:"controller,attr"` + Domain *uint `xml:"domain,attr"` + Bus *uint `xml:"bus,attr"` + Port *uint `xml:"port,attr"` + Slot *uint `xml:"slot,attr"` + Function *uint `xml:"function,attr"` + Target *uint `xml:"target,attr"` + Unit *uint `xml:"unit,attr"` +} + +type DomainConsole struct { + XMLName xml.Name `xml:"console"` + Type string `xml:"type,attr"` + Source *DomainChardevSource `xml:"source"` + Target *DomainConsoleTarget `xml:"target"` + Alias *DomainAlias `xml:"alias"` + Address *DomainAddress `xml:"address"` +} + +type DomainSerial struct { + XMLName xml.Name `xml:"serial"` + Type string `xml:"type,attr"` + Source *DomainChardevSource `xml:"source"` + Target *DomainSerialTarget `xml:"target"` + Alias *DomainAlias `xml:"alias"` + Address *DomainAddress `xml:"address"` +} + +type DomainChannel struct { + XMLName xml.Name `xml:"channel"` + Type string `xml:"type,attr"` + Source *DomainChardevSource `xml:"source"` + Target *DomainChannelTarget `xml:"target"` + Alias *DomainAlias `xml:"alias"` + Address *DomainAddress `xml:"address"` +} + +type DomainInput struct { + XMLName xml.Name `xml:"input"` + Type string `xml:"type,attr"` + Bus string `xml:"bus,attr"` + Address *DomainAddress `xml:"address"` +} + +type DomainGraphicListener struct { + Type string `xml:"type,attr"` + Address string `xml:"address,attr,omitempty"` + Network string `xml:"network,attr,omitempty"` + Socket string `xml:"socket,attr,omitempty"` +} + +type DomainGraphic struct { + XMLName xml.Name `xml:"graphics"` + Type string `xml:"type,attr"` + AutoPort string `xml:"autoport,attr,omitempty"` + Port int `xml:"port,attr,omitempty"` + TLSPort int `xml:"tlsPort,attr,omitempty"` + WebSocket int `xml:"websocket,attr,omitempty"` + Listen string `xml:"listen,attr,omitempty"` + Socket string `xml:"socket,attr,omitempty"` + Keymap string `xml:"keymap,attr,omitempty"` + Passwd string `xml:"passwd,attr,omitempty"` + PasswdValidTo string `xml:"passwdValidTo,attr,omitempty"` + Connected string `xml:"connected,attr,omitempty"` + SharePolicy string `xml:"sharePolicy,attr,omitempty"` + DefaultMode string `xml:"defaultMode,attr,omitempty"` + Display string `xml:"display,attr,omitempty"` + XAuth string `xml:"xauth,attr,omitempty"` + FullScreen string `xml:"fullscreen,attr,omitempty"` + ReplaceUser string `xml:"replaceUser,attr,omitempty"` + MultiUser string `xml:"multiUser,attr,omitempty"` + Listeners []DomainGraphicListener `xml:"listen"` +} + +type DomainVideoModel struct { + Type string `xml:"type,attr"` + Heads uint `xml:"heads,attr,omitempty"` + Ram uint `xml:"ram,attr,omitempty"` + VRam uint `xml:"vram,attr,omitempty"` + VGAMem uint `xml:"vgamem,attr,omitempty"` +} + +type DomainVideo struct { + XMLName xml.Name `xml:"video"` + Model DomainVideoModel `xml:"model"` + Address *DomainAddress `xml:"address"` +} + +type DomainMemBalloon struct { + XMLName xml.Name `xml:"memballoon"` + Model string `xml:"model,attr"` + Address *DomainAddress `xml:"address"` +} + +type DomainSoundCodec struct { + Type string `xml:"type,attr"` +} + +type DomainSound struct { + XMLName xml.Name `xml:"sound"` + Model string `xml:"model,attr"` + Codec *DomainSoundCodec `xml:"codec"` + Address *DomainAddress `xml:"address"` +} + +type DomainRNGRate struct { + Bytes uint `xml:"bytes,attr"` + Period uint `xml:"period,attr,omitempty"` +} + +type DomainRNGBackend struct { + Device 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"` + Disks []DomainDisk `xml:"disk"` + Filesystems []DomainFilesystem `xml:"filesystem"` + Interfaces []DomainInterface `xml:"interface"` + Serials []DomainSerial `xml:"serial"` + Consoles []DomainConsole `xml:"console"` + Inputs []DomainInput `xml:"input"` + Graphics []DomainGraphic `xml:"graphics"` + Videos []DomainVideo `xml:"video"` + Channels []DomainChannel `xml:"channel"` + MemBalloon *DomainMemBalloon `xml:"memballoon"` + Sounds []DomainSound `xml:"sound"` + RNGs []DomainRNG `xml:"rng"` +} + +type DomainMemory struct { + Value uint `xml:",chardata"` + Unit string `xml:"unit,attr,omitempty"` +} + +type DomainMaxMemory struct { + Value uint `xml:",chardata"` + Unit string `xml:"unit,attr,omitempty"` + Slots uint `xml:"slots,attr,omitempty"` +} + +type DomainOSType struct { + Arch string `xml:"arch,attr,omitempty"` + Machine string `xml:"machine,attr,omitempty"` + Type string `xml:",chardata"` +} + +type DomainSMBios struct { + Mode string `xml:"mode,attr"` +} + +type DomainNVRam struct { + NVRam string `xml:",chardata"` + Template string `xml:"template,attr"` +} + +type DomainBootDevice struct { + Dev string `xml:"dev,attr"` +} + +type DomainBootMenu struct { + Enabled string `xml:"enabled,attr"` + Timeout string `xml:"timeout,attr"` +} + +type DomainSysInfo struct { + Type string `xml:"type,attr"` + System []DomainSysInfoEntry `xml:"system>entry"` + BIOS []DomainSysInfoEntry `xml:"bios>entry"` + BaseBoard []DomainSysInfoEntry `xml:"baseBoard>entry"` +} + +type DomainSysInfoEntry struct { + Name string `xml:"name,attr"` + Value string `xml:",chardata"` +} + +type DomainBIOS struct { + UseSerial string `xml:"useserial,attr"` + RebootTimeout string `xml:"rebootTimeout,attr"` +} + +type DomainLoader struct { + Path string `xml:",chardata"` + Readonly string `xml:"readonly,attr"` + Secure string `xml:"secure,attr"` + Type string `xml:"type,attr"` +} + +type DomainOS struct { + Type *DomainOSType `xml:"type"` + Loader *DomainLoader `xml:"loader"` + NVRam *DomainNVRam `xml:"nvram"` + Kernel string `xml:"kernel,omitempty"` + Initrd string `xml:"initrd,omitempty"` + KernelArgs string `xml:"cmdline,omitempty"` + BootDevices []DomainBootDevice `xml:"boot"` + BootMenu *DomainBootMenu `xml:"bootmenu"` + SMBios *DomainSMBios `xml:"smbios"` + BIOS *DomainBIOS `xml:"bios"` + Init string `xml:"init,omitempty"` + InitArgs []string `xml:"initarg"` +} + +type DomainResource struct { + Partition string `xml:"partition,omitempty"` +} + +type DomainVCPU struct { + Placement string `xml:"placement,attr,omitempty"` + CPUSet string `xml:"cpuset,attr,omitempty"` + Current string `xml:"current,attr,omitempty"` + Value int `xml:",chardata"` +} + +type DomainCPUModel struct { + Fallback string `xml:"fallback,attr,omitempty"` + Value string `xml:",chardata"` +} + +type DomainCPUTopology struct { + Sockets int `xml:"sockets,attr,omitempty"` + Cores int `xml:"cores,attr,omitempty"` + Threads int `xml:"threads,attr,omitempty"` +} + +type DomainCPUFeature struct { + Policy string `xml:"policy,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` +} + +type DomainCPU struct { + Match string `xml:"match,attr,omitempty"` + Mode string `xml:"mode,attr,omitempty"` + Model *DomainCPUModel `xml:"model"` + Vendor string `xml:"vendor,omitempty"` + Topology *DomainCPUTopology `xml:"topology"` + Features []DomainCPUFeature `xml:"feature"` +} + +type DomainClock struct { + Offset string `xml:"offset,attr,omitempty"` + Basis string `xml:"basis,attr,omitempty"` + Adjustment int `xml:"adjustment,attr,omitempty"` +} + +type DomainFeature struct { +} + +type DomainFeatureState struct { + State string `xml:"state,attr,omitempty"` +} + +type DomainFeatureAPIC struct { + EOI string `xml:"eio,attr,omitempty"` +} + +type DomainFeatureHyperVVendorId struct { + DomainFeatureState + Value string `xml:"value,attr,omitempty"` +} + +type DomainFeatureHyperVSpinlocks struct { + DomainFeatureState + Retries uint `xml:"retries,attr,omitempty"` +} + +type DomainFeatureHyperV struct { + DomainFeature + Relaxed *DomainFeatureState `xml:"relaxed"` + VAPIC *DomainFeatureState `xml:"vapic"` + Spinlocks *DomainFeatureHyperVSpinlocks `xml:"spinlocks"` + VPIndex *DomainFeatureState `xml:"vpindex"` + Runtime *DomainFeatureState `xml:"runtime"` + Synic *DomainFeatureState `xml:"synic"` + STimer *DomainFeatureState `xml:"stimer"` + Reset *DomainFeatureState `xml:"reset"` + VendorId *DomainFeatureHyperVVendorId `xml:"vendor_id"` +} + +type DomainFeatureKVM struct { + Hidden *DomainFeatureState `xml:"hidden"` +} + +type DomainFeatureGIC struct { + Version string `xml:"version,attr,omitempty"` +} + +type DomainFeatureList struct { + PAE *DomainFeature `xml:"pae"` + ACPI *DomainFeature `xml:"acpi"` + APIC *DomainFeatureAPIC `xml:"apic"` + HAP *DomainFeatureState `xml:"hap"` + Viridian *DomainFeature `xml:"viridian"` + PrivNet *DomainFeature `xml:"privnet"` + HyperV *DomainFeatureHyperV `xml:"hyperv"` + KVM *DomainFeatureKVM `xml:"kvm"` + PVSpinlock *DomainFeatureState `xml:"pvspinlock"` + PMU *DomainFeatureState `xml:"pmu"` + VMPort *DomainFeatureState `xml:"vmport"` + GIC *DomainFeatureGIC `xml:"gic"` + SMM *DomainFeatureState `xml:"smm"` +} + +type DomainQEMUCommandlineArg struct { + Value string `xml:"value,attr"` +} + +type DomainQEMUCommandlineEnv struct { + Name string `xml:"name,attr"` + Value string `xml:"value,attr,omitempty"` +} + +type DomainQEMUCommandline struct { + XMLName xml.Name `xml:"http://libvirt.org/schemas/domain/qemu/1.0 commandline"` + Args []DomainQEMUCommandlineArg `xml:"arg"` + Envs []DomainQEMUCommandlineEnv `xml:"env"` +} + +// NB, try to keep the order of fields in this struct +// matching the order of XML elements that libvirt +// will generate when dumping XML. +type Domain struct { + XMLName xml.Name `xml:"domain"` + Type string `xml:"type,attr,omitempty"` + Name string `xml:"name"` + UUID string `xml:"uuid,omitempty"` + Memory *DomainMemory `xml:"memory"` + CurrentMemory *DomainMemory `xml:"currentMemory"` + MaximumMemory *DomainMaxMemory `xml:"maxMemory"` + VCPU *DomainVCPU `xml:"vcpu"` + Resource *DomainResource `xml:"resource"` + SysInfo *DomainSysInfo `xml:"sysinfo"` + OS *DomainOS `xml:"os"` + Features *DomainFeatureList `xml:"features"` + CPU *DomainCPU `xml:"cpu"` + Clock *DomainClock `xml:"clock,omitempty"` + OnPoweroff string `xml:"on_poweroff,omitempty"` + OnReboot string `xml:"on_reboot,omitempty"` + OnCrash string `xml:"on_crash,omitempty"` + Devices *DomainDeviceList `xml:"devices"` + QEMUCommandline *DomainQEMUCommandline +} + +func (d *Domain) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *Domain) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainController) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainController) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainDisk) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainDisk) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainFilesystem) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainFilesystem) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainInterface) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainInterface) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainConsole) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainConsole) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainSerial) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainSerial) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainInput) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainInput) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainVideo) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainVideo) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainChannel) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainChannel) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainMemBalloon) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainMemBalloon) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} + +func (d *DomainSound) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), d) +} + +func (d *DomainSound) Marshal() (string, error) { + doc, err := xml.MarshalIndent(d, "", " ") + if err != nil { + return "", err + } + 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/vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot.go b/vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot.go new file mode 100644 index 00000000..226cd09f --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot.go @@ -0,0 +1,79 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +import "encoding/xml" + +type DomainSnapshotDiskDriver struct { + Type string `xml:"type,attr"` +} + +type DomainSnapshotDiskSource struct { + File string `xml:"file,attr"` +} + +type DomainSnapshotDisk struct { + Name string `xml:"name,attr"` + Snapshot string `xml:"snapshot,attr,omitempty"` + Driver *DomainSnapshotDiskDriver `xml:"driver"` + Source *DomainSnapshotDiskSource `xml:"source"` +} + +type DomainSnapshotDisks struct { + Disks []DomainSnapshotDisk `xml:"disk"` +} + +type DomainSnapshotMemory struct { + Snapshot string `xml:"snapshot,attr"` +} + +type DomainSnapshotParent struct { + Name string `xml:"name"` +} + +type DomainSnapshot struct { + XMLName xml.Name `xml:"domainsnapshot"` + Name string `xml:"name,omitempty"` + Description string `xml:"description,omitempty"` + State string `xml:"state,omitempty"` + CreationTime string `xml:"creationTime,omitempty"` + Parent *DomainSnapshotParent `xml:"parent"` + Memory *DomainSnapshotMemory `xml:"memory"` + Disks *DomainSnapshotDisks `xml:"disks"` + Domain *Domain `xml:"domain"` +} + +func (s *DomainSnapshot) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), s) +} + +func (s *DomainSnapshot) Marshal() (string, error) { + doc, err := xml.MarshalIndent(s, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot_test.go b/vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot_test.go new file mode 100644 index 00000000..b61744ac --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot_test.go @@ -0,0 +1,190 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +var domainSnapshotTestData = []struct { + Object *DomainSnapshot + Expected []string +}{ + { + Object: &DomainSnapshot{ + Description: "Snapshot", + Disks: &DomainSnapshotDisks{ + []DomainSnapshotDisk{ + DomainSnapshotDisk{ + Name: "/old", + Source: &DomainSnapshotDiskSource{ + File: "/new", + }, + }, + DomainSnapshotDisk{ + Name: "vdb", + Snapshot: "no", + }, + }, + }, + }, + Expected: []string{ + `<domainsnapshot>`, + ` <description>Snapshot</description>`, + ` <disks>`, + ` <disk name="/old">`, + ` <source file="/new"></source>`, + ` </disk>`, + ` <disk name="vdb" snapshot="no"></disk>`, + ` </disks>`, + `</domainsnapshot>`, + }, + }, + { + Object: &DomainSnapshot{ + Name: "1270477159", + Description: "Snapshot of OS install and updates", + State: "running", + CreationTime: "1270477159", + Parent: &DomainSnapshotParent{ + Name: "bare-os-install", + }, + Memory: &DomainSnapshotMemory{ + Snapshot: "no", + }, + Disks: &DomainSnapshotDisks{ + Disks: []DomainSnapshotDisk{ + DomainSnapshotDisk{ + Name: "vda", + Snapshot: "external", + Driver: &DomainSnapshotDiskDriver{ + Type: "qcow2", + }, + Source: &DomainSnapshotDiskSource{ + File: "/path/to/new", + }, + }, + DomainSnapshotDisk{ + Name: "vdb", + Snapshot: "no", + }, + }, + }, + Domain: &Domain{ + Name: "fedora", + Memory: &DomainMemory{ + Value: 1048576, + }, + Devices: &DomainDeviceList{ + Disks: []DomainDisk{ + DomainDisk{ + Type: "file", + Device: "disk", + Driver: &DomainDiskDriver{ + Name: "qemu", + Type: "raw", + }, + Source: &DomainDiskSource{ + File: "/path/to/old", + }, + Target: &DomainDiskTarget{ + Dev: "vda", + Bus: "virtio", + }, + }, + DomainDisk{ + Type: "file", + Device: "disk", + Snapshot: "external", + Driver: &DomainDiskDriver{ + Name: "qemu", + Type: "raw", + }, + Source: &DomainDiskSource{ + File: "/path/to/old2", + }, + Target: &DomainDiskTarget{ + Dev: "vdb", + Bus: "virtio", + }, + }, + }, + }, + }, + }, + Expected: []string{ + `<domainsnapshot>`, + ` <name>1270477159</name>`, + ` <description>Snapshot of OS install and updates</description>`, + ` <state>running</state>`, + ` <creationTime>1270477159</creationTime>`, + ` <parent>`, + ` <name>bare-os-install</name>`, + ` </parent>`, + ` <memory snapshot="no"></memory>`, + ` <disks>`, + ` <disk name="vda" snapshot="external">`, + ` <driver type="qcow2"></driver>`, + ` <source file="/path/to/new"></source>`, + ` </disk>`, + ` <disk name="vdb" snapshot="no"></disk>`, + ` </disks>`, + ` <domain>`, + ` <name>fedora</name>`, + ` <memory>1048576</memory>`, + ` <devices>`, + ` <disk type="file" device="disk">`, + ` <driver name="qemu" type="raw"></driver>`, + ` <source file="/path/to/old"></source>`, + ` <target dev="vda" bus="virtio"></target>`, + ` </disk>`, + ` <disk type="file" device="disk" snapshot="external">`, + ` <driver name="qemu" type="raw"></driver>`, + ` <source file="/path/to/old2"></source>`, + ` <target dev="vdb" bus="virtio"></target>`, + ` </disk>`, + ` </devices>`, + ` </domain>`, + `</domainsnapshot>`, + }, + }, +} + +func TestDomainSnapshot(t *testing.T) { + for _, test := range domainSnapshotTestData { + doc, err := test.Object.Marshal() + if err != nil { + t.Fatal(err) + } + + expect := strings.Join(test.Expected, "\n") + + if doc != expect { + t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n") + } + } +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/domain_test.go b/vendor/github.com/libvirt/libvirt-go-xml/domain_test.go new file mode 100644 index 00000000..2af451f4 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/domain_test.go @@ -0,0 +1,1475 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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) 2016 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +type Address struct { + Domain uint + Bus uint + Slot uint + Function uint +} + +var uhciIndex uint = 0 +var uhciAddr = Address{0, 0, 1, 2} + +var diskAddr = Address{0, 0, 3, 0} +var ifaceAddr = Address{0, 0, 4, 0} +var videoAddr = Address{0, 0, 5, 0} +var fsAddr = Address{0, 0, 6, 0} +var balloonAddr = Address{0, 0, 7, 0} +var duplexAddr = Address{0, 0, 8, 0} + +var serialPort uint = 0 +var tabletBus uint = 0 +var tabletPort uint = 1 + +var nicAverage int = 1000 +var nicBurst int = 10000 + +var domainTestData = []struct { + Object Document + Expected []string +}{ + { + Object: &Domain{ + Type: "kvm", + Name: "test", + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Disks: []DomainDisk{ + DomainDisk{ + Type: "file", + Device: "cdrom", + Driver: &DomainDiskDriver{ + Name: "qemu", + Type: "qcow2", + }, + Source: &DomainDiskSource{ + File: "/var/lib/libvirt/images/demo.qcow2", + }, + Target: &DomainDiskTarget{ + Dev: "vda", + Bus: "virtio", + }, + Serial: "fishfood", + Boot: &DomainDeviceBoot{ + Order: 1, + }, + }, + DomainDisk{ + Type: "block", + Device: "disk", + Driver: &DomainDiskDriver{ + Name: "qemu", + Type: "raw", + }, + Source: &DomainDiskSource{ + Device: "/dev/sda1", + }, + Target: &DomainDiskTarget{ + Dev: "vdb", + Bus: "virtio", + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &diskAddr.Domain, + Bus: &diskAddr.Bus, + Slot: &diskAddr.Slot, + Function: &diskAddr.Function, + }, + }, + DomainDisk{ + Type: "network", + Device: "disk", + Auth: &DomainDiskAuth{ + Username: "fred", + Secret: &DomainDiskSecret{ + Type: "ceph", + UUID: "e49f09c9-119e-43fd-b5a9-000d41e65493", + }, + }, + Source: &DomainDiskSource{ + Protocol: "rbd", + Name: "somepool/somevol", + Hosts: []DomainDiskSourceHost{ + DomainDiskSourceHost{ + Transport: "tcp", + Name: "rbd1.example.com", + Port: "3000", + }, + DomainDiskSourceHost{ + Transport: "tcp", + Name: "rbd2.example.com", + Port: "3000", + }, + }, + }, + Target: &DomainDiskTarget{ + Dev: "vdc", + Bus: "virtio", + }, + }, + DomainDisk{ + Type: "network", + Device: "disk", + Source: &DomainDiskSource{ + Protocol: "nbd", + Hosts: []DomainDiskSourceHost{ + DomainDiskSourceHost{ + Transport: "unix", + Socket: "/var/run/nbd.sock", + }, + }, + }, + Target: &DomainDiskTarget{ + Dev: "vdd", + Bus: "virtio", + }, + Shareable: &DomainDiskShareable{}, + }, + DomainDisk{ + Type: "volume", + Device: "cdrom", + Driver: &DomainDiskDriver{ + Cache: "none", + IO: "native", + ErrorPolicy: "stop", + }, + Source: &DomainDiskSource{ + Pool: "default", + Volume: "myvolume", + }, + Target: &DomainDiskTarget{ + Dev: "vde", + Bus: "virtio", + }, + ReadOnly: &DomainDiskReadOnly{}, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <disk type="file" device="cdrom">`, + ` <driver name="qemu" type="qcow2"></driver>`, + ` <source file="/var/lib/libvirt/images/demo.qcow2"></source>`, + ` <target dev="vda" bus="virtio"></target>`, + ` <serial>fishfood</serial>`, + ` <boot order="1"></boot>`, + ` </disk>`, + ` <disk type="block" device="disk">`, + ` <driver name="qemu" type="raw"></driver>`, + ` <source dev="/dev/sda1"></source>`, + ` <target dev="vdb" bus="virtio"></target>`, + ` <address type="pci" domain="0" bus="0" slot="3" function="0"></address>`, + ` </disk>`, + ` <disk type="network" device="disk">`, + ` <auth username="fred">`, + ` <secret type="ceph" uuid="e49f09c9-119e-43fd-b5a9-000d41e65493"></secret>`, + ` </auth>`, + ` <source protocol="rbd" name="somepool/somevol">`, + ` <host transport="tcp" name="rbd1.example.com" port="3000"></host>`, + ` <host transport="tcp" name="rbd2.example.com" port="3000"></host>`, + ` </source>`, + ` <target dev="vdc" bus="virtio"></target>`, + ` </disk>`, + ` <disk type="network" device="disk">`, + ` <source protocol="nbd">`, + ` <host transport="unix" socket="/var/run/nbd.sock"></host>`, + ` </source>`, + ` <target dev="vdd" bus="virtio"></target>`, + ` <shareable></shareable>`, + ` </disk>`, + ` <disk type="volume" device="cdrom">`, + ` <driver cache="none" io="native" error_policy="stop"></driver>`, + ` <source pool="default" volume="myvolume"></source>`, + ` <target dev="vde" bus="virtio"></target>`, + ` <readonly></readonly>`, + ` </disk>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Inputs: []DomainInput{ + DomainInput{ + Type: "tablet", + Bus: "usb", + Address: &DomainAddress{ + Type: "usb", + Bus: &tabletBus, + Port: &tabletPort, + }, + }, + DomainInput{ + Type: "keyboard", + Bus: "ps2", + }, + }, + Videos: []DomainVideo{ + DomainVideo{ + Model: DomainVideoModel{ + Type: "cirrus", + Heads: 1, + Ram: 4096, + VRam: 8192, + VGAMem: 256, + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &videoAddr.Domain, + Bus: &videoAddr.Bus, + Slot: &videoAddr.Slot, + Function: &videoAddr.Function, + }, + }, + }, + Graphics: []DomainGraphic{ + DomainGraphic{ + Type: "vnc", + }, + }, + MemBalloon: &DomainMemBalloon{ + Model: "virtio", + Address: &DomainAddress{ + Type: "pci", + Domain: &balloonAddr.Domain, + Bus: &balloonAddr.Bus, + Slot: &balloonAddr.Slot, + Function: &balloonAddr.Function, + }, + }, + Consoles: []DomainConsole{ + DomainConsole{ + Type: "pty", + Target: &DomainConsoleTarget{ + Type: "virtio", + Port: &serialPort, + }, + }, + }, + Serials: []DomainSerial{ + DomainSerial{ + Type: "pty", + Target: &DomainSerialTarget{ + Type: "isa", + Port: &serialPort, + }, + }, + DomainSerial{ + Type: "file", + Source: &DomainChardevSource{ + Path: "/tmp/serial.log", + Append: "off", + }, + Target: &DomainSerialTarget{ + Port: &serialPort, + }, + }, + }, + Channels: []DomainChannel{ + DomainChannel{ + Type: "pty", + Target: &DomainChannelTarget{ + Type: "virtio", + Name: "org.redhat.spice", + State: "connected", + }, + }, + }, + Sounds: []DomainSound{ + DomainSound{ + Model: "ich6", + Codec: &DomainSoundCodec{ + Type: "duplex", + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &duplexAddr.Domain, + Bus: &duplexAddr.Bus, + Slot: &duplexAddr.Slot, + Function: &duplexAddr.Function, + }, + }, + }, + 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{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <serial type="pty">`, + ` <target type="isa" port="0"></target>`, + ` </serial>`, + ` <serial type="file">`, + ` <source path="/tmp/serial.log" append="off"></source>`, + ` <target port="0"></target>`, + ` </serial>`, + ` <console type="pty">`, + ` <target type="virtio" port="0"></target>`, + ` </console>`, + ` <input type="tablet" bus="usb">`, + ` <address type="usb" bus="0" port="1"></address>`, + ` </input>`, + ` <input type="keyboard" bus="ps2"></input>`, + ` <graphics type="vnc"></graphics>`, + ` <video>`, + ` <model type="cirrus" heads="1" ram="4096" vram="8192" vgamem="256"></model>`, + ` <address type="pci" domain="0" bus="0" slot="5" function="0"></address>`, + ` </video>`, + ` <channel type="pty">`, + ` <target type="virtio" name="org.redhat.spice" state="connected"></target>`, + ` </channel>`, + ` <memballoon model="virtio">`, + ` <address type="pci" domain="0" bus="0" slot="7" function="0"></address>`, + ` </memballoon>`, + ` <sound model="ich6">`, + ` <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>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Memory: &DomainMemory{ + Unit: "KiB", + Value: 8192, + }, + CurrentMemory: &DomainMemory{ + Unit: "KiB", + Value: 4096, + }, + MaximumMemory: &DomainMaxMemory{ + Unit: "KiB", + Value: 16384, + Slots: 2, + }, + OS: &DomainOS{ + Type: &DomainOSType{ + Arch: "x86_64", + Machine: "pc", + Type: "hvm", + }, + BootDevices: []DomainBootDevice{ + DomainBootDevice{ + Dev: "hd", + }, + }, + Loader: &DomainLoader{ + Readonly: "yes", + Secure: "no", + Type: "rom", + Path: "/loader", + }, + SMBios: &DomainSMBios{ + Mode: "sysinfo", + }, + BIOS: &DomainBIOS{ + UseSerial: "yes", + RebootTimeout: "0", + }, + Init: "/bin/systemd", + InitArgs: []string{ + "--unit", + "emergency.service", + }, + }, + SysInfo: &DomainSysInfo{ + Type: "smbios", + BIOS: []DomainSysInfoEntry{ + DomainSysInfoEntry{ + Name: "vendor", + Value: "vendor", + }, + }, + System: []DomainSysInfoEntry{ + DomainSysInfoEntry{ + Name: "manufacturer", + Value: "manufacturer", + }, + DomainSysInfoEntry{ + Name: "product", + Value: "product", + }, + DomainSysInfoEntry{ + Name: "version", + Value: "version", + }, + }, + BaseBoard: []DomainSysInfoEntry{ + DomainSysInfoEntry{ + Name: "manufacturer", + Value: "manufacturer", + }, + DomainSysInfoEntry{ + Name: "product", + Value: "product", + }, + DomainSysInfoEntry{ + Name: "version", + Value: "version", + }, + DomainSysInfoEntry{ + Name: "serial", + Value: "serial", + }, + }, + }, + Clock: &DomainClock{ + Offset: "variable", + Basis: "utc", + Adjustment: 28794, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <memory unit="KiB">8192</memory>`, + ` <currentMemory unit="KiB">4096</currentMemory>`, + ` <maxMemory unit="KiB" slots="2">16384</maxMemory>`, + ` <sysinfo type="smbios">`, + ` <system>`, + ` <entry name="manufacturer">manufacturer</entry>`, + ` <entry name="product">product</entry>`, + ` <entry name="version">version</entry>`, + ` </system>`, + ` <bios>`, + ` <entry name="vendor">vendor</entry>`, + ` </bios>`, + ` <baseBoard>`, + ` <entry name="manufacturer">manufacturer</entry>`, + ` <entry name="product">product</entry>`, + ` <entry name="version">version</entry>`, + ` <entry name="serial">serial</entry>`, + ` </baseBoard>`, + ` </sysinfo>`, + ` <os>`, + ` <type arch="x86_64" machine="pc">hvm</type>`, + ` <loader readonly="yes" secure="no" type="rom">/loader</loader>`, + ` <boot dev="hd"></boot>`, + ` <smbios mode="sysinfo"></smbios>`, + ` <bios useserial="yes" rebootTimeout="0"></bios>`, + ` <init>/bin/systemd</init>`, + ` <initarg>--unit</initarg>`, + ` <initarg>emergency.service</initarg>`, + ` </os>`, + ` <clock offset="variable" basis="utc" adjustment="28794"></clock>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + OS: &DomainOS{ + NVRam: &DomainNVRam{ + Template: "/t.fd", + NVRam: "/vars.fd", + }, + BootMenu: &DomainBootMenu{ + Enabled: "yes", + Timeout: "3000", + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <os>`, + ` <nvram template="/t.fd">/vars.fd</nvram>`, + ` <bootmenu enabled="yes" timeout="3000"></bootmenu>`, + ` </os>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + OS: &DomainOS{ + Kernel: "/vmlinuz", + Initrd: "/initrd", + KernelArgs: "arg", + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <os>`, + ` <kernel>/vmlinuz</kernel>`, + ` <initrd>/initrd</initrd>`, + ` <cmdline>arg</cmdline>`, + ` </os>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Resource: &DomainResource{ + Partition: "/machines/production", + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <resource>`, + ` <partition>/machines/production</partition>`, + ` </resource>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + VCPU: &DomainVCPU{ + Placement: "static", + CPUSet: "1-4,^3,6", + Current: "1", + Value: 2, + }, + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "network", + MAC: &DomainInterfaceMAC{ + Address: "00:11:22:33:44:55", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Virtualport: &DomainInterfaceVirtualport{ + Type: "openvswitch", + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <vcpu placement="static" cpuset="1-4,^3,6" current="1">2</vcpu>`, + ` <devices>`, + ` <interface type="network">`, + ` <mac address="00:11:22:33:44:55"></mac>`, + ` <model type="virtio"></model>`, + ` <virtualport type="openvswitch"></virtualport>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + CPU: &DomainCPU{ + Match: "exact", + Model: &DomainCPUModel{ + Fallback: "allow", + Value: "core2duo", + }, + Vendor: "Intel", + Topology: &DomainCPUTopology{ + Sockets: 1, + Cores: 2, + Threads: 1, + }, + Features: []DomainCPUFeature{ + DomainCPUFeature{Policy: "disable", Name: "lahf_lm"}, + }, + }, + Devices: &DomainDeviceList{ + Emulator: "/bin/qemu-kvm", + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <cpu match="exact">`, + ` <model fallback="allow">core2duo</model>`, + ` <vendor>Intel</vendor>`, + ` <topology sockets="1" cores="2" threads="1"></topology>`, + ` <feature policy="disable" name="lahf_lm"></feature>`, + ` </cpu>`, + ` <devices>`, + ` <emulator>/bin/qemu-kvm</emulator>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "bridge", + MAC: &DomainInterfaceMAC{ + Address: "06:39:b4:00:00:46", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Source: &DomainInterfaceSource{ + Bridge: "private", + }, + Target: &DomainInterfaceTarget{ + Dev: "vnet3", + }, + Alias: &DomainInterfaceAlias{ + Name: "net1", + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="bridge">`, + ` <mac address="06:39:b4:00:00:46"></mac>`, + ` <model type="virtio"></model>`, + ` <source bridge="private"></source>`, + ` <target dev="vnet3"></target>`, + ` <alias name="net1"></alias>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "network", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "e1000", + }, + Source: &DomainInterfaceSource{ + Network: "default", + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="network">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="e1000"></model>`, + ` <source network="default"></source>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "direct", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "e1000", + }, + Source: &DomainInterfaceSource{ + Dev: "eth0", + Mode: "bridge", + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="direct">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="e1000"></model>`, + ` <source dev="eth0" mode="bridge"></source>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "user", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Link: &DomainInterfaceLink{ + State: "up", + }, + Boot: &DomainDeviceBoot{ + Order: 1, + }, + Driver: &DomainInterfaceDriver{ + Name: "vhost", + Queues: 5, + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="user">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="virtio"></model>`, + ` <link state="up"></link>`, + ` <boot order="1"></boot>`, + ` <driver name="vhost" queues="5"></driver>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "server", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Source: &DomainInterfaceSource{ + Address: "127.0.0.1", + Port: 1234, + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="server">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="virtio"></model>`, + ` <source address="127.0.0.1" port="1234"></source>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "ethernet", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Script: &DomainInterfaceScript{ + Path: "/etc/qemu-ifup", + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &ifaceAddr.Domain, + Bus: &ifaceAddr.Bus, + Slot: &ifaceAddr.Slot, + Function: &ifaceAddr.Function, + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="ethernet">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="virtio"></model>`, + ` <script path="/etc/qemu-ifup"></script>`, + ` <address type="pci" domain="0" bus="0" slot="4" function="0"></address>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "vhostuser", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Source: &DomainInterfaceSource{ + Type: "unix", + Path: "/tmp/vhost0.sock", + Mode: "server", + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="vhostuser">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="virtio"></model>`, + ` <source type="unix" path="/tmp/vhost0.sock" mode="server"></source>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Interfaces: []DomainInterface{ + DomainInterface{ + Type: "vhostuser", + MAC: &DomainInterfaceMAC{ + Address: "52:54:00:39:97:ac", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + Bandwidth: &DomainInterfaceBandwidth{ + Inbound: &DomainInterfaceBandwidthParams{ + Average: &nicAverage, + Burst: &nicBurst, + }, + Outbound: &DomainInterfaceBandwidthParams{ + Average: new(int), + Burst: new(int), + }, + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <interface type="vhostuser">`, + ` <mac address="52:54:00:39:97:ac"></mac>`, + ` <model type="virtio"></model>`, + ` <bandwidth>`, + ` <inbound average="1000" burst="10000"></inbound>`, + ` <outbound average="0" burst="0"></outbound>`, + ` </bandwidth>`, + ` </interface>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Filesystems: []DomainFilesystem{ + DomainFilesystem{ + Type: "mount", + AccessMode: "mapped", + Driver: &DomainFilesystemDriver{ + Type: "path", + WRPolicy: "immediate", + }, + Source: &DomainFilesystemSource{ + Dir: "/home/user/test", + }, + Target: &DomainFilesystemTarget{ + Dir: "user-test-mount", + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &fsAddr.Domain, + Bus: &fsAddr.Bus, + Slot: &fsAddr.Slot, + Function: &fsAddr.Function, + }, + }, + DomainFilesystem{ + Type: "file", + AccessMode: "passthrough", + Driver: &DomainFilesystemDriver{ + Name: "loop", + Type: "raw", + }, + Source: &DomainFilesystemSource{ + File: "/home/user/test.img", + }, + Target: &DomainFilesystemTarget{ + Dir: "user-file-test-mount", + }, + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <filesystem type="mount" accessmode="mapped">`, + ` <driver type="path" wrpolicy="immediate"></driver>`, + ` <source dir="/home/user/test"></source>`, + ` <target dir="user-test-mount"></target>`, + ` <address type="pci" domain="0" bus="0" slot="6" function="0"></address>`, + ` </filesystem>`, + ` <filesystem type="file" accessmode="passthrough">`, + ` <driver type="raw" name="loop"></driver>`, + ` <source file="/home/user/test.img"></source>`, + ` <target dir="user-file-test-mount"></target>`, + ` </filesystem>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Features: &DomainFeatureList{ + PAE: &DomainFeature{}, + ACPI: &DomainFeature{}, + APIC: &DomainFeatureAPIC{}, + HAP: &DomainFeatureState{}, + PrivNet: &DomainFeature{}, + HyperV: &DomainFeatureHyperV{ + Relaxed: &DomainFeatureState{State: "on"}, + VAPIC: &DomainFeatureState{State: "on"}, + Spinlocks: &DomainFeatureHyperVSpinlocks{ + DomainFeatureState{State: "on"}, 4096, + }, + VPIndex: &DomainFeatureState{State: "on"}, + Runtime: &DomainFeatureState{State: "on"}, + Synic: &DomainFeatureState{State: "on"}, + Reset: &DomainFeatureState{State: "on"}, + VendorId: &DomainFeatureHyperVVendorId{ + DomainFeatureState{State: "on"}, "KVM Hv", + }, + }, + KVM: &DomainFeatureKVM{ + Hidden: &DomainFeatureState{State: "on"}, + }, + PVSpinlock: &DomainFeatureState{State: "on"}, + GIC: &DomainFeatureGIC{Version: "2"}, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <features>`, + ` <pae></pae>`, + ` <acpi></acpi>`, + ` <apic></apic>`, + ` <hap></hap>`, + ` <privnet></privnet>`, + ` <hyperv>`, + ` <relaxed state="on"></relaxed>`, + ` <vapic state="on"></vapic>`, + ` <spinlocks state="on" retries="4096"></spinlocks>`, + ` <vpindex state="on"></vpindex>`, + ` <runtime state="on"></runtime>`, + ` <synic state="on"></synic>`, + ` <reset state="on"></reset>`, + ` <vendor_id state="on" value="KVM Hv"></vendor_id>`, + ` </hyperv>`, + ` <kvm>`, + ` <hidden state="on"></hidden>`, + ` </kvm>`, + ` <pvspinlock state="on"></pvspinlock>`, + ` <gic version="2"></gic>`, + ` </features>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Devices: &DomainDeviceList{ + Controllers: []DomainController{ + DomainController{ + Type: "usb", + Index: &uhciIndex, + Model: "piix3-uhci", + Address: &DomainAddress{ + Type: "pci", + Domain: &uhciAddr.Domain, + Bus: &uhciAddr.Bus, + Slot: &uhciAddr.Slot, + Function: &uhciAddr.Function, + }, + }, + DomainController{ + Type: "usb", + Index: nil, + Model: "ehci", + }, + }, + }, + }, + Expected: []string{ + `<domain type="kvm">`, + ` <name>test</name>`, + ` <devices>`, + ` <controller type="usb" index="0" model="piix3-uhci">`, + ` <address type="pci" domain="0" bus="0" slot="1" function="2"></address>`, + ` </controller>`, + ` <controller type="usb" model="ehci"></controller>`, + ` </devices>`, + `</domain>`, + }, + }, + { + Object: &Domain{ + Type: "qemu", + Name: "test", + QEMUCommandline: &DomainQEMUCommandline{ + Args: []DomainQEMUCommandlineArg{ + DomainQEMUCommandlineArg{Value: "-newarg"}, + DomainQEMUCommandlineArg{Value: "-oldarg"}, + }, + Envs: []DomainQEMUCommandlineEnv{ + DomainQEMUCommandlineEnv{Name: "QEMU_ENV", Value: "VAL"}, + DomainQEMUCommandlineEnv{Name: "QEMU_VAR", Value: "VAR"}, + }, + }, + }, + Expected: []string{ + `<domain type="qemu">`, + ` <name>test</name>`, + ` <commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0">`, + ` <arg value="-newarg"></arg>`, + ` <arg value="-oldarg"></arg>`, + ` <env name="QEMU_ENV" value="VAL"></env>`, + ` <env name="QEMU_VAR" value="VAR"></env>`, + ` </commandline>`, + `</domain>`, + }, + }, + + /* Tests for sub-documents that can be hotplugged */ + { + Object: &DomainController{ + Type: "usb", + Index: &uhciIndex, + Model: "piix3-uhci", + Address: &DomainAddress{ + Type: "pci", + Domain: &uhciAddr.Domain, + Bus: &uhciAddr.Bus, + Slot: &uhciAddr.Slot, + Function: &uhciAddr.Function, + }, + }, + Expected: []string{ + `<controller type="usb" index="0" model="piix3-uhci">`, + ` <address type="pci" domain="0" bus="0" slot="1" function="2"></address>`, + `</controller>`, + }, + }, + { + Object: &DomainDisk{ + Type: "file", + Device: "cdrom", + Driver: &DomainDiskDriver{ + Name: "qemu", + Type: "qcow2", + }, + Source: &DomainDiskSource{ + File: "/var/lib/libvirt/images/demo.qcow2", + }, + Target: &DomainDiskTarget{ + Dev: "vda", + Bus: "virtio", + }, + Serial: "fishfood", + WWN: "0123456789abcdef", + }, + Expected: []string{ + `<disk type="file" device="cdrom">`, + ` <driver name="qemu" type="qcow2"></driver>`, + ` <source file="/var/lib/libvirt/images/demo.qcow2"></source>`, + ` <target dev="vda" bus="virtio"></target>`, + ` <serial>fishfood</serial>`, + ` <wwn>0123456789abcdef</wwn>`, + `</disk>`, + }, + }, + { + Object: &DomainFilesystem{ + Type: "mount", + AccessMode: "mapped", + Driver: &DomainFilesystemDriver{ + Type: "path", + WRPolicy: "immediate", + }, + Source: &DomainFilesystemSource{ + Dir: "/home/user/test", + }, + Target: &DomainFilesystemTarget{ + Dir: "user-test-mount", + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &fsAddr.Domain, + Bus: &fsAddr.Bus, + Slot: &fsAddr.Slot, + Function: &fsAddr.Function, + }, + }, + + Expected: []string{ + `<filesystem type="mount" accessmode="mapped">`, + ` <driver type="path" wrpolicy="immediate"></driver>`, + ` <source dir="/home/user/test"></source>`, + ` <target dir="user-test-mount"></target>`, + ` <address type="pci" domain="0" bus="0" slot="6" function="0"></address>`, + `</filesystem>`, + }, + }, + { + Object: &DomainInterface{ + Type: "network", + MAC: &DomainInterfaceMAC{ + Address: "00:11:22:33:44:55", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + }, + Expected: []string{ + `<interface type="network">`, + ` <mac address="00:11:22:33:44:55"></mac>`, + ` <model type="virtio"></model>`, + `</interface>`, + }, + }, + { + Object: &DomainSerial{ + Type: "pty", + Target: &DomainSerialTarget{ + Type: "isa", + Port: &serialPort, + }, + }, + + Expected: []string{ + `<serial type="pty">`, + ` <target type="isa" port="0"></target>`, + `</serial>`, + }, + }, + { + Object: &DomainConsole{ + Type: "pty", + Target: &DomainConsoleTarget{ + Type: "virtio", + Port: &serialPort, + }, + }, + + Expected: []string{ + `<console type="pty">`, + ` <target type="virtio" port="0"></target>`, + `</console>`, + }, + }, + { + Object: &DomainInput{ + Type: "tablet", + Bus: "usb", + Address: &DomainAddress{ + Type: "usb", + Bus: &tabletBus, + Port: &tabletPort, + }, + }, + + Expected: []string{ + `<input type="tablet" bus="usb">`, + ` <address type="usb" bus="0" port="1"></address>`, + `</input>`, + }, + }, + { + Object: &DomainVideo{ + Model: DomainVideoModel{ + Type: "cirrus", + Heads: 1, + Ram: 4096, + VRam: 8192, + VGAMem: 256, + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &videoAddr.Domain, + Bus: &videoAddr.Bus, + Slot: &videoAddr.Slot, + Function: &videoAddr.Function, + }, + }, + + Expected: []string{ + `<video>`, + ` <model type="cirrus" heads="1" ram="4096" vram="8192" vgamem="256"></model>`, + ` <address type="pci" domain="0" bus="0" slot="5" function="0"></address>`, + `</video>`, + }, + }, + { + Object: &DomainChannel{ + Type: "pty", + Target: &DomainChannelTarget{ + Type: "virtio", + Name: "org.redhat.spice", + State: "connected", + }, + }, + + Expected: []string{ + `<channel type="pty">`, + ` <target type="virtio" name="org.redhat.spice" state="connected"></target>`, + `</channel>`, + }, + }, + { + Object: &DomainMemBalloon{ + Model: "virtio", + Address: &DomainAddress{ + Type: "pci", + Domain: &balloonAddr.Domain, + Bus: &balloonAddr.Bus, + Slot: &balloonAddr.Slot, + Function: &balloonAddr.Function, + }, + }, + + Expected: []string{ + `<memballoon model="virtio">`, + ` <address type="pci" domain="0" bus="0" slot="7" function="0"></address>`, + `</memballoon>`, + }, + }, + { + Object: &DomainSound{ + Model: "ich6", + Codec: &DomainSoundCodec{ + Type: "duplex", + }, + Address: &DomainAddress{ + Type: "pci", + Domain: &duplexAddr.Domain, + Bus: &duplexAddr.Bus, + Slot: &duplexAddr.Slot, + Function: &duplexAddr.Function, + }, + }, + + Expected: []string{ + `<sound model="ich6">`, + ` <codec type="duplex"></codec>`, + ` <address type="pci" domain="0" bus="0" slot="8" function="0"></address>`, + `</sound>`, + }, + }, + { + Object: &DomainRNG{ + Model: "virtio", + Rate: &DomainRNGRate{ + Period: 2000, + Bytes: 1234, + }, + Backend: &DomainRNGBackend{ + Device: "/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>`, + }, + }, +} + +func TestDomain(t *testing.T) { + for _, test := range domainTestData { + doc, err := test.Object.Marshal() + if err != nil { + t.Fatal(err) + } + + expect := strings.Join(test.Expected, "\n") + + if doc != expect { + t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n") + } + } +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/network.go b/vendor/github.com/libvirt/libvirt-go-xml/network.go new file mode 100644 index 00000000..32f125ac --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/network.go @@ -0,0 +1,166 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 <blazeblue@gmail.com> + * + */ + +package libvirtxml + +import ( + "encoding/xml" +) + +type NetworkBridge struct { + Name string `xml:"name,attr,omitempty"` + STP string `xml:"stp,attr,omitempty"` + Delay string `xml:"delay,attr,omitempty"` + MACTableManager string `xml:"macTableManager,attr,omitempty"` +} + +type NetworkDomain struct { + Name string `xml:"name,attr,omitempty"` + LocalOnly string `xml:"localOnly,attr,omitempty"` +} + +type NetworkForwardNATAddress struct { + Start string `xml:"start,attr"` + End string `xml:"end,attr"` +} + +type NetworkForwardNATPort struct { + Start uint `xml:"start,attr"` + End uint `xml:"end,attr"` +} + +type NetworkForwardNAT struct { + Addresses []NetworkForwardNATAddress `xml:"address"` + Ports []NetworkForwardNATPort `xml:"port"` +} + +type NetworkForward struct { + Mode string `xml:"mode,attr,omitempty"` + Dev string `xml:"dev,attr,omitempty"` + NAT *NetworkForwardNAT `xml:"nat"` +} + +type NetworkMAC struct { + Address string `xml:"address,attr,omitempty"` +} + +type NetworkDHCPRange struct { + Start string `xml:"start,attr,omitempty"` + End string `xml:"end,attr,omitempty"` +} + +type NetworkDHCPHost struct { + ID string `xml:"id,attr,omitempty"` + MAC string `xml:"mac,attr,omitempty"` + Name string `xml:"name,attr,omitempty"` + IP string `xml:"ip,attr,omitempty"` +} + +type NetworkDHCP struct { + Ranges []NetworkDHCPRange `xml:"range"` + Hosts []NetworkDHCPHost `xml:"host"` +} + +type NetworkIP struct { + Address string `xml:"address,attr,omitempty"` + Family string `xml:"family,attr,omitempty"` + Netmask string `xml:"netmask,attr,omitempty"` + Prefix string `xml:"prefix,attr,omitempty"` + LocalPtr string `xml:"localPtr,attr,omitempty"` + DHCP *NetworkDHCP `xml:"dhcp"` +} + +type NetworkRoute struct { + Address string `xml:"address,attr,omitempty"` + Family string `xml:"family,attr,omitempty"` + Prefix string `xml:"prefix,attr,omitempty"` + Metric string `xml:"metric,attr,omitempty"` + 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"` + TrustGuestRxFilters string `xml:"trustGuestRxFilters,attr,omitempty"` + Name string `xml:"name,omitempty"` + UUID string `xml:"uuid,omitempty"` + MAC *NetworkMAC `xml:"mac"` + Bridge *NetworkBridge `xml:"bridge"` + Forward *NetworkForward `xml:"forward"` + Domain *NetworkDomain `xml:"domain"` + IPs []NetworkIP `xml:"ip"` + Routes []NetworkRoute `xml:"route"` + DNS *NetworkDNS `xml:"dns"` +} + +func (s *Network) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), s) +} + +func (s *Network) Marshal() (string, error) { + doc, err := xml.MarshalIndent(s, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/network_test.go b/vendor/github.com/libvirt/libvirt-go-xml/network_test.go new file mode 100644 index 00000000..b1bd168b --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/network_test.go @@ -0,0 +1,219 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 <blazeblue@gmail.com> + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +var networkTestData = []struct { + Object *Network + Expected []string +}{ + { + Object: &Network{ + Name: "test", + IPv6: "yes", + }, + Expected: []string{ + `<network ipv6="yes">`, + ` <name>test</name>`, + `</network>`, + }, + }, + { + Object: &Network{ + Name: "test", + Domain: &NetworkDomain{ + Name: "example.com", + }, + }, + Expected: []string{ + `<network>`, + ` <name>test</name>`, + ` <domain name="example.com"></domain>`, + `</network>`, + }, + }, + { + Object: &Network{ + Name: "test", + Bridge: &NetworkBridge{ + Name: "virbr0", + }, + Forward: &NetworkForward{ + Mode: "nat", + NAT: &NetworkForwardNAT{ + Addresses: []NetworkForwardNATAddress{ + NetworkForwardNATAddress{ + Start: "1.2.3.4", + End: "1.2.3.10", + }, + }, + Ports: []NetworkForwardNATPort{ + NetworkForwardNATPort{ + Start: 500, + End: 1000, + }, + }, + }, + }, + IPs: []NetworkIP{ + NetworkIP{ + Address: "192.168.122.1", + Netmask: "255.255.255.0", + DHCP: &NetworkDHCP{ + Ranges: []NetworkDHCPRange{ + NetworkDHCPRange{ + Start: "192.168.122.2", + End: "192.168.122.254", + }, + }, + Hosts: []NetworkDHCPHost{ + NetworkDHCPHost{ + MAC: "00:16:3e:77:e2:ed", + Name: "foo.example.com", + IP: "192.168.122.10", + }, + }, + }, + }, + NetworkIP{ + Family: "ipv6", + Address: "2001:db8:ca2:2::1", + Prefix: "64", + DHCP: &NetworkDHCP{ + Hosts: []NetworkDHCPHost{ + NetworkDHCPHost{ + IP: "2001:db8:ca2:2:3::1", + 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", + }, + }, + }, + }, + }, + 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>`, + ` <name>test</name>`, + ` <bridge name="virbr0"></bridge>`, + ` <forward mode="nat">`, + ` <nat>`, + ` <address start="1.2.3.4" end="1.2.3.10"></address>`, + ` <port start="500" end="1000"></port>`, + ` </nat>`, + ` </forward>`, + ` <ip address="192.168.122.1" netmask="255.255.255.0">`, + ` <dhcp>`, + ` <range start="192.168.122.2" end="192.168.122.254"></range>`, + ` <host mac="00:16:3e:77:e2:ed" name="foo.example.com" ip="192.168.122.10"></host>`, + ` </dhcp>`, + ` </ip>`, + ` <ip address="2001:db8:ca2:2::1" family="ipv6" prefix="64">`, + ` <dhcp>`, + ` <host name="paul" ip="2001:db8:ca2:2:3::1"></host>`, + ` <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>`, + }, + }, +} + +func TestNetwork(t *testing.T) { + for _, test := range networkTestData { + doc, err := test.Object.Marshal() + if err != nil { + t.Fatal(err) + } + + expect := strings.Join(test.Expected, "\n") + + if doc != expect { + t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n") + } + } +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/secret.go b/vendor/github.com/libvirt/libvirt-go-xml/secret.go new file mode 100644 index 00000000..b48d541f --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/secret.go @@ -0,0 +1,58 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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) 2016 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "encoding/xml" +) + +type SecretUsage struct { + Type string `xml:"type,attr"` + Volume string `xml:"volume,omitempty"` + Name string `xml:"name,omitempty"` + Target string `xml:"target,omitempty"` +} + +type Secret struct { + XMLName xml.Name `xml:"secret"` + Ephemeral string `xml:"ephemeral,attr,omitempty"` + Private string `xml:"private,attr,omitempty"` + Description string `xml:"description,omitempty"` + UUID string `xml:"uuid,omitempty"` + Usage *SecretUsage `xml:"usage"` +} + +func (s *Secret) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), s) +} + +func (s *Secret) Marshal() (string, error) { + doc, err := xml.MarshalIndent(s, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/secret_test.go b/vendor/github.com/libvirt/libvirt-go-xml/secret_test.go new file mode 100644 index 00000000..9763263d --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/secret_test.go @@ -0,0 +1,160 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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) 2016 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +var secretTestData = []struct { + Object *Secret + Expected []string +}{ + { + Object: &Secret{ + Description: "Demo", + }, + Expected: []string{ + `<secret>`, + ` <description>Demo</description>`, + `</secret>`, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + }, + Expected: []string{ + `<secret ephemeral="yes" private="yes">`, + ` <description>Demo</description>`, + ` <uuid>55806c7d-8e93-456f-829b-607d8c198367</uuid>`, + `</secret>`, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "volume", + Volume: "/var/lib/libvirt/images/puppyname.img", + }, + }, + Expected: []string{ + `<secret ephemeral="yes" private="yes">`, + ` <description>Demo</description>`, + ` <uuid>55806c7d-8e93-456f-829b-607d8c198367</uuid>`, + ` <usage type="volume">`, + ` <volume>/var/lib/libvirt/images/puppyname.img</volume>`, + ` </usage>`, + `</secret>`, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "ceph", + Name: "mycluster", + }, + }, + Expected: []string{ + `<secret ephemeral="yes" private="yes">`, + ` <description>Demo</description>`, + ` <uuid>55806c7d-8e93-456f-829b-607d8c198367</uuid>`, + ` <usage type="ceph">`, + ` <name>mycluster</name>`, + ` </usage>`, + `</secret>`, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "iscsi", + Target: "libvirtiscsi", + }, + }, + Expected: []string{ + `<secret ephemeral="yes" private="yes">`, + ` <description>Demo</description>`, + ` <uuid>55806c7d-8e93-456f-829b-607d8c198367</uuid>`, + ` <usage type="iscsi">`, + ` <target>libvirtiscsi</target>`, + ` </usage>`, + `</secret>`, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "tls", + Name: "Demo cert", + }, + }, + Expected: []string{ + `<secret ephemeral="yes" private="yes">`, + ` <description>Demo</description>`, + ` <uuid>55806c7d-8e93-456f-829b-607d8c198367</uuid>`, + ` <usage type="tls">`, + ` <name>Demo cert</name>`, + ` </usage>`, + `</secret>`, + }, + }, +} + +func TestSecret(t *testing.T) { + for _, test := range secretTestData { + doc, err := test.Object.Marshal() + if err != nil { + t.Fatal(err) + } + + expect := strings.Join(test.Expected, "\n") + + if doc != expect { + t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n") + } + } +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/storage_encryption.go b/vendor/github.com/libvirt/libvirt-go-xml/storage_encryption.go new file mode 100644 index 00000000..f66314cc --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/storage_encryption.go @@ -0,0 +1,50 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +type StorageEncryptionSecret struct { + Type string `xml:"type,attr"` + UUID string `xml:"uuid,attr"` +} + +type StorageEncryptionCipher struct { + Name string `xml:"name,attr"` + Size uint64 `xml:"size,attr"` + Mode string `xml:"mode,attr"` + Hash string `xml:"hash,attr"` +} + +type StorageEncryptionIvgen struct { + Name string `xml:"name,attr"` + Hash string `xml:"hash,attr"` +} + +type StorageEncryption struct { + Format string `xml:"format,attr"` + Secret *StorageEncryptionSecret `xml:"secret"` + Cipher *StorageEncryptionCipher `xml:"cipher"` + Ivgen *StorageEncryptionIvgen `xml:"ivgen"` +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/storage_pool.go b/vendor/github.com/libvirt/libvirt-go-xml/storage_pool.go new file mode 100644 index 00000000..48a637db --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/storage_pool.go @@ -0,0 +1,138 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +import "encoding/xml" + +type StoragePoolSize struct { + Unit string `xml:"unit,attr,omitempty"` + Value uint64 `xml:",chardata"` +} + +type StoragePoolTargetPermissions struct { + Owner string `xml:"owner,omitempty"` + Group string `xml:"group,omitempty"` + Mode string `xml:"mode,omitempty"` + Label string `xml:"label,omitempty"` +} + +type StoragePoolTargetTimestamps struct { + Atime string `xml:"atime"` + Mtime string `xml:"mtime"` + Ctime string `xml:"ctime"` +} + +type StoragePoolTarget struct { + Path string `xml:"path,omitempty"` + Permissions *StoragePoolTargetPermissions `xml:"permissions"` + Timestamps *StoragePoolTargetTimestamps `xml:"timestamps"` + Encryption *StorageEncryption `xml:"encryption"` +} + +type StoragePoolSourceFormat struct { + Type string `xml:"type,attr"` +} +type StoragePoolSourceHost struct { + Name string `xml:"name,attr"` +} + +type StoragePoolSourceDevice struct { + Path string `xml:"path,attr"` + PartSeparator string `xml:"part_separator,attr,omitempty"` +} + +type StoragePoolSourceAuthSecret struct { + Usage string `xml:"usage,attr"` +} + +type StoragePoolSourceAuth struct { + Type string `xml:"type,attr"` + Username string `xml:"username,attr"` + Secret *StoragePoolSourceAuthSecret `xml:"secret"` +} + +type StoragePoolSourceVendor struct { + Name string `xml:"name,attr"` +} + +type StoragePoolSourceProduct struct { + Name string `xml:"name,attr"` +} + +type StoragePoolSourceAdapterParentAddrAddress struct { + Domain string `xml:"domain,attr"` + Bus string `xml:"bus,attr"` + Slot string `xml:"slot,attr"` + Addr string `xml:"addr,attr"` +} + +type StoragePoolSourceAdapterParentAddr struct { + UniqueID uint64 `xml:"unique_id,attr"` + Address *StoragePoolSourceAdapterParentAddrAddress `xml:"address"` +} + +type StoragePoolSourceAdapter struct { + Type string `xml:"type,attr"` + Name string `xml:"name,attr,omitempty"` + Parent string `xml:"parent,attr,omitempty"` + WWNN string `xml:"wwnn,attr,omitempty"` + WWPN string `xml:"wwpn,attr,omitempty"` + ParentAddr *StoragePoolSourceAdapterParentAddr `xml:"parentaddr"` +} + +type StoragePoolSource struct { + Host *StoragePoolSourceHost `xml:"host"` + Device *StoragePoolSourceDevice `xml:"device"` + Auth *StoragePoolSourceAuth `xml:"auth"` + Vendor *StoragePoolSourceVendor `xml:"vendor"` + Product *StoragePoolSourceProduct `xml:"product"` + Format *StoragePoolSourceFormat `xml:"format"` + Adapter *StoragePoolSourceAdapter `xml:"adapter"` +} + +type StoragePool struct { + XMLName xml.Name `xml:"pool"` + Type string `xml:"type,attr"` + Name string `xml:"name"` + UUID string `xml:"uuid,omitempty"` + Allocation *StoragePoolSize `xml:"allocation,omitempty"` + Capacity *StoragePoolSize `xml:"capacity,omitempty"` + Available *StoragePoolSize `xml:"available,omitempty"` + Target *StoragePoolTarget `xml:"target"` + Source *StoragePoolSource `xml:"source"` +} + +func (s *StoragePool) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), s) +} + +func (s *StoragePool) Marshal() (string, error) { + doc, err := xml.MarshalIndent(s, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/storage_pool_test.go b/vendor/github.com/libvirt/libvirt-go-xml/storage_pool_test.go new file mode 100644 index 00000000..c1ccfb4b --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/storage_pool_test.go @@ -0,0 +1,239 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +var storagePoolTestData = []struct { + Object *StoragePool + Expected []string +}{ + { + Object: &StoragePool{ + Type: "dir", + Name: "pool", + UUID: "3e3fce45-4f53-4fa7-bb32-11f34168b82b", + Allocation: &StoragePoolSize{Value: 1000000}, + Capacity: &StoragePoolSize{Value: 5000000}, + Available: &StoragePoolSize{Value: 3000000}, + }, + Expected: []string{ + `<pool type="dir">`, + ` <name>pool</name>`, + ` <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid>`, + ` <allocation>1000000</allocation>`, + ` <capacity>5000000</capacity>`, + ` <available>3000000</available>`, + `</pool>`, + }, + }, + { + Object: &StoragePool{ + Type: "iscsi", + Name: "pool", + Source: &StoragePoolSource{ + Host: &StoragePoolSourceHost{ + Name: "host.example.com", + }, + Device: &StoragePoolSourceDevice{ + Path: "pool.example.com:iscsi-pool", + }, + Auth: &StoragePoolSourceAuth{ + Type: "chap", + Username: "username", + Secret: &StoragePoolSourceAuthSecret{ + Usage: "cluster", + }, + }, + Vendor: &StoragePoolSourceVendor{ + Name: "vendor", + }, + Product: &StoragePoolSourceProduct{ + Name: "product", + }, + }, + }, + Expected: []string{ + `<pool type="iscsi">`, + ` <name>pool</name>`, + ` <source>`, + ` <host name="host.example.com"></host>`, + ` <device path="pool.example.com:iscsi-pool"></device>`, + ` <auth type="chap" username="username">`, + ` <secret usage="cluster"></secret>`, + ` </auth>`, + ` <vendor name="vendor"></vendor>`, + ` <product name="product"></product>`, + ` </source>`, + `</pool>`, + }, + }, + { + Object: &StoragePool{ + Type: "disk", + Name: "pool", + Source: &StoragePoolSource{ + Device: &StoragePoolSourceDevice{ + Path: "/dev/mapper/pool", + PartSeparator: "no", + }, + Format: &StoragePoolSourceFormat{ + Type: "gpt", + }, + }, + }, + Expected: []string{ + `<pool type="disk">`, + ` <name>pool</name>`, + ` <source>`, + ` <device path="/dev/mapper/pool" part_separator="no"></device>`, + ` <format type="gpt"></format>`, + ` </source>`, + `</pool>`, + }, + }, + { + Object: &StoragePool{ + Type: "scsi", + Name: "pool", + Source: &StoragePoolSource{ + Adapter: &StoragePoolSourceAdapter{ + Type: "scsi_host", + Name: "scsi_host", + }, + }, + }, + Expected: []string{ + `<pool type="scsi">`, + ` <name>pool</name>`, + ` <source>`, + ` <adapter type="scsi_host" name="scsi_host"></adapter>`, + ` </source>`, + `</pool>`, + }, + }, + { + Object: &StoragePool{ + Type: "scsi", + Name: "pool", + Source: &StoragePoolSource{ + Adapter: &StoragePoolSourceAdapter{ + Type: "scsi_host", + ParentAddr: &StoragePoolSourceAdapterParentAddr{ + UniqueID: 1, + Address: &StoragePoolSourceAdapterParentAddrAddress{ + Domain: "0x0000", + Bus: "0x00", + Slot: "0x1f", + Addr: "0x2", + }, + }, + }, + }, + }, + Expected: []string{ + `<pool type="scsi">`, + ` <name>pool</name>`, + ` <source>`, + ` <adapter type="scsi_host">`, + ` <parentaddr unique_id="1">`, + ` <address domain="0x0000" bus="0x00" slot="0x1f" addr="0x2"></address>`, + ` </parentaddr>`, + ` </adapter>`, + ` </source>`, + `</pool>`, + }, + }, + { + Object: &StoragePool{ + Type: "fs", + Name: "pool", + Source: &StoragePoolSource{ + Adapter: &StoragePoolSourceAdapter{ + Type: "fc_host", + Parent: "scsi_parent", + WWNN: "20000000c9831b4b", + WWPN: "10000000c9831b4b", + }, + }, + }, + Expected: []string{ + `<pool type="fs">`, + ` <name>pool</name>`, + ` <source>`, + ` <adapter type="fc_host" parent="scsi_parent" wwnn="20000000c9831b4b" wwpn="10000000c9831b4b"></adapter>`, + ` </source>`, + `</pool>`, + }, + }, + { + Object: &StoragePool{ + Type: "dir", + Name: "pool", + Target: &StoragePoolTarget{ + Path: "/pool", + Permissions: &StoragePoolTargetPermissions{ + Owner: "1", + Group: "1", + Mode: "0744", + Label: "pool", + }, + }, + }, + Expected: []string{ + `<pool type="dir">`, + ` <name>pool</name>`, + ` <target>`, + ` <path>/pool</path>`, + ` <permissions>`, + ` <owner>1</owner>`, + ` <group>1</group>`, + ` <mode>0744</mode>`, + ` <label>pool</label>`, + ` </permissions>`, + ` </target>`, + `</pool>`, + }, + }, +} + +func TestStoragePool(t *testing.T) { + for _, test := range storagePoolTestData { + doc, err := test.Object.Marshal() + if err != nil { + t.Fatal(err) + } + + expect := strings.Join(test.Expected, "\n") + + if doc != expect { + t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n") + } + } +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/storage_vol.go b/vendor/github.com/libvirt/libvirt-go-xml/storage_vol.go new file mode 100644 index 00000000..8d4bdfd3 --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/storage_vol.go @@ -0,0 +1,95 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +import "encoding/xml" + +type StorageVolumeSize struct { + Unit string `xml:"unit,attr,omitempty"` + Value uint64 `xml:",chardata"` +} + +type StorageVolumeTargetPermissions struct { + Owner string `xml:"owner,omitempty"` + Group string `xml:"group,omitempty"` + Mode string `xml:"mode,omitempty"` + Label string `xml:"label,omitempty"` +} + +type StorageVolumeTargetFeature struct { + LazyRefcounts *struct{} `xml:"lazy_refcounts"` +} + +type StorageVolumeTargetFormat struct { + Type string `xml:"type,attr"` +} + +type StorageVolumeTargetTimestamps struct { + Atime string `xml:"atime"` + Mtime string `xml:"mtime"` + Ctime string `xml:"ctime"` +} + +type StorageVolumeTarget struct { + Path string `xml:"path,omitempty"` + Format *StorageVolumeTargetFormat `xml:"format"` + Permissions *StorageVolumeTargetPermissions `xml:"permissions"` + Timestamps *StorageVolumeTargetTimestamps `xml:"timestamps"` + Compat string `xml:"compat,omitempty"` + NoCOW *struct{} `xml:"nocow"` + Features []StorageVolumeTargetFeature `xml:"features"` + Encryption *StorageEncryption `xml:"encryption"` +} + +type StorageVolumeBackingStore struct { + Path string `xml:"path"` + Format *StorageVolumeTargetFormat `xml:"format"` + Permissions *StorageVolumeTargetPermissions `xml:"permissions"` +} + +type StorageVolume struct { + XMLName xml.Name `xml:"volume"` + Type string `xml:"type,attr,omitempty"` + Name string `xml:"name"` + Key string `xml:"key,omitempty"` + Allocation *StorageVolumeSize `xml:"allocation"` + Capacity *StorageVolumeSize `xml:"capacity"` + Physical *StorageVolumeSize `xml:"physical"` + Target *StorageVolumeTarget `xml:"target"` + BackingStore *StorageVolumeBackingStore `xml:"backingStore"` +} + +func (s *StorageVolume) Unmarshal(doc string) error { + return xml.Unmarshal([]byte(doc), s) +} + +func (s *StorageVolume) Marshal() (string, error) { + doc, err := xml.MarshalIndent(s, "", " ") + if err != nil { + return "", err + } + return string(doc), nil +} diff --git a/vendor/github.com/libvirt/libvirt-go-xml/storage_vol_test.go b/vendor/github.com/libvirt/libvirt-go-xml/storage_vol_test.go new file mode 100644 index 00000000..14809d7a --- /dev/null +++ b/vendor/github.com/libvirt/libvirt-go-xml/storage_vol_test.go @@ -0,0 +1,245 @@ +/* + * 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 Red Hat, Inc. + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +var storageVolumeTestData = []struct { + Object *StorageVolume + Expected []string +}{ + { + Object: &StorageVolume{ + Type: "file", + Name: "file.img", + Key: "/file.img", + Allocation: &StorageVolumeSize{ + Value: 0, + }, + + Capacity: &StorageVolumeSize{ + Unit: "T", + Value: 1, + }, + }, + Expected: []string{ + `<volume type="file">`, + ` <name>file.img</name>`, + ` <key>/file.img</key>`, + ` <allocation>0</allocation>`, + ` <capacity unit="T">1</capacity>`, + `</volume>`, + }, + }, + { + Object: &StorageVolume{ + Type: "file", + Name: "file.img", + Target: &StorageVolumeTarget{ + Path: "/file.img", + Format: &StorageVolumeTargetFormat{ + Type: "qcow2", + }, + Permissions: &StorageVolumeTargetPermissions{ + Owner: "107", + Group: "107", + Mode: "0744", + Label: "image", + }, + Timestamps: &StorageVolumeTargetTimestamps{ + Atime: "1341933637.273190990", + Mtime: "1341930622.047245868", + Ctime: "1341930622.047245868", + }, + Compat: "1.1", + NoCOW: &struct{}{}, + Features: []StorageVolumeTargetFeature{ + StorageVolumeTargetFeature{ + LazyRefcounts: &struct{}{}, + }, + }, + }, + }, + Expected: []string{ + `<volume type="file">`, + ` <name>file.img</name>`, + ` <target>`, + ` <path>/file.img</path>`, + ` <format type="qcow2"></format>`, + ` <permissions>`, + ` <owner>107</owner>`, + ` <group>107</group>`, + ` <mode>0744</mode>`, + ` <label>image</label>`, + ` </permissions>`, + ` <timestamps>`, + ` <atime>1341933637.273190990</atime>`, + ` <mtime>1341930622.047245868</mtime>`, + ` <ctime>1341930622.047245868</ctime>`, + ` </timestamps>`, + ` <compat>1.1</compat>`, + ` <nocow></nocow>`, + ` <features>`, + ` <lazy_refcounts></lazy_refcounts>`, + ` </features>`, + ` </target>`, + `</volume>`, + }, + }, + { + Object: &StorageVolume{ + Type: "file", + Name: "file.img", + BackingStore: &StorageVolumeBackingStore{ + Path: "/master.img", + Format: &StorageVolumeTargetFormat{ + Type: "raw", + }, + Permissions: &StorageVolumeTargetPermissions{ + Owner: "107", + Group: "107", + Mode: "0744", + Label: "label", + }, + }, + }, + Expected: []string{ + `<volume type="file">`, + ` <name>file.img</name>`, + ` <backingStore>`, + ` <path>/master.img</path>`, + ` <format type="raw"></format>`, + ` <permissions>`, + ` <owner>107</owner>`, + ` <group>107</group>`, + ` <mode>0744</mode>`, + ` <label>label</label>`, + ` </permissions>`, + ` </backingStore>`, + `</volume>`, + }, + }, + { + Object: &StorageVolume{ + Name: "luks.img", + Capacity: &StorageVolumeSize{ + Unit: "G", + Value: 5, + }, + Target: &StorageVolumeTarget{ + Path: "/luks.img", + Format: &StorageVolumeTargetFormat{ + Type: "raw", + }, + Encryption: &StorageEncryption{ + Format: "luks", + Secret: &StorageEncryptionSecret{ + Type: "passphrase", + UUID: "f52a81b2-424e-490c-823d-6bd4235bc572", + }, + }, + }, + }, + Expected: []string{ + `<volume>`, + ` <name>luks.img</name>`, + ` <capacity unit="G">5</capacity>`, + ` <target>`, + ` <path>/luks.img</path>`, + ` <format type="raw"></format>`, + ` <encryption format="luks">`, + ` <secret type="passphrase" uuid="f52a81b2-424e-490c-823d-6bd4235bc572"></secret>`, + ` </encryption>`, + ` </target>`, + `</volume>`, + }, + }, + { + Object: &StorageVolume{ + Name: "twofish", + Capacity: &StorageVolumeSize{ + Unit: "G", + Value: 5, + }, + Target: &StorageVolumeTarget{ + Path: "/twofish.luks", + Format: &StorageVolumeTargetFormat{ + Type: "raw", + }, + Encryption: &StorageEncryption{ + Format: "luks", + Secret: &StorageEncryptionSecret{ + Type: "passphrase", + UUID: "f52a81b2-424e-490c-823d-6bd4235bc572", + }, + Cipher: &StorageEncryptionCipher{ + Name: "twofish", + Size: 256, + Mode: "cbc", + Hash: "sha256", + }, + Ivgen: &StorageEncryptionIvgen{ + Name: "plain64", + Hash: "sha256", + }, + }, + }, + }, + Expected: []string{ + `<volume>`, + ` <name>twofish</name>`, + ` <capacity unit="G">5</capacity>`, + ` <target>`, + ` <path>/twofish.luks</path>`, + ` <format type="raw"></format>`, + ` <encryption format="luks">`, + ` <secret type="passphrase" uuid="f52a81b2-424e-490c-823d-6bd4235bc572"></secret>`, + ` <cipher name="twofish" size="256" mode="cbc" hash="sha256"></cipher>`, + ` <ivgen name="plain64" hash="sha256"></ivgen>`, + ` </encryption>`, + ` </target>`, + `</volume>`, + }, + }, +} + +func TestStorageVolume(t *testing.T) { + for _, test := range storageVolumeTestData { + doc, err := test.Object.Marshal() + if err != nil { + t.Fatal(err) + } + + expect := strings.Join(test.Expected, "\n") + + if doc != expect { + t.Fatal("Bad xml:\n", string(doc), "\n does not match\n", expect, "\n") + } + } +} diff --git a/vendor/github.com/libvirt/libvirt-go/domain.go b/vendor/github.com/libvirt/libvirt-go/domain.go index f2ac6fc5..cc786dde 100644 --- a/vendor/github.com/libvirt/libvirt-go/domain.go +++ b/vendor/github.com/libvirt/libvirt-go/domain.go @@ -606,8 +606,9 @@ const ( type DomainBlockCopyFlags int const ( - DOMAIN_BLOCK_COPY_SHALLOW = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_SHALLOW) - DOMAIN_BLOCK_COPY_REUSE_EXT = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_REUSE_EXT) + DOMAIN_BLOCK_COPY_SHALLOW = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_SHALLOW) + DOMAIN_BLOCK_COPY_REUSE_EXT = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_REUSE_EXT) + DOMAIN_BLOCK_COPY_TRANSIENT_JOB = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB) ) type DomainBlockRebaseFlags int diff --git a/vendor/github.com/libvirt/libvirt-go/domain_compat.h b/vendor/github.com/libvirt/libvirt-go/domain_compat.h index 8f218eff..60538038 100644 --- a/vendor/github.com/libvirt/libvirt-go/domain_compat.h +++ b/vendor/github.com/libvirt/libvirt-go/domain_compat.h @@ -952,4 +952,10 @@ int virDomainSetBlockThresholdCompat(virDomainPtr domain, #endif +/* 3.5.0 */ + +#ifndef VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB +#define VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB 1 << 2 +#endif + #endif /* LIBVIRT_GO_DOMAIN_COMPAT_H__ */ |