Bring KVM driver in-tree

Add boilerplate

Review feedback
pull/1828/head
Matt Rickard 2017-08-16 11:17:25 -07:00
parent 1052dda37a
commit 48b165808c
79 changed files with 18022 additions and 2 deletions

5
Godeps/Godeps.json generated
View File

@ -1758,6 +1758,11 @@
"ImportPath": "github.com/libopenstorage/openstorage/volume",
"Rev": "6e787003b91ddba85f108b8aede075b1af0d3606"
},
{
"ImportPath": "github.com/libvirt/libvirt-go",
"Comment": "v3.4.0",
"Rev": "5ba8227244c30438609adcec6ea84dc1e688dfbd"
},
{
"ImportPath": "github.com/lpabon/godbc",
"Comment": "v1.0-1-g9577782",

View File

@ -53,6 +53,8 @@ LOCALKUBEFILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' ./cmd/local
MINIKUBEFILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' ./cmd/minikube/ | grep k8s.io | GOPATH=$(GOPATH) xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}'
HYPERKIT_FILES := GOPATH=$(GOPATH) go list -f '{{join .Deps "\n"}}' k8s.io/minikube/cmd/drivers/hyperkit | grep k8s.io | GOPATH=$(GOPATH) xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}'
KVM_DRIVER_FILES := $(shell go list -f '{{join .Deps "\n"}}' ./cmd/drivers/kvm/ | grep k8s.io | xargs go list -f '{{ range $$file := .GoFiles }} {{$$.Dir}}/{{$$file}}{{"\n"}}{{end}}')
MINIKUBE_ENV_linux := CGO_ENABLED=1 GOARCH=amd64 GOOS=linux
MINIKUBE_ENV_darwin := CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin
MINIKUBE_ENV_windows := CGO_ENABLED=0 GOARCH=amd64 GOOS=windows
@ -163,7 +165,7 @@ $(GOPATH)/bin/go-bindata:
GOBIN=$(GOPATH)/bin go get github.com/jteeuwen/go-bindata/...
.PHONY: cross
cross: out/localkube out/minikube-linux-amd64 out/minikube-darwin-amd64 out/minikube-windows-amd64.exe out/docker-machine-driver-hyperkit
cross: out/localkube out/minikube-linux-amd64 out/minikube-darwin-amd64 out/minikube-windows-amd64.exe out/docker-machine-driver-hyperkit out/docker-machine-driver-kvm2
.PHONY: e2e-cross
e2e-cross: e2e-linux-amd64 e2e-darwin-amd64 e2e-windows-amd64.exe

28
cmd/drivers/kvm/main.go Normal file
View File

@ -0,0 +1,28 @@
// +build linux
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"github.com/docker/machine/libmachine/drivers/plugin"
"k8s.io/minikube/pkg/drivers/kvm"
)
func main() {
plugin.RegisterDriver(kvm.NewDriver("", ""))
}

View File

@ -79,6 +79,9 @@ sudo rm -rf $HOME/.kube || true
# See the default image
./out/minikube-${OS_ARCH} start -h | grep iso
# see what driver we are using
which docker-machine-driver-${VM_DRIVER} || true
# Allow this to fail, we'll switch on the return code below.
set +e
${SUDO_PREFIX}out/e2e-${OS_ARCH} -minikube-args="--vm-driver=${VM_DRIVER} --v=10 --logtostderr" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH}

View File

@ -40,9 +40,10 @@ fi
export GOPATH=~/go
# Cross build the binary and test binary for all platforms (Windows, Linux, OSX).
# Build the e2e test target for Darwin and Linux. We don't run tests on Windows yet.
# We build these on Linux, but run the tests on different platforms.
# This makes it easier to provision slaves, since they don't need to have a go toolchain.'
# Cross also builds the hyperkit and kvm2 drivers.
BUILD_IN_DOCKER=y make cross e2e-cross
cp -r test/integration/testdata out/

152
pkg/drivers/kvm/domain.go Normal file
View File

@ -0,0 +1,152 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kvm
import (
"bytes"
"fmt"
"text/template"
libvirt "github.com/libvirt/libvirt-go"
"github.com/pkg/errors"
)
const domainTmpl = `
<domain type='kvm'>
<name>{{.MachineName}}</name>
<memory unit='MB'>{{.Memory}}</memory>
<vcpu>{{.CPU}}</vcpu>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<os>
<type>hvm</type>
<boot dev='cdrom'/>
<boot dev='hd'/>
<bootmenu enable='no'/>
</os>
<devices>
<disk type='file' device='cdrom'>
<source file='{{.ISO}}'/>
<target dev='hdc' bus='scsi'/>
<readonly/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='default' io='threads' />
<source file='{{.DiskPath}}'/>
<target dev='hda' bus='virtio'/>
</disk>
<interface type='network'>
<source network='{{.Network}}'/>
<model type='virtio'/>
</interface>
<interface type='network'>
<source network='{{.PrivateNetwork}}'/>
<model type='virtio'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target port='0'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target port='0'/>
</console>
<rng model='virtio'>
<backend model='random'>/dev/random</backend>
</rng>
</devices>
</domain>
`
const connectionErrorText = `
Error connecting to libvirt socket. Have you set up libvirt correctly?
# Install libvirt and qemu-kvm on your system, e.g.
# Debian/Ubuntu
$ sudo apt install libvirt-bin qemu-kvm
# Fedora/CentOS/RHEL
$ sudo yum install libvirt-daemon-kvm qemu-kvm
# Add yourself to the libvirtd group (use libvirt group for rpm based distros) so you don't need to sudo
# Debian/Ubuntu (NOTE: For Ubuntu 17.04 change the group to libvirt)
$ sudo usermod -a -G libvirtd $(whoami)
# Fedora/CentOS/RHEL
$ sudo usermod -a -G libvirt $(whoami)
# Update your current session for the group change to take effect
# Debian/Ubuntu (NOTE: For Ubuntu 17.04 change the group to libvirt)
$ newgrp libvirtd
# Fedora/CentOS/RHEL
$ newgrp libvirt
Visit https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#kvm-driver for more information.
`
func (d *Driver) getDomain() (*libvirt.Domain, *libvirt.Connect, error) {
conn, err := getConnection()
if err != nil {
return nil, nil, errors.Wrap(err, "getting domain")
}
dom, err := conn.LookupDomainByName(d.MachineName)
if err != nil {
return nil, nil, errors.Wrap(err, "looking up domain")
}
return dom, conn, nil
}
func getConnection() (*libvirt.Connect, error) {
conn, err := libvirt.NewConnect(qemusystem)
if err != nil {
return nil, errors.Wrap(err, connectionErrorText)
}
return conn, nil
}
func closeDomain(dom *libvirt.Domain, conn *libvirt.Connect) error {
dom.Free()
if res, _ := conn.Close(); res != 0 {
return fmt.Errorf("Error closing connection CloseConnection() == %d, expected 0", res)
}
return nil
}
func (d *Driver) createDomain() (*libvirt.Domain, error) {
tmpl := template.Must(template.New("domain").Parse(domainTmpl))
var domainXml bytes.Buffer
if err := tmpl.Execute(&domainXml, d); err != nil {
return nil, errors.Wrap(err, "executing domain xml")
}
conn, err := getConnection()
if err != nil {
return nil, errors.Wrap(err, "Error getting libvirt connection")
}
defer conn.Close()
dom, err := conn.DomainDefineXML(domainXml.String())
if err != nil {
return nil, errors.Wrapf(err, "Error defining domain xml: %s", domainXml.String())
}
return dom, nil
}

382
pkg/drivers/kvm/kvm.go Normal file
View File

@ -0,0 +1,382 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kvm
import (
"fmt"
"os"
"path/filepath"
"time"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/util"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/state"
libvirt "github.com/libvirt/libvirt-go"
"github.com/pkg/errors"
)
const (
qemusystem = "qemu:///system"
defaultPrivateNetworkName = "minikube-net"
)
type Driver struct {
*drivers.BaseDriver
// How much memory, in MB, to allocate to the VM
Memory int
// How many cpus to allocate to the VM
CPU int
// The name of the default network
Network string
// The name of the private network
PrivateNetwork string
// The size of the disk to be created for the VM, in MB
DiskSize int
// The path of the disk .img
DiskPath string
// A file or network URI to fetch the minikube ISO
Boot2DockerURL string
// The location of the iso to boot from
ISO string
}
func NewDriver(hostName, storePath string) *Driver {
return &Driver{
BaseDriver: &drivers.BaseDriver{
MachineName: hostName,
StorePath: storePath,
},
Boot2DockerURL: constants.DefaultIsoUrl,
CPU: constants.DefaultCPUS,
PrivateNetwork: defaultPrivateNetworkName,
DiskSize: util.CalculateDiskSizeInMB(constants.DefaultDiskSize),
Memory: constants.DefaultMemory,
Network: defaultNetworkName,
DiskPath: filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), fmt.Sprintf("%s.img", config.GetMachineName())),
ISO: filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), "boot2docker.iso"),
}
}
//Not implemented yet
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return nil
}
//Not implemented yet
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil
}
func (d *Driver) PreCommandCheck() error {
conn, err := getConnection()
if err != nil {
return errors.Wrap(err, "Error connecting to libvirt socket. Have you added yourself to the libvirtd group?")
}
libVersion, err := conn.GetLibVersion()
if err != nil {
return errors.Wrap(err, "getting libvirt version")
}
log.Debugf("Using libvirt version %d", libVersion)
return nil
}
func (d *Driver) GetURL() (string, error) {
if err := d.PreCommandCheck(); err != nil {
return "", errors.Wrap(err, "getting URL, precheck failed")
}
ip, err := d.GetIP()
if err != nil {
return "", errors.Wrap(err, "getting URL, could not get IP")
}
if ip == "" {
return "", nil
}
return fmt.Sprintf("tcp://%s:2376", ip), nil
}
func (d *Driver) GetState() (state.State, error) {
dom, conn, err := d.getDomain()
if err != nil {
return state.None, errors.Wrap(err, "getting connection")
}
defer closeDomain(dom, conn)
libvirtState, _, err := dom.GetState() // state, reason, error
if err != nil {
return state.None, errors.Wrap(err, "getting domain state")
}
switch libvirtState {
case libvirt.DOMAIN_RUNNING:
return state.Running, nil
case libvirt.DOMAIN_BLOCKED, libvirt.DOMAIN_CRASHED:
return state.Error, nil
case libvirt.DOMAIN_PAUSED:
return state.Paused, nil
case libvirt.DOMAIN_SHUTDOWN, libvirt.DOMAIN_SHUTOFF:
return state.Stopped, nil
case libvirt.DOMAIN_PMSUSPENDED:
return state.Saved, nil
case libvirt.DOMAIN_NOSTATE:
return state.None, nil
default:
return state.None, nil
}
}
func (d *Driver) GetIP() (string, error) {
s, err := d.GetState()
if err != nil {
return "", errors.Wrap(err, "machine in unknown state")
}
if s != state.Running {
return "", errors.New("host is not running.")
}
ip, err := d.lookupIP()
if err != nil {
return "", errors.Wrap(err, "getting IP")
}
return ip, nil
}
func (d *Driver) GetMachineName() string {
return d.MachineName
}
func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP()
}
func (d *Driver) GetSSHUsername() string {
return "docker"
}
func (d *Driver) GetSSHKeyPath() string {
return d.ResolveStorePath("id_rsa")
}
func (d *Driver) GetSSHPort() (int, error) {
if d.SSHPort == 0 {
d.SSHPort = 22
}
return d.SSHPort, nil
}
func (d *Driver) DriverName() string {
return "kvm"
}
func (d *Driver) Kill() error {
dom, conn, err := d.getDomain()
if err != nil {
return errors.Wrap(err, "getting connection")
}
defer closeDomain(dom, conn)
return dom.Destroy()
}
func (d *Driver) Restart() error {
dom, conn, err := d.getDomain()
if err != nil {
return errors.Wrap(err, "getting connection")
}
defer closeDomain(dom, conn)
if err := d.Stop(); err != nil {
return errors.Wrap(err, "stopping VM:")
}
return d.Start()
}
func (d *Driver) Start() error {
log.Info("Getting domain xml...")
dom, conn, err := d.getDomain()
if err != nil {
return errors.Wrap(err, "getting connection")
}
defer closeDomain(dom, conn)
log.Info("Creating domain...")
if err := dom.Create(); err != nil {
return errors.Wrap(err, "Error creating VM")
}
log.Info("Waiting to get IP...")
for i := 0; i <= 40; i++ {
ip, err := d.GetIP()
if err != nil {
return errors.Wrap(err, "getting ip during machine start")
}
if ip == "" {
log.Debugf("Waiting for machine to come up %d/%d", i, 40)
time.Sleep(3 * time.Second)
continue
}
if ip != "" {
log.Infof("Found IP for machine: %s", ip)
d.IPAddress = ip
break
}
}
if d.IPAddress == "" {
return errors.New("Machine didn't return an IP after 120 seconds")
}
log.Info("Waiting for SSH to be available...")
if err := drivers.WaitForSSH(d); err != nil {
d.IPAddress = ""
return errors.Wrap(err, "SSH not available after waiting")
}
return nil
}
func (d *Driver) Create() error {
log.Info("Creating machine...")
//TODO(r2d4): rewrite this, not using b2dutils
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, d.MachineName); err != nil {
return errors.Wrap(err, "Error copying ISO to machine dir")
}
log.Info("Creating network...")
err := d.createNetwork()
if err != nil {
return errors.Wrap(err, "creating network")
}
log.Info("Setting up minikube home directory...")
if err := os.MkdirAll(d.ResolveStorePath("."), 0755); err != nil {
return errors.Wrap(err, "Error making store path directory")
}
for dir := d.ResolveStorePath("."); dir != "/"; dir = filepath.Dir(dir) {
info, err := os.Stat(dir)
if err != nil {
return err
}
mode := info.Mode()
if mode&0001 != 1 {
log.Debugf("Setting executable bit set on %s", dir)
mode |= 0001
os.Chmod(dir, mode)
}
}
log.Info("Building disk image...")
err = d.buildDiskImage()
if err != nil {
return errors.Wrap(err, "Error creating disk")
}
log.Info("Creating domain...")
dom, err := d.createDomain()
if err != nil {
return errors.Wrap(err, "creating domain")
}
defer dom.Free()
log.Debug("Finished creating machine, now starting machine...")
return d.Start()
}
func (d *Driver) Stop() error {
d.IPAddress = ""
s, err := d.GetState()
if err != nil {
return errors.Wrap(err, "getting state of VM")
}
if s != state.Stopped {
dom, conn, err := d.getDomain()
defer closeDomain(dom, conn)
if err != nil {
return errors.Wrap(err, "getting connection")
}
err = dom.Shutdown()
if err != nil {
return errors.Wrap(err, "stopping vm")
}
for i := 0; i < 60; i++ {
s, err := d.GetState()
if err != nil {
return errors.Wrap(err, "Error getting state of VM")
}
if s == state.Stopped {
return nil
}
log.Info("Waiting for machine to stop %d/%d", i, 60)
time.Sleep(1 * time.Second)
}
}
return fmt.Errorf("Could not stop VM, current state %s", s.String())
}
func (d *Driver) Remove() error {
log.Debug("Removing machine...")
conn, err := getConnection()
if err != nil {
return errors.Wrap(err, "getting connection")
}
defer conn.Close()
//Tear down network and disk if they exist
network, _ := conn.LookupNetworkByName(d.PrivateNetwork)
log.Debug("Checking if the network needs to be deleted")
if network != nil {
log.Infof("Network %s exists, removing...", d.PrivateNetwork)
network.Destroy()
network.Undefine()
}
log.Debug("Checking if the domain needs to be deleted")
dom, err := conn.LookupDomainByName(d.MachineName)
if dom != nil {
log.Infof("Domain %s exists, removing...", d.MachineName)
dom.Destroy()
dom.Undefine()
}
return nil
}

163
pkg/drivers/kvm/network.go Normal file
View File

@ -0,0 +1,163 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kvm
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"text/template"
"github.com/docker/machine/libmachine/log"
libvirt "github.com/libvirt/libvirt-go"
"github.com/pkg/errors"
)
// Replace with hardcoded range with CIDR
// https://play.golang.org/p/m8TNTtygK0
const networkTmpl = `
<network>
<name>{{.PrivateNetwork}}</name>
<ip address='192.168.39.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.39.2' end='192.168.39.254'/>
</dhcp>
</ip>
</network>
`
const defaultNetworkName = "minikube-net"
func (d *Driver) createNetwork() error {
conn, err := getConnection()
if err != nil {
return errors.Wrap(err, "getting libvirt connection")
}
defer conn.Close()
tmpl := template.Must(template.New("network").Parse(networkTmpl))
var networkXML bytes.Buffer
err = tmpl.Execute(&networkXML, d)
if err != nil {
return errors.Wrap(err, "executing network template")
}
//Check if network already exists
network, err := conn.LookupNetworkByName(d.PrivateNetwork)
if err == nil {
return nil
}
network, err = conn.NetworkDefineXML(networkXML.String())
if err != nil {
return errors.Wrapf(err, "defining network from xml: %s", networkXML.String())
}
err = network.SetAutostart(true)
if err != nil {
return errors.Wrap(err, "setting network to autostart")
}
err = network.Create()
if err != nil {
return errors.Wrap(err, "creating network")
}
return nil
}
func (d *Driver) lookupIP() (string, error) {
conn, err := getConnection()
if err != nil {
return "", errors.Wrap(err, "getting connection and domain")
}
defer conn.Close()
libVersion, err := conn.GetLibVersion()
if err != nil {
return "", errors.Wrap(err, "getting libversion")
}
// Earlier versions of libvirt use a lease file instead of a status file
if libVersion < 1002006 {
return d.lookupIPFromLeasesFile()
}
return d.lookupIPFromStatusFile(conn)
}
func (d *Driver) lookupIPFromStatusFile(conn *libvirt.Connect) (string, error) {
network, err := conn.LookupNetworkByName(d.PrivateNetwork)
if err != nil {
return "", errors.Wrap(err, "looking up network by name")
}
bridge, err := network.GetBridgeName()
if err != nil {
log.Warnf("Failed to get network bridge: %s", err)
return "", err
}
statusFile := fmt.Sprintf("/var/lib/libvirt/dnsmasq/%s.status", bridge)
statuses, err := ioutil.ReadFile(statusFile)
if err != nil {
return "", errors.Wrap(err, "reading status file")
}
type StatusEntry struct {
IPAddress string `json:"ip-address"`
Hostname string `json:"hostname"`
}
var statusEntries []StatusEntry
// If the status file is empty, parsing will fail, ignore this error.
_ = json.Unmarshal(statuses, &statusEntries)
ipAddress := ""
for _, status := range statusEntries {
if status.Hostname == d.MachineName {
ipAddress = status.IPAddress
}
}
return ipAddress, nil
}
func (d *Driver) lookupIPFromLeasesFile() (string, error) {
leasesFile := fmt.Sprintf("/var/lib/libvirt/dnsmasq/%s.leases", d.PrivateNetwork)
leases, err := ioutil.ReadFile(leasesFile)
if err != nil {
return "", errors.Wrap(err, "reading leases file")
}
ipAddress := ""
for _, lease := range strings.Split(string(leases), "\n") {
if len(lease) == 0 {
continue
}
// format for lease entry
// ExpiryTime MAC IP Hostname ExtendedMAC
entry := strings.Split(lease, " ")
if len(entry) != 5 {
return "", fmt.Errorf("Malformed leases entry: %s", entry)
}
if entry[3] == d.MachineName {
ipAddress = entry[2]
}
}
return ipAddress, nil
}

115
pkg/drivers/kvm/storage.go Normal file
View File

@ -0,0 +1,115 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kvm
import (
"archive/tar"
"bytes"
"fmt"
"io/ioutil"
"math"
"os"
"github.com/docker/machine/libmachine/ssh"
"github.com/pkg/errors"
)
func createRawDiskImage(dest string, size int) error {
f, err := os.OpenFile(dest, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
if err != nil {
if os.IsExist(err) {
return nil
}
return errors.Wrap(err, "opening file for raw disk image")
}
f.Close()
if err := os.Truncate(dest, int64(float64(size)*math.Pow10(6))); err != nil {
return errors.Wrap(err, "writing sparse file")
}
return nil
}
func (d *Driver) buildDiskImage() error {
diskPath := d.ResolveStorePath(fmt.Sprintf("%s.img", d.MachineName))
err := createRawDiskImage(diskPath, d.DiskSize)
if err := createRawDiskImage(diskPath, d.DiskSize); err != nil {
return errors.Wrap(err, "creating raw disk image")
}
tarBuf, err := d.generateCertBundle()
if err != nil {
return errors.Wrap(err, "generating cert bundle")
}
f, err := os.OpenFile(d.DiskPath, os.O_WRONLY, 0644)
if err != nil {
return errors.Wrap(err, "opening raw disk image to write cert bundle")
}
defer f.Close()
f.Seek(0, os.SEEK_SET)
_, err = f.Write(tarBuf.Bytes())
if err != nil {
return errors.Wrap(err, "wrting cert bundle to disk image")
}
return nil
}
func (d *Driver) generateCertBundle() (*bytes.Buffer, error) {
magicString := "boot2docker, please format-me"
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, errors.Wrap(err, "generating ssh key")
}
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
file := &tar.Header{Name: magicString, Size: int64(len(magicString))}
if err := tw.WriteHeader(file); err != nil {
return nil, errors.Wrap(err, "writing magic string header to tar")
}
if _, err := tw.Write([]byte(magicString)); err != nil {
return nil, errors.Wrap(err, "writing magic string to tar")
}
// .ssh/key.pub => authorized_keys
file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700}
if err := tw.WriteHeader(file); err != nil {
return nil, errors.Wrap(err, "writing .ssh header to tar")
}
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return nil, errors.Wrap(err, "reading ssh pub key for tar")
}
file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return nil, errors.Wrap(err, "writing header for authorized_keys to tar")
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return nil, errors.Wrap(err, "writing pub key to tar")
}
if err := tw.Close(); err != nil {
return nil, errors.Wrap(err, "closing tar writer")
}
return buf, nil
}
func (d *Driver) publicSSHKeyPath() string {
return d.GetSSHKeyPath() + ".pub"
}

7
vendor/github.com/libvirt/libvirt-go/.gitignore generated vendored Normal file
View File

@ -0,0 +1,7 @@
*.sublime-workspace
*.sublime-project
.vagrant
/libvirt-go.test
*~
.#*
\#*

38
vendor/github.com/libvirt/libvirt-go/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,38 @@
language: go
os: linux
dist: trusty
sudo: require
go:
- 1.5
- 1.6
- 1.7
env:
- LIBVIRT=1.2.0 EXT=gz
- LIBVIRT=1.2.10 EXT=gz
- LIBVIRT=1.2.20 EXT=gz
- LIBVIRT=2.5.0 EXT=xz
install:
- sudo apt-get -qqy build-dep libvirt
- sudo apt-get -qqy install curl qemu-system-x86 sasl2-bin
- sudo mkdir -p /usr/src && sudo chown $(id -u) /usr/src
- curl -O -s https://libvirt.org/sources/libvirt-${LIBVIRT}.tar.${EXT}
- tar -C /usr/src -xf libvirt-${LIBVIRT}.tar.${EXT}
- pushd /usr/src/libvirt-${LIBVIRT}
- |
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc \
--without-polkit \
--without-esx --without-vbox --without-xen --without-libxl \
--with-qemu --with-lxc
- make
- sudo make install
- popd
- sudo libvirtd -d -l -f libvirtd.conf
- sudo virtlogd -d || true
- sudo chmod a+rwx /var/run/libvirt/libvirt-sock*
- echo "pass" | sudo saslpasswd2 -p -a libvirt user
script:
go test -timeout 1m -tags "integration" -v

19
vendor/github.com/libvirt/libvirt-go/FAQ.md generated vendored Normal file
View File

@ -0,0 +1,19 @@
#libvirt-go
##FAQ - Frequently asked questions
If your question is a good one, please ask it as a well-formatted patch to this
repository, and we'll merge it along with the answer.
###Why does this fail when added to my project in travis?
This lib requires a newish version of the libvirt-dev library to compile. These
are only available in the newer travis environment. You can add:
```
sudo: true
dist: trusty
install: sudo apt-get install -y libvirt-dev
```
to your `.travis.yaml` file to avoid these errors.

21
vendor/github.com/libvirt/libvirt-go/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License
Copyright (c) 2013 Alex Zorin
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.

136
vendor/github.com/libvirt/libvirt-go/README.md generated vendored Normal file
View File

@ -0,0 +1,136 @@
# libvirt-go [![Build Status](https://travis-ci.org/libvirt/libvirt-go.svg?branch=master)](https://travis-ci.org/libvirt/libvirt-go) [![GoDoc](https://godoc.org/github.com/libvirt/libvirt-go?status.svg)](https://godoc.org/github.com/libvirt/libvirt-go)
Go bindings for libvirt.
Make sure to have `libvirt-dev` package (or the development files otherwise somewhere in your include path)
## Version Support
The libvirt go package provides API coverage for libvirt versions
from 1.2.0 onwards, through conditional compilation of newer APIs.
By default the binding will support APIs in libvirt.so, libvirt-qemu.so
and libvirt-lxc.so. Coverage for the latter two libraries can be dropped
from the build using build tags 'without_qemu' or 'without_lxc'
respectively.
## Development status
The Go API is considered to be production ready and aims to be kept
stable across future versions. Note, however, that the following
changes may apply to future versions:
* Existing structs can be augmented with new fields, but no existing
fields will be changed / removed. New fields are needed when libvirt
defines new typed parameters for various methods
* Any method with an 'flags uint32' parameter will have its parameter
type changed to a specific typedef, if & when the libvirt API defines
constants for the flags. To avoid breakage, always pass a literal
'0' to any 'flags uint32' parameter, since this will auto-cast to
any future typedef that is introduced.
## Documentation
* [api documentation for the bindings](https://godoc.org/github.com/libvirt/libvirt-go)
* [api documentation for libvirt](http://libvirt.org/html/libvirt-libvirt.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" \
--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" \
--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.
## Testing
The core API unit tests are all written to use the built-in
test driver (test:///default), so they have no interaction
with the host OS environment.
Coverage of libvirt C library APIs / constants is verified
using automated tests. These can be run by passing the 'api'
build tag. eg go test -tags api
For areas where the test driver lacks functionality, it is
possible to use the QEMU or LXC drivers to exercise code.
Such tests must be part of the 'integration_test.go' file
though, which is only run when passing the 'integration'
build tag. eg go test -tags integration
In order to run the unit tests, libvirtd should be configured
to allow your user account read-write access with no passwords.
This can be easily done using polkit config files
```
# cat > /etc/polkit-1/localauthority/50-local.d/50-libvirt.pkla <<EOF
[Passwordless libvirt access]
Identity=unix-group:berrange
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF
```
(Replace 'berrange' with your UNIX user name).
One of the integration tests also requires that libvirtd is
listening for TCP connections on localhost, with sasl auth
This can be setup by editing /etc/libvirt/libvirtd.conf to
set
```
listen_tls=0
listen_tcp=1
auth_tcp=sasl
listen_addr="127.0.0.1"
```
and then start libvirtd with the --listen flag (this can
be set in /etc/sysconfig/libvirtd to make it persistent).
Then create a sasl user
```
saslpasswd2 -a libvirt user
```
and enter "pass" as the password.
Alternatively a `Vagrantfile`, requiring use of virtualbox,
is included to run the integration tests:
* `cd ./vagrant`
* `vagrant up` to provision the virtual machine
* `vagrant ssh` to login to the virtual machine
Once inside, `sudo su -` and `go test -tags integration libvirt`.

102
vendor/github.com/libvirt/libvirt-go/callbacks.go generated vendored Normal file
View File

@ -0,0 +1,102 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
// Helpers functions to register a Go callback function to a C
// function. For a simple example, look at how SetErrorFunc works in
// error.go.
//
// - Create a struct that will contain at least the Go callback to
// invoke (errorContext).
//
// - Create an exported Golang function whose job will be to retrieve
// the context and execute the callback in it
// (connErrCallback). Such a function should receive a callback ID
// and will use it to retrive the context.
//
// - Create a CGO function similar to the above function but with the
// appropriate signature to be registered as a callback in C code
// (connErrCallback_cgo). Notably, it will have a void* argument
// that should be cast to long to retrieve the callback ID. It
// should be just a thin wrapper to transform the opaque argument to
// a callback ID.
//
// - Create a CGO function which will be a wrapper around the C
// function to register the callback (virConnSetErrorFunc_cgo). Its
// only role is to transform a callback ID (long) to an opaque (void*)
// and call the C function.
//
// - When setting up a callback (SetErrorFunc), register the struct from first step
// with registerCallbackId and invoke the CGO function from the
// previous step with the appropriate ID.
//
// - When unregistering the callback, don't forget to call freecallbackId.
//
// If you need to associate some additional data with the connection,
// look at saveConnectionData, getConnectionData and
// releaseConnectionData.
import "C"
import (
"sync"
)
const firstGoCallbackId int = 100 // help catch some additional errors during test
var goCallbackLock sync.RWMutex
var goCallbacks = make(map[int]interface{})
var nextGoCallbackId int = firstGoCallbackId
//export freeCallbackId
func freeCallbackId(goCallbackId int) {
goCallbackLock.Lock()
delete(goCallbacks, goCallbackId)
goCallbackLock.Unlock()
}
func getCallbackId(goCallbackId int) interface{} {
goCallbackLock.RLock()
ctx := goCallbacks[goCallbackId]
goCallbackLock.RUnlock()
if ctx == nil {
// If this happens there must be a bug in libvirt
panic("Callback arrived after freeCallbackId was called")
}
return ctx
}
func registerCallbackId(ctx interface{}) int {
goCallbackLock.Lock()
goCallBackId := nextGoCallbackId
nextGoCallbackId++
for goCallbacks[nextGoCallbackId] != nil {
nextGoCallbackId++
}
goCallbacks[goCallBackId] = ctx
goCallbackLock.Unlock()
return goCallBackId
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "callbacks_cfuncs.h"
extern void freeCallbackId(long);
void freeGoCallback_cgo(void* goCallbackId) {
freeCallbackId((long)goCallbackId);
}
*/
import "C"

View File

@ -0,0 +1,32 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_CALLBACKS_CFUNCS_H__
#define LIBVIRT_GO_CALLBACKS_CFUNCS_H__
void freeGoCallback_cgo(void* goCallbackId);
#endif /* LIBVIRT_GO_CALLBACKS_CFUNCS_H__ */

2567
vendor/github.com/libvirt/libvirt-go/connect.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

71
vendor/github.com/libvirt/libvirt-go/connect_cfuncs.go generated vendored Normal file
View File

@ -0,0 +1,71 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "connect_cfuncs.h"
#include "callbacks_cfuncs.h"
extern void closeCallback(virConnectPtr, int, long);
void closeCallback_cgo(virConnectPtr conn, int reason, void *opaque)
{
closeCallback(conn, reason, (long)opaque);
}
int virConnectRegisterCloseCallback_cgo(virConnectPtr c, virConnectCloseFunc cb, long goCallbackId)
{
void *id = (void*)goCallbackId;
return virConnectRegisterCloseCallback(c, cb, id, freeGoCallback_cgo);
}
#include <stdio.h>
extern int connectAuthCallback(virConnectCredentialPtr, unsigned int, int);
int connectAuthCallback_cgo(virConnectCredentialPtr cred, unsigned int ncred, void *cbdata)
{
int *callbackID = cbdata;
return connectAuthCallback(cred, ncred, *callbackID);
}
virConnectPtr virConnectOpenAuthWrap(const char *name, int *credtype, uint ncredtype, int callbackID, unsigned int flags)
{
virConnectAuth auth = {
.credtype = credtype,
.ncredtype = ncredtype,
.cb = connectAuthCallback_cgo,
.cbdata = &callbackID,
};
return virConnectOpenAuth(name, &auth, flags);
}
*/
import "C"

34
vendor/github.com/libvirt/libvirt-go/connect_cfuncs.h generated vendored Normal file
View File

@ -0,0 +1,34 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_CONNECT_CFUNCS_H__
#define LIBVIRT_GO_CONNECT_CFUNCS_H__
void closeCallback_cgo(virConnectPtr conn, int reason, void *opaque);
int virConnectRegisterCloseCallback_cgo(virConnectPtr c, virConnectCloseFunc cb, long goCallbackId);
virConnectPtr virConnectOpenAuthWrap(const char *name, int *credtype, uint ncredtype, int callbackID, unsigned int flags);
#endif /* LIBVIRT_GO_CONNECT_CFUNCS_H__ */

120
vendor/github.com/libvirt/libvirt-go/connect_compat.go generated vendored Normal file
View File

@ -0,0 +1,120 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "connect_compat.h"
int virNodeGetFreePagesCompat(virConnectPtr conn,
unsigned int npages,
unsigned int *pages,
int startcell,
unsigned int cellcount,
unsigned long long *counts,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002006
assert(0); // Caller should have checked version
#else
return virNodeGetFreePages(conn, npages, pages, startcell, cellcount, counts, flags);
#endif
}
char * virConnectGetDomainCapabilitiesCompat(virConnectPtr conn,
const char *emulatorbin,
const char *arch,
const char *machine,
const char *virttype,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002007
assert(0); // Caller should have checked version
#else
return virConnectGetDomainCapabilities(conn, emulatorbin, arch, machine, virttype, flags);
#endif
}
int virConnectGetAllDomainStatsCompat(virConnectPtr conn,
unsigned int stats,
virDomainStatsRecordPtr **retStats,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002008
assert(0); // Caller should have checked version
#else
return virConnectGetAllDomainStats(conn, stats, retStats, flags);
#endif
}
int virDomainListGetStatsCompat(virDomainPtr *doms,
unsigned int stats,
virDomainStatsRecordPtr **retStats,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002008
assert(0); // Caller should have checked version
#else
return virDomainListGetStats(doms, stats, retStats, flags);
#endif
}
void virDomainStatsRecordListFreeCompat(virDomainStatsRecordPtr *stats)
{
}
int virNodeAllocPagesCompat(virConnectPtr conn,
unsigned int npages,
unsigned int *pageSizes,
unsigned long long *pageCounts,
int startCell,
unsigned int cellCount,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002009
assert(0); // Caller should have checked version
#else
return virNodeAllocPages(conn, npages, pageSizes, pageCounts, startCell, cellCount, flags);
#endif
}
virDomainPtr virDomainDefineXMLFlagsCompat(virConnectPtr conn,
const char *xml,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002012
assert(0); // Caller should have checked version
#else
return virDomainDefineXMLFlags(conn, xml, flags);
#endif
}
*/
import "C"

215
vendor/github.com/libvirt/libvirt-go/connect_compat.h generated vendored Normal file
View File

@ -0,0 +1,215 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_CONNECT_COMPAT_H__
#define LIBVIRT_GO_CONNECT_COMPAT_H__
/* 1.2.1 */
#ifndef VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER
#define VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER 1 << 16
#endif
/* 1.2.2 */
#ifndef VIR_NODE_CPU_STATS_INTR
#define VIR_NODE_CPU_STATS_INTR "intr"
#endif
/* 1.2.6 */
#ifndef VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE
#define VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE 1 << 0
#endif
int virNodeGetFreePagesCompat(virConnectPtr conn,
unsigned int npages,
unsigned int *pages,
int startcell,
unsigned int cellcount,
unsigned long long *counts,
unsigned int flags);
/* 1.2.7 */
char * virConnectGetDomainCapabilitiesCompat(virConnectPtr conn,
const char *emulatorbin,
const char *arch,
const char *machine,
const char *virttype,
unsigned int flags);
/* 1.2.8 */
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE 1 << 0
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE 1 << 1
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT 1 << 2
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT 1 << 3
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING 1 << 4
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED 1 << 5
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF 1 << 6
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER 1 << 7
#endif
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS 1U << 31
#endif
#ifndef VIR_CONNECT_LIST_STORAGE_POOLS_ZFS
#define VIR_CONNECT_LIST_STORAGE_POOLS_ZFS 1 << 17
#endif
#if LIBVIR_VERSION_NUMBER < 1002008
typedef struct _virDomainStatsRecord virDomainStatsRecord;
typedef virDomainStatsRecord *virDomainStatsRecordPtr;
struct _virDomainStatsRecord {
virDomainPtr dom;
virTypedParameterPtr params;
int nparams;
};
#endif
int virConnectGetAllDomainStatsCompat(virConnectPtr conn,
unsigned int stats,
virDomainStatsRecordPtr **retStats,
unsigned int flags);
int virDomainListGetStatsCompat(virDomainPtr *doms,
unsigned int stats,
virDomainStatsRecordPtr **retStats,
unsigned int flags);
void virDomainStatsRecordListFreeCompat(virDomainStatsRecordPtr *stats);
/* 1.2.9 */
#ifndef VIR_NODE_ALLOC_PAGES_ADD
#define VIR_NODE_ALLOC_PAGES_ADD 0
#endif
#ifndef VIR_NODE_ALLOC_PAGES_SET
#define VIR_NODE_ALLOC_PAGES_SET 1 << 0
#endif
int virNodeAllocPagesCompat(virConnectPtr conn,
unsigned int npages,
unsigned int *pageSizes,
unsigned long long *pageCounts,
int startCell,
unsigned int cellCount,
unsigned int flags);
/* 1.2.11 */
#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED
#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED 1
#endif
#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED
#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED 2
#endif
#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN
#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN 0
#endif
#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED
#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED 1
#endif
#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL
#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL 2
#endif
/* 1.2.12 */
#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING
#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING 1 << 30
#endif
virDomainPtr virDomainDefineXMLFlagsCompat(virConnectPtr conn,
const char *xml,
unsigned int flags);
/* 1.2.14 */
#ifndef VIR_CONNECT_BASELINE_CPU_MIGRATABLE
#define VIR_CONNECT_BASELINE_CPU_MIGRATABLE 1 << 1
#endif
/* 3.1.0 */
#ifndef VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE
#define VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE 1 << 18
#endif
#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM
#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM 1 << 12
#endif
/* 3.4.0 */
#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES
#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES 1 << 13
#endif
#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV
#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV 1 << 14
#endif
#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV
#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV 1 << 15
#endif
#endif /* LIBVIRT_GO_CONNECT_COMPAT_H__ */

141
vendor/github.com/libvirt/libvirt-go/doc.go generated vendored Normal file
View File

@ -0,0 +1,141 @@
/*
* This file is part of the libvirt-go 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 libvirt provides a Go binding to the libvirt C library
//
// Through conditional compilation it supports libvirt versions 1.2.0 onwards.
// This is done automatically, with no requirement to use magic Go build tags.
// If an API was not available in the particular version of libvirt this package
// was built against, an error will be returned with a code of ERR_NO_SUPPORT.
// This is the same code seen if using a new libvirt library to talk to an old
// libvirtd lacking the API, or if a hypervisor does not support a given feature,
// so an application can easily handle all scenarios together.
//
// The Go binding is a fairly direct mapping of the underling C API which seeks
// to maximise the use of the Go type system to allow strong compiler type
// checking. The following rules describe how APIs/constants are mapped from C
// to Go
//
// For structs, the 'vir' prefix and 'Ptr' suffix are removed from the name.
// e.g. virConnectPtr in C becomes 'Connect' in Go.
//
// For structs which are reference counted at the C level, it is neccessary to
// explicitly release the reference at the Go level. e.g. if a Go method returns
// a '* Domain' struct, it is neccessary to call 'Free' on this when no longer
// required. The use of 'defer' is recommended for this purpose
//
// dom, err := conn.LookupDomainByName("myguest")
// if err != nil {
// ...
// }
// defer dom.Free()
//
// If multiple goroutines are using the same libvirt object struct, it may
// not be possible to determine which goroutine should call 'Free'. In such
// scenarios each new goroutine should call 'Ref' to obtain a private reference
// on the underlying C struct. All goroutines can call 'Free' unconditionally
// with the final one causing the release of the C object.
//
// For methods, the 'vir' prefix and object name prefix are remove from the name.
// The C functions become methods with an object receiver. e.g.
// 'virDomainScreenshot' in C becomes 'Screenshot' with a 'Domain *' receiver.
//
// For methods which accept a 'unsigned int flags' parameter in the C level,
// the corresponding Go parameter will be a named type corresponding to the
// C enum that defines the valid flags. For example, the ListAllDomains
// method takes a 'flags ConnectListAllDomainsFlags' parameter. If there are
// not currently any flags defined for a method in the C API, then the Go
// method parameter will be declared as a "flags uint32". Callers should always
// pass the literal integer value 0 for such parameters, without forcing any
// specific type. This will allow compatibility with future updates to the
// libvirt-go binding which may replace the 'uint32' type with a enum type
// at a later date.
//
// For enums, the VIR_ prefix is removed from the name. The enums get a dedicated
// type defined in Go. e.g. the VIR_NODE_SUSPEND_TARGET_MEM enum constant in C,
// becomes NODE_SUSPEND_TARGET_MEM with a type of NodeSuspendTarget.
//
// Methods accepting or returning virTypedParameter arrays in C will map the
// parameters into a Go struct. The struct will contain two fields for each
// possible parameter. One boolean field with a suffix of 'Set' indicates whether
// the parameter has a value set, and the other custom typed field provides the
// parameter value. This makes it possible to distinguish a parameter with a
// default value of '0' from a parameter which is 0 because it isn't supported by
// the hypervisor. If the C API defines additional typed parameters, then the
// corresponding Go struct will be extended to have further fields.
// e.g. the GetMemoryStats method in Go (which is backed by
// virNodeGetMemoryStats in C) will return a NodeMemoryStats struct containing
// the typed parameter values.
//
// stats, err := conn.GetMemoryParameters()
// if err != nil {
// ....
// }
// if stats.TotalSet {
// fmt.Printf("Total memory: %d KB", stats.Total)
// }
//
// Every method that can fail will include an 'error' object as the last return
// value. This will be an instance of the Error struct if an error occurred. To
// check for specific libvirt error codes, it is neccessary to cast the error.
//
// err := storage_vol.Wipe(0)
// if err != nil {
// lverr, ok := err.(libvirt.Error)
// if ok && lverr.Code == libvirt.ERR_NO_SUPPORT {
// fmt.Println("Wiping storage volumes is not supported");
// } else {
// fmt.Println("Error wiping storage volume: %s", err)
// }
// }
//
// Example usage
//
// To connect to libvirt
//
// import (
// libvirt "github.com/libvirt/libvirt-go"
// )
// conn, err := libvirt.NewConnect("qemu:///system")
// if err != nil {
// ...
// }
// defer conn.Close()
//
// doms, err := conn.ListAllDomains(libvirt.CONNECT_LIST_DOMAINS_ACTIVE)
// if err != nil {
// ...
// }
//
// fmt.Printf("%d running domains:\n", len(doms))
// for _, dom := range doms {
// name, err := dom.GetName()
// if err == nil {
// fmt.Printf(" %s\n", name)
// }
// dom.Free()
// }
//
package libvirt

4305
vendor/github.com/libvirt/libvirt-go/domain.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

315
vendor/github.com/libvirt/libvirt-go/domain_compat.go generated vendored Normal file
View File

@ -0,0 +1,315 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "domain_compat.h"
int virDomainCoreDumpWithFormatCompat(virDomainPtr domain,
const char *to,
unsigned int dumpformat,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002003
assert(0); // Caller should have checked version
#else
return virDomainCoreDumpWithFormat(domain, to, dumpformat, flags);
#endif
}
int virDomainGetTimeCompat(virDomainPtr dom,
long long *seconds,
unsigned int *nseconds,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002005
assert(0); // Caller should have checked version
#else
return virDomainGetTime(dom, seconds, nseconds, flags);
#endif
}
int virDomainSetTimeCompat(virDomainPtr dom,
long long seconds,
unsigned int nseconds,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002005
assert(0); // Caller should have checked version
#else
return virDomainSetTime(dom, seconds, nseconds, flags);
#endif
}
int virDomainFSFreezeCompat(virDomainPtr dom,
const char **mountpoints,
unsigned int nmountpoints,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002005
assert(0); // Caller should have checked version
#else
return virDomainFSFreeze(dom, mountpoints, nmountpoints, flags);
#endif
}
int virDomainFSThawCompat(virDomainPtr dom,
const char **mountpoints,
unsigned int nmountpoints,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002005
assert(0); // Caller should have checked version
#else
return virDomainFSThaw(dom, mountpoints, nmountpoints, flags);
#endif
}
int virDomainBlockCopyCompat(virDomainPtr dom, const char *disk,
const char *destxml,
virTypedParameterPtr params,
int nparams,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002008
assert(0); // Caller should have checked version
#else
return virDomainBlockCopy(dom, disk, destxml, params, nparams, flags);
#endif
}
int virDomainOpenGraphicsFDCompat(virDomainPtr dom,
unsigned int idx,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002008
assert(0); // Caller should have checked version
#else
return virDomainOpenGraphicsFD(dom, idx, flags);
#endif
}
void virDomainFSInfoFreeCompat(virDomainFSInfoPtr info)
{
}
int virDomainGetFSInfoCompat(virDomainPtr dom,
virDomainFSInfoPtr **info,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002011
assert(0); // Caller should have checked version
#else
return virDomainGetFSInfo(dom, info, flags);
#endif
}
int virDomainInterfaceAddressesCompat(virDomainPtr dom,
virDomainInterfacePtr **ifaces,
unsigned int source,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002014
assert(0); // Caller should have checked version
#else
return virDomainInterfaceAddresses(dom, ifaces, source, flags);
#endif
}
void virDomainInterfaceFreeCompat(virDomainInterfacePtr iface)
{
}
void virDomainIOThreadInfoFreeCompat(virDomainIOThreadInfoPtr info)
{
}
int virDomainGetIOThreadInfoCompat(virDomainPtr domain,
virDomainIOThreadInfoPtr **info,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002014
assert(0); // Caller should have checked version
#else
return virDomainGetIOThreadInfo(domain, info, flags);
#endif
}
int virDomainPinIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned char *cpumap,
int maplen,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002014
assert(0); // Caller should have checked version
#else
return virDomainPinIOThread(domain, iothread_id, cpumap, maplen, flags);
#endif
}
int virDomainAddIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002015
assert(0); // Caller should have checked version
#else
return virDomainAddIOThread(domain, iothread_id, flags);
#endif
}
int virDomainDelIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002015
assert(0); // Caller should have checked version
#else
return virDomainDelIOThread(domain, iothread_id, flags);
#endif
}
int virDomainSetUserPasswordCompat(virDomainPtr dom,
const char *user,
const char *password,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002016
assert(0); // Caller should have checked version
#else
return virDomainSetUserPassword(dom, user, password, flags);
#endif
}
int virDomainRenameCompat(virDomainPtr dom,
const char *new_name,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002019
assert(0); // Caller should have checked version
#else
return virDomainRename(dom, new_name, flags);
#endif
}
int virDomainGetPerfEventsCompat(virDomainPtr dom,
virTypedParameterPtr *params,
int *nparams,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1003003
assert(0); // Caller should have checked version
#else
return virDomainGetPerfEvents(dom, params, nparams, flags);
#endif
}
int virDomainSetPerfEventsCompat(virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1003003
assert(0); // Caller should have checked version
#else
return virDomainSetPerfEvents(dom, params, nparams, flags);
#endif
}
int virDomainMigrateStartPostCopyCompat(virDomainPtr domain,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1003003
assert(0); // Caller should have checked version
#else
return virDomainMigrateStartPostCopy(domain, flags);
#endif
}
int virDomainGetGuestVcpusCompat(virDomainPtr domain,
virTypedParameterPtr *params,
unsigned int *nparams,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 2000000
assert(0); // Caller should have checked version
#else
return virDomainGetGuestVcpus(domain, params, nparams, flags);
#endif
}
int virDomainSetGuestVcpusCompat(virDomainPtr domain,
const char *cpumap,
int state,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 2000000
assert(0); // Caller should have checked version
#else
return virDomainSetGuestVcpus(domain, cpumap, state, flags);
#endif
}
int virDomainSetVcpuCompat(virDomainPtr domain,
const char *cpumap,
int state,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 3001000
assert(0); // Caller should have checked version
#else
return virDomainSetVcpu(domain, cpumap, state, flags);
#endif
}
int virDomainSetBlockThresholdCompat(virDomainPtr domain,
const char *dev,
unsigned long long threshold,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 3002000
assert(0); // Caller should have checked version
#else
return virDomainSetBlockThreshold(domain, dev, threshold, flags);
#endif
}
*/
import "C"

955
vendor/github.com/libvirt/libvirt-go/domain_compat.h generated vendored Normal file
View File

@ -0,0 +1,955 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_DOMAIN_COMPAT_H__
#define LIBVIRT_GO_DOMAIN_COMPAT_H__
/* 1.2.2 */
#ifndef VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS
#define VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS "device_read_iops_sec"
#endif
#ifndef VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS
#define VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS "device_write_iops_sec"
#endif
#ifndef VIR_DOMAIN_BLKIO_DEVICE_READ_BPS
#define VIR_DOMAIN_BLKIO_DEVICE_READ_BPS "device_read_bytes_sec"
#endif
#ifndef VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS
#define VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS "device_write_bytes_sec"
#endif
/* 1.2.3 */
#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_RAW
#define VIR_DOMAIN_CORE_DUMP_FORMAT_RAW 0
#endif
#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB
#define VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB 1
#endif
#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO
#define VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO 2
#endif
#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY
#define VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY 3
#endif
#ifndef VIR_MIGRATE_AUTO_CONVERGE
#define VIR_MIGRATE_AUTO_CONVERGE 1 << 13
#endif
int virDomainCoreDumpWithFormatCompat(virDomainPtr domain,
const char *to,
unsigned int dumpformat,
unsigned int flags);
/* 1.2.5 */
#ifndef VIR_DOMAIN_REBOOT_PARAVIRT
#define VIR_DOMAIN_REBOOT_PARAVIRT 1 << 4
#endif
#ifndef VIR_DOMAIN_SHUTDOWN_PARAVIRT
#define VIR_DOMAIN_SHUTDOWN_PARAVIRT 1 << 4
#endif
#ifndef VIR_DOMAIN_TIME_SYNC
#define VIR_DOMAIN_TIME_SYNC 1 << 0
#endif
int virDomainGetTimeCompat(virDomainPtr dom,
long long *seconds,
unsigned int *nseconds,
unsigned int flags);
int virDomainSetTimeCompat(virDomainPtr dom,
long long seconds,
unsigned int nseconds,
unsigned int flags);
int virDomainFSFreezeCompat(virDomainPtr dom,
const char **mountpoints,
unsigned int nmountpoints,
unsigned int flags);
int virDomainFSThawCompat(virDomainPtr dom,
const char **mountpoints,
unsigned int nmountpoints,
unsigned int flags);
/* 1.2.6 */
#ifndef VIR_DOMAIN_BLOCK_COMMIT_ACTIVE
#define VIR_DOMAIN_BLOCK_COMMIT_ACTIVE 1 << 2
#endif
#ifndef VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT
#define VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT 4
#endif
#ifndef VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
#define VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 16
#endif
/* 1.2.7 */
#ifndef VIR_DOMAIN_BLOCK_COMMIT_RELATIVE
#define VIR_DOMAIN_BLOCK_COMMIT_RELATIVE 1 << 3
#endif
#ifndef VIR_DOMAIN_BLOCK_REBASE_RELATIVE
#define VIR_DOMAIN_BLOCK_REBASE_RELATIVE 1 << 4
#endif
/* 1.2.8 */
#ifndef VIR_DOMAIN_BLOCK_COPY_SHALLOW
#define VIR_DOMAIN_BLOCK_COPY_SHALLOW 1 << 0
#endif
#ifndef VIR_DOMAIN_BLOCK_COPY_REUSE_EXT
#define VIR_DOMAIN_BLOCK_COPY_REUSE_EXT 1 << 1
#endif
#ifndef VIR_DOMAIN_BLOCK_COPY_BANDWIDTH
#define VIR_DOMAIN_BLOCK_COPY_BANDWIDTH "bandwidth"
#endif
#ifndef VIR_DOMAIN_BLOCK_COPY_GRANULARITY
#define VIR_DOMAIN_BLOCK_COPY_GRANULARITY "granularity"
#endif
#ifndef VIR_DOMAIN_BLOCK_COPY_BUF_SIZE
#define VIR_DOMAIN_BLOCK_COPY_BUF_SIZE "buf-size"
#endif
#ifndef VIR_DOMAIN_STATS_STATE
#define VIR_DOMAIN_STATS_STATE 1 << 0
#endif
int virDomainBlockCopyCompat(virDomainPtr dom, const char *disk,
const char *destxml,
virTypedParameterPtr params,
int nparams,
unsigned int flags);
int virDomainOpenGraphicsFDCompat(virDomainPtr dom,
unsigned int idx,
unsigned int flags);
/* 1.2.9 */
#ifndef VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES
#define VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES 1 << 4
#endif
#ifndef VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES
#define VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES 1 << 0
#endif
#ifndef VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES
#define VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES 1 << 0
#endif
#ifndef VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES
#define VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES 1 << 6
#endif
#ifndef VIR_DOMAIN_BLOCK_REBASE_COPY_DEV
#define VIR_DOMAIN_BLOCK_REBASE_COPY_DEV 1 << 5
#endif
#ifndef VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES
#define VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES 1 << 6
#endif
#ifndef VIR_DOMAIN_JOB_DISK_BPS
#define VIR_DOMAIN_JOB_DISK_BPS "disk_bps"
#endif
#ifndef VIR_DOMAIN_JOB_MEMORY_BPS
#define VIR_DOMAIN_JOB_MEMORY_BPS "memory_bps"
#endif
#ifndef VIR_DOMAIN_JOB_SETUP_TIME
#define VIR_DOMAIN_JOB_SETUP_TIME "setup_time"
#endif
#ifndef VIR_DOMAIN_JOB_STATS_COMPLETED
#define VIR_DOMAIN_JOB_STATS_COMPLETED 1 << 0
#endif
#ifndef VIR_DOMAIN_STATS_CPU_TOTAL
#define VIR_DOMAIN_STATS_CPU_TOTAL 1 << 1
#endif
#ifndef VIR_DOMAIN_STATS_BALLOON
#define VIR_DOMAIN_STATS_BALLOON 1 << 2
#endif
#ifndef VIR_DOMAIN_STATS_VCPU
#define VIR_DOMAIN_STATS_VCPU 1 << 3
#endif
#ifndef VIR_DOMAIN_STATS_INTERFACE
#define VIR_DOMAIN_STATS_INTERFACE 1 << 4
#endif
#ifndef VIR_DOMAIN_STATS_BLOCK
#define VIR_DOMAIN_STATS_BLOCK 1 << 5
#endif
#ifndef VIR_DOMAIN_UNDEFINE_NVRAM
#define VIR_DOMAIN_UNDEFINE_NVRAM 1 << 2
#endif
#ifndef VIR_MIGRATE_RDMA_PIN_ALL
#define VIR_MIGRATE_RDMA_PIN_ALL 1 << 14
#endif
#ifndef VIR_DOMAIN_EVENT_ID_TUNABLE
#define VIR_DOMAIN_EVENT_ID_TUNABLE 17
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_DISK
#define VIR_DOMAIN_TUNABLE_BLKDEV_DISK "blkdeviotune.disk"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC "blkdeviotune.total_bytes_sec"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC "blkdeviotune.read_bytes_sec"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC "blkdeviotune.write_bytes_sec"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC "blkdeviotune.total_iops_sec"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC "blkdeviotune.read_iops_sec"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC "blkdeviotune.write_iops_sec"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES
#define VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES "cputune.cpu_shares"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN
#define VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN "cputune.emulatorpin"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_EMULATOR_PERIOD
#define VIR_DOMAIN_TUNABLE_CPU_EMULATOR_PERIOD "cputune.emulator_period"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_EMULATOR_QUOTA
#define VIR_DOMAIN_TUNABLE_CPU_EMULATOR_QUOTA "cputune.emulator_quota"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_VCPU_PERIOD
#define VIR_DOMAIN_TUNABLE_CPU_VCPU_PERIOD "cputune.vcpu_period"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_VCPU_QUOTA
#define VIR_DOMAIN_TUNABLE_CPU_VCPU_QUOTA "cputune.vcpu_quota"
#endif
/* 1.2.11 */
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX
#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX "blkdeviotune.total_bytes_sec_max"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX
#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX "blkdeviotune.read_bytes_sec_max"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX
#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX "blkdeviotune.write_bytes_sec_max"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX
#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX "blkdeviotune.total_iops_sec_max"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX
#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX "blkdeviotune.read_iops_sec_max"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX
#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX "blkdeviotune.write_iops_sec_max"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_SIZE_IOPS_SEC
#define VIR_DOMAIN_TUNABLE_BLKDEV_SIZE_IOPS_SEC "blkdeviotune.size_iops_sec"
#endif
#ifndef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
#define VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE 18
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX
#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX "total_bytes_sec_max"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX
#define VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX "read_bytes_sec_max"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX
#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX "write_bytes_sec_max"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX
#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX "total_iops_sec_max"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX
#define VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX "read_iops_sec_max"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX
#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX "write_iops_sec_max"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC
#define VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC "size_iops_sec"
#endif
#if LIBVIR_VERSION_NUMBER < 1002011
typedef struct _virDomainFSInfo virDomainFSInfo;
typedef virDomainFSInfo *virDomainFSInfoPtr;
struct _virDomainFSInfo {
char *mountpoint; /* path to mount point */
char *name; /* device name in the guest (e.g. "sda1") */
char *fstype; /* filesystem type */
size_t ndevAlias; /* number of elements in devAlias */
char **devAlias; /* array of disk device aliases */
};
#endif
void virDomainFSInfoFreeCompat(virDomainFSInfoPtr info);
int virDomainGetFSInfoCompat(virDomainPtr dom,
virDomainFSInfoPtr **info,
unsigned int flags);
/* 1.2.12 */
#ifndef VIR_DOMAIN_DEFINE_VALIDATE
#define VIR_DOMAIN_DEFINE_VALIDATE 1 << 0
#endif
#ifndef VIR_DOMAIN_START_VALIDATE
#define VIR_DOMAIN_START_VALIDATE 1 << 4
#endif
/* 1.2.14 */
#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_NONE
#define VIR_DOMAIN_CONTROL_ERROR_REASON_NONE 0
#endif
#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN
#define VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN 1
#endif
#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR
#define VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR 2
#endif
#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL
#define VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL 3
#endif
#ifndef VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE
#define VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE 0
#endif
#ifndef VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT
#define VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT 1
#endif
#ifndef VIR_DOMAIN_PAUSED_STARTING_UP
#define VIR_DOMAIN_PAUSED_STARTING_UP 11
#endif
#if LIBVIR_VERSION_NUMBER < 1002014
typedef struct _virDomainIOThreadInfo virDomainIOThreadInfo;
typedef virDomainIOThreadInfo *virDomainIOThreadInfoPtr;
struct _virDomainIOThreadInfo {
unsigned int iothread_id; /* IOThread ID */
unsigned char *cpumap; /* CPU map for thread. A pointer to an */
/* array of real CPUs (in 8-bit bytes) */
int cpumaplen; /* cpumap size */
};
typedef struct _virDomainInterfaceIPAddress virDomainIPAddress;
typedef virDomainIPAddress *virDomainIPAddressPtr;
struct _virDomainInterfaceIPAddress {
int type; /* virIPAddrType */
char *addr; /* IP address */
unsigned int prefix; /* IP address prefix */
};
typedef struct _virDomainInterface virDomainInterface;
typedef virDomainInterface *virDomainInterfacePtr;
struct _virDomainInterface {
char *name; /* interface name */
char *hwaddr; /* hardware address, may be NULL */
unsigned int naddrs; /* number of items in @addrs */
virDomainIPAddressPtr addrs; /* array of IP addresses */
};
#endif
int virDomainInterfaceAddressesCompat(virDomainPtr dom,
virDomainInterfacePtr **ifaces,
unsigned int source,
unsigned int flags);
void virDomainInterfaceFreeCompat(virDomainInterfacePtr iface);
void virDomainIOThreadInfoFreeCompat(virDomainIOThreadInfoPtr info);
int virDomainGetIOThreadInfoCompat(virDomainPtr domain,
virDomainIOThreadInfoPtr **info,
unsigned int flags);
int virDomainPinIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned char *cpumap,
int maplen,
unsigned int flags);
/* 1.2.15 */
#ifndef VIR_DOMAIN_JOB_DOWNTIME_NET
#define VIR_DOMAIN_JOB_DOWNTIME_NET "downtime_net"
#endif
#ifndef VIR_DOMAIN_JOB_TIME_ELAPSED_NET
#define VIR_DOMAIN_JOB_TIME_ELAPSED_NET "time_elapsed_net"
#endif
#ifndef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
#define VIR_DOMAIN_EVENT_ID_DEVICE_ADDED 19
#endif
int virDomainAddIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned int flags);
int virDomainDelIOThreadCompat(virDomainPtr domain,
unsigned int iothread_id,
unsigned int flags);
/* 1.2.16 */
#ifndef VIR_DOMAIN_PASSWORD_ENCRYPTED
#define VIR_DOMAIN_PASSWORD_ENCRYPTED 1 << 0
#endif
int virDomainSetUserPasswordCompat(virDomainPtr dom,
const char *user,
const char *password,
unsigned int flags);
/* 1.2.17 */
#ifndef VIR_DOMAIN_EVENT_WATCHDOG_INJECTNMI
#define VIR_DOMAIN_EVENT_WATCHDOG_INJECTNMI 6
#endif
#ifndef VIR_MIGRATE_PARAM_MIGRATE_DISKS
#define VIR_MIGRATE_PARAM_MIGRATE_DISKS "migrate_disks"
#endif
/* 1.2.19 */
#ifndef VIR_DOMAIN_BANDWIDTH_IN_FLOOR
#define VIR_DOMAIN_BANDWIDTH_IN_FLOOR "inbound.floor"
#endif
#ifndef VIR_DOMAIN_EVENT_DEFINED_RENAMED
#define VIR_DOMAIN_EVENT_DEFINED_RENAMED 2
#endif
#ifndef VIR_DOMAIN_EVENT_UNDEFINED_RENAMED
#define VIR_DOMAIN_EVENT_UNDEFINED_RENAMED 1
#endif
int virDomainRenameCompat(virDomainPtr dom,
const char *new_name,
unsigned int flags);
/* 1.3.1 */
#ifndef VIR_DOMAIN_JOB_MEMORY_DIRTY_RATE
#define VIR_DOMAIN_JOB_MEMORY_DIRTY_RATE "memory_dirty_rate"
#endif
#ifndef VIR_DOMAIN_JOB_MEMORY_ITERATION
#define VIR_DOMAIN_JOB_MEMORY_ITERATION "memory_iteration"
#endif
/* 1.3.2 */
#ifndef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
#define VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION 20
#endif
/* 1.3.3 */
#ifndef VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT
#define VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT 3
#endif
#ifndef VIR_DOMAIN_EVENT_RESUMED_POSTCOPY
#define VIR_DOMAIN_EVENT_RESUMED_POSTCOPY 3
#endif
#ifndef VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY
#define VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY 7
#endif
#ifndef VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED
#define VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED 8
#endif
#ifndef VIR_DOMAIN_PAUSED_POSTCOPY
#define VIR_DOMAIN_PAUSED_POSTCOPY 12
#endif
#ifndef VIR_DOMAIN_PAUSED_POSTCOPY_FAILED
#define VIR_DOMAIN_PAUSED_POSTCOPY_FAILED 13
#endif
#ifndef VIR_DOMAIN_RUNNING_POSTCOPY
#define VIR_DOMAIN_RUNNING_POSTCOPY 10
#endif
#ifndef VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD
#define VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD "global_period"
#endif
#ifndef VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA
#define VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA "global_quota"
#endif
#ifndef VIR_DOMAIN_STATS_PERF
#define VIR_DOMAIN_STATS_PERF (1 << 6)
#endif
#ifndef VIR_MIGRATE_PARAM_DISKS_PORT
#define VIR_MIGRATE_PARAM_DISKS_PORT "disks_port"
#endif
#ifndef VIR_PERF_PARAM_CMT
#define VIR_PERF_PARAM_CMT "cmt"
#endif
#ifndef VIR_MIGRATE_POSTCOPY
#define VIR_MIGRATE_POSTCOPY (1 << 15)
#endif
#ifndef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
#define VIR_DOMAIN_EVENT_ID_JOB_COMPLETED 21
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_GLOBAL_PERIOD
#define VIR_DOMAIN_TUNABLE_CPU_GLOBAL_PERIOD "cputune.global_period"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_GLOBAL_QUOTA
#define VIR_DOMAIN_TUNABLE_CPU_GLOBAL_QUOTA "cputune.global_quota"
#endif
int virDomainGetPerfEventsCompat(virDomainPtr dom,
virTypedParameterPtr *params,
int *nparams,
unsigned int flags);
int virDomainSetPerfEventsCompat(virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
unsigned int flags);
int virDomainMigrateStartPostCopyCompat(virDomainPtr domain,
unsigned int flags);
/* 1.3.4 */
#ifndef VIR_MIGRATE_PARAM_COMPRESSION
#define VIR_MIGRATE_PARAM_COMPRESSION "compression"
#endif
#ifndef VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS
#define VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS "compression.mt.threads"
#endif
#ifndef VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS
#define VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS "compression.mt.dthreads"
#endif
#ifndef VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL
#define VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL "compression.mt.level"
#endif
#ifndef VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE
#define VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE "compression.xbzrle.cache"
#endif
#ifndef VIR_MIGRATE_PARAM_PERSIST_XML
#define VIR_MIGRATE_PARAM_PERSIST_XML "persistent_xml"
#endif
#ifndef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
#define VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED 22
#endif
/* 1.3.5 */
#ifndef VIR_PERF_PARAM_MBML
#define VIR_PERF_PARAM_MBML "mbml"
#endif
#ifndef VIR_PERF_PARAM_MBMT
#define VIR_PERF_PARAM_MBMT "mbmt"
#endif
/* 2.0.0 */
#ifndef VIR_DOMAIN_JOB_AUTO_CONVERGE_THROTTLE
#define VIR_DOMAIN_JOB_AUTO_CONVERGE_THROTTLE "auto_converge_throttle"
#endif
#ifndef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL
#define VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL "auto_converge.initial"
#endif
#ifndef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT
#define VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT "auto_converge.increment"
#endif
int virDomainGetGuestVcpusCompat(virDomainPtr domain,
virTypedParameterPtr *params,
unsigned int *nparams,
unsigned int flags);
int virDomainSetGuestVcpusCompat(virDomainPtr domain,
const char *cpumap,
int state,
unsigned int flags);
/* 2.1.0 */
#ifndef VIR_DOMAIN_MEMORY_STAT_USABLE
#define VIR_DOMAIN_MEMORY_STAT_USABLE 8
#endif
#ifndef VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE
#define VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE 9
#endif
/* 2.2.0 */
#ifndef VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD
#define VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD "iothread_period"
#endif
#ifndef VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA
#define VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA "iothread_quota"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD
#define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD "cputune.iothread_period"
#endif
#ifndef VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA
# define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA "cputune.iothread_quota"
#endif
/* 2.3.0 */
#ifndef VIR_DOMAIN_UNDEFINE_KEEP_NVRAM
#define VIR_DOMAIN_UNDEFINE_KEEP_NVRAM (1 << 3)
#endif
#ifndef VIR_PERF_PARAM_CACHE_MISSES
#define VIR_PERF_PARAM_CACHE_MISSES "cache_misses"
#endif
#ifndef VIR_PERF_PARAM_CACHE_REFERENCES
#define VIR_PERF_PARAM_CACHE_REFERENCES "cache_references"
#endif
#ifndef VIR_PERF_PARAM_INSTRUCTIONS
#define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
#endif
#ifndef VIR_PERF_PARAM_CPU_CYCLES
#define VIR_PERF_PARAM_CPU_CYCLES "cpu_cycles"
#endif
/* 2.4.0 */
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH
#define VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH "read_bytes_sec_max_length"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH
#define VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH "read_iops_sec_max_length"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH
#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH "total_bytes_sec_max_length"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH
#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH "total_iops_sec_max_length"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH
#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH "write_bytes_sec_max_length"
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH
#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH "write_iopcs_sec_max_length"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX_LENGTH
#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX_LENGTH "blkdeviotune.total_bytes_sec_max_length"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX_LENGTH
#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX_LENGTH "blkdeviotune.read_bytes_sec_max_length"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX_LENGTH
#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX_LENGTH "blkdeviotune.write_bytes_sec_max_length"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX_LENGTH
#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX_LENGTH "blkdeviotune.total_iops_sec_max_length"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX_LENGTH
#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX_LENGTH "blkdeviotune.read_iops_sec_max_length"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX_LENGTH
#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX_LENGTH "blkdeviotune.write_iops_sec_max_length"
#endif
#ifndef VIR_DOMAIN_VCPU_HOTPLUGGABLE
#define VIR_DOMAIN_VCPU_HOTPLUGGABLE (1 << 4)
#endif
/* 3.0.0 */
#ifndef VIR_PERF_PARAM_BRANCH_INSTRUCTIONS
#define VIR_PERF_PARAM_BRANCH_INSTRUCTIONS "branch_instructions"
#endif
#ifndef VIR_PERF_PARAM_BRANCH_MISSES
#define VIR_PERF_PARAM_BRANCH_MISSES "branch_misses"
#endif
#ifndef VIR_PERF_PARAM_BUS_CYCLES
#define VIR_PERF_PARAM_BUS_CYCLES "bus_cycles"
#endif
#ifndef VIR_PERF_PARAM_STALLED_CYCLES_FRONTEND
#define VIR_PERF_PARAM_STALLED_CYCLES_FRONTEND "stalled_cycles_frontend"
#endif
#ifndef VIR_PERF_PARAM_STALLED_CYCLES_BACKEND
#define VIR_PERF_PARAM_STALLED_CYCLES_BACKEND "stalled_cycles_backend"
#endif
#ifndef VIR_PERF_PARAM_REF_CPU_CYCLES
#define VIR_PERF_PARAM_REF_CPU_CYCLES "ref_cpu_cycles"
#endif
#ifndef VIR_PERF_PARAM_CPU_CLOCK
#define VIR_PERF_PARAM_CPU_CLOCK "cpu_clock"
#endif
#ifndef VIR_PERF_PARAM_TASK_CLOCK
#define VIR_PERF_PARAM_TASK_CLOCK "task_clock"
#endif
#ifndef VIR_PERF_PARAM_PAGE_FAULTS
#define VIR_PERF_PARAM_PAGE_FAULTS "page_faults"
#endif
#ifndef VIR_PERF_PARAM_CONTEXT_SWITCHES
#define VIR_PERF_PARAM_CONTEXT_SWITCHES "context_switches"
#endif
#ifndef VIR_PERF_PARAM_CPU_MIGRATIONS
#define VIR_PERF_PARAM_CPU_MIGRATIONS "cpu_migrations"
#endif
#ifndef VIR_PERF_PARAM_PAGE_FAULTS_MIN
#define VIR_PERF_PARAM_PAGE_FAULTS_MIN "page_faults_min"
#endif
#ifndef VIR_PERF_PARAM_PAGE_FAULTS_MAJ
#define VIR_PERF_PARAM_PAGE_FAULTS_MAJ "page_faults_maj"
#endif
#ifndef VIR_PERF_PARAM_ALIGNMENT_FAULTS
#define VIR_PERF_PARAM_ALIGNMENT_FAULTS "alignment_faults"
#endif
#ifndef VIR_PERF_PARAM_EMULATION_FAULTS
#define VIR_PERF_PARAM_EMULATION_FAULTS "emulation_faults"
#endif
#ifndef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
#define VIR_DOMAIN_EVENT_ID_METADATA_CHANGE 23
#endif
#ifndef VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME
#define VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME "group_name"
#endif
#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME
#define VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME "blkdeviotune.group_name"
#endif
/* 3.1.0 */
int virDomainSetVcpuCompat(virDomainPtr domain,
const char *cpumap,
int state,
unsigned int flags);
/* 3.2.0 */
#ifndef VIR_MIGRATE_TLS
#define VIR_MIGRATE_TLS 1 << 16
#endif
#ifndef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
#define VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD 24
#endif
int virDomainSetBlockThresholdCompat(virDomainPtr domain,
const char *dev,
unsigned long long threshold,
unsigned int flags);
/* 3.3.0 */
#ifndef VIR_DOMAIN_JOB_OPERATION
#define VIR_DOMAIN_JOB_OPERATION "operation"
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_UNKNOWN
#define VIR_DOMAIN_JOB_OPERATION_UNKNOWN 0
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_START
#define VIR_DOMAIN_JOB_OPERATION_START 1
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_SAVE
#define VIR_DOMAIN_JOB_OPERATION_SAVE 2
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_RESTORE
#define VIR_DOMAIN_JOB_OPERATION_RESTORE 3
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN
#define VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN 4
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT
#define VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT 5
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_SNAPSHOT
#define VIR_DOMAIN_JOB_OPERATION_SNAPSHOT 6
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT
#define VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT 7
#endif
#ifndef VIR_DOMAIN_JOB_OPERATION_DUMP
#define VIR_DOMAIN_JOB_OPERATION_DUMP 8
#endif
/* 3.4.0 */
#ifndef VIR_DOMAIN_EVENT_SHUTDOWN_GUEST
#define VIR_DOMAIN_EVENT_SHUTDOWN_GUEST 1
#endif
#ifndef VIR_DOMAIN_EVENT_SHUTDOWN_HOST
#define VIR_DOMAIN_EVENT_SHUTDOWN_HOST 2
#endif
#endif /* LIBVIRT_GO_DOMAIN_COMPAT_H__ */

1608
vendor/github.com/libvirt/libvirt-go/domain_events.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,238 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "domain_events_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
extern void domainEventLifecycleCallback(virConnectPtr, virDomainPtr, int, int, int);
void domainEventLifecycleCallback_cgo(virConnectPtr c, virDomainPtr d,
int event, int detail, void *data)
{
domainEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
}
extern void domainEventGenericCallback(virConnectPtr, virDomainPtr, int);
void domainEventGenericCallback_cgo(virConnectPtr c, virDomainPtr d, void *data)
{
domainEventGenericCallback(c, d, (int)(intptr_t)data);
}
extern void domainEventRTCChangeCallback(virConnectPtr, virDomainPtr, long long, int);
void domainEventRTCChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
long long utcoffset, void *data)
{
domainEventRTCChangeCallback(c, d, utcoffset, (int)(intptr_t)data);
}
extern void domainEventWatchdogCallback(virConnectPtr, virDomainPtr, int, int);
void domainEventWatchdogCallback_cgo(virConnectPtr c, virDomainPtr d,
int action, void *data)
{
domainEventWatchdogCallback(c, d, action, (int)(intptr_t)data);
}
extern void domainEventIOErrorCallback(virConnectPtr, virDomainPtr, const char *, const char *, int, int);
void domainEventIOErrorCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *srcPath, const char *devAlias,
int action, void *data)
{
domainEventIOErrorCallback(c, d, srcPath, devAlias, action, (int)(intptr_t)data);
}
extern void domainEventGraphicsCallback(virConnectPtr, virDomainPtr, int, const virDomainEventGraphicsAddress *,
const virDomainEventGraphicsAddress *, const char *,
const virDomainEventGraphicsSubject *, int);
void domainEventGraphicsCallback_cgo(virConnectPtr c, virDomainPtr d,
int phase, const virDomainEventGraphicsAddress *local,
const virDomainEventGraphicsAddress *remote,
const char *authScheme,
const virDomainEventGraphicsSubject *subject, void *data)
{
domainEventGraphicsCallback(c, d, phase, local, remote, authScheme, subject, (int)(intptr_t)data);
}
extern void domainEventIOErrorReasonCallback(virConnectPtr, virDomainPtr, const char *, const char *,
int, const char *, int);
void domainEventIOErrorReasonCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *srcPath, const char *devAlias,
int action, const char *reason, void *data)
{
domainEventIOErrorReasonCallback(c, d, srcPath, devAlias, action, reason, (int)(intptr_t)data);
}
extern void domainEventBlockJobCallback(virConnectPtr, virDomainPtr, const char *, int, int, int);
void domainEventBlockJobCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *disk, int type, int status, void *data)
{
domainEventBlockJobCallback(c, d, disk, type, status, (int)(intptr_t)data);
}
extern void domainEventDiskChangeCallback(virConnectPtr, virDomainPtr, const char *, const char *,
const char *, int, int);
void domainEventDiskChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *oldSrcPath, const char *newSrcPath,
const char *devAlias, int reason, void *data)
{
domainEventDiskChangeCallback(c, d, oldSrcPath, newSrcPath, devAlias, reason, (int)(intptr_t)data);
}
extern void domainEventTrayChangeCallback(virConnectPtr, virDomainPtr, const char *, int, int);
void domainEventTrayChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *devAlias, int reason, void *data)
{
domainEventTrayChangeCallback(c, d, devAlias, reason, (int)(intptr_t)data);
}
extern void domainEventPMSuspendCallback(virConnectPtr, virDomainPtr, int, int);
void domainEventPMSuspendCallback_cgo(virConnectPtr c, virDomainPtr d,
int reason, void *data)
{
domainEventPMSuspendCallback(c, d, reason, (int)(intptr_t)data);
}
extern void domainEventPMWakeupCallback(virConnectPtr, virDomainPtr, int, int);
void domainEventPMWakeupCallback_cgo(virConnectPtr c, virDomainPtr d,
int reason, void *data)
{
domainEventPMWakeupCallback(c, d, reason, (int)(intptr_t)data);
}
extern void domainEventPMSuspendDiskCallback(virConnectPtr, virDomainPtr, int, int);
void domainEventPMSuspendDiskCallback_cgo(virConnectPtr c, virDomainPtr d,
int reason, void *data)
{
domainEventPMSuspendDiskCallback(c, d, reason, (int)(intptr_t)data);
}
extern void domainEventBalloonChangeCallback(virConnectPtr, virDomainPtr, unsigned long long, int);
void domainEventBalloonChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
unsigned long long actual, void *data)
{
domainEventBalloonChangeCallback(c, d, actual, (int)(intptr_t)data);
}
extern void domainEventDeviceRemovedCallback(virConnectPtr, virDomainPtr, const char *, int);
void domainEventDeviceRemovedCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *devAlias, void *data)
{
domainEventDeviceRemovedCallback(c, d, devAlias, (int)(intptr_t)data);
}
extern void domainEventTunableCallback(virConnectPtr, virDomainPtr, virTypedParameterPtr, int, int);
void domainEventTunableCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
void *opaque)
{
domainEventTunableCallback(conn, dom, params, nparams, (int)(intptr_t)opaque);
}
extern void domainEventAgentLifecycleCallback(virConnectPtr, virDomainPtr, int, int, int);
void domainEventAgentLifecycleCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
int state,
int reason,
void *opaque)
{
domainEventAgentLifecycleCallback(conn, dom, state, reason, (int)(intptr_t)opaque);
}
extern void domainEventDeviceAddedCallback(virConnectPtr, virDomainPtr, const char *, int);
void domainEventDeviceAddedCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
void *opaque)
{
domainEventDeviceAddedCallback(conn, dom, devAlias, (int)(intptr_t)opaque);
}
extern void domainEventMigrationIterationCallback(virConnectPtr, virDomainPtr, int, int);
void domainEventMigrationIterationCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
int iteration,
void *opaque)
{
domainEventMigrationIterationCallback(conn, dom, iteration, (int)(intptr_t)opaque);
}
extern void domainEventJobCompletedCallback(virConnectPtr, virDomainPtr, virTypedParameterPtr, int, int);
void domainEventJobCompletedCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
void *opaque)
{
domainEventJobCompletedCallback(conn, dom, params, nparams, (int)(intptr_t)opaque);
}
extern void domainEventDeviceRemovalFailedCallback(virConnectPtr, virDomainPtr, const char *, int);
void domainEventDeviceRemovalFailedCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
void *opaque)
{
domainEventDeviceRemovalFailedCallback(conn, dom, devAlias, (int)(intptr_t)opaque);
}
extern void domainEventMetadataChangeCallback(virConnectPtr, virDomainPtr, int, const char *, int);
void domainEventMetadataChangeCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
int type,
const char *nsuri,
void *opaque)
{
domainEventMetadataChangeCallback(conn, dom, type, nsuri, (int)(intptr_t)opaque);
}
extern void domainEventBlockThresholdCallback(virConnectPtr, virDomainPtr, const char *, const char *, unsigned long long, unsigned long long, int);
void domainEventBlockThresholdCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
const char *dev,
const char *path,
unsigned long long threshold,
unsigned long long excess,
void *opaque)
{
domainEventBlockThresholdCallback(conn, dom, dev, path, threshold, excess, (int)(intptr_t)opaque);
}
int virConnectDomainEventRegisterAny_cgo(virConnectPtr c, virDomainPtr d,
int eventID, virConnectDomainEventGenericCallback cb,
long goCallbackId) {
void* id = (void*)goCallbackId;
return virConnectDomainEventRegisterAny(c, d, eventID, cb, id, freeGoCallback_cgo);
}
*/
import "C"

View File

@ -0,0 +1,124 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__
void domainEventLifecycleCallback_cgo(virConnectPtr c, virDomainPtr d,
int event, int detail, void* data);
void domainEventGenericCallback_cgo(virConnectPtr c, virDomainPtr d, void* data);
void domainEventRTCChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
long long utcoffset, void* data);
void domainEventWatchdogCallback_cgo(virConnectPtr c, virDomainPtr d,
int action, void* data);
void domainEventIOErrorCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *srcPath, const char *devAlias,
int action, void* data);
void domainEventGraphicsCallback_cgo(virConnectPtr c, virDomainPtr d,
int phase, const virDomainEventGraphicsAddress *local,
const virDomainEventGraphicsAddress *remote,
const char *authScheme,
const virDomainEventGraphicsSubject *subject, void* data);
void domainEventIOErrorReasonCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *srcPath, const char *devAlias,
int action, const char *reason, void* data);
void domainEventBlockJobCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *disk, int type, int status, void* data);
void domainEventDiskChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *oldSrcPath, const char *newSrcPath,
const char *devAlias, int reason, void* data);
void domainEventTrayChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *devAlias, int reason, void* data);
void domainEventPMSuspendCallback_cgo(virConnectPtr c, virDomainPtr d,
int reason, void* data);
void domainEventPMWakeupCallback_cgo(virConnectPtr c, virDomainPtr d,
int reason, void* data);
void domainEventPMSuspendDiskCallback_cgo(virConnectPtr c, virDomainPtr d,
int reason, void* data);
void domainEventBalloonChangeCallback_cgo(virConnectPtr c, virDomainPtr d,
unsigned long long actual, void* data);
void domainEventDeviceRemovedCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *devAlias, void* data);
void domainEventTunableCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
void *opaque);
void domainEventAgentLifecycleCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
int state,
int reason,
void *opaque);
void domainEventDeviceAddedCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
void *opaque);
void domainEventMigrationIterationCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
int iteration,
void *opaque);
void domainEventJobCompletedCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
virTypedParameterPtr params,
int nparams,
void *opaque);
void domainEventDeviceRemovalFailedCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
const char *devAlias,
void *opaque);
void domainEventMetadataChangeCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
int type,
const char *nsuri,
void *opaque);
void domainEventBlockThresholdCallback_cgo(virConnectPtr conn,
virDomainPtr dom,
const char *dev,
const char *path,
unsigned long long threshold,
unsigned long long excess,
void *opaque);
int virConnectDomainEventRegisterAny_cgo(virConnectPtr c, virDomainPtr d,
int eventID, virConnectDomainEventGenericCallback cb,
long goCallbackId);
#endif /* LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__ */

217
vendor/github.com/libvirt/libvirt-go/domain_snapshot.go generated vendored Normal file
View File

@ -0,0 +1,217 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"reflect"
"unsafe"
)
type DomainSnapshotCreateFlags int
const (
DOMAIN_SNAPSHOT_CREATE_REDEFINE = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)
DOMAIN_SNAPSHOT_CREATE_CURRENT = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)
DOMAIN_SNAPSHOT_CREATE_NO_METADATA = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)
DOMAIN_SNAPSHOT_CREATE_HALT = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_HALT)
DOMAIN_SNAPSHOT_CREATE_DISK_ONLY = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
DOMAIN_SNAPSHOT_CREATE_REUSE_EXT = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT)
DOMAIN_SNAPSHOT_CREATE_QUIESCE = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE)
DOMAIN_SNAPSHOT_CREATE_ATOMIC = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC)
DOMAIN_SNAPSHOT_CREATE_LIVE = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_LIVE)
)
type DomainSnapshotListFlags int
const (
DOMAIN_SNAPSHOT_LIST_ROOTS = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)
DOMAIN_SNAPSHOT_LIST_DESCENDANTS = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS)
DOMAIN_SNAPSHOT_LIST_LEAVES = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_LEAVES)
DOMAIN_SNAPSHOT_LIST_NO_LEAVES = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)
DOMAIN_SNAPSHOT_LIST_METADATA = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_METADATA)
DOMAIN_SNAPSHOT_LIST_NO_METADATA = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA)
DOMAIN_SNAPSHOT_LIST_INACTIVE = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE)
DOMAIN_SNAPSHOT_LIST_ACTIVE = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE)
DOMAIN_SNAPSHOT_LIST_DISK_ONLY = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY)
DOMAIN_SNAPSHOT_LIST_INTERNAL = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL)
DOMAIN_SNAPSHOT_LIST_EXTERNAL = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)
)
type DomainSnapshotRevertFlags int
const (
DOMAIN_SNAPSHOT_REVERT_RUNNING = DomainSnapshotRevertFlags(C.VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING)
DOMAIN_SNAPSHOT_REVERT_PAUSED = DomainSnapshotRevertFlags(C.VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)
DOMAIN_SNAPSHOT_REVERT_FORCE = DomainSnapshotRevertFlags(C.VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)
)
type DomainSnapshotDeleteFlags int
const (
DOMAIN_SNAPSHOT_DELETE_CHILDREN = DomainSnapshotDeleteFlags(C.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)
DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY = DomainSnapshotDeleteFlags(C.VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)
DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY = DomainSnapshotDeleteFlags(C.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)
)
type DomainSnapshot struct {
ptr C.virDomainSnapshotPtr
}
func (s *DomainSnapshot) Free() error {
ret := C.virDomainSnapshotFree(s.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *DomainSnapshot) Ref() error {
ret := C.virDomainSnapshotRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (s *DomainSnapshot) Delete(flags DomainSnapshotDeleteFlags) error {
result := C.virDomainSnapshotDelete(s.ptr, C.uint(flags))
if result != 0 {
return GetLastError()
}
return nil
}
func (s *DomainSnapshot) RevertToSnapshot(flags DomainSnapshotRevertFlags) error {
result := C.virDomainRevertToSnapshot(s.ptr, C.uint(flags))
if result != 0 {
return GetLastError()
}
return nil
}
func (s *DomainSnapshot) IsCurrent(flags uint32) (bool, error) {
result := C.virDomainSnapshotIsCurrent(s.ptr, C.uint(flags))
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (s *DomainSnapshot) HasMetadata(flags uint32) (bool, error) {
result := C.virDomainSnapshotHasMetadata(s.ptr, C.uint(flags))
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (s *DomainSnapshot) GetXMLDesc(flags DomainXMLFlags) (string, error) {
result := C.virDomainSnapshotGetXMLDesc(s.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (s *DomainSnapshot) GetName() (string, error) {
name := C.virDomainSnapshotGetName(s.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (s *DomainSnapshot) GetParent(flags uint32) (*DomainSnapshot, error) {
ptr := C.virDomainSnapshotGetParent(s.ptr, C.uint(flags))
if ptr == nil {
return nil, GetLastError()
}
return &DomainSnapshot{ptr: ptr}, nil
}
func (s *DomainSnapshot) NumChildren(flags DomainSnapshotListFlags) (int, error) {
result := int(C.virDomainSnapshotNumChildren(s.ptr, C.uint(flags)))
if result == -1 {
return 0, GetLastError()
}
return result, nil
}
func (s *DomainSnapshot) ListChildrenNames(flags DomainSnapshotListFlags) ([]string, error) {
const maxNames = 1024
var names [maxNames](*C.char)
namesPtr := unsafe.Pointer(&names)
numNames := C.virDomainSnapshotListChildrenNames(
s.ptr,
(**C.char)(namesPtr),
maxNames, C.uint(flags))
if numNames == -1 {
return nil, GetLastError()
}
goNames := make([]string, numNames)
for k := 0; k < int(numNames); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
func (d *DomainSnapshot) ListAllChildren(flags DomainSnapshotListFlags) ([]DomainSnapshot, error) {
var cList *C.virDomainSnapshotPtr
numVols := C.virDomainSnapshotListAllChildren(d.ptr, (**C.virDomainSnapshotPtr)(&cList), C.uint(flags))
if numVols == -1 {
return nil, GetLastError()
}
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(cList)),
Len: int(numVols),
Cap: int(numVols),
}
var pools []DomainSnapshot
slice := *(*[]C.virDomainSnapshotPtr)(unsafe.Pointer(&hdr))
for _, ptr := range slice {
pools = append(pools, DomainSnapshot{ptr})
}
C.free(unsafe.Pointer(cList))
return pools, nil
}

601
vendor/github.com/libvirt/libvirt-go/error.go generated vendored Normal file
View File

@ -0,0 +1,601 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "error_compat.h"
void ignoreErrorFunc(void *userData, virErrorPtr error) {
// no-op
}
*/
import "C"
import (
"fmt"
)
func init() {
C.virSetErrorFunc(nil, (C.virErrorFunc)(C.ignoreErrorFunc))
C.virInitialize()
}
type ErrorLevel int
const (
ERR_NONE = ErrorLevel(C.VIR_ERR_NONE)
ERR_WARNING = ErrorLevel(C.VIR_ERR_WARNING)
ERR_ERROR = ErrorLevel(C.VIR_ERR_ERROR)
)
type ErrorNumber int
const (
ERR_OK = ErrorNumber(C.VIR_ERR_OK)
// internal error
ERR_INTERNAL_ERROR = ErrorNumber(C.VIR_ERR_INTERNAL_ERROR)
// memory allocation failure
ERR_NO_MEMORY = ErrorNumber(C.VIR_ERR_NO_MEMORY)
// no support for this function
ERR_NO_SUPPORT = ErrorNumber(C.VIR_ERR_NO_SUPPORT)
// could not resolve hostname
ERR_UNKNOWN_HOST = ErrorNumber(C.VIR_ERR_UNKNOWN_HOST)
// can't connect to hypervisor
ERR_NO_CONNECT = ErrorNumber(C.VIR_ERR_NO_CONNECT)
// invalid connection object
ERR_INVALID_CONN = ErrorNumber(C.VIR_ERR_INVALID_CONN)
// invalid domain object
ERR_INVALID_DOMAIN = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN)
// invalid function argument
ERR_INVALID_ARG = ErrorNumber(C.VIR_ERR_INVALID_ARG)
// a command to hypervisor failed
ERR_OPERATION_FAILED = ErrorNumber(C.VIR_ERR_OPERATION_FAILED)
// a HTTP GET command to failed
ERR_GET_FAILED = ErrorNumber(C.VIR_ERR_GET_FAILED)
// a HTTP POST command to failed
ERR_POST_FAILED = ErrorNumber(C.VIR_ERR_POST_FAILED)
// unexpected HTTP error code
ERR_HTTP_ERROR = ErrorNumber(C.VIR_ERR_HTTP_ERROR)
// failure to serialize an S-Expr
ERR_SEXPR_SERIAL = ErrorNumber(C.VIR_ERR_SEXPR_SERIAL)
// could not open Xen hypervisor control
ERR_NO_XEN = ErrorNumber(C.VIR_ERR_NO_XEN)
// failure doing an hypervisor call
ERR_XEN_CALL = ErrorNumber(C.VIR_ERR_XEN_CALL)
// unknown OS type
ERR_OS_TYPE = ErrorNumber(C.VIR_ERR_OS_TYPE)
// missing kernel information
ERR_NO_KERNEL = ErrorNumber(C.VIR_ERR_NO_KERNEL)
// missing root device information
ERR_NO_ROOT = ErrorNumber(C.VIR_ERR_NO_ROOT)
// missing source device information
ERR_NO_SOURCE = ErrorNumber(C.VIR_ERR_NO_SOURCE)
// missing target device information
ERR_NO_TARGET = ErrorNumber(C.VIR_ERR_NO_TARGET)
// missing domain name information
ERR_NO_NAME = ErrorNumber(C.VIR_ERR_NO_NAME)
// missing domain OS information
ERR_NO_OS = ErrorNumber(C.VIR_ERR_NO_OS)
// missing domain devices information
ERR_NO_DEVICE = ErrorNumber(C.VIR_ERR_NO_DEVICE)
// could not open Xen Store control
ERR_NO_XENSTORE = ErrorNumber(C.VIR_ERR_NO_XENSTORE)
// too many drivers registered
ERR_DRIVER_FULL = ErrorNumber(C.VIR_ERR_DRIVER_FULL)
// not supported by the drivers (DEPRECATED)
ERR_CALL_FAILED = ErrorNumber(C.VIR_ERR_CALL_FAILED)
// an XML description is not well formed or broken
ERR_XML_ERROR = ErrorNumber(C.VIR_ERR_XML_ERROR)
// the domain already exist
ERR_DOM_EXIST = ErrorNumber(C.VIR_ERR_DOM_EXIST)
// operation forbidden on read-only connections
ERR_OPERATION_DENIED = ErrorNumber(C.VIR_ERR_OPERATION_DENIED)
// failed to open a conf file
ERR_OPEN_FAILED = ErrorNumber(C.VIR_ERR_OPEN_FAILED)
// failed to read a conf file
ERR_READ_FAILED = ErrorNumber(C.VIR_ERR_READ_FAILED)
// failed to parse a conf file
ERR_PARSE_FAILED = ErrorNumber(C.VIR_ERR_PARSE_FAILED)
// failed to parse the syntax of a conf file
ERR_CONF_SYNTAX = ErrorNumber(C.VIR_ERR_CONF_SYNTAX)
// failed to write a conf file
ERR_WRITE_FAILED = ErrorNumber(C.VIR_ERR_WRITE_FAILED)
// detail of an XML error
ERR_XML_DETAIL = ErrorNumber(C.VIR_ERR_XML_DETAIL)
// invalid network object
ERR_INVALID_NETWORK = ErrorNumber(C.VIR_ERR_INVALID_NETWORK)
// the network already exist
ERR_NETWORK_EXIST = ErrorNumber(C.VIR_ERR_NETWORK_EXIST)
// general system call failure
ERR_SYSTEM_ERROR = ErrorNumber(C.VIR_ERR_SYSTEM_ERROR)
// some sort of RPC error
ERR_RPC = ErrorNumber(C.VIR_ERR_RPC)
// error from a GNUTLS call
ERR_GNUTLS_ERROR = ErrorNumber(C.VIR_ERR_GNUTLS_ERROR)
// failed to start network
WAR_NO_NETWORK = ErrorNumber(C.VIR_WAR_NO_NETWORK)
// domain not found or unexpectedly disappeared
ERR_NO_DOMAIN = ErrorNumber(C.VIR_ERR_NO_DOMAIN)
// network not found
ERR_NO_NETWORK = ErrorNumber(C.VIR_ERR_NO_NETWORK)
// invalid MAC address
ERR_INVALID_MAC = ErrorNumber(C.VIR_ERR_INVALID_MAC)
// authentication failed
ERR_AUTH_FAILED = ErrorNumber(C.VIR_ERR_AUTH_FAILED)
// invalid storage pool object
ERR_INVALID_STORAGE_POOL = ErrorNumber(C.VIR_ERR_INVALID_STORAGE_POOL)
// invalid storage vol object
ERR_INVALID_STORAGE_VOL = ErrorNumber(C.VIR_ERR_INVALID_STORAGE_VOL)
// failed to start storage
WAR_NO_STORAGE = ErrorNumber(C.VIR_WAR_NO_STORAGE)
// storage pool not found
ERR_NO_STORAGE_POOL = ErrorNumber(C.VIR_ERR_NO_STORAGE_POOL)
// storage volume not found
ERR_NO_STORAGE_VOL = ErrorNumber(C.VIR_ERR_NO_STORAGE_VOL)
// failed to start node driver
WAR_NO_NODE = ErrorNumber(C.VIR_WAR_NO_NODE)
// invalid node device object
ERR_INVALID_NODE_DEVICE = ErrorNumber(C.VIR_ERR_INVALID_NODE_DEVICE)
// node device not found
ERR_NO_NODE_DEVICE = ErrorNumber(C.VIR_ERR_NO_NODE_DEVICE)
// security model not found
ERR_NO_SECURITY_MODEL = ErrorNumber(C.VIR_ERR_NO_SECURITY_MODEL)
// operation is not applicable at this time
ERR_OPERATION_INVALID = ErrorNumber(C.VIR_ERR_OPERATION_INVALID)
// failed to start interface driver
WAR_NO_INTERFACE = ErrorNumber(C.VIR_WAR_NO_INTERFACE)
// interface driver not running
ERR_NO_INTERFACE = ErrorNumber(C.VIR_ERR_NO_INTERFACE)
// invalid interface object
ERR_INVALID_INTERFACE = ErrorNumber(C.VIR_ERR_INVALID_INTERFACE)
// more than one matching interface found
ERR_MULTIPLE_INTERFACES = ErrorNumber(C.VIR_ERR_MULTIPLE_INTERFACES)
// failed to start nwfilter driver
WAR_NO_NWFILTER = ErrorNumber(C.VIR_WAR_NO_NWFILTER)
// invalid nwfilter object
ERR_INVALID_NWFILTER = ErrorNumber(C.VIR_ERR_INVALID_NWFILTER)
// nw filter pool not found
ERR_NO_NWFILTER = ErrorNumber(C.VIR_ERR_NO_NWFILTER)
// nw filter pool not found
ERR_BUILD_FIREWALL = ErrorNumber(C.VIR_ERR_BUILD_FIREWALL)
// failed to start secret storage
WAR_NO_SECRET = ErrorNumber(C.VIR_WAR_NO_SECRET)
// invalid secret
ERR_INVALID_SECRET = ErrorNumber(C.VIR_ERR_INVALID_SECRET)
// secret not found
ERR_NO_SECRET = ErrorNumber(C.VIR_ERR_NO_SECRET)
// unsupported configuration construct
ERR_CONFIG_UNSUPPORTED = ErrorNumber(C.VIR_ERR_CONFIG_UNSUPPORTED)
// timeout occurred during operation
ERR_OPERATION_TIMEOUT = ErrorNumber(C.VIR_ERR_OPERATION_TIMEOUT)
// a migration worked, but making the VM persist on the dest host failed
ERR_MIGRATE_PERSIST_FAILED = ErrorNumber(C.VIR_ERR_MIGRATE_PERSIST_FAILED)
// a synchronous hook script failed
ERR_HOOK_SCRIPT_FAILED = ErrorNumber(C.VIR_ERR_HOOK_SCRIPT_FAILED)
// invalid domain snapshot
ERR_INVALID_DOMAIN_SNAPSHOT = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN_SNAPSHOT)
// domain snapshot not found
ERR_NO_DOMAIN_SNAPSHOT = ErrorNumber(C.VIR_ERR_NO_DOMAIN_SNAPSHOT)
// stream pointer not valid
ERR_INVALID_STREAM = ErrorNumber(C.VIR_ERR_INVALID_STREAM)
// valid API use but unsupported by the given driver
ERR_ARGUMENT_UNSUPPORTED = ErrorNumber(C.VIR_ERR_ARGUMENT_UNSUPPORTED)
// storage pool probe failed
ERR_STORAGE_PROBE_FAILED = ErrorNumber(C.VIR_ERR_STORAGE_PROBE_FAILED)
// storage pool already built
ERR_STORAGE_POOL_BUILT = ErrorNumber(C.VIR_ERR_STORAGE_POOL_BUILT)
// force was not requested for a risky domain snapshot revert
ERR_SNAPSHOT_REVERT_RISKY = ErrorNumber(C.VIR_ERR_SNAPSHOT_REVERT_RISKY)
// operation on a domain was canceled/aborted by user
ERR_OPERATION_ABORTED = ErrorNumber(C.VIR_ERR_OPERATION_ABORTED)
// authentication cancelled
ERR_AUTH_CANCELLED = ErrorNumber(C.VIR_ERR_AUTH_CANCELLED)
// The metadata is not present
ERR_NO_DOMAIN_METADATA = ErrorNumber(C.VIR_ERR_NO_DOMAIN_METADATA)
// Migration is not safe
ERR_MIGRATE_UNSAFE = ErrorNumber(C.VIR_ERR_MIGRATE_UNSAFE)
// integer overflow
ERR_OVERFLOW = ErrorNumber(C.VIR_ERR_OVERFLOW)
// action prevented by block copy job
ERR_BLOCK_COPY_ACTIVE = ErrorNumber(C.VIR_ERR_BLOCK_COPY_ACTIVE)
// The requested operation is not supported
ERR_OPERATION_UNSUPPORTED = ErrorNumber(C.VIR_ERR_OPERATION_UNSUPPORTED)
// error in ssh transport driver
ERR_SSH = ErrorNumber(C.VIR_ERR_SSH)
// guest agent is unresponsive, not running or not usable
ERR_AGENT_UNRESPONSIVE = ErrorNumber(C.VIR_ERR_AGENT_UNRESPONSIVE)
// resource is already in use
ERR_RESOURCE_BUSY = ErrorNumber(C.VIR_ERR_RESOURCE_BUSY)
// operation on the object/resource was denied
ERR_ACCESS_DENIED = ErrorNumber(C.VIR_ERR_ACCESS_DENIED)
// error from a dbus service
ERR_DBUS_SERVICE = ErrorNumber(C.VIR_ERR_DBUS_SERVICE)
// the storage vol already exists
ERR_STORAGE_VOL_EXIST = ErrorNumber(C.VIR_ERR_STORAGE_VOL_EXIST)
// given CPU is incompatible with host CPU
ERR_CPU_INCOMPATIBLE = ErrorNumber(C.VIR_ERR_CPU_INCOMPATIBLE)
// XML document doesn't validate against schema
ERR_XML_INVALID_SCHEMA = ErrorNumber(C.VIR_ERR_XML_INVALID_SCHEMA)
// Finish API succeeded but it is expected to return NULL */
ERR_MIGRATE_FINISH_OK = ErrorNumber(C.VIR_ERR_MIGRATE_FINISH_OK)
// authentication unavailable
ERR_AUTH_UNAVAILABLE = ErrorNumber(C.VIR_ERR_AUTH_UNAVAILABLE)
// Server was not found
ERR_NO_SERVER = ErrorNumber(C.VIR_ERR_NO_SERVER)
// Client was not found
ERR_NO_CLIENT = ErrorNumber(C.VIR_ERR_NO_CLIENT)
// guest agent replies with wrong id to guest sync command
ERR_AGENT_UNSYNCED = ErrorNumber(C.VIR_ERR_AGENT_UNSYNCED)
// error in libssh transport driver
ERR_LIBSSH = ErrorNumber(C.VIR_ERR_LIBSSH)
)
type ErrorDomain int
const (
FROM_NONE = ErrorDomain(C.VIR_FROM_NONE)
// Error at Xen hypervisor layer
FROM_XEN = ErrorDomain(C.VIR_FROM_XEN)
// Error at connection with xend daemon
FROM_XEND = ErrorDomain(C.VIR_FROM_XEND)
// Error at connection with xen store
FROM_XENSTORE = ErrorDomain(C.VIR_FROM_XENSTORE)
// Error in the S-Expression code
FROM_SEXPR = ErrorDomain(C.VIR_FROM_SEXPR)
// Error in the XML code
FROM_XML = ErrorDomain(C.VIR_FROM_XML)
// Error when operating on a domain
FROM_DOM = ErrorDomain(C.VIR_FROM_DOM)
// Error in the XML-RPC code
FROM_RPC = ErrorDomain(C.VIR_FROM_RPC)
// Error in the proxy code; unused since 0.8.6
FROM_PROXY = ErrorDomain(C.VIR_FROM_PROXY)
// Error in the configuration file handling
FROM_CONF = ErrorDomain(C.VIR_FROM_CONF)
// Error at the QEMU daemon
FROM_QEMU = ErrorDomain(C.VIR_FROM_QEMU)
// Error when operating on a network
FROM_NET = ErrorDomain(C.VIR_FROM_NET)
// Error from test driver
FROM_TEST = ErrorDomain(C.VIR_FROM_TEST)
// Error from remote driver
FROM_REMOTE = ErrorDomain(C.VIR_FROM_REMOTE)
// Error from OpenVZ driver
FROM_OPENVZ = ErrorDomain(C.VIR_FROM_OPENVZ)
// Error at Xen XM layer
FROM_XENXM = ErrorDomain(C.VIR_FROM_XENXM)
// Error in the Linux Stats code
FROM_STATS_LINUX = ErrorDomain(C.VIR_FROM_STATS_LINUX)
// Error from Linux Container driver
FROM_LXC = ErrorDomain(C.VIR_FROM_LXC)
// Error from storage driver
FROM_STORAGE = ErrorDomain(C.VIR_FROM_STORAGE)
// Error from network config
FROM_NETWORK = ErrorDomain(C.VIR_FROM_NETWORK)
// Error from domain config
FROM_DOMAIN = ErrorDomain(C.VIR_FROM_DOMAIN)
// Error at the UML driver
FROM_UML = ErrorDomain(C.VIR_FROM_UML)
// Error from node device monitor
FROM_NODEDEV = ErrorDomain(C.VIR_FROM_NODEDEV)
// Error from xen inotify layer
FROM_XEN_INOTIFY = ErrorDomain(C.VIR_FROM_XEN_INOTIFY)
// Error from security framework
FROM_SECURITY = ErrorDomain(C.VIR_FROM_SECURITY)
// Error from VirtualBox driver
FROM_VBOX = ErrorDomain(C.VIR_FROM_VBOX)
// Error when operating on an interface
FROM_INTERFACE = ErrorDomain(C.VIR_FROM_INTERFACE)
// The OpenNebula driver no longer exists. Retained for ABI/API compat only
FROM_ONE = ErrorDomain(C.VIR_FROM_ONE)
// Error from ESX driver
FROM_ESX = ErrorDomain(C.VIR_FROM_ESX)
// Error from IBM power hypervisor
FROM_PHYP = ErrorDomain(C.VIR_FROM_PHYP)
// Error from secret storage
FROM_SECRET = ErrorDomain(C.VIR_FROM_SECRET)
// Error from CPU driver
FROM_CPU = ErrorDomain(C.VIR_FROM_CPU)
// Error from XenAPI
FROM_XENAPI = ErrorDomain(C.VIR_FROM_XENAPI)
// Error from network filter driver
FROM_NWFILTER = ErrorDomain(C.VIR_FROM_NWFILTER)
// Error from Synchronous hooks
FROM_HOOK = ErrorDomain(C.VIR_FROM_HOOK)
// Error from domain snapshot
FROM_DOMAIN_SNAPSHOT = ErrorDomain(C.VIR_FROM_DOMAIN_SNAPSHOT)
// Error from auditing subsystem
FROM_AUDIT = ErrorDomain(C.VIR_FROM_AUDIT)
// Error from sysinfo/SMBIOS
FROM_SYSINFO = ErrorDomain(C.VIR_FROM_SYSINFO)
// Error from I/O streams
FROM_STREAMS = ErrorDomain(C.VIR_FROM_STREAMS)
// Error from VMware driver
FROM_VMWARE = ErrorDomain(C.VIR_FROM_VMWARE)
// Error from event loop impl
FROM_EVENT = ErrorDomain(C.VIR_FROM_EVENT)
// Error from libxenlight driver
FROM_LIBXL = ErrorDomain(C.VIR_FROM_LIBXL)
// Error from lock manager
FROM_LOCKING = ErrorDomain(C.VIR_FROM_LOCKING)
// Error from Hyper-V driver
FROM_HYPERV = ErrorDomain(C.VIR_FROM_HYPERV)
// Error from capabilities
FROM_CAPABILITIES = ErrorDomain(C.VIR_FROM_CAPABILITIES)
// Error from URI handling
FROM_URI = ErrorDomain(C.VIR_FROM_URI)
// Error from auth handling
FROM_AUTH = ErrorDomain(C.VIR_FROM_AUTH)
// Error from DBus
FROM_DBUS = ErrorDomain(C.VIR_FROM_DBUS)
// Error from Parallels
FROM_PARALLELS = ErrorDomain(C.VIR_FROM_PARALLELS)
// Error from Device
FROM_DEVICE = ErrorDomain(C.VIR_FROM_DEVICE)
// Error from libssh2 connection transport
FROM_SSH = ErrorDomain(C.VIR_FROM_SSH)
// Error from lockspace
FROM_LOCKSPACE = ErrorDomain(C.VIR_FROM_LOCKSPACE)
// Error from initctl device communication
FROM_INITCTL = ErrorDomain(C.VIR_FROM_INITCTL)
// Error from identity code
FROM_IDENTITY = ErrorDomain(C.VIR_FROM_IDENTITY)
// Error from cgroups
FROM_CGROUP = ErrorDomain(C.VIR_FROM_CGROUP)
// Error from access control manager
FROM_ACCESS = ErrorDomain(C.VIR_FROM_ACCESS)
// Error from systemd code
FROM_SYSTEMD = ErrorDomain(C.VIR_FROM_SYSTEMD)
// Error from bhyve driver
FROM_BHYVE = ErrorDomain(C.VIR_FROM_BHYVE)
// Error from crypto code
FROM_CRYPTO = ErrorDomain(C.VIR_FROM_CRYPTO)
// Error from firewall
FROM_FIREWALL = ErrorDomain(C.VIR_FROM_FIREWALL)
// Erorr from polkit code
FROM_POLKIT = ErrorDomain(C.VIR_FROM_POLKIT)
// Error from thread utils
FROM_THREAD = ErrorDomain(C.VIR_FROM_THREAD)
// Error from admin backend
FROM_ADMIN = ErrorDomain(C.VIR_FROM_ADMIN)
// Error from log manager
FROM_LOGGING = ErrorDomain(C.VIR_FROM_LOGGING)
// Error from Xen xl config code
FROM_XENXL = ErrorDomain(C.VIR_FROM_XENXL)
// Error from perf
FROM_PERF = ErrorDomain(C.VIR_FROM_PERF)
// Error from libssh
FROM_LIBSSH = ErrorDomain(C.VIR_FROM_LIBSSH)
)
type Error struct {
Code ErrorNumber
Domain ErrorDomain
Message string
Level ErrorLevel
}
func (err Error) Error() string {
return fmt.Sprintf("virError(Code=%d, Domain=%d, Message='%s')",
err.Code, err.Domain, err.Message)
}
func GetLastError() Error {
err := C.virGetLastError()
if err == nil {
return Error{
Code: ERR_OK,
Domain: FROM_NONE,
Message: "Missing error",
Level: ERR_NONE,
}
}
virErr := Error{
Code: ErrorNumber(err.code),
Domain: ErrorDomain(err.domain),
Message: C.GoString(err.message),
Level: ErrorLevel(err.level),
}
C.virResetError(err)
return virErr
}
func GetNotImplementedError(apiname string) Error {
return Error{
Code: ERR_NO_SUPPORT,
Domain: FROM_NONE,
Message: fmt.Sprintf("Function '%s' not available in the libvirt library used during Go build", apiname),
Level: ERR_ERROR,
}
}

144
vendor/github.com/libvirt/libvirt-go/error_compat.h generated vendored Normal file
View File

@ -0,0 +1,144 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_ERROR_COMPAT_H__
#define LIBVIRT_GO_ERROR_COMPAT_H__
/* 1.2.2 */
#ifndef VIR_FROM_BHYVE
#define VIR_FROM_BHYVE 57
#endif
/* 1.2.3 */
#ifndef VIR_FROM_CRYPTO
#define VIR_FROM_CRYPTO 58
#endif
/* 1.2.4 */
#ifndef VIR_FROM_FIREWALL
#define VIR_FROM_FIREWALL 59
#endif
/* 1.2.6 */
#ifndef VIR_ERR_CPU_INCOMPATIBLE
#define VIR_ERR_CPU_INCOMPATIBLE 91
#endif
/* 1.2.9 */
#ifndef VIR_FROM_POLKIT
#define VIR_FROM_POLKIT 60
#endif
/* 1.2.12 */
#ifndef VIR_ERR_XML_INVALID_SCHEMA
#define VIR_ERR_XML_INVALID_SCHEMA 92
#endif
/* 1.2.14 */
#ifndef VIR_FROM_THREAD
#define VIR_FROM_THREAD 61
#endif
/* 1.2.17 */
#ifndef VIR_FROM_ADMIN
#define VIR_FROM_ADMIN 62
#endif
/* 1.2.18 */
#ifndef VIR_ERR_MIGRATE_FINISH_OK
#define VIR_ERR_MIGRATE_FINISH_OK 93
#endif
/* 1.3.0 */
#ifndef VIR_FROM_LOGGING
#define VIR_FROM_LOGGING 63
#endif
/* 1.3.2 */
#ifndef VIR_FROM_XENXL
#define VIR_FROM_XENXL 64
#endif
/* 1.3.3 */
#ifndef VIR_FROM_PERF
#define VIR_FROM_PERF 65
#endif
#ifndef VIR_ERR_AUTH_UNAVAILABLE
#define VIR_ERR_AUTH_UNAVAILABLE 94
#endif
#ifndef VIR_ERR_NO_SERVER
#define VIR_ERR_NO_SERVER 95
#endif
/* 1.3.5 */
#ifndef VIR_ERR_NO_CLIENT
#define VIR_ERR_NO_CLIENT 96
#endif
/* 2.3.0 */
#ifndef VIR_ERR_AGENT_UNSYNCED
#define VIR_ERR_AGENT_UNSYNCED 97
#endif
/* 2.5.0 */
#ifndef VIR_ERR_LIBSSH
#define VIR_ERR_LIBSSH 98
#endif
#ifndef VIR_FROM_LIBSSH
#define VIR_FROM_LIBSSH 66
#endif
#endif /* LIBVIRT_GO_ERROR_COMPAT_H__ */

234
vendor/github.com/libvirt/libvirt-go/events.go generated vendored Normal file
View File

@ -0,0 +1,234 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <stdint.h>
#include "events_cfuncs.h"
*/
import "C"
type EventHandleType int
const (
EVENT_HANDLE_READABLE = EventHandleType(C.VIR_EVENT_HANDLE_READABLE)
EVENT_HANDLE_WRITABLE = EventHandleType(C.VIR_EVENT_HANDLE_WRITABLE)
EVENT_HANDLE_ERROR = EventHandleType(C.VIR_EVENT_HANDLE_ERROR)
EVENT_HANDLE_HANGUP = EventHandleType(C.VIR_EVENT_HANDLE_HANGUP)
)
func EventRegisterDefaultImpl() error {
if i := int(C.virEventRegisterDefaultImpl()); i != 0 {
return GetLastError()
}
return nil
}
func EventRunDefaultImpl() error {
if i := int(C.virEventRunDefaultImpl()); i != 0 {
return GetLastError()
}
return nil
}
type EventHandleCallback func(watch int, file int, events EventHandleType)
//export eventHandleCallback
func eventHandleCallback(watch int, fd int, events int, callbackID int) {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(EventHandleCallback)
if !ok {
panic("Incorrect event handle callback data")
}
callback(watch, fd, (EventHandleType)(events))
}
func EventAddHandle(fd int, events EventHandleType, callback EventHandleCallback) (int, error) {
callbackID := registerCallbackId(callback)
ret := C.virEventAddHandle_cgo((C.int)(fd), (C.int)(events), (C.int)(callbackID))
if ret == -1 {
return 0, GetLastError()
}
return int(ret), nil
}
func EventUpdateHandle(watch int, events EventHandleType) {
C.virEventUpdateHandle((C.int)(watch), (C.int)(events))
}
func EventRemoveHandle(watch int) {
C.virEventRemoveHandle((C.int)(watch))
}
type EventTimeoutCallback func(timer int)
//export eventTimeoutCallback
func eventTimeoutCallback(timer int, callbackID int) {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(EventTimeoutCallback)
if !ok {
panic("Incorrect event timeout callback data")
}
callback(timer)
}
func EventAddTimeout(freq int, callback EventTimeoutCallback) (int, error) {
callbackID := registerCallbackId(callback)
ret := C.virEventAddTimeout_cgo((C.int)(freq), (C.int)(callbackID))
if ret == -1 {
return 0, GetLastError()
}
return int(ret), nil
}
func EventUpdateTimeout(timer int, freq int) {
C.virEventUpdateTimeout((C.int)(timer), (C.int)(freq))
}
func EventRemoveTimeout(timer int) {
C.virEventRemoveTimeout((C.int)(timer))
}
type EventHandleCallbackInfo struct {
callback uintptr
opaque uintptr
free uintptr
}
type EventTimeoutCallbackInfo struct {
callback uintptr
opaque uintptr
free uintptr
}
func (i *EventHandleCallbackInfo) Invoke(watch int, fd int, event EventHandleType) {
C.eventHandleCallbackInvoke(C.int(watch), C.int(fd), C.int(event), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
}
func (i *EventTimeoutCallbackInfo) Invoke(timer int) {
C.eventTimeoutCallbackInvoke(C.int(timer), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
}
func (i *EventHandleCallbackInfo) Free() {
C.eventHandleCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
}
func (i *EventTimeoutCallbackInfo) Free() {
C.eventTimeoutCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
}
type EventLoop interface {
AddHandleFunc(fd int, event EventHandleType, callback *EventHandleCallbackInfo) int
UpdateHandleFunc(watch int, event EventHandleType)
RemoveHandleFunc(watch int) int
AddTimeoutFunc(freq int, callback *EventTimeoutCallbackInfo) int
UpdateTimeoutFunc(timer int, freq int)
RemoveTimeoutFunc(timer int) int
}
var eventLoopImpl EventLoop
func EventRegisterImpl(impl EventLoop) {
eventLoopImpl = impl
C.virEventRegisterImpl_cgo()
}
//export eventAddHandleFunc
func eventAddHandleFunc(fd C.int, event C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
if eventLoopImpl == nil {
panic("Event loop impl is missing")
}
cbinfo := &EventHandleCallbackInfo{
callback: callback,
opaque: opaque,
free: free,
}
return C.int(eventLoopImpl.AddHandleFunc(int(fd), EventHandleType(event), cbinfo))
}
//export eventUpdateHandleFunc
func eventUpdateHandleFunc(watch C.int, event C.int) {
if eventLoopImpl == nil {
panic("Event loop impl is missing")
}
eventLoopImpl.UpdateHandleFunc(int(watch), EventHandleType(event))
}
//export eventRemoveHandleFunc
func eventRemoveHandleFunc(watch C.int) {
if eventLoopImpl == nil {
panic("Event loop impl is missing")
}
eventLoopImpl.RemoveHandleFunc(int(watch))
}
//export eventAddTimeoutFunc
func eventAddTimeoutFunc(freq C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
if eventLoopImpl == nil {
panic("Event loop impl is missing")
}
cbinfo := &EventTimeoutCallbackInfo{
callback: callback,
opaque: opaque,
free: free,
}
return C.int(eventLoopImpl.AddTimeoutFunc(int(freq), cbinfo))
}
//export eventUpdateTimeoutFunc
func eventUpdateTimeoutFunc(timer C.int, freq C.int) {
if eventLoopImpl == nil {
panic("Event loop impl is missing")
}
eventLoopImpl.UpdateTimeoutFunc(int(timer), int(freq))
}
//export eventRemoveTimeoutFunc
func eventRemoveTimeoutFunc(timer C.int) {
if eventLoopImpl == nil {
panic("Event loop impl is missing")
}
eventLoopImpl.RemoveTimeoutFunc(int(timer))
}

132
vendor/github.com/libvirt/libvirt-go/events_cfuncs.go generated vendored Normal file
View File

@ -0,0 +1,132 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdint.h>
#include <stdlib.h>
#include "events_cfuncs.h"
void eventHandleCallback(int watch, int fd, int events, int callbackID);
static void eventAddHandleHelper(int watch, int fd, int events, void *opaque)
{
eventHandleCallback(watch, fd, events, (int)(intptr_t)opaque);
}
int virEventAddHandle_cgo(int fd, int events, int callbackID)
{
return virEventAddHandle(fd, events, eventAddHandleHelper, (void *)(intptr_t)callbackID, NULL);
}
void eventTimeoutCallback(int timer, int callbackID);
static void eventAddTimeoutHelper(int timer, void *opaque)
{
eventTimeoutCallback(timer, (int)(intptr_t)opaque);
}
int virEventAddTimeout_cgo(int freq, int callbackID)
{
return virEventAddTimeout(freq, eventAddTimeoutHelper, (void *)(intptr_t)callbackID, NULL);
}
int eventAddHandleFunc(int fd, int event, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
void eventUpdateHandleFunc(int watch, int event);
int eventRemoveHandleFunc(int watch);
int eventAddTimeoutFunc(int freq, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
void eventUpdateTimeoutFunc(int timer, int freq);
int eventRemoveTimeoutFunc(int timer);
int eventAddHandleFuncHelper(int fd, int event, virEventHandleCallback callback, void *opaque, virFreeCallback freecb)
{
return eventAddHandleFunc(fd, event, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
}
void eventUpdateHandleFuncHelper(int watch, int event)
{
eventUpdateHandleFunc(watch, event);
}
int eventRemoveHandleFuncHelper(int watch)
{
return eventRemoveHandleFunc(watch);
}
int eventAddTimeoutFuncHelper(int freq, virEventTimeoutCallback callback, void *opaque, virFreeCallback freecb)
{
return eventAddTimeoutFunc(freq, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
}
void eventUpdateTimeoutFuncHelper(int timer, int freq)
{
eventUpdateTimeoutFunc(timer, freq);
}
int eventRemoveTimeoutFuncHelper(int timer)
{
return eventRemoveTimeoutFunc(timer);
}
void virEventRegisterImpl_cgo(void)
{
virEventRegisterImpl(eventAddHandleFuncHelper,
eventUpdateHandleFuncHelper,
eventRemoveHandleFuncHelper,
eventAddTimeoutFuncHelper,
eventUpdateTimeoutFuncHelper,
eventRemoveTimeoutFuncHelper);
}
void eventHandleCallbackInvoke(int watch, int fd, int events, uintptr_t callback, uintptr_t opaque)
{
((virEventHandleCallback)callback)(watch, fd, events, (void *)opaque);
}
void eventTimeoutCallbackInvoke(int timer, uintptr_t callback, uintptr_t opaque)
{
((virEventTimeoutCallback)callback)(timer, (void *)opaque);
}
void eventHandleCallbackFree(uintptr_t callback, uintptr_t opaque)
{
((virFreeCallback)callback)((void *)opaque);
}
void eventTimeoutCallbackFree(uintptr_t callback, uintptr_t opaque)
{
((virFreeCallback)callback)((void *)opaque);
}
*/
import "C"

39
vendor/github.com/libvirt/libvirt-go/events_cfuncs.h generated vendored Normal file
View File

@ -0,0 +1,39 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_EVENTS_CFUNCS_H__
int virEventAddHandle_cgo(int fd, int events, int callbackID);
int virEventAddTimeout_cgo(int freq, int callbackID);
void virEventRegisterImpl_cgo(void);
void eventHandleCallbackInvoke(int watch, int fd, int events, uintptr_t callback, uintptr_t opaque);
void eventTimeoutCallbackInvoke(int timer, uintptr_t callback, uintptr_t opaque);
void eventHandleCallbackFree(uintptr_t callback, uintptr_t opaque);
void eventTimeoutCallbackFree(uintptr_t callback, uintptr_t opaque);
#endif /* LIBVIRT_GO_EVENTS_CFUNCS_H__ */

128
vendor/github.com/libvirt/libvirt-go/interface.go generated vendored Normal file
View File

@ -0,0 +1,128 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
type InterfaceXMLFlags int
const (
INTERFACE_XML_INACTIVE = InterfaceXMLFlags(C.VIR_INTERFACE_XML_INACTIVE)
)
type Interface struct {
ptr C.virInterfacePtr
}
func (n *Interface) Create(flags uint32) error {
result := C.virInterfaceCreate(n.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Interface) Destroy(flags uint32) error {
result := C.virInterfaceDestroy(n.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Interface) IsActive() (bool, error) {
result := C.virInterfaceIsActive(n.ptr)
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (n *Interface) GetMACString() (string, error) {
result := C.virInterfaceGetMACString(n.ptr)
if result == nil {
return "", GetLastError()
}
mac := C.GoString(result)
return mac, nil
}
func (n *Interface) GetName() (string, error) {
result := C.virInterfaceGetName(n.ptr)
if result == nil {
return "", GetLastError()
}
name := C.GoString(result)
return name, nil
}
func (n *Interface) GetXMLDesc(flags InterfaceXMLFlags) (string, error) {
result := C.virInterfaceGetXMLDesc(n.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (n *Interface) Undefine() error {
result := C.virInterfaceUndefine(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Interface) Free() error {
ret := C.virInterfaceFree(n.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *Interface) Ref() error {
ret := C.virInterfaceRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}

6
vendor/github.com/libvirt/libvirt-go/libvirtd.conf generated vendored Normal file
View File

@ -0,0 +1,6 @@
listen_tls = 0
listen_tcp = 1
tcp_port = "16509"
listen_addr = "127.0.0.1"
auth_unix_rw = "none"
auth_tcp = "sasl"

154
vendor/github.com/libvirt/libvirt-go/lxc.go generated vendored Normal file
View File

@ -0,0 +1,154 @@
// +build !without_lxc
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-lxc since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-lxc
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-lxc.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include <string.h>
#include "lxc_compat.h"
*/
import "C"
import (
"os"
"unsafe"
)
func (d *Domain) LxcOpenNamespace(flags uint32) ([]os.File, error) {
var cfdlist *C.int
ret := C.virDomainLxcOpenNamespace(d.ptr, &cfdlist, C.uint(flags))
if ret == -1 {
return []os.File{}, GetLastError()
}
fdlist := make([]os.File, ret)
for i := 0; i < int(ret); i++ {
var cfd C.int
cfd = *(*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(cfdlist)) + (unsafe.Sizeof(cfd) * uintptr(i))))
fdlist[i] = *os.NewFile(uintptr(cfd), "namespace")
}
defer C.free(unsafe.Pointer(cfdlist))
return fdlist, nil
}
func (d *Domain) LxcEnterNamespace(fdlist []os.File, flags uint32) ([]os.File, error) {
var coldfdlist *C.int
var ncoldfdlist C.uint
cfdlist := make([]C.int, len(fdlist))
for i := 0; i < len(fdlist); i++ {
cfdlist[i] = C.int(fdlist[i].Fd())
}
ret := C.virDomainLxcEnterNamespace(d.ptr, C.uint(len(fdlist)), &cfdlist[0], &ncoldfdlist, &coldfdlist, C.uint(flags))
if ret == -1 {
return []os.File{}, GetLastError()
}
oldfdlist := make([]os.File, ncoldfdlist)
for i := 0; i < int(ncoldfdlist); i++ {
var cfd C.int
cfd = *(*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(coldfdlist)) + (unsafe.Sizeof(cfd) * uintptr(i))))
oldfdlist[i] = *os.NewFile(uintptr(cfd), "namespace")
}
defer C.free(unsafe.Pointer(coldfdlist))
return oldfdlist, nil
}
func DomainLxcEnterSecurityLabel(model *NodeSecurityModel, label *SecurityLabel, flags uint32) (*SecurityLabel, error) {
var cmodel C.virSecurityModel
var clabel C.virSecurityLabel
var coldlabel C.virSecurityLabel
cmodelstrlen := len(model.Model)
if cmodelstrlen > (C.VIR_SECURITY_MODEL_BUFLEN - 1) {
cmodelstrlen = C.VIR_SECURITY_MODEL_BUFLEN - 1
}
cmodelstr := C.CString(model.Model)
defer C.free(unsafe.Pointer(cmodelstr))
cdoistrlen := len(model.Doi)
if cdoistrlen >= (C.VIR_SECURITY_DOI_BUFLEN - 1) {
cdoistrlen = C.VIR_SECURITY_DOI_BUFLEN - 1
}
cdoistr := C.CString(model.Doi)
defer C.free(unsafe.Pointer(cdoistr))
C.memcpy(unsafe.Pointer(&cmodel.model), unsafe.Pointer(cmodelstr), C.size_t(cmodelstrlen))
C.memcpy(unsafe.Pointer(&cmodel.doi), unsafe.Pointer(cdoistr), C.size_t(cdoistrlen))
clabelstrlen := len(label.Label)
if clabelstrlen > (C.VIR_SECURITY_LABEL_BUFLEN - 1) {
clabelstrlen = C.VIR_SECURITY_LABEL_BUFLEN - 1
}
clabelstr := C.CString(label.Label)
defer C.free(unsafe.Pointer(clabelstr))
C.memcpy(unsafe.Pointer(&clabel.label), unsafe.Pointer(clabelstr), C.size_t(clabelstrlen))
if label.Enforcing {
clabel.enforcing = 1
} else {
clabel.enforcing = 0
}
ret := C.virDomainLxcEnterSecurityLabel(&cmodel, &clabel, &coldlabel, C.uint(flags))
if ret == -1 {
return nil, GetLastError()
}
var oldlabel SecurityLabel
oldlabel.Label = C.GoString((*C.char)(unsafe.Pointer(&coldlabel.label)))
if coldlabel.enforcing != 0 {
oldlabel.Enforcing = true
} else {
oldlabel.Enforcing = false
}
return &oldlabel, nil
}
func (d *Domain) DomainLxcEnterCGroup(flags uint32) error {
if C.LIBVIR_VERSION_NUMBER < 2000000 {
return GetNotImplementedError("virDomainLxcEnterCGroup")
}
ret := C.virDomainLxcEnterCGroupCompat(d.ptr, C.uint(flags))
if ret == -1 {
return GetLastError()
}
return nil
}

51
vendor/github.com/libvirt/libvirt-go/lxc_compat.go generated vendored Normal file
View File

@ -0,0 +1,51 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-lxc since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-lxc
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-lxc.h>
#include <assert.h>
#include "lxc_compat.h"
int virDomainLxcEnterCGroupCompat(virDomainPtr domain,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 2000000
assert(0); // Caller should have checked version
#else
return virDomainLxcEnterCGroup(domain, flags);
#endif
}
*/
import "C"

36
vendor/github.com/libvirt/libvirt-go/lxc_compat.h generated vendored Normal file
View File

@ -0,0 +1,36 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_LXC_COMPAT_H__
#define LIBVIRT_GO_LXC_COMPAT_H__
/* 2.0.0 */
int virDomainLxcEnterCGroupCompat(virDomainPtr domain,
unsigned int flags);
#endif /* LIBVIRT_GO_LXC_COMPAT_H__ */

305
vendor/github.com/libvirt/libvirt-go/network.go generated vendored Normal file
View File

@ -0,0 +1,305 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "network_compat.h"
*/
import "C"
import (
"reflect"
"time"
"unsafe"
)
type IPAddrType int
const (
IP_ADDR_TYPE_IPV4 = IPAddrType(C.VIR_IP_ADDR_TYPE_IPV4)
IP_ADDR_TYPE_IPV6 = IPAddrType(C.VIR_IP_ADDR_TYPE_IPV6)
)
type NetworkXMLFlags int
const (
NETWORK_XML_INACTIVE = NetworkXMLFlags(C.VIR_NETWORK_XML_INACTIVE)
)
type NetworkUpdateCommand int
const (
NETWORK_UPDATE_COMMAND_NONE = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_NONE)
NETWORK_UPDATE_COMMAND_MODIFY = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_MODIFY)
NETWORK_UPDATE_COMMAND_DELETE = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_DELETE)
NETWORK_UPDATE_COMMAND_ADD_LAST = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)
NETWORK_UPDATE_COMMAND_ADD_FIRST = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST)
)
type NetworkUpdateSection int
const (
NETWORK_SECTION_NONE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_NONE)
NETWORK_SECTION_BRIDGE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_BRIDGE)
NETWORK_SECTION_DOMAIN = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DOMAIN)
NETWORK_SECTION_IP = NetworkUpdateSection(C.VIR_NETWORK_SECTION_IP)
NETWORK_SECTION_IP_DHCP_HOST = NetworkUpdateSection(C.VIR_NETWORK_SECTION_IP_DHCP_HOST)
NETWORK_SECTION_IP_DHCP_RANGE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_IP_DHCP_RANGE)
NETWORK_SECTION_FORWARD = NetworkUpdateSection(C.VIR_NETWORK_SECTION_FORWARD)
NETWORK_SECTION_FORWARD_INTERFACE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_FORWARD_INTERFACE)
NETWORK_SECTION_FORWARD_PF = NetworkUpdateSection(C.VIR_NETWORK_SECTION_FORWARD_PF)
NETWORK_SECTION_PORTGROUP = NetworkUpdateSection(C.VIR_NETWORK_SECTION_PORTGROUP)
NETWORK_SECTION_DNS_HOST = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DNS_HOST)
NETWORK_SECTION_DNS_TXT = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DNS_TXT)
NETWORK_SECTION_DNS_SRV = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DNS_SRV)
)
type NetworkUpdateFlags int
const (
NETWORK_UPDATE_AFFECT_CURRENT = NetworkUpdateFlags(C.VIR_NETWORK_UPDATE_AFFECT_CURRENT)
NETWORK_UPDATE_AFFECT_LIVE = NetworkUpdateFlags(C.VIR_NETWORK_UPDATE_AFFECT_LIVE)
NETWORK_UPDATE_AFFECT_CONFIG = NetworkUpdateFlags(C.VIR_NETWORK_UPDATE_AFFECT_CONFIG)
)
type NetworkEventLifecycleType int
const (
NETWORK_EVENT_DEFINED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_DEFINED)
NETWORK_EVENT_UNDEFINED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_UNDEFINED)
NETWORK_EVENT_STARTED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_STARTED)
NETWORK_EVENT_STOPPED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_STOPPED)
)
type NetworkEventID int
const (
NETWORK_EVENT_ID_LIFECYCLE = NetworkEventID(C.VIR_NETWORK_EVENT_ID_LIFECYCLE)
)
type Network struct {
ptr C.virNetworkPtr
}
type NetworkDHCPLease struct {
Iface string
ExpiryTime time.Time
Type IPAddrType
Mac string
Iaid string
IPaddr string
Prefix uint
Hostname string
Clientid string
}
func (n *Network) Free() error {
ret := C.virNetworkFree(n.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *Network) Ref() error {
ret := C.virNetworkRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (n *Network) Create() error {
result := C.virNetworkCreate(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Network) Destroy() error {
result := C.virNetworkDestroy(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Network) IsActive() (bool, error) {
result := C.virNetworkIsActive(n.ptr)
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (n *Network) IsPersistent() (bool, error) {
result := C.virNetworkIsPersistent(n.ptr)
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (n *Network) GetAutostart() (bool, error) {
var out C.int
result := C.virNetworkGetAutostart(n.ptr, (*C.int)(unsafe.Pointer(&out)))
if result == -1 {
return false, GetLastError()
}
switch out {
case 1:
return true, nil
default:
return false, nil
}
}
func (n *Network) SetAutostart(autostart bool) error {
var cAutostart C.int
switch autostart {
case true:
cAutostart = 1
default:
cAutostart = 0
}
result := C.virNetworkSetAutostart(n.ptr, cAutostart)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Network) GetName() (string, error) {
name := C.virNetworkGetName(n.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (n *Network) GetUUID() ([]byte, error) {
var cUuid [C.VIR_UUID_BUFLEN](byte)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virNetworkGetUUID(n.ptr, (*C.uchar)(cuidPtr))
if result != 0 {
return []byte{}, GetLastError()
}
return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
}
func (n *Network) GetUUIDString() (string, error) {
var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virNetworkGetUUIDString(n.ptr, (*C.char)(cuidPtr))
if result != 0 {
return "", GetLastError()
}
return C.GoString((*C.char)(cuidPtr)), nil
}
func (n *Network) GetBridgeName() (string, error) {
result := C.virNetworkGetBridgeName(n.ptr)
if result == nil {
return "", GetLastError()
}
bridge := C.GoString(result)
C.free(unsafe.Pointer(result))
return bridge, nil
}
func (n *Network) GetXMLDesc(flags NetworkXMLFlags) (string, error) {
result := C.virNetworkGetXMLDesc(n.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (n *Network) Undefine() error {
result := C.virNetworkUndefine(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Network) Update(cmd NetworkUpdateCommand, section NetworkUpdateSection, parentIndex int, xml string, flags NetworkUpdateFlags) error {
cxml := C.CString(xml)
defer C.free(unsafe.Pointer(cxml))
result := C.virNetworkUpdate(n.ptr, C.uint(cmd), C.uint(section), C.int(parentIndex), cxml, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (n *Network) GetDHCPLeases() ([]NetworkDHCPLease, error) {
if C.LIBVIR_VERSION_NUMBER < 1002006 {
return []NetworkDHCPLease{}, GetNotImplementedError("virNetworkGetDHCPLeases")
}
var cLeases *C.virNetworkDHCPLeasePtr
numLeases := C.virNetworkGetDHCPLeasesCompat(n.ptr, nil, (**C.virNetworkDHCPLeasePtr)(&cLeases), C.uint(0))
if numLeases == -1 {
return nil, GetLastError()
}
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(cLeases)),
Len: int(numLeases),
Cap: int(numLeases),
}
var leases []NetworkDHCPLease
slice := *(*[]C.virNetworkDHCPLeasePtr)(unsafe.Pointer(&hdr))
for _, clease := range slice {
leases = append(leases, NetworkDHCPLease{
Iface: C.GoString(clease.iface),
ExpiryTime: time.Unix(int64(clease.expirytime), 0),
Type: IPAddrType(clease._type),
Mac: C.GoString(clease.mac),
Iaid: C.GoString(clease.iaid),
IPaddr: C.GoString(clease.ipaddr),
Prefix: uint(clease.prefix),
Hostname: C.GoString(clease.hostname),
Clientid: C.GoString(clease.clientid),
})
C.virNetworkDHCPLeaseFreeCompat(clease)
}
C.free(unsafe.Pointer(cLeases))
return leases, nil
}

62
vendor/github.com/libvirt/libvirt-go/network_compat.go generated vendored Normal file
View File

@ -0,0 +1,62 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "network_compat.h"
int virConnectNetworkEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID)
{
#if LIBVIR_VERSION_NUMBER < 1002001
assert(0); // Caller should have checked version
#else
return virConnectNetworkEventDeregisterAny(conn, callbackID);
#endif
}
void virNetworkDHCPLeaseFreeCompat(virNetworkDHCPLeasePtr lease)
{
}
int virNetworkGetDHCPLeasesCompat(virNetworkPtr network,
const char *mac,
virNetworkDHCPLeasePtr **leases,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 1002006
assert(0); // Caller should have checked version
#else
return virNetworkGetDHCPLeases(network, mac, leases, flags);
#endif
}
*/
import "C"

96
vendor/github.com/libvirt/libvirt-go/network_compat.h generated vendored Normal file
View File

@ -0,0 +1,96 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_NETWORK_COMPAT_H__
#define LIBVIRT_GO_NETWORK_COMPAT_H__
/* 1.2.1 */
#ifndef VIR_NETWORK_EVENT_DEFINED
#define VIR_NETWORK_EVENT_DEFINED 0
#endif
#ifndef VIR_NETWORK_EVENT_UNDEFINED
#define VIR_NETWORK_EVENT_UNDEFINED 1
#endif
#ifndef VIR_NETWORK_EVENT_STARTED
#define VIR_NETWORK_EVENT_STARTED 2
#endif
#ifndef VIR_NETWORK_EVENT_STOPPED
#define VIR_NETWORK_EVENT_STOPPED 3
#endif
#ifndef VIR_NETWORK_EVENT_ID_LIFECYCLE
#define VIR_NETWORK_EVENT_ID_LIFECYCLE 0
#endif
#if LIBVIR_VERSION_NUMBER < 1002001
typedef void (*virConnectNetworkEventGenericCallback)(virConnectPtr conn,
virNetworkPtr net,
void *opaque);
#endif
int virConnectNetworkEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID);
/* 1.2.5 */
#ifndef VIR_IP_ADDR_TYPE_IPV4
#define VIR_IP_ADDR_TYPE_IPV4 0
#endif
#ifndef VIR_IP_ADDR_TYPE_IPV6
#define VIR_IP_ADDR_TYPE_IPV6 1
#endif
#if LIBVIR_VERSION_NUMBER < 1002006
typedef struct _virNetworkDHCPLease virNetworkDHCPLease;
typedef virNetworkDHCPLease *virNetworkDHCPLeasePtr;
struct _virNetworkDHCPLease {
char *iface; /* Network interface name */
long long expirytime; /* Seconds since epoch */
int type; /* virIPAddrType */
char *mac; /* MAC address */
char *iaid; /* IAID */
char *ipaddr; /* IP address */
unsigned int prefix; /* IP address prefix */
char *hostname; /* Hostname */
char *clientid; /* Client ID or DUID */
};
#endif
void virNetworkDHCPLeaseFreeCompat(virNetworkDHCPLeasePtr lease);
int virNetworkGetDHCPLeasesCompat(virNetworkPtr network,
const char *mac,
virNetworkDHCPLeasePtr **leases,
unsigned int flags);
#endif /* LIBVIRT_GO_NETWORK_COMPAT_H__ */

124
vendor/github.com/libvirt/libvirt-go/network_events.go generated vendored Normal file
View File

@ -0,0 +1,124 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
import (
"fmt"
"unsafe"
)
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include "network_compat.h"
#include "network_events_cfuncs.h"
*/
import "C"
type NetworkEventLifecycle struct {
Event NetworkEventLifecycleType
// TODO: we can make Detail typesafe somehow ?
Detail int
}
type NetworkEventLifecycleCallback func(c *Connect, n *Network, event *NetworkEventLifecycle)
//export networkEventLifecycleCallback
func networkEventLifecycleCallback(c C.virConnectPtr, n C.virNetworkPtr,
event int, detail int,
goCallbackId int) {
network := &Network{ptr: n}
connection := &Connect{ptr: c}
eventDetails := &NetworkEventLifecycle{
Event: NetworkEventLifecycleType(event),
Detail: detail,
}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(NetworkEventLifecycleCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, network, eventDetails)
}
func (c *Connect) NetworkEventLifecycleRegister(net *Network, callback NetworkEventLifecycleCallback) (int, error) {
goCallBackId := registerCallbackId(callback)
if C.LIBVIR_VERSION_NUMBER < 1002001 {
return 0, GetNotImplementedError("virConnectNetworkEventRegisterAny")
}
callbackPtr := unsafe.Pointer(C.networkEventLifecycleCallback_cgo)
var cnet C.virNetworkPtr
if net != nil {
cnet = net.ptr
}
ret := C.virConnectNetworkEventRegisterAny_cgo(c.ptr, cnet,
C.VIR_NETWORK_EVENT_ID_LIFECYCLE,
C.virConnectNetworkEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) NetworkEventDeregister(callbackId int) error {
if C.LIBVIR_VERSION_NUMBER < 1002001 {
return GetNotImplementedError("virConnectNetworkEventDeregisterAny")
}
// Deregister the callback
if i := int(C.virConnectNetworkEventDeregisterAnyCompat(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
}
func (e NetworkEventLifecycle) String() string {
var event string
switch e.Event {
case NETWORK_EVENT_DEFINED:
event = "defined"
case NETWORK_EVENT_UNDEFINED:
event = "undefined"
case NETWORK_EVENT_STARTED:
event = "started"
case NETWORK_EVENT_STOPPED:
event = "stopped"
default:
event = "unknown"
}
return fmt.Sprintf("Network event=%q", event)
}

View File

@ -0,0 +1,58 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <assert.h>
#include "network_compat.h"
#include "network_events_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
extern void networkEventLifecycleCallback(virConnectPtr, virNetworkPtr, int, int, int);
void networkEventLifecycleCallback_cgo(virConnectPtr c, virNetworkPtr d,
int event, int detail, void *data)
{
networkEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
}
int virConnectNetworkEventRegisterAny_cgo(virConnectPtr c, virNetworkPtr d,
int eventID, virConnectNetworkEventGenericCallback cb,
long goCallbackId) {
void* id = (void*)goCallbackId;
#if LIBVIR_VERSION_NUMBER < 1002001
assert(0); // Caller should have checked version
#else
return virConnectNetworkEventRegisterAny(c, d, eventID, cb, id, freeGoCallback_cgo);
#endif
}
*/
import "C"

View File

@ -0,0 +1,38 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_NETWORK_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_NETWORK_EVENTS_CFUNCS_H__
void networkEventLifecycleCallback_cgo(virConnectPtr c, virNetworkPtr d,
int event, int detail, void* data);
int virConnectNetworkEventRegisterAny_cgo(virConnectPtr c, virNetworkPtr d,
int eventID, virConnectNetworkEventGenericCallback cb,
long goCallbackId);
#endif /* LIBVIRT_GO_NETWORK_EVENTS_CFUNCS_H__ */

170
vendor/github.com/libvirt/libvirt-go/node_device.go generated vendored Normal file
View File

@ -0,0 +1,170 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "node_device_compat.h"
*/
import "C"
import (
"unsafe"
)
type NodeDeviceEventID int
const (
NODE_DEVICE_EVENT_ID_LIFECYCLE = NodeDeviceEventID(C.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE)
NODE_DEVICE_EVENT_ID_UPDATE = NodeDeviceEventID(C.VIR_NODE_DEVICE_EVENT_ID_UPDATE)
)
type NodeDeviceEventLifecycleType int
const (
NODE_DEVICE_EVENT_CREATED = NodeDeviceEventLifecycleType(C.VIR_NODE_DEVICE_EVENT_CREATED)
NODE_DEVICE_EVENT_DELETED = NodeDeviceEventLifecycleType(C.VIR_NODE_DEVICE_EVENT_DELETED)
)
type NodeDevice struct {
ptr C.virNodeDevicePtr
}
func (n *NodeDevice) Free() error {
ret := C.virNodeDeviceFree(n.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *NodeDevice) Ref() error {
ret := C.virNodeDeviceRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (n *NodeDevice) Destroy() error {
result := C.virNodeDeviceDestroy(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *NodeDevice) Reset() error {
result := C.virNodeDeviceReset(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *NodeDevice) Detach() error {
result := C.virNodeDeviceDettach(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *NodeDevice) DetachFlags(driverName string, flags uint32) error {
cDriverName := C.CString(driverName)
defer C.free(unsafe.Pointer(cDriverName))
result := C.virNodeDeviceDetachFlags(n.ptr, cDriverName, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (n *NodeDevice) ReAttach() error {
result := C.virNodeDeviceReAttach(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *NodeDevice) GetName() (string, error) {
name := C.virNodeDeviceGetName(n.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (n *NodeDevice) GetXMLDesc(flags uint32) (string, error) {
result := C.virNodeDeviceGetXMLDesc(n.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (n *NodeDevice) GetParent() (string, error) {
result := C.virNodeDeviceGetParent(n.ptr)
if result == nil {
return "", GetLastError()
}
defer C.free(unsafe.Pointer(result))
return C.GoString(result), nil
}
func (p *NodeDevice) NumOfStorageCaps() (int, error) {
result := int(C.virNodeDeviceNumOfCaps(p.ptr))
if result == -1 {
return 0, GetLastError()
}
return result, nil
}
func (p *NodeDevice) ListStorageCaps() ([]string, error) {
const maxCaps = 1024
var names [maxCaps](*C.char)
namesPtr := unsafe.Pointer(&names)
numCaps := C.virNodeDeviceListCaps(
p.ptr,
(**C.char)(namesPtr),
maxCaps)
if numCaps == -1 {
return nil, GetLastError()
}
goNames := make([]string, numCaps)
for k := 0; k < int(numCaps); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "node_device_compat.h"
int virConnectNodeDeviceEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID)
{
#if LIBVIR_VERSION_NUMBER < 2002000
assert(0); // Caller should have checked version
#else
return virConnectNodeDeviceEventDeregisterAny(conn, callbackID);
#endif
}
*/
import "C"

View File

@ -0,0 +1,58 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_NODE_DEVICE_COMPAT_H__
#define LIBVIRT_GO_NODE_DEVICE_COMPAT_H__
/* 2.2.0 */
#ifndef VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE
#define VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE 0
#endif
#ifndef VIR_NODE_DEVICE_EVENT_ID_UPDATE
#define VIR_NODE_DEVICE_EVENT_ID_UPDATE 1
#endif
#ifndef VIR_NODE_DEVICE_EVENT_CREATED
#define VIR_NODE_DEVICE_EVENT_CREATED 0
#endif
#ifndef VIR_NODE_DEVICE_EVENT_DELETED
#define VIR_NODE_DEVICE_EVENT_DELETED 1
#endif
#if LIBVIR_VERSION_NUMBER < 2002000
typedef void (*virConnectNodeDeviceEventGenericCallback)(virConnectPtr conn,
virNodeDevicePtr dev,
void *opaque);
#endif
int virConnectNodeDeviceEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID);
#endif /* LIBVIRT_GO_NODE_DEVICE_COMPAT_H__ */

View File

@ -0,0 +1,154 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
import (
"fmt"
"unsafe"
)
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include "node_device_compat.h"
#include "node_device_events_cfuncs.h"
*/
import "C"
type NodeDeviceEventGenericCallback func(c *Connect, d *NodeDevice)
type NodeDeviceEventLifecycle struct {
Event NodeDeviceEventLifecycleType
// TODO: we can make Detail typesafe somehow ?
Detail int
}
type NodeDeviceEventLifecycleCallback func(c *Connect, n *NodeDevice, event *NodeDeviceEventLifecycle)
//export nodeDeviceEventLifecycleCallback
func nodeDeviceEventLifecycleCallback(c C.virConnectPtr, s C.virNodeDevicePtr,
event int, detail int,
goCallbackId int) {
node_device := &NodeDevice{ptr: s}
connection := &Connect{ptr: c}
eventDetails := &NodeDeviceEventLifecycle{
Event: NodeDeviceEventLifecycleType(event),
Detail: detail,
}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(NodeDeviceEventLifecycleCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, node_device, eventDetails)
}
//export nodeDeviceEventGenericCallback
func nodeDeviceEventGenericCallback(c C.virConnectPtr, d C.virNodeDevicePtr,
goCallbackId int) {
node_device := &NodeDevice{ptr: d}
connection := &Connect{ptr: c}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(NodeDeviceEventGenericCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, node_device)
}
func (c *Connect) NodeDeviceEventLifecycleRegister(device *NodeDevice, callback NodeDeviceEventLifecycleCallback) (int, error) {
if C.LIBVIR_VERSION_NUMBER < 2002000 {
return 0, GetNotImplementedError("virConnectNodeDeviceEventRegisterAny")
}
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.nodeDeviceEventLifecycleCallback_cgo)
var cdevice C.virNodeDevicePtr
if device != nil {
cdevice = device.ptr
}
ret := C.virConnectNodeDeviceEventRegisterAny_cgo(c.ptr, cdevice,
C.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
C.virConnectNodeDeviceEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) NodeDeviceEventUpdateRegister(device *NodeDevice, callback NodeDeviceEventGenericCallback) (int, error) {
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.nodeDeviceEventGenericCallback_cgo)
var cdevice C.virNodeDevicePtr
if device != nil {
cdevice = device.ptr
}
ret := C.virConnectNodeDeviceEventRegisterAny_cgo(c.ptr, cdevice,
C.VIR_NODE_DEVICE_EVENT_ID_UPDATE,
C.virConnectNodeDeviceEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) NodeDeviceEventDeregister(callbackId int) error {
if C.LIBVIR_VERSION_NUMBER < 2002000 {
return GetNotImplementedError("virConnectNodeDeviceEventDeregisterAny")
}
// Deregister the callback
if i := int(C.virConnectNodeDeviceEventDeregisterAnyCompat(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
}
func (e NodeDeviceEventLifecycle) String() string {
var event string
switch e.Event {
case NODE_DEVICE_EVENT_CREATED:
event = "created"
case NODE_DEVICE_EVENT_DELETED:
event = "deleted"
default:
event = "unknown"
}
return fmt.Sprintf("NodeDevice event=%q", event)
}

View File

@ -0,0 +1,64 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <assert.h>
#include "node_device_compat.h"
#include "node_device_events_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
extern void nodeDeviceEventLifecycleCallback(virConnectPtr, virNodeDevicePtr, int, int, int);
void nodeDeviceEventLifecycleCallback_cgo(virConnectPtr c, virNodeDevicePtr d,
int event, int detail, void *data)
{
nodeDeviceEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
}
extern void nodeDeviceEventGenericCallback(virConnectPtr, virNodeDevicePtr, int);
void nodeDeviceEventGenericCallback_cgo(virConnectPtr c, virNodeDevicePtr d, void *data)
{
nodeDeviceEventGenericCallback(c, d, (int)(intptr_t)data);
}
int virConnectNodeDeviceEventRegisterAny_cgo(virConnectPtr c, virNodeDevicePtr d,
int eventID, virConnectNodeDeviceEventGenericCallback cb,
long goCallbackId) {
void* id = (void*)goCallbackId;
#if LIBVIR_VERSION_NUMBER < 2002000
assert(0); // Caller should have checked version
#else
return virConnectNodeDeviceEventRegisterAny(c, d, eventID, cb, id, freeGoCallback_cgo);
#endif
}
*/
import "C"

View File

@ -0,0 +1,40 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_NODE_DEVICE_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_NODE_DEVICE_EVENTS_CFUNCS_H__
void nodeDeviceEventLifecycleCallback_cgo(virConnectPtr c, virNodeDevicePtr d,
int event, int detail, void* data);
void nodeDeviceEventGenericCallback_cgo(virConnectPtr c, virNodeDevicePtr d, void* data);
int virConnectNodeDeviceEventRegisterAny_cgo(virConnectPtr c, virNodeDevicePtr d,
int eventID, virConnectNodeDeviceEventGenericCallback cb,
long goCallbackId);
#endif /* LIBVIRT_GO_NODE_DEVICE_EVENTS_CFUNCS_H__ */

105
vendor/github.com/libvirt/libvirt-go/nwfilter.go generated vendored Normal file
View File

@ -0,0 +1,105 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
type NWFilter struct {
ptr C.virNWFilterPtr
}
func (f *NWFilter) Free() error {
ret := C.virNWFilterFree(f.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *NWFilter) Ref() error {
ret := C.virNWFilterRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (f *NWFilter) GetName() (string, error) {
name := C.virNWFilterGetName(f.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (f *NWFilter) Undefine() error {
result := C.virNWFilterUndefine(f.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (f *NWFilter) GetUUID() ([]byte, error) {
var cUuid [C.VIR_UUID_BUFLEN](byte)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virNWFilterGetUUID(f.ptr, (*C.uchar)(cuidPtr))
if result != 0 {
return []byte{}, GetLastError()
}
return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
}
func (f *NWFilter) GetUUIDString() (string, error) {
var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virNWFilterGetUUIDString(f.ptr, (*C.char)(cuidPtr))
if result != 0 {
return "", GetLastError()
}
return C.GoString((*C.char)(cuidPtr)), nil
}
func (f *NWFilter) GetXMLDesc(flags uint32) (string, error) {
result := C.virNWFilterGetXMLDesc(f.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}

190
vendor/github.com/libvirt/libvirt-go/qemu.go generated vendored Normal file
View File

@ -0,0 +1,190 @@
// +build !without_qemu
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-qemu since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-qemu
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "qemu_compat.h"
#include "qemu_cfuncs.h"
*/
import "C"
import (
"unsafe"
)
/*
* QMP has two different kinds of ways to talk to QEMU. One is legacy (HMP,
* or 'human' monitor protocol. The default is QMP, which is all-JSON.
*
* QMP json commands are of the format:
* {"execute" : "query-cpus"}
*
* whereas the same command in 'HMP' would be:
* 'info cpus'
*/
type DomainQemuMonitorCommandFlags int
const (
DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT)
DOMAIN_QEMU_MONITOR_COMMAND_HMP = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP)
)
type DomainQemuAgentCommandTimeout int
const (
DOMAIN_QEMU_AGENT_COMMAND_MIN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN)
DOMAIN_QEMU_AGENT_COMMAND_BLOCK = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK)
DOMAIN_QEMU_AGENT_COMMAND_DEFAULT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT)
DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT)
DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN)
)
type DomainQemuMonitorEventFlags int
const (
CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX = DomainQemuMonitorEventFlags(C.VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE = DomainQemuMonitorEventFlags(C.VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE)
)
func (d *Domain) QemuMonitorCommand(command string, flags DomainQemuMonitorCommandFlags) (string, error) {
var cResult *C.char
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
result := C.virDomainQemuMonitorCommand(d.ptr, cCommand, &cResult, C.uint(flags))
if result != 0 {
return "", GetLastError()
}
rstring := C.GoString(cResult)
C.free(unsafe.Pointer(cResult))
return rstring, nil
}
func (d *Domain) QemuAgentCommand(command string, timeout DomainQemuAgentCommandTimeout, flags uint32) (string, error) {
cCommand := C.CString(command)
defer C.free(unsafe.Pointer(cCommand))
result := C.virDomainQemuAgentCommand(d.ptr, cCommand, C.int(timeout), C.uint(flags))
if result == nil {
return "", GetLastError()
}
rstring := C.GoString(result)
C.free(unsafe.Pointer(result))
return rstring, nil
}
func (c *Connect) DomainQemuAttach(pid uint32, flags uint32) (*Domain, error) {
ptr := C.virDomainQemuAttach(c.ptr, C.uint(pid), C.uint(flags))
if ptr == nil {
return nil, GetLastError()
}
return &Domain{ptr: ptr}, nil
}
type DomainQemuMonitorEvent struct {
Event string
Seconds int64
Micros uint
Details string
}
type DomainQemuMonitorEventCallback func(c *Connect, d *Domain, event *DomainQemuMonitorEvent)
//export domainQemuMonitorEventCallback
func domainQemuMonitorEventCallback(c C.virConnectPtr, d C.virDomainPtr,
event *C.char, seconds C.longlong, micros C.uint, details *C.char, goCallbackId int) {
domain := &Domain{ptr: d}
connection := &Connect{ptr: c}
eventDetails := &DomainQemuMonitorEvent{
Event: C.GoString(event),
Seconds: int64(seconds),
Micros: uint(micros),
Details: C.GoString(details),
}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(DomainQemuMonitorEventCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, domain, eventDetails)
}
func (c *Connect) DomainQemuMonitorEventRegister(dom *Domain, event string, callback DomainQemuMonitorEventCallback, flags DomainQemuMonitorEventFlags) (int, error) {
if C.LIBVIR_VERSION_NUMBER < 1002003 {
return 0, GetNotImplementedError("virConnectDomainQemuMonitorEventRegister")
}
cEvent := C.CString(event)
defer C.free(unsafe.Pointer(cEvent))
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.domainQemuMonitorEventCallback_cgo)
var cdom C.virDomainPtr
if dom != nil {
cdom = dom.ptr
}
ret := C.virConnectDomainQemuMonitorEventRegister_cgo(c.ptr, cdom,
cEvent,
C.virConnectDomainEventGenericCallback(callbackPtr),
C.long(goCallBackId),
C.uint(flags))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) DomainQemuEventDeregister(callbackId int) error {
if C.LIBVIR_VERSION_NUMBER < 1002003 {
return GetNotImplementedError("virConnectDomainQemuMonitorEventDeregister")
}
// Deregister the callback
if i := int(C.virConnectDomainQemuMonitorEventDeregisterCompat(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
}

64
vendor/github.com/libvirt/libvirt-go/qemu_cfuncs.go generated vendored Normal file
View File

@ -0,0 +1,64 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
// Can't rely on pkg-config for libvirt-qemu since it was not
// installed until 2.6.0 onwards
#cgo LDFLAGS: -lvirt-qemu
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-qemu.h>
#include <libvirt/virterror.h>
#include "qemu_compat.h"
#include "qemu_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <assert.h>
#include <stdint.h>
extern void domainQemuMonitorEventCallback(virConnectPtr, virDomainPtr, const char *, long long, unsigned int, const char *, int);
void domainQemuMonitorEventCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *event, long long secs,
unsigned int micros, const char *details, void *data)
{
domainQemuMonitorEventCallback(c, d, event, secs, micros, details, (int)(intptr_t)data);
}
int virConnectDomainQemuMonitorEventRegister_cgo(virConnectPtr c, virDomainPtr d,
const char *event, virConnectDomainQemuMonitorEventCallback cb,
long goCallbackId, unsigned int flags) {
#if LIBVIR_VERSION_NUMBER < 1002003
assert(0); // Caller should have checked version
#else
void* id = (void*)goCallbackId;
return virConnectDomainQemuMonitorEventRegister(c, d, event, cb, id, freeGoCallback_cgo, flags);
#endif
}
*/
import "C"

39
vendor/github.com/libvirt/libvirt-go/qemu_cfuncs.h generated vendored Normal file
View File

@ -0,0 +1,39 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__
void domainQemuMonitorEventCallback_cgo(virConnectPtr c, virDomainPtr d,
const char *event, long long secs,
unsigned int micros, const char *details, void *data);
int virConnectDomainQemuMonitorEventRegister_cgo(virConnectPtr c, virDomainPtr d,
const char *event, virConnectDomainQemuMonitorEventCallback cb,
long goCallbackId, unsigned int flags);
#endif /* LIBVIRT_GO_DOMAIN_EVENTS_CFUNCS_H__ */

48
vendor/github.com/libvirt/libvirt-go/qemu_compat.go generated vendored Normal file
View File

@ -0,0 +1,48 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/libvirt-qemu.h>
#include <assert.h>
#include "qemu_compat.h"
int virConnectDomainQemuMonitorEventDeregisterCompat(virConnectPtr conn,
int callbackID)
{
#if LIBVIR_VERSION_NUMBER < 1002003
assert(0); // Caller should have checked version
#else
return virConnectDomainQemuMonitorEventDeregister(conn, callbackID);
#endif
}
*/
import "C"

60
vendor/github.com/libvirt/libvirt-go/qemu_compat.h generated vendored Normal file
View File

@ -0,0 +1,60 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_QEMU_COMPAT_H__
#define LIBVIRT_GO_QEMU_COMPAT_H__
/* 1.2.3 */
#if LIBVIR_VERSION_NUMBER < 1002003
typedef void (*virConnectDomainQemuMonitorEventCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *event,
long long seconds,
unsigned int micros,
const char *details,
void *opaque);
#endif
int virConnectDomainQemuMonitorEventDeregisterCompat(virConnectPtr conn,
int callbackID);
#ifndef VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX
#define VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX (1 << 0)
#endif
#ifndef VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE
#define VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE (1 << 1)
#endif
/* 1.2.15 */
#ifndef VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN
#define VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN 60
#endif
#endif /* LIBVIRT_GO_QEMU_COMPAT_H__ */

166
vendor/github.com/libvirt/libvirt-go/secret.go generated vendored Normal file
View File

@ -0,0 +1,166 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "secret_compat.h"
*/
import "C"
import (
"unsafe"
)
type SecretUsageType int
const (
SECRET_USAGE_TYPE_NONE = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_NONE)
SECRET_USAGE_TYPE_VOLUME = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_VOLUME)
SECRET_USAGE_TYPE_CEPH = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_CEPH)
SECRET_USAGE_TYPE_ISCSI = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_ISCSI)
SECRET_USAGE_TYPE_TLS = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_TLS)
)
type SecretEventLifecycleType int
const (
SECRET_EVENT_DEFINED = SecretEventLifecycleType(C.VIR_SECRET_EVENT_DEFINED)
SECRET_EVENT_UNDEFINED = SecretEventLifecycleType(C.VIR_SECRET_EVENT_UNDEFINED)
)
type SecretEventID int
const (
SECRET_EVENT_ID_LIFECYCLE = SecretEventID(C.VIR_SECRET_EVENT_ID_LIFECYCLE)
SECRET_EVENT_ID_VALUE_CHANGED = SecretEventID(C.VIR_SECRET_EVENT_ID_VALUE_CHANGED)
)
type Secret struct {
ptr C.virSecretPtr
}
func (s *Secret) Free() error {
ret := C.virSecretFree(s.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *Secret) Ref() error {
ret := C.virSecretRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (s *Secret) Undefine() error {
result := C.virSecretUndefine(s.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (s *Secret) GetUUID() ([]byte, error) {
var cUuid [C.VIR_UUID_BUFLEN](byte)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virSecretGetUUID(s.ptr, (*C.uchar)(cuidPtr))
if result != 0 {
return []byte{}, GetLastError()
}
return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
}
func (s *Secret) GetUUIDString() (string, error) {
var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virSecretGetUUIDString(s.ptr, (*C.char)(cuidPtr))
if result != 0 {
return "", GetLastError()
}
return C.GoString((*C.char)(cuidPtr)), nil
}
func (s *Secret) GetUsageID() (string, error) {
result := C.virSecretGetUsageID(s.ptr)
if result == nil {
return "", GetLastError()
}
return C.GoString(result), nil
}
func (s *Secret) GetUsageType() (SecretUsageType, error) {
result := SecretUsageType(C.virSecretGetUsageType(s.ptr))
if result == -1 {
return 0, GetLastError()
}
return result, nil
}
func (s *Secret) GetXMLDesc(flags uint32) (string, error) {
result := C.virSecretGetXMLDesc(s.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (s *Secret) GetValue(flags uint32) ([]byte, error) {
var cvalue_size C.size_t
cvalue := C.virSecretGetValue(s.ptr, &cvalue_size, C.uint(flags))
if cvalue == nil {
return nil, GetLastError()
}
defer C.free(unsafe.Pointer(cvalue))
ret := C.GoBytes(unsafe.Pointer(cvalue), C.int(cvalue_size))
return ret, nil
}
func (s *Secret) SetValue(value []byte, flags uint32) error {
cvalue := make([]C.uchar, len(value))
for i := 0; i < len(value); i++ {
cvalue[i] = C.uchar(value[i])
}
result := C.virSecretSetValue(s.ptr, &cvalue[0], C.size_t(len(value)), C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}

47
vendor/github.com/libvirt/libvirt-go/secret_compat.go generated vendored Normal file
View File

@ -0,0 +1,47 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "secret_compat.h"
int virConnectSecretEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID)
{
#if LIBVIR_VERSION_NUMBER < 3000000
assert(0); // Caller should have checked version
#else
return virConnectSecretEventDeregisterAny(conn, callbackID);
#endif
}
*/
import "C"

64
vendor/github.com/libvirt/libvirt-go/secret_compat.h generated vendored Normal file
View File

@ -0,0 +1,64 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_SECRET_COMPAT_H__
#define LIBVIRT_GO_SECRET_COMPAT_H__
/* 3.0.0 */
#ifndef VIR_SECRET_EVENT_DEFINED
#define VIR_SECRET_EVENT_DEFINED 0
#endif
#ifndef VIR_SECRET_EVENT_UNDEFINED
#define VIR_SECRET_EVENT_UNDEFINED 1
#endif
#ifndef VIR_SECRET_EVENT_ID_LIFECYCLE
#define VIR_SECRET_EVENT_ID_LIFECYCLE 0
#endif
#ifndef VIR_SECRET_EVENT_ID_VALUE_CHANGED
#define VIR_SECRET_EVENT_ID_VALUE_CHANGED 1
#endif
#if LIBVIR_VERSION_NUMBER < 3000000
typedef void (*virConnectSecretEventGenericCallback)(virConnectPtr conn,
virSecretPtr secret,
void *opaque);
#endif
int virConnectSecretEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID);
/* 2.2.1 */
#ifndef VIR_SECRET_USAGE_TYPE_TLS
#define VIR_SECRET_USAGE_TYPE_TLS 4
#endif
#endif /* LIBVIRT_GO_SECRET_COMPAT_H__ */

157
vendor/github.com/libvirt/libvirt-go/secret_events.go generated vendored Normal file
View File

@ -0,0 +1,157 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
import (
"fmt"
"unsafe"
)
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include "secret_compat.h"
#include "secret_events_cfuncs.h"
*/
import "C"
type SecretEventLifecycle struct {
Event SecretEventLifecycleType
// TODO: we can make Detail typesafe somehow ?
Detail int
}
type SecretEventLifecycleCallback func(c *Connect, n *Secret, event *SecretEventLifecycle)
type SecretEventGenericCallback func(c *Connect, n *Secret)
//export secretEventLifecycleCallback
func secretEventLifecycleCallback(c C.virConnectPtr, n C.virSecretPtr,
event int, detail int,
goCallbackId int) {
secret := &Secret{ptr: n}
connection := &Connect{ptr: c}
eventDetails := &SecretEventLifecycle{
Event: SecretEventLifecycleType(event),
Detail: detail,
}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(SecretEventLifecycleCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, secret, eventDetails)
}
//export secretEventGenericCallback
func secretEventGenericCallback(c C.virConnectPtr, n C.virSecretPtr,
goCallbackId int) {
secret := &Secret{ptr: n}
connection := &Connect{ptr: c}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(SecretEventGenericCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, secret)
}
func (c *Connect) SecretEventLifecycleRegister(secret *Secret, callback SecretEventLifecycleCallback) (int, error) {
goCallBackId := registerCallbackId(callback)
if C.LIBVIR_VERSION_NUMBER < 3000000 {
return 0, GetNotImplementedError("virConnectSecretEventRegisterAny")
}
callbackPtr := unsafe.Pointer(C.secretEventLifecycleCallback_cgo)
var csecret C.virSecretPtr
if secret != nil {
csecret = secret.ptr
}
ret := C.virConnectSecretEventRegisterAny_cgo(c.ptr, csecret,
C.VIR_SECRET_EVENT_ID_LIFECYCLE,
C.virConnectSecretEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) SecretEventValueChangedRegister(secret *Secret, callback SecretEventGenericCallback) (int, error) {
goCallBackId := registerCallbackId(callback)
if C.LIBVIR_VERSION_NUMBER < 3000000 {
return 0, GetNotImplementedError("virConnectSecretEventRegisterAny")
}
callbackPtr := unsafe.Pointer(C.secretEventGenericCallback_cgo)
var csecret C.virSecretPtr
if secret != nil {
csecret = secret.ptr
}
ret := C.virConnectSecretEventRegisterAny_cgo(c.ptr, csecret,
C.VIR_SECRET_EVENT_ID_VALUE_CHANGED,
C.virConnectSecretEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) SecretEventDeregister(callbackId int) error {
if C.LIBVIR_VERSION_NUMBER < 3000000 {
return GetNotImplementedError("virConnectSecretEventDeregisterAny")
}
// Deregister the callback
if i := int(C.virConnectSecretEventDeregisterAnyCompat(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
}
func (e SecretEventLifecycle) String() string {
var event string
switch e.Event {
case SECRET_EVENT_DEFINED:
event = "defined"
case SECRET_EVENT_UNDEFINED:
event = "undefined"
default:
event = "unknown"
}
return fmt.Sprintf("Secret event=%q", event)
}

View File

@ -0,0 +1,65 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <assert.h>
#include "secret_compat.h"
#include "secret_events_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
extern void secretEventLifecycleCallback(virConnectPtr, virSecretPtr, int, int, int);
void secretEventLifecycleCallback_cgo(virConnectPtr c, virSecretPtr d,
int event, int detail, void *data)
{
secretEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
}
extern void secretEventGenericCallback(virConnectPtr, virSecretPtr, int);
void secretEventGenericCallback_cgo(virConnectPtr c, virSecretPtr d,
void *data)
{
secretEventGenericCallback(c, d, (int)(intptr_t)data);
}
int virConnectSecretEventRegisterAny_cgo(virConnectPtr c, virSecretPtr d,
int eventID, virConnectSecretEventGenericCallback cb,
long goCallbackId) {
void* id = (void*)goCallbackId;
#if LIBVIR_VERSION_NUMBER < 3000000
assert(0); // Caller should have checked version
#else
return virConnectSecretEventRegisterAny(c, d, eventID, cb, id, freeGoCallback_cgo);
#endif
}
*/
import "C"

View File

@ -0,0 +1,40 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_SECRET_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_SECRET_EVENTS_CFUNCS_H__
void secretEventLifecycleCallback_cgo(virConnectPtr c, virSecretPtr d,
int event, int detail, void* data);
void secretEventGenericCallback_cgo(virConnectPtr c, virSecretPtr d,
void* data);
int virConnectSecretEventRegisterAny_cgo(virConnectPtr c, virSecretPtr d,
int eventID, virConnectSecretEventGenericCallback cb,
long goCallbackId);
#endif /* LIBVIRT_GO_SECRET_EVENTS_CFUNCS_H__ */

348
vendor/github.com/libvirt/libvirt-go/storage_pool.go generated vendored Normal file
View File

@ -0,0 +1,348 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "storage_pool_compat.h"
*/
import "C"
import (
"reflect"
"unsafe"
)
type StoragePoolState int
const (
STORAGE_POOL_INACTIVE = StoragePoolState(C.VIR_STORAGE_POOL_INACTIVE) // Not running
STORAGE_POOL_BUILDING = StoragePoolState(C.VIR_STORAGE_POOL_BUILDING) // Initializing pool,not available
STORAGE_POOL_RUNNING = StoragePoolState(C.VIR_STORAGE_POOL_RUNNING) // Running normally
STORAGE_POOL_DEGRADED = StoragePoolState(C.VIR_STORAGE_POOL_DEGRADED) // Running degraded
STORAGE_POOL_INACCESSIBLE = StoragePoolState(C.VIR_STORAGE_POOL_INACCESSIBLE) // Running,but not accessible
)
type StoragePoolBuildFlags int
const (
STORAGE_POOL_BUILD_NEW = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_NEW) // Regular build from scratch
STORAGE_POOL_BUILD_REPAIR = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_REPAIR) // Repair / reinitialize
STORAGE_POOL_BUILD_RESIZE = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_RESIZE) // Extend existing pool
STORAGE_POOL_BUILD_NO_OVERWRITE = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_NO_OVERWRITE) // Do not overwrite existing pool
STORAGE_POOL_BUILD_OVERWRITE = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_OVERWRITE) // Overwrite data
)
type StoragePoolCreateFlags int
const (
STORAGE_POOL_CREATE_NORMAL = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_NORMAL)
STORAGE_POOL_CREATE_WITH_BUILD = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_WITH_BUILD)
STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
)
type StoragePoolDeleteFlags int
const (
STORAGE_POOL_DELETE_NORMAL = StoragePoolDeleteFlags(C.VIR_STORAGE_POOL_DELETE_NORMAL)
STORAGE_POOL_DELETE_ZEROED = StoragePoolDeleteFlags(C.VIR_STORAGE_POOL_DELETE_ZEROED)
)
type StoragePoolEventID int
const (
STORAGE_POOL_EVENT_ID_LIFECYCLE = StoragePoolEventID(C.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE)
STORAGE_POOL_EVENT_ID_REFRESH = StoragePoolEventID(C.VIR_STORAGE_POOL_EVENT_ID_REFRESH)
)
type StoragePoolEventLifecycleType int
const (
STORAGE_POOL_EVENT_DEFINED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_DEFINED)
STORAGE_POOL_EVENT_UNDEFINED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_UNDEFINED)
STORAGE_POOL_EVENT_STARTED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_STARTED)
STORAGE_POOL_EVENT_STOPPED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_STOPPED)
)
type StoragePool struct {
ptr C.virStoragePoolPtr
}
type StoragePoolInfo struct {
State StoragePoolState
Capacity uint64
Allocation uint64
Available uint64
}
func (p *StoragePool) Build(flags StoragePoolBuildFlags) error {
result := C.virStoragePoolBuild(p.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) Create(flags StoragePoolCreateFlags) error {
result := C.virStoragePoolCreate(p.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) Delete(flags StoragePoolDeleteFlags) error {
result := C.virStoragePoolDelete(p.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) Destroy() error {
result := C.virStoragePoolDestroy(p.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) Free() error {
ret := C.virStoragePoolFree(p.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *StoragePool) Ref() error {
ret := C.virStoragePoolRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) GetAutostart() (bool, error) {
var out C.int
result := C.virStoragePoolGetAutostart(p.ptr, (*C.int)(unsafe.Pointer(&out)))
if result == -1 {
return false, GetLastError()
}
switch out {
case 1:
return true, nil
default:
return false, nil
}
}
func (p *StoragePool) GetInfo() (*StoragePoolInfo, error) {
var cinfo C.virStoragePoolInfo
result := C.virStoragePoolGetInfo(p.ptr, &cinfo)
if result == -1 {
return nil, GetLastError()
}
return &StoragePoolInfo{
State: StoragePoolState(cinfo.state),
Capacity: uint64(cinfo.capacity),
Allocation: uint64(cinfo.allocation),
Available: uint64(cinfo.available),
}, nil
}
func (p *StoragePool) GetName() (string, error) {
name := C.virStoragePoolGetName(p.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (p *StoragePool) GetUUID() ([]byte, error) {
var cUuid [C.VIR_UUID_BUFLEN](byte)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virStoragePoolGetUUID(p.ptr, (*C.uchar)(cuidPtr))
if result != 0 {
return []byte{}, GetLastError()
}
return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
}
func (p *StoragePool) GetUUIDString() (string, error) {
var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
cuidPtr := unsafe.Pointer(&cUuid)
result := C.virStoragePoolGetUUIDString(p.ptr, (*C.char)(cuidPtr))
if result != 0 {
return "", GetLastError()
}
return C.GoString((*C.char)(cuidPtr)), nil
}
func (p *StoragePool) GetXMLDesc(flags StorageXMLFlags) (string, error) {
result := C.virStoragePoolGetXMLDesc(p.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (p *StoragePool) IsActive() (bool, error) {
result := C.virStoragePoolIsActive(p.ptr)
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (p *StoragePool) IsPersistent() (bool, error) {
result := C.virStoragePoolIsPersistent(p.ptr)
if result == -1 {
return false, GetLastError()
}
if result == 1 {
return true, nil
}
return false, nil
}
func (p *StoragePool) SetAutostart(autostart bool) error {
var cAutostart C.int
switch autostart {
case true:
cAutostart = 1
default:
cAutostart = 0
}
result := C.virStoragePoolSetAutostart(p.ptr, cAutostart)
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) Refresh(flags uint32) error {
result := C.virStoragePoolRefresh(p.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) Undefine() error {
result := C.virStoragePoolUndefine(p.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (p *StoragePool) StorageVolCreateXML(xmlConfig string, flags StorageVolCreateFlags) (*StorageVol, error) {
cXml := C.CString(string(xmlConfig))
defer C.free(unsafe.Pointer(cXml))
ptr := C.virStorageVolCreateXML(p.ptr, cXml, C.uint(flags))
if ptr == nil {
return nil, GetLastError()
}
return &StorageVol{ptr: ptr}, nil
}
func (p *StoragePool) StorageVolCreateXMLFrom(xmlConfig string, clonevol *StorageVol, flags StorageVolCreateFlags) (*StorageVol, error) {
cXml := C.CString(string(xmlConfig))
defer C.free(unsafe.Pointer(cXml))
ptr := C.virStorageVolCreateXMLFrom(p.ptr, cXml, clonevol.ptr, C.uint(flags))
if ptr == nil {
return nil, GetLastError()
}
return &StorageVol{ptr: ptr}, nil
}
func (p *StoragePool) LookupStorageVolByName(name string) (*StorageVol, error) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
ptr := C.virStorageVolLookupByName(p.ptr, cName)
if ptr == nil {
return nil, GetLastError()
}
return &StorageVol{ptr: ptr}, nil
}
func (p *StoragePool) NumOfStorageVolumes() (int, error) {
result := int(C.virStoragePoolNumOfVolumes(p.ptr))
if result == -1 {
return 0, GetLastError()
}
return result, nil
}
func (p *StoragePool) ListStorageVolumes() ([]string, error) {
const maxVols = 1024
var names [maxVols](*C.char)
namesPtr := unsafe.Pointer(&names)
numStorageVols := C.virStoragePoolListVolumes(
p.ptr,
(**C.char)(namesPtr),
maxVols)
if numStorageVols == -1 {
return nil, GetLastError()
}
goNames := make([]string, numStorageVols)
for k := 0; k < int(numStorageVols); k++ {
goNames[k] = C.GoString(names[k])
C.free(unsafe.Pointer(names[k]))
}
return goNames, nil
}
func (p *StoragePool) ListAllStorageVolumes(flags uint32) ([]StorageVol, error) {
var cList *C.virStorageVolPtr
numVols := C.virStoragePoolListAllVolumes(p.ptr, (**C.virStorageVolPtr)(&cList), C.uint(flags))
if numVols == -1 {
return nil, GetLastError()
}
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(cList)),
Len: int(numVols),
Cap: int(numVols),
}
var pools []StorageVol
slice := *(*[]C.virStorageVolPtr)(unsafe.Pointer(&hdr))
for _, ptr := range slice {
pools = append(pools, StorageVol{ptr})
}
C.free(unsafe.Pointer(cList))
return pools, nil
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "storage_pool_compat.h"
int virConnectStoragePoolEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID)
{
#if LIBVIR_VERSION_NUMBER < 2000000
assert(0); // Caller shouuld have checked version
#else
return virConnectStoragePoolEventDeregisterAny(conn, callbackID);
#endif
}
*/
import "C"

View File

@ -0,0 +1,85 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_STORAGE_POOL_COMPAT_H__
#define LIBVIRT_GO_STORAGE_POOL_COMPAT_H__
/* 1.3.1 */
#ifndef VIR_STORAGE_POOL_CREATE_NORMAL
#define VIR_STORAGE_POOL_CREATE_NORMAL 0
#endif
#ifndef VIR_STORAGE_POOL_CREATE_WITH_BUILD
#define VIR_STORAGE_POOL_CREATE_WITH_BUILD 1 << 0
#endif
#ifndef VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE
#define VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE 1 << 1
#endif
#ifndef VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE
#define VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE 1 << 2
#endif
/* 2.0.0 */
#ifndef VIVIR_STORAGE_POOL_EVENT_DEFINED
#define VIR_STORAGE_POOL_EVENT_DEFINED 0
#endif
#ifndef VIR_STORAGE_POOL_EVENT_UNDEFINED
#define VIR_STORAGE_POOL_EVENT_UNDEFINED 1
#endif
#ifndef VIR_STORAGE_POOL_EVENT_STARTED
#define VIR_STORAGE_POOL_EVENT_STARTED 2
#endif
#ifndef VIR_STORAGE_POOL_EVENT_STOPPED
#define VIR_STORAGE_POOL_EVENT_STOPPED 3
#endif
#ifndef VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE
#define VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE 0
#endif
#ifndef VIR_STORAGE_POOL_EVENT_ID_REFRESH
#define VIR_STORAGE_POOL_EVENT_ID_REFRESH 1
#endif
#if LIBVIR_VERSION_NUMBER < 2000000
typedef void (*virConnectStoragePoolEventGenericCallback)(virConnectPtr conn,
virStoragePoolPtr pool,
void *opaque);
#endif
int virConnectStoragePoolEventDeregisterAnyCompat(virConnectPtr conn,
int callbackID);
#endif /* LIBVIRT_GO_STORAGE_POOL_COMPAT_H__ */

View File

@ -0,0 +1,166 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
import (
"fmt"
"unsafe"
)
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include "storage_pool_compat.h"
#include "storage_pool_events_cfuncs.h"
*/
import "C"
type StoragePoolEventLifecycle struct {
Event StoragePoolEventLifecycleType
// TODO: we can make Detail typesafe somehow ?
Detail int
}
type StoragePoolEventLifecycleCallback func(c *Connect, n *StoragePool, event *StoragePoolEventLifecycle)
type StoragePoolEventGenericCallback func(c *Connect, n *StoragePool)
//export storagePoolEventLifecycleCallback
func storagePoolEventLifecycleCallback(c C.virConnectPtr, s C.virStoragePoolPtr,
event int, detail int,
goCallbackId int) {
storage_pool := &StoragePool{ptr: s}
connection := &Connect{ptr: c}
eventDetails := &StoragePoolEventLifecycle{
Event: StoragePoolEventLifecycleType(event),
Detail: detail,
}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(StoragePoolEventLifecycleCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, storage_pool, eventDetails)
}
//export storagePoolEventGenericCallback
func storagePoolEventGenericCallback(c C.virConnectPtr, s C.virStoragePoolPtr,
goCallbackId int) {
storage_pool := &StoragePool{ptr: s}
connection := &Connect{ptr: c}
callbackFunc := getCallbackId(goCallbackId)
callback, ok := callbackFunc.(StoragePoolEventGenericCallback)
if !ok {
panic("Inappropriate callback type called")
}
callback(connection, storage_pool)
}
func (c *Connect) StoragePoolEventLifecycleRegister(pool *StoragePool, callback StoragePoolEventLifecycleCallback) (int, error) {
if C.LIBVIR_VERSION_NUMBER < 2000000 {
return 0, GetNotImplementedError("virConnectStoragePoolEventRegisterAny")
}
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.storagePoolEventLifecycleCallback_cgo)
var cpool C.virStoragePoolPtr
if pool != nil {
cpool = pool.ptr
}
ret := C.virConnectStoragePoolEventRegisterAny_cgo(c.ptr, cpool,
C.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
C.virConnectStoragePoolEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) StoragePoolEventRefreshRegister(pool *StoragePool, callback StoragePoolEventGenericCallback) (int, error) {
if C.LIBVIR_VERSION_NUMBER < 2000000 {
return 0, GetNotImplementedError("virConnectStoragePoolEventRegisterAny")
}
goCallBackId := registerCallbackId(callback)
callbackPtr := unsafe.Pointer(C.storagePoolEventGenericCallback_cgo)
var cpool C.virStoragePoolPtr
if pool != nil {
cpool = pool.ptr
}
ret := C.virConnectStoragePoolEventRegisterAny_cgo(c.ptr, cpool,
C.VIR_STORAGE_POOL_EVENT_ID_REFRESH,
C.virConnectStoragePoolEventGenericCallback(callbackPtr),
C.long(goCallBackId))
if ret == -1 {
freeCallbackId(goCallBackId)
return 0, GetLastError()
}
return int(ret), nil
}
func (c *Connect) StoragePoolEventDeregister(callbackId int) error {
if C.LIBVIR_VERSION_NUMBER < 2000000 {
return GetNotImplementedError("virConnectStoragePoolEventDeregisterAny")
}
// Deregister the callback
if i := int(C.virConnectStoragePoolEventDeregisterAnyCompat(c.ptr, C.int(callbackId))); i != 0 {
return GetLastError()
}
return nil
}
func (e StoragePoolEventLifecycle) String() string {
var event string
switch e.Event {
case STORAGE_POOL_EVENT_DEFINED:
event = "defined"
case STORAGE_POOL_EVENT_UNDEFINED:
event = "undefined"
case STORAGE_POOL_EVENT_STARTED:
event = "started"
case STORAGE_POOL_EVENT_STOPPED:
event = "stopped"
default:
event = "unknown"
}
return fmt.Sprintf("StoragePool event=%q", event)
}

View File

@ -0,0 +1,65 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <assert.h>
#include "storage_pool_compat.h"
#include "storage_pool_events_cfuncs.h"
#include "callbacks_cfuncs.h"
#include <stdint.h>
extern void storagePoolEventLifecycleCallback(virConnectPtr, virStoragePoolPtr, int, int, int);
void storagePoolEventLifecycleCallback_cgo(virConnectPtr c, virStoragePoolPtr d,
int event, int detail, void *data)
{
storagePoolEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
}
extern void storagePoolEventGenericCallback(virConnectPtr, virStoragePoolPtr, int);
void storagePoolEventGenericCallback_cgo(virConnectPtr c, virStoragePoolPtr d,
void *data)
{
storagePoolEventGenericCallback(c, d, (int)(intptr_t)data);
}
int virConnectStoragePoolEventRegisterAny_cgo(virConnectPtr c, virStoragePoolPtr d,
int eventID, virConnectStoragePoolEventGenericCallback cb,
long goCallbackId) {
#if LIBVIR_VERSION_NUMBER < 2000000
assert(0); // Caller should have checked version
#else
void* id = (void*)goCallbackId;
return virConnectStoragePoolEventRegisterAny(c, d, eventID, cb, id, freeGoCallback_cgo);
#endif
}
*/
import "C"

View File

@ -0,0 +1,40 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_STORAGE_POOL_EVENTS_CFUNCS_H__
#define LIBVIRT_GO_STORAGE_POOL_EVENTS_CFUNCS_H__
void storagePoolEventLifecycleCallback_cgo(virConnectPtr c, virStoragePoolPtr d,
int event, int detail, void* data);
void storagePoolEventGenericCallback_cgo(virConnectPtr c, virStoragePoolPtr d,
void* data);
int virConnectStoragePoolEventRegisterAny_cgo(virConnectPtr c, virStoragePoolPtr d,
int eventID, virConnectStoragePoolEventGenericCallback cb,
long goCallbackId);
#endif /* LIBVIRT_GO_STORAGE_POOL_EVENTS_CFUNCS_H__ */

261
vendor/github.com/libvirt/libvirt-go/storage_volume.go generated vendored Normal file
View File

@ -0,0 +1,261 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "storage_volume_compat.h"
*/
import "C"
import (
"unsafe"
)
type StorageVolCreateFlags int
const (
STORAGE_VOL_CREATE_PREALLOC_METADATA = StorageVolCreateFlags(C.VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA)
STORAGE_VOL_CREATE_REFLINK = StorageVolCreateFlags(C.VIR_STORAGE_VOL_CREATE_REFLINK)
)
type StorageVolDeleteFlags int
const (
STORAGE_VOL_DELETE_NORMAL = StorageVolDeleteFlags(C.VIR_STORAGE_VOL_DELETE_NORMAL) // Delete metadata only (fast)
STORAGE_VOL_DELETE_ZEROED = StorageVolDeleteFlags(C.VIR_STORAGE_VOL_DELETE_ZEROED) // Clear all data to zeros (slow)
STORAGE_VOL_DELETE_WITH_SNAPSHOTS = StorageVolDeleteFlags(C.VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS) // Force removal of volume, even if in use
)
type StorageVolResizeFlags int
const (
STORAGE_VOL_RESIZE_ALLOCATE = StorageVolResizeFlags(C.VIR_STORAGE_VOL_RESIZE_ALLOCATE) // force allocation of new size
STORAGE_VOL_RESIZE_DELTA = StorageVolResizeFlags(C.VIR_STORAGE_VOL_RESIZE_DELTA) // size is relative to current
STORAGE_VOL_RESIZE_SHRINK = StorageVolResizeFlags(C.VIR_STORAGE_VOL_RESIZE_SHRINK) // allow decrease in capacity
)
type StorageVolType int
const (
STORAGE_VOL_FILE = StorageVolType(C.VIR_STORAGE_VOL_FILE) // Regular file based volumes
STORAGE_VOL_BLOCK = StorageVolType(C.VIR_STORAGE_VOL_BLOCK) // Block based volumes
STORAGE_VOL_DIR = StorageVolType(C.VIR_STORAGE_VOL_DIR) // Directory-passthrough based volume
STORAGE_VOL_NETWORK = StorageVolType(C.VIR_STORAGE_VOL_NETWORK) //Network volumes like RBD (RADOS Block Device)
STORAGE_VOL_NETDIR = StorageVolType(C.VIR_STORAGE_VOL_NETDIR) // Network accessible directory that can contain other network volumes
STORAGE_VOL_PLOOP = StorageVolType(C.VIR_STORAGE_VOL_PLOOP) // Ploop directory based volumes
)
type StorageVolWipeAlgorithm int
const (
STORAGE_VOL_WIPE_ALG_ZERO = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_ZERO) // 1-pass, all zeroes
STORAGE_VOL_WIPE_ALG_NNSA = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_NNSA) // 4-pass NNSA Policy Letter NAP-14.1-C (XVI-8)
STORAGE_VOL_WIPE_ALG_DOD = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_DOD) // 4-pass DoD 5220.22-M section 8-306 procedure
STORAGE_VOL_WIPE_ALG_BSI = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_BSI) // 9-pass method recommended by the German Center of Security in Information Technologies
STORAGE_VOL_WIPE_ALG_GUTMANN = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_GUTMANN) // The canonical 35-pass sequence
STORAGE_VOL_WIPE_ALG_SCHNEIER = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_SCHNEIER) // 7-pass method described by Bruce Schneier in "Applied Cryptography" (1996)
STORAGE_VOL_WIPE_ALG_PFITZNER7 = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7) // 7-pass random
STORAGE_VOL_WIPE_ALG_PFITZNER33 = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33) // 33-pass random
STORAGE_VOL_WIPE_ALG_RANDOM = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_RANDOM) // 1-pass random
STORAGE_VOL_WIPE_ALG_TRIM = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_TRIM) // Trim the underlying storage
)
type StorageXMLFlags int
const (
STORAGE_XML_INACTIVE = StorageXMLFlags(C.VIR_STORAGE_XML_INACTIVE)
)
type StorageVolInfoFlags int
const (
STORAGE_VOL_USE_ALLOCATION = StorageVolInfoFlags(C.VIR_STORAGE_VOL_USE_ALLOCATION)
STORAGE_VOL_GET_PHYSICAL = StorageVolInfoFlags(C.VIR_STORAGE_VOL_GET_PHYSICAL)
)
type StorageVolUploadFlags int
const (
STORAGE_VOL_UPLOAD_SPARSE_STREAM = StorageVolUploadFlags(C.VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM)
)
type StorageVolDownloadFlags int
const (
STORAGE_VOL_DOWNLOAD_SPARSE_STREAM = StorageVolDownloadFlags(C.VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM)
)
type StorageVol struct {
ptr C.virStorageVolPtr
}
type StorageVolInfo struct {
Type StorageVolType
Capacity uint64
Allocation uint64
}
func (v *StorageVol) Delete(flags StorageVolDeleteFlags) error {
result := C.virStorageVolDelete(v.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) Free() error {
ret := C.virStorageVolFree(v.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *StorageVol) Ref() error {
ret := C.virStorageVolRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) GetInfo() (*StorageVolInfo, error) {
var cinfo C.virStorageVolInfo
result := C.virStorageVolGetInfo(v.ptr, &cinfo)
if result == -1 {
return nil, GetLastError()
}
return &StorageVolInfo{
Type: StorageVolType(cinfo._type),
Capacity: uint64(cinfo.capacity),
Allocation: uint64(cinfo.allocation),
}, nil
}
func (v *StorageVol) GetInfoFlags(flags StorageVolInfoFlags) (*StorageVolInfo, error) {
if C.LIBVIR_VERSION_NUMBER < 3000000 {
return nil, GetNotImplementedError("virStorageVolGetInfoFlags")
}
var cinfo C.virStorageVolInfo
result := C.virStorageVolGetInfoFlagsCompat(v.ptr, &cinfo, C.uint(flags))
if result == -1 {
return nil, GetLastError()
}
return &StorageVolInfo{
Type: StorageVolType(cinfo._type),
Capacity: uint64(cinfo.capacity),
Allocation: uint64(cinfo.allocation),
}, nil
}
func (v *StorageVol) GetKey() (string, error) {
key := C.virStorageVolGetKey(v.ptr)
if key == nil {
return "", GetLastError()
}
return C.GoString(key), nil
}
func (v *StorageVol) GetName() (string, error) {
name := C.virStorageVolGetName(v.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (v *StorageVol) GetPath() (string, error) {
result := C.virStorageVolGetPath(v.ptr)
if result == nil {
return "", GetLastError()
}
path := C.GoString(result)
C.free(unsafe.Pointer(result))
return path, nil
}
func (v *StorageVol) GetXMLDesc(flags uint32) (string, error) {
result := C.virStorageVolGetXMLDesc(v.ptr, C.uint(flags))
if result == nil {
return "", GetLastError()
}
xml := C.GoString(result)
C.free(unsafe.Pointer(result))
return xml, nil
}
func (v *StorageVol) Resize(capacity uint64, flags StorageVolResizeFlags) error {
result := C.virStorageVolResize(v.ptr, C.ulonglong(capacity), C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) Wipe(flags uint32) error {
result := C.virStorageVolWipe(v.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) WipePattern(algorithm StorageVolWipeAlgorithm, flags uint32) error {
result := C.virStorageVolWipePattern(v.ptr, C.uint(algorithm), C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) Upload(stream *Stream, offset, length uint64, flags StorageVolUploadFlags) error {
if C.virStorageVolUpload(v.ptr, stream.ptr, C.ulonglong(offset),
C.ulonglong(length), C.uint(flags)) == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) Download(stream *Stream, offset, length uint64, flags StorageVolDownloadFlags) error {
if C.virStorageVolDownload(v.ptr, stream.ptr, C.ulonglong(offset),
C.ulonglong(length), C.uint(flags)) == -1 {
return GetLastError()
}
return nil
}
func (v *StorageVol) LookupPoolByVolume() (*StoragePool, error) {
poolPtr := C.virStoragePoolLookupByVolume(v.ptr)
if poolPtr == nil {
return nil, GetLastError()
}
return &StoragePool{ptr: poolPtr}, nil
}

View File

@ -0,0 +1,47 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "storage_volume_compat.h"
int virStorageVolGetInfoFlagsCompat(virStorageVolPtr vol,
virStorageVolInfoPtr info,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 3000000
assert(0); // Caller should have checked version
#else
return virStorageVolGetInfoFlags(vol, info, flags);
#endif
}
*/
import "C"

View File

@ -0,0 +1,82 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_STORAGE_VOLUME_COMPAT_H__
#define LIBVIRT_GO_STORAGE_VOLUME_COMPAT_H__
/* 3.0.0 */
int virStorageVolGetInfoFlagsCompat(virStorageVolPtr vol,
virStorageVolInfoPtr info,
unsigned int flags);
#ifndef VIR_STORAGE_VOL_USE_ALLOCATION
#define VIR_STORAGE_VOL_USE_ALLOCATION 0
#endif
#ifndef VIR_STORAGE_VOL_GET_PHYSICAL
#define VIR_STORAGE_VOL_GET_PHYSICAL 1 << 0
#endif
/* 1.2.13 */
#ifndef VIR_STORAGE_VOL_CREATE_REFLINK
#define VIR_STORAGE_VOL_CREATE_REFLINK 1<< 1
#endif
/* 1.2.21 */
#ifndef VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS
#define VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS 1 << 1
#endif
/* 1.3.2 */
#ifndef VIR_STORAGE_VOL_WIPE_ALG_TRIM
#define VIR_STORAGE_VOL_WIPE_ALG_TRIM 9
#endif
/* 1.3.4 */
#ifndef VIR_STORAGE_VOL_PLOOP
#define VIR_STORAGE_VOL_PLOOP 5
#endif
/* 3.4.0 */
#ifndef VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM
#define VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM (1 << 0)
#endif
#ifndef VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM
#define VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM (1 << 0)
#endif
#endif /* LIBVIRT_GO_STORAGE_VOLUME_COMPAT_H__ */

389
vendor/github.com/libvirt/libvirt-go/stream.go generated vendored Normal file
View File

@ -0,0 +1,389 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include "stream_cfuncs.h"
#include "stream_compat.h"
*/
import "C"
import (
"io"
"unsafe"
)
type StreamFlags int
const (
STREAM_NONBLOCK = StreamFlags(C.VIR_STREAM_NONBLOCK)
)
type StreamEventType int
const (
STREAM_EVENT_READABLE = StreamEventType(C.VIR_STREAM_EVENT_READABLE)
STREAM_EVENT_WRITABLE = StreamEventType(C.VIR_STREAM_EVENT_WRITABLE)
STREAM_EVENT_ERROR = StreamEventType(C.VIR_STREAM_EVENT_ERROR)
STREAM_EVENT_HANGUP = StreamEventType(C.VIR_STREAM_EVENT_HANGUP)
)
type StreamRecvFlagsValues int
const (
STREAM_RECV_STOP_AT_HOLE = StreamRecvFlagsValues(C.VIR_STREAM_RECV_STOP_AT_HOLE)
)
type Stream struct {
ptr C.virStreamPtr
}
func (v *Stream) Abort() error {
result := C.virStreamAbort(v.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (v *Stream) Finish() error {
result := C.virStreamFinish(v.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (v *Stream) Free() error {
ret := C.virStreamFree(v.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (c *Stream) Ref() error {
ret := C.virStreamRef(c.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}
func (v *Stream) Recv(p []byte) (int, error) {
n := C.virStreamRecv(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)))
if n < 0 {
return 0, GetLastError()
}
if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (v *Stream) RecvFlags(p []byte, flags StreamRecvFlagsValues) (int, error) {
if C.LIBVIR_VERSION_NUMBER < 3004000 {
return 0, GetNotImplementedError("virStreamRecvFlags")
}
n := C.virStreamRecvFlagsCompat(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)), C.uint(flags))
if n < 0 {
return 0, GetLastError()
}
if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (v *Stream) RecvHole(flags uint) (int64, error) {
if C.LIBVIR_VERSION_NUMBER < 3004000 {
return 0, GetNotImplementedError("virStreamSparseRecvHole")
}
var len C.longlong
ret := C.virStreamRecvHoleCompat(v.ptr, &len, C.uint(flags))
if ret < 0 {
return 0, GetLastError()
}
return int64(len), nil
}
func (v *Stream) Send(p []byte) (int, error) {
n := C.virStreamSend(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)))
if n < 0 {
return 0, GetLastError()
}
if n == 0 {
return 0, io.EOF
}
return int(n), nil
}
func (v *Stream) SendHole(len int64, flags uint32) error {
if C.LIBVIR_VERSION_NUMBER < 3004000 {
return GetNotImplementedError("virStreamSendHole")
}
ret := C.virStreamSendHoleCompat(v.ptr, C.longlong(len), C.uint(flags))
if ret < 0 {
return GetLastError()
}
return nil
}
type StreamSinkFunc func(*Stream, []byte) (int, error)
type StreamSinkHoleFunc func(*Stream, int64) error
//export streamSinkCallback
func streamSinkCallback(stream C.virStreamPtr, cdata *C.char, nbytes C.size_t, callbackID int) int {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(StreamSinkFunc)
if !ok {
panic("Incorrect stream sink func callback")
}
data := make([]byte, int(nbytes))
for i := 0; i < int(nbytes); i++ {
cdatabyte := (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cdata)) + (unsafe.Sizeof(*cdata) * uintptr(i))))
data[i] = (byte)(*cdatabyte)
}
retnbytes, err := callback(&Stream{ptr: stream}, data)
if err != nil {
return -1
}
return retnbytes
}
//export streamSinkHoleCallback
func streamSinkHoleCallback(stream C.virStreamPtr, length C.longlong, callbackID int) int {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(StreamSinkHoleFunc)
if !ok {
panic("Incorrect stream sink hole func callback")
}
err := callback(&Stream{ptr: stream}, int64(length))
if err != nil {
return -1
}
return 0
}
func (v *Stream) RecvAll(handler StreamSinkFunc) error {
callbackID := registerCallbackId(handler)
ret := C.virStreamRecvAll_cgo(v.ptr, (C.int)(callbackID))
freeCallbackId(callbackID)
if ret == -1 {
return GetLastError()
}
return nil
}
func (v *Stream) SparseRecvAll(handler StreamSinkFunc, holeHandler StreamSinkHoleFunc) error {
if C.LIBVIR_VERSION_NUMBER < 3004000 {
return GetNotImplementedError("virStreamSparseSendAll")
}
callbackID := registerCallbackId(handler)
holeCallbackID := registerCallbackId(holeHandler)
ret := C.virStreamSparseRecvAll_cgo(v.ptr, (C.int)(callbackID), (C.int)(holeCallbackID))
freeCallbackId(callbackID)
freeCallbackId(holeCallbackID)
if ret == -1 {
return GetLastError()
}
return nil
}
type StreamSourceFunc func(*Stream, int) ([]byte, error)
type StreamSourceHoleFunc func(*Stream) (bool, int64, error)
type StreamSourceSkipFunc func(*Stream, int64) error
//export streamSourceCallback
func streamSourceCallback(stream C.virStreamPtr, cdata *C.char, nbytes C.size_t, callbackID int) int {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(StreamSourceFunc)
if !ok {
panic("Incorrect stream sink func callback")
}
data, err := callback(&Stream{ptr: stream}, (int)(nbytes))
if err != nil {
return -1
}
nretbytes := int(nbytes)
if len(data) < nretbytes {
nretbytes = len(data)
}
for i := 0; i < nretbytes; i++ {
cdatabyte := (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cdata)) + (unsafe.Sizeof(*cdata) * uintptr(i))))
*cdatabyte = (C.char)(data[i])
}
return nretbytes
}
//export streamSourceHoleCallback
func streamSourceHoleCallback(stream C.virStreamPtr, cinData *C.int, clength *C.longlong, callbackID int) int {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(StreamSourceHoleFunc)
if !ok {
panic("Incorrect stream sink hole func callback")
}
inData, length, err := callback(&Stream{ptr: stream})
if err != nil {
return -1
}
if inData {
*cinData = 1
} else {
*cinData = 0
}
*clength = C.longlong(length)
return 0
}
//export streamSourceSkipCallback
func streamSourceSkipCallback(stream C.virStreamPtr, length C.longlong, callbackID int) int {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(StreamSourceSkipFunc)
if !ok {
panic("Incorrect stream sink skip func callback")
}
err := callback(&Stream{ptr: stream}, int64(length))
if err != nil {
return -1
}
return 0
}
func (v *Stream) SendAll(handler StreamSourceFunc) error {
callbackID := registerCallbackId(handler)
ret := C.virStreamSendAll_cgo(v.ptr, (C.int)(callbackID))
freeCallbackId(callbackID)
if ret == -1 {
return GetLastError()
}
return nil
}
func (v *Stream) SparseSendAll(handler StreamSourceFunc, holeHandler StreamSourceHoleFunc, skipHandler StreamSourceSkipFunc) error {
if C.LIBVIR_VERSION_NUMBER < 3004000 {
return GetNotImplementedError("virStreamSparseSendAll")
}
callbackID := registerCallbackId(handler)
holeCallbackID := registerCallbackId(holeHandler)
skipCallbackID := registerCallbackId(skipHandler)
ret := C.virStreamSparseSendAll_cgo(v.ptr, (C.int)(callbackID), (C.int)(holeCallbackID), (C.int)(skipCallbackID))
freeCallbackId(callbackID)
freeCallbackId(holeCallbackID)
freeCallbackId(skipCallbackID)
if ret == -1 {
return GetLastError()
}
return nil
}
type StreamEventCallback func(*Stream, StreamEventType)
func (v *Stream) EventAddCallback(events StreamEventType, callback StreamEventCallback) error {
callbackID := registerCallbackId(callback)
ret := C.virStreamEventAddCallback_cgo(v.ptr, (C.int)(events), (C.int)(callbackID))
if ret == -1 {
return GetLastError()
}
return nil
}
//export streamEventCallback
func streamEventCallback(st C.virStreamPtr, events int, callbackID int) {
callbackFunc := getCallbackId(callbackID)
callback, ok := callbackFunc.(StreamEventCallback)
if !ok {
panic("Incorrect stream event func callback")
}
callback(&Stream{ptr: st}, StreamEventType(events))
}
func (v *Stream) EventUpdateCallback(events StreamEventType) error {
ret := C.virStreamEventUpdateCallback(v.ptr, (C.int)(events))
if ret == -1 {
return GetLastError()
}
return nil
}
func (v *Stream) EventRemoveCallback() error {
ret := C.virStreamEventRemoveCallback(v.ptr)
if ret == -1 {
return GetLastError()
}
return nil
}

132
vendor/github.com/libvirt/libvirt-go/stream_cfuncs.go generated vendored Normal file
View File

@ -0,0 +1,132 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include "stream_cfuncs.h"
int streamSourceCallback(virStreamPtr st, char *cdata, size_t nbytes, int callbackID);
int streamSourceHoleCallback(virStreamPtr st, int *inData, long long *length, int callbackID);
int streamSourceSkipCallback(virStreamPtr st, long long length, int callbackID);
int streamSinkCallback(virStreamPtr st, const char *cdata, size_t nbytes, int callbackID);
int streamSinkHoleCallback(virStreamPtr st, long long length, int callbackID);
struct CallbackData {
int callbackID;
int holeCallbackID;
int skipCallbackID;
};
static int streamSourceCallbackHelper(virStreamPtr st, char *data, size_t nbytes, void *opaque)
{
struct CallbackData *cbdata = opaque;
return streamSourceCallback(st, data, nbytes, cbdata->callbackID);
}
static int streamSourceHoleCallbackHelper(virStreamPtr st, int *inData, long long *length, void *opaque)
{
struct CallbackData *cbdata = opaque;
return streamSourceHoleCallback(st, inData, length, cbdata->holeCallbackID);
}
static int streamSourceSkipCallbackHelper(virStreamPtr st, long long length, void *opaque)
{
struct CallbackData *cbdata = opaque;
return streamSourceSkipCallback(st, length, cbdata->skipCallbackID);
}
static int streamSinkCallbackHelper(virStreamPtr st, const char *data, size_t nbytes, void *opaque)
{
struct CallbackData *cbdata = opaque;
return streamSinkCallback(st, data, nbytes, cbdata->callbackID);
}
static int streamSinkHoleCallbackHelper(virStreamPtr st, long long length, void *opaque)
{
struct CallbackData *cbdata = opaque;
return streamSinkHoleCallback(st, length, cbdata->holeCallbackID);
}
int virStreamSendAll_cgo(virStreamPtr st, int callbackID)
{
struct CallbackData cbdata = { .callbackID = callbackID };
return virStreamSendAll(st, streamSourceCallbackHelper, &cbdata);
}
int virStreamSparseSendAll_cgo(virStreamPtr st, int callbackID, int holeCallbackID, int skipCallbackID)
{
struct CallbackData cbdata = { .callbackID = callbackID, .holeCallbackID = holeCallbackID, .skipCallbackID = skipCallbackID };
#if LIBVIR_VERSION_NUMBER < 3004000
assert(0); // Caller should have checked version
#else
return virStreamSparseSendAll(st, streamSourceCallbackHelper, streamSourceHoleCallbackHelper, streamSourceSkipCallbackHelper, &cbdata);
#endif
}
int virStreamRecvAll_cgo(virStreamPtr st, int callbackID)
{
struct CallbackData cbdata = { .callbackID = callbackID };
return virStreamRecvAll(st, streamSinkCallbackHelper, &cbdata);
}
int virStreamSparseRecvAll_cgo(virStreamPtr st, int callbackID, int holeCallbackID)
{
struct CallbackData cbdata = { .callbackID = callbackID, .holeCallbackID = holeCallbackID };
#if LIBVIR_VERSION_NUMBER < 3004000
assert(0); // Caller should have checked version
#else
return virStreamSparseRecvAll(st, streamSinkCallbackHelper, streamSinkHoleCallbackHelper, &cbdata);
#endif
}
void streamEventCallback(virStreamPtr st, int events, int callbackID);
static void streamEventCallbackHelper(virStreamPtr st, int events, void *opaque)
{
streamEventCallback(st, events, (int)(intptr_t)opaque);
}
int virStreamEventAddCallback_cgo(virStreamPtr st, int events, int callbackID)
{
return virStreamEventAddCallback(st, events, streamEventCallbackHelper, (void *)(intptr_t)callbackID, NULL);
}
*/
import "C"

37
vendor/github.com/libvirt/libvirt-go/stream_cfuncs.h generated vendored Normal file
View File

@ -0,0 +1,37 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_STREAM_CFUNCS_H__
#define LIBVIRT_GO_STREAM_CFUNCS_H__
int virStreamSendAll_cgo(virStreamPtr st, int callbackID);
int virStreamRecvAll_cgo(virStreamPtr st, int callbackID);
int virStreamSparseSendAll_cgo(virStreamPtr st, int callbackID, int holeCallbackID, int skipCallbackID);
int virStreamSparseRecvAll_cgo(virStreamPtr st, int callbackID, int holeCallbackID);
int virStreamEventAddCallback_cgo(virStreamPtr st, int events, int callbackID);
#endif /* LIBVIRT_GO_STREAM_CFUNCS_H__ */

69
vendor/github.com/libvirt/libvirt-go/stream_compat.go generated vendored Normal file
View File

@ -0,0 +1,69 @@
/*
* This file is part of the libvirt-go 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
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <assert.h>
#include "stream_compat.h"
int virStreamRecvFlagsCompat(virStreamPtr st,
char *data,
size_t nbytes,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 3004000
assert(0); // Caller should have checked version
#else
return virStreamRecvFlags(st, data, nbytes, flags);
#endif
}
int virStreamSendHoleCompat(virStreamPtr st,
long long length,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 3004000
assert(0); // Caller should have checked version
#else
return virStreamSendHole(st, length, flags);
#endif
}
int virStreamRecvHoleCompat(virStreamPtr st,
long long *length,
unsigned int flags)
{
#if LIBVIR_VERSION_NUMBER < 3004000
assert(0); // Caller should have checked version
#else
return virStreamRecvHole(st, length, flags);
#endif
}
*/
import "C"

49
vendor/github.com/libvirt/libvirt-go/stream_compat.h generated vendored Normal file
View File

@ -0,0 +1,49 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
#ifndef LIBVIRT_GO_STREAM_COMPAT_H__
#define LIBVIRT_GO_STREAM_COMPAT_H__
/* 3.4.0 */
#ifndef VIR_STREAM_RECV_STOP_AT_HOLE
#define VIR_STREAM_RECV_STOP_AT_HOLE (1 << 0)
#endif
int virStreamRecvFlagsCompat(virStreamPtr st,
char *data,
size_t nbytes,
unsigned int flags);
int virStreamSendHoleCompat(virStreamPtr st,
long long length,
unsigned int flags);
int virStreamRecvHoleCompat(virStreamPtr,
long long *length,
unsigned int flags);
#endif /* LIBVIRT_GO_STREAM_COMPAT_H__ */

262
vendor/github.com/libvirt/libvirt-go/typedparams.go generated vendored Normal file
View File

@ -0,0 +1,262 @@
/*
* This file is part of the libvirt-go 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) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
#include <string.h>
*/
import "C"
import (
"fmt"
"unsafe"
)
type typedParamsFieldInfo struct {
set *bool
i *int
ui *uint
l *int64
ul *uint64
b *bool
d *float64
s *string
sl *[]string
}
func typedParamsUnpackLen(cparams *C.virTypedParameter, nparams int, infomap map[string]typedParamsFieldInfo) (uint, error) {
count := uint(0)
for i := 0; i < nparams; i++ {
var cparam *C.virTypedParameter
cparam = (*C.virTypedParameter)(unsafe.Pointer(uintptr(unsafe.Pointer(cparams)) + unsafe.Sizeof(*cparam)*uintptr(i)))
name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
info, ok := infomap[name]
if !ok {
// Ignore unknown keys so that we don't break if
// run against a newer libvirt that returns more
// parameters than we currently have code to
// consume
continue
}
switch cparam._type {
case C.VIR_TYPED_PARAM_INT:
if info.i == nil {
return 0, fmt.Errorf("field %s expects an int", name)
}
*info.i = int(*(*C.int)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_UINT:
if info.ui == nil {
return 0, fmt.Errorf("field %s expects a uint", name)
}
*info.ui = uint(*(*C.uint)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_LLONG:
if info.l == nil {
return 0, fmt.Errorf("field %s expects an int64", name)
}
*info.l = int64(*(*C.longlong)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_ULLONG:
if info.ul == nil {
return 0, fmt.Errorf("field %s expects a uint64", name)
}
*info.ul = uint64(*(*C.ulonglong)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_DOUBLE:
if info.d == nil {
return 0, fmt.Errorf("field %s expects a float64", name)
}
*info.d = float64(*(*C.double)(unsafe.Pointer(&cparam.value)))
*info.set = true
case C.VIR_TYPED_PARAM_BOOLEAN:
if info.b == nil {
return 0, fmt.Errorf("field %s expects a bool", name)
}
*info.b = *(*C.char)(unsafe.Pointer(&cparam.value)) == 1
*info.set = true
case C.VIR_TYPED_PARAM_STRING:
if info.s != nil {
*info.s = C.GoString(*(**C.char)(unsafe.Pointer(&cparam.value)))
*info.set = true
} else if info.sl != nil {
*info.sl = append(*info.sl, C.GoString(*(**C.char)(unsafe.Pointer(&cparam.value))))
*info.set = true
} else {
return 0, fmt.Errorf("field %s expects a string/string list", name)
}
}
count++
}
return count, nil
}
func typedParamsUnpack(cparams []C.virTypedParameter, infomap map[string]typedParamsFieldInfo) (uint, error) {
return typedParamsUnpackLen(&cparams[0], len(cparams), infomap)
}
func typedParamsPackLen(cparams *C.virTypedParameter, nparams int, infomap map[string]typedParamsFieldInfo) error {
stringOffsets := make(map[string]uint)
for i := 0; i < nparams; i++ {
var cparam *C.virTypedParameter
cparam = (*C.virTypedParameter)(unsafe.Pointer(uintptr(unsafe.Pointer(cparams)) + unsafe.Sizeof(*cparam)*uintptr(i)))
name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
info, ok := infomap[name]
if !ok {
// Ignore unknown keys so that we don't break if
// run against a newer libvirt that returns more
// parameters than we currently have code to
// consume
continue
}
if !*info.set {
continue
}
switch cparam._type {
case C.VIR_TYPED_PARAM_INT:
if info.i == nil {
return fmt.Errorf("field %s expects an int", name)
}
*(*C.int)(unsafe.Pointer(&cparam.value)) = C.int(*info.i)
case C.VIR_TYPED_PARAM_UINT:
if info.ui == nil {
return fmt.Errorf("field %s expects a uint", name)
}
*(*C.uint)(unsafe.Pointer(&cparam.value)) = C.uint(*info.ui)
case C.VIR_TYPED_PARAM_LLONG:
if info.l == nil {
return fmt.Errorf("field %s expects an int64", name)
}
*(*C.longlong)(unsafe.Pointer(&cparam.value)) = C.longlong(*info.l)
case C.VIR_TYPED_PARAM_ULLONG:
if info.ul == nil {
return fmt.Errorf("field %s expects a uint64", name)
}
*(*C.ulonglong)(unsafe.Pointer(&cparam.value)) = C.ulonglong(*info.ul)
case C.VIR_TYPED_PARAM_DOUBLE:
if info.d == nil {
return fmt.Errorf("field %s expects a float64", name)
}
*(*C.double)(unsafe.Pointer(&cparam.value)) = C.double(*info.d)
case C.VIR_TYPED_PARAM_BOOLEAN:
if info.b == nil {
return fmt.Errorf("field %s expects a bool", name)
}
if *info.b {
*(*C.char)(unsafe.Pointer(&cparam.value)) = 1
} else {
*(*C.char)(unsafe.Pointer(&cparam.value)) = 0
}
case C.VIR_TYPED_PARAM_STRING:
if info.s != nil {
*(**C.char)(unsafe.Pointer(&cparam.value)) = C.CString(*info.s)
} else if info.sl != nil {
count := stringOffsets[name]
*(**C.char)(unsafe.Pointer(&cparam.value)) = C.CString((*info.sl)[count])
stringOffsets[name] = count + 1
} else {
return fmt.Errorf("field %s expects a string", name)
}
}
}
return nil
}
func typedParamsPack(cparams []C.virTypedParameter, infomap map[string]typedParamsFieldInfo) error {
return typedParamsPackLen(&cparams[0], len(cparams), infomap)
}
func typedParamsPackNew(infomap map[string]typedParamsFieldInfo) (*[]C.virTypedParameter, error) {
nparams := 0
for _, value := range infomap {
if !*value.set {
continue
}
if value.sl != nil {
nparams += len(*value.sl)
} else {
nparams++
}
}
cparams := make([]C.virTypedParameter, nparams)
nparams = 0
for key, value := range infomap {
if !*value.set {
continue
}
cfield := C.CString(key)
defer C.free(unsafe.Pointer(cfield))
clen := len(key) + 1
if clen > C.VIR_TYPED_PARAM_FIELD_LENGTH {
clen = C.VIR_TYPED_PARAM_FIELD_LENGTH
}
if value.sl != nil {
for i := 0; i < len(*value.sl); i++ {
cparam := &cparams[nparams]
cparam._type = C.VIR_TYPED_PARAM_STRING
C.memcpy(unsafe.Pointer(&cparam.field[0]), unsafe.Pointer(cfield), C.size_t(clen))
nparams++
}
} else {
cparam := &cparams[nparams]
if value.i != nil {
cparam._type = C.VIR_TYPED_PARAM_INT
} else if value.ui != nil {
cparam._type = C.VIR_TYPED_PARAM_UINT
} else if value.l != nil {
cparam._type = C.VIR_TYPED_PARAM_LLONG
} else if value.ul != nil {
cparam._type = C.VIR_TYPED_PARAM_ULLONG
} else if value.b != nil {
cparam._type = C.VIR_TYPED_PARAM_BOOLEAN
} else if value.d != nil {
cparam._type = C.VIR_TYPED_PARAM_DOUBLE
} else if value.s != nil {
cparam._type = C.VIR_TYPED_PARAM_STRING
}
C.memcpy(unsafe.Pointer(&cparam.field[0]), unsafe.Pointer(cfield), C.size_t(clen))
nparams++
}
}
err := typedParamsPack(cparams, infomap)
if err != nil {
C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), C.int(nparams))
return nil, err
}
return &cparams, nil
}