From ed3000f4d3b2ee5eeab855f32e9fde80193944df Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Thu, 20 Jul 2017 12:17:18 +0200 Subject: vendor: add libvirt-go-xml Signed-off-by: Thomas Hipp --- .../github.com/libvirt/libvirt-go-xml/.gitignore | 3 + .../github.com/libvirt/libvirt-go-xml/.travis.yml | 11 + vendor/github.com/libvirt/libvirt-go-xml/LICENSE | 19 + vendor/github.com/libvirt/libvirt-go-xml/README.md | 67 + .../libvirt/libvirt-go-xml/capabilities.go | 156 +++ vendor/github.com/libvirt/libvirt-go-xml/doc.go | 62 + .../github.com/libvirt/libvirt-go-xml/document.go | 6 + vendor/github.com/libvirt/libvirt-go-xml/domain.go | 794 +++++++++++ .../libvirt/libvirt-go-xml/domain_snapshot.go | 79 ++ .../libvirt/libvirt-go-xml/domain_snapshot_test.go | 190 +++ .../libvirt/libvirt-go-xml/domain_test.go | 1475 ++++++++++++++++++++ .../github.com/libvirt/libvirt-go-xml/network.go | 166 +++ .../libvirt/libvirt-go-xml/network_test.go | 219 +++ vendor/github.com/libvirt/libvirt-go-xml/secret.go | 58 + .../libvirt/libvirt-go-xml/secret_test.go | 160 +++ .../libvirt/libvirt-go-xml/storage_encryption.go | 50 + .../libvirt/libvirt-go-xml/storage_pool.go | 138 ++ .../libvirt/libvirt-go-xml/storage_pool_test.go | 239 ++++ .../libvirt/libvirt-go-xml/storage_vol.go | 95 ++ .../libvirt/libvirt-go-xml/storage_vol_test.go | 245 ++++ vendor/github.com/libvirt/libvirt-go/domain.go | 5 +- .../github.com/libvirt/libvirt-go/domain_compat.h | 6 + 22 files changed, 4241 insertions(+), 2 deletions(-) create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/.gitignore create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/.travis.yml create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/LICENSE create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/README.md create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/capabilities.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/doc.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/document.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/domain.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/domain_snapshot_test.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/domain_test.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/network.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/network_test.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/secret.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/secret_test.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/storage_encryption.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/storage_pool.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/storage_pool_test.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/storage_vol.go create mode 100644 vendor/github.com/libvirt/libvirt-go-xml/storage_vol_test.go (limited to 'vendor') 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{ + ``, + ` Snapshot`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` 1270477159`, + ` Snapshot of OS install and updates`, + ` running`, + ` 1270477159`, + ` `, + ` bare-os-install`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` fedora`, + ` 1048576`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, +} + +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{ + ``, + ` test`, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` fishfood`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + ` `, + ` `, + `
`, + `
`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` test`, + ` 8192`, + ` 4096`, + ` 16384`, + ` `, + ` `, + ` manufacturer`, + ` product`, + ` version`, + ` `, + ` `, + ` vendor`, + ` `, + ` `, + ` manufacturer`, + ` product`, + ` version`, + ` serial`, + ` `, + ` `, + ` `, + ` hvm`, + ` /loader`, + ` `, + ` `, + ` `, + ` /bin/systemd`, + ` --unit`, + ` emergency.service`, + ` `, + ` `, + ``, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + OS: &DomainOS{ + NVRam: &DomainNVRam{ + Template: "/t.fd", + NVRam: "/vars.fd", + }, + BootMenu: &DomainBootMenu{ + Enabled: "yes", + Timeout: "3000", + }, + }, + }, + Expected: []string{ + ``, + ` test`, + ` `, + ` /vars.fd`, + ` `, + ` `, + ``, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + OS: &DomainOS{ + Kernel: "/vmlinuz", + Initrd: "/initrd", + KernelArgs: "arg", + }, + }, + Expected: []string{ + ``, + ` test`, + ` `, + ` /vmlinuz`, + ` /initrd`, + ` arg`, + ` `, + ``, + }, + }, + { + Object: &Domain{ + Type: "kvm", + Name: "test", + Resource: &DomainResource{ + Partition: "/machines/production", + }, + }, + Expected: []string{ + ``, + ` test`, + ` `, + ` /machines/production`, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` 2`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` core2duo`, + ` Intel`, + ` `, + ` `, + ` `, + ` `, + ` /bin/qemu-kvm`, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + ` `, + ` `, + ` `, + ` `, + ` `, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + `
`, + `
`, + ` `, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + + /* 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{ + ``, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` `, + ` `, + ` `, + ` fishfood`, + ` 0123456789abcdef`, + ``, + }, + }, + { + 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{ + ``, + ` `, + ` `, + ` `, + `
`, + `
`, + }, + }, + { + Object: &DomainInterface{ + Type: "network", + MAC: &DomainInterfaceMAC{ + Address: "00:11:22:33:44:55", + }, + Model: &DomainInterfaceModel{ + Type: "virtio", + }, + }, + Expected: []string{ + ``, + ` `, + ` `, + ``, + }, + }, + { + Object: &DomainSerial{ + Type: "pty", + Target: &DomainSerialTarget{ + Type: "isa", + Port: &serialPort, + }, + }, + + Expected: []string{ + ``, + ` `, + ``, + }, + }, + { + Object: &DomainConsole{ + Type: "pty", + Target: &DomainConsoleTarget{ + Type: "virtio", + Port: &serialPort, + }, + }, + + Expected: []string{ + ``, + ` `, + ``, + }, + }, + { + Object: &DomainInput{ + Type: "tablet", + Bus: "usb", + Address: &DomainAddress{ + Type: "usb", + Bus: &tabletBus, + Port: &tabletPort, + }, + }, + + Expected: []string{ + ``, + `
`, + ``, + }, + }, + { + 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{ + ``, + }, + }, + { + Object: &DomainChannel{ + Type: "pty", + Target: &DomainChannelTarget{ + Type: "virtio", + Name: "org.redhat.spice", + State: "connected", + }, + }, + + Expected: []string{ + ``, + ` `, + ``, + }, + }, + { + Object: &DomainMemBalloon{ + Model: "virtio", + Address: &DomainAddress{ + Type: "pci", + Domain: &balloonAddr.Domain, + Bus: &balloonAddr.Bus, + Slot: &balloonAddr.Slot, + Function: &balloonAddr.Function, + }, + }, + + Expected: []string{ + ``, + `
`, + `
`, + }, + }, + { + 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{ + ``, + ` `, + `
`, + `
`, + }, + }, + { + Object: &DomainRNG{ + Model: "virtio", + Rate: &DomainRNGRate{ + Period: 2000, + Bytes: 1234, + }, + Backend: &DomainRNGBackend{ + Device: "/dev/random", + Model: "random", + }, + }, + + Expected: []string{ + ``, + ` `, + ` /dev/random`, + ``, + }, + }, + { + Object: &DomainRNG{ + Model: "virtio", + Rate: &DomainRNGRate{ + Period: 2000, + Bytes: 1234, + }, + Backend: &DomainRNGBackend{ + Model: "egd", + Type: "udp", + Sources: []DomainInterfaceSource{ + DomainInterfaceSource{ + Mode: "bind", + Service: "1234", + }, + DomainInterfaceSource{ + Mode: "connect", + Host: "1.2.3.4", + Service: "1234", + }, + }, + }, + }, + + Expected: []string{ + ``, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, +} + +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 + * + */ + +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 + * + */ + +package libvirtxml + +import ( + "strings" + "testing" +) + +var networkTestData = []struct { + Object *Network + Expected []string +}{ + { + Object: &Network{ + Name: "test", + IPv6: "yes", + }, + Expected: []string{ + ``, + ` test`, + ``, + }, + }, + { + Object: &Network{ + Name: "test", + Domain: &NetworkDomain{ + Name: "example.com", + }, + }, + Expected: []string{ + ``, + ` test`, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` test`, + ` `, + ` `, + ` `, + `
`, + ` `, + `
`, + `
`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` myhost`, + ` myhostalias`, + ` `, + ` `, + ` `, + `
`, + }, + }, +} + +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{ + ``, + ` Demo`, + ``, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + }, + Expected: []string{ + ``, + ` Demo`, + ` 55806c7d-8e93-456f-829b-607d8c198367`, + ``, + }, + }, + { + 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{ + ``, + ` Demo`, + ` 55806c7d-8e93-456f-829b-607d8c198367`, + ` `, + ` /var/lib/libvirt/images/puppyname.img`, + ` `, + ``, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "ceph", + Name: "mycluster", + }, + }, + Expected: []string{ + ``, + ` Demo`, + ` 55806c7d-8e93-456f-829b-607d8c198367`, + ` `, + ` mycluster`, + ` `, + ``, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "iscsi", + Target: "libvirtiscsi", + }, + }, + Expected: []string{ + ``, + ` Demo`, + ` 55806c7d-8e93-456f-829b-607d8c198367`, + ` `, + ` libvirtiscsi`, + ` `, + ``, + }, + }, + { + Object: &Secret{ + Description: "Demo", + Private: "yes", + Ephemeral: "yes", + UUID: "55806c7d-8e93-456f-829b-607d8c198367", + Usage: &SecretUsage{ + Type: "tls", + Name: "Demo cert", + }, + }, + Expected: []string{ + ``, + ` Demo`, + ` 55806c7d-8e93-456f-829b-607d8c198367`, + ` `, + ` Demo cert`, + ` `, + ``, + }, + }, +} + +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`, + ` 3e3fce45-4f53-4fa7-bb32-11f34168b82b`, + ` 1000000`, + ` 5000000`, + ` 3000000`, + ``, + }, + }, + { + 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`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + Object: &StoragePool{ + Type: "disk", + Name: "pool", + Source: &StoragePoolSource{ + Device: &StoragePoolSourceDevice{ + Path: "/dev/mapper/pool", + PartSeparator: "no", + }, + Format: &StoragePoolSourceFormat{ + Type: "gpt", + }, + }, + }, + Expected: []string{ + ``, + ` pool`, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + Object: &StoragePool{ + Type: "scsi", + Name: "pool", + Source: &StoragePoolSource{ + Adapter: &StoragePoolSourceAdapter{ + Type: "scsi_host", + Name: "scsi_host", + }, + }, + }, + Expected: []string{ + ``, + ` 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`, + ` `, + ` `, + ` `, + `
`, + `
`, + `
`, + ` `, + `
`, + }, + }, + { + Object: &StoragePool{ + Type: "fs", + Name: "pool", + Source: &StoragePoolSource{ + Adapter: &StoragePoolSourceAdapter{ + Type: "fc_host", + Parent: "scsi_parent", + WWNN: "20000000c9831b4b", + WWPN: "10000000c9831b4b", + }, + }, + }, + Expected: []string{ + ``, + ` pool`, + ` `, + ` `, + ` `, + ``, + }, + }, + { + Object: &StoragePool{ + Type: "dir", + Name: "pool", + Target: &StoragePoolTarget{ + Path: "/pool", + Permissions: &StoragePoolTargetPermissions{ + Owner: "1", + Group: "1", + Mode: "0744", + Label: "pool", + }, + }, + }, + Expected: []string{ + ``, + ` pool`, + ` `, + ` /pool`, + ` `, + ` 1`, + ` 1`, + ` 0744`, + ` `, + ` `, + ` `, + ``, + }, + }, +} + +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{ + ``, + ` file.img`, + ` /file.img`, + ` 0`, + ` 1`, + ``, + }, + }, + { + 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{ + ``, + ` file.img`, + ` `, + ` /file.img`, + ` `, + ` `, + ` 107`, + ` 107`, + ` 0744`, + ` `, + ` `, + ` `, + ` 1341933637.273190990`, + ` 1341930622.047245868`, + ` 1341930622.047245868`, + ` `, + ` 1.1`, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` file.img`, + ` `, + ` /master.img`, + ` `, + ` `, + ` 107`, + ` 107`, + ` 0744`, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` luks.img`, + ` 5`, + ` `, + ` /luks.img`, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, + { + 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{ + ``, + ` twofish`, + ` 5`, + ` `, + ` /twofish.luks`, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ` `, + ``, + }, + }, +} + +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__ */ -- cgit v1.2.3