Commit bd42aabd authored by Daniel P. Berrange's avatar Daniel P. Berrange

Change all APIs to return object pointers

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 705dd5ac
This diff is collapsed.
......@@ -6,7 +6,7 @@ import (
"time"
)
func buildTestConnection() VirConnection {
func buildTestConnection() *VirConnection {
conn, err := NewVirConnection("test:///default")
if err != nil {
panic(err)
......@@ -391,7 +391,6 @@ func TestLookupInvalidDomainByName(t *testing.T) {
func TestDomainCreateXML(t *testing.T) {
conn := buildTestConnection()
nodom := VirDomain{}
defer func() {
if res, _ := conn.CloseConnection(); res != 0 {
t.Errorf("CloseConnection() == %d, expected 0", res)
......@@ -432,11 +431,11 @@ func TestDomainCreateXML(t *testing.T) {
}
testeddom, err := conn.LookupDomainByName(defName)
if testeddom != nodom {
if err == nil {
testeddom.Free()
t.Fatal("Created domain is persisting")
return
}
testeddom.Free()
}
func TestDomainDefineXML(t *testing.T) {
......
......@@ -1008,17 +1008,16 @@ func (d *VirDomain) GetAutostart() (bool, error) {
}
}
func (d *VirDomain) GetBlockInfo(disk string, flag uint) (VirDomainBlockInfo, error) {
bi := VirDomainBlockInfo{}
func (d *VirDomain) GetBlockInfo(disk string, flag uint) (*VirDomainBlockInfo, error) {
var ptr C.virDomainBlockInfo
cDisk := C.CString(disk)
defer C.free(unsafe.Pointer(cDisk))
result := C.virDomainGetBlockInfo(d.ptr, cDisk, (*C.virDomainBlockInfo)(unsafe.Pointer(&ptr)), C.uint(flag))
if result == -1 {
return bi, GetLastError()
return nil, GetLastError()
}
bi.ptr = ptr
return bi, nil
return &VirDomainBlockInfo{ptr: ptr}, nil
}
func (b *VirDomainBlockInfo) Allocation() uint64 {
......@@ -1082,15 +1081,13 @@ func (d *VirDomain) GetUUIDString() (string, error) {
return C.GoString((*C.char)(cuidPtr)), nil
}
func (d *VirDomain) GetInfo() (VirDomainInfo, error) {
di := VirDomainInfo{}
func (d *VirDomain) GetInfo() (*VirDomainInfo, error) {
var ptr C.virDomainInfo
result := C.virDomainGetInfo(d.ptr, (*C.virDomainInfo)(unsafe.Pointer(&ptr)))
if result == -1 {
return di, GetLastError()
return nil, GetLastError()
}
di.ptr = ptr
return di, nil
return &VirDomainInfo{ptr: ptr}, nil
}
func (d *VirDomain) GetXMLDesc(flags uint32) (string, error) {
......@@ -1913,12 +1910,12 @@ func (d *VirDomain) ListAllInterfaceAddresses(src uint) ([]VirDomainInterface, e
return ifaces, nil
}
func (d *VirDomain) SnapshotCurrent(flags uint32) (VirDomainSnapshot, error) {
func (d *VirDomain) SnapshotCurrent(flags uint32) (*VirDomainSnapshot, error) {
result := C.virDomainSnapshotCurrent(d.ptr, C.uint(flags))
if result == nil {
return VirDomainSnapshot{}, GetLastError()
return nil, GetLastError()
}
return VirDomainSnapshot{ptr: result}, nil
return &VirDomainSnapshot{ptr: result}, nil
}
......@@ -1930,14 +1927,14 @@ func (d *VirDomain) SnapshotNum(flags VirDomainSnapshotListFlags) (int, error) {
return result, nil
}
func (d *VirDomain) SnapshotLookupByName(name string, flags uint32) (VirDomainSnapshot, error) {
func (d *VirDomain) SnapshotLookupByName(name string, flags uint32) (*VirDomainSnapshot, error) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
ptr := C.virDomainSnapshotLookupByName(d.ptr, cName, C.uint(flags))
if ptr == nil {
return VirDomainSnapshot{}, GetLastError()
return nil, GetLastError()
}
return VirDomainSnapshot{ptr: ptr}, nil
return &VirDomainSnapshot{ptr: ptr}, nil
}
func (d *VirDomain) SnapshotListNames(flags VirDomainSnapshotListFlags) ([]string, error) {
......
......@@ -26,7 +26,6 @@ func TestDomainEventRegister(t *testing.T) {
}
}()
nodom := VirDomain{}
defName := time.Now().String()
nbEvents := 0
......@@ -83,10 +82,8 @@ func TestDomainEventRegister(t *testing.T) {
}
defer func() {
if dom != nodom {
dom.Destroy()
dom.Free()
}
dom.Destroy()
dom.Free()
}()
// Check that the internal context entry was added, and that there only is
......
......@@ -86,14 +86,14 @@ func (s *VirDomainSnapshot) RevertToSnapshot(flags uint32) error {
return nil
}
func (d *VirDomain) CreateSnapshotXML(xml string, flags uint32) (VirDomainSnapshot, error) {
func (d *VirDomain) CreateSnapshotXML(xml string, flags uint32) (*VirDomainSnapshot, error) {
cXml := C.CString(xml)
defer C.free(unsafe.Pointer(cXml))
result := C.virDomainSnapshotCreateXML(d.ptr, cXml, C.uint(flags))
if result == nil {
return VirDomainSnapshot{}, GetLastError()
return nil, GetLastError()
}
return VirDomainSnapshot{ptr: result}, nil
return &VirDomainSnapshot{ptr: result}, nil
}
func (d *VirDomain) Save(destFile string) error {
......@@ -181,12 +181,12 @@ func (s *VirDomainSnapshot) GetName() (string, error) {
return C.GoString(name), nil
}
func (s *VirDomainSnapshot) GetParent(flags uint32) (VirDomainSnapshot, error) {
func (s *VirDomainSnapshot) GetParent(flags uint32) (*VirDomainSnapshot, error) {
ptr := C.virDomainSnapshotGetParent(s.ptr, C.uint(flags))
if ptr == nil {
return VirDomainSnapshot{}, GetLastError()
return nil, GetLastError()
}
return VirDomainSnapshot{ptr: ptr}, nil
return &VirDomainSnapshot{ptr: ptr}, nil
}
func (s *VirDomainSnapshot) NumChildren(flags VirDomainSnapshotListFlags) (int, error) {
......
......@@ -6,7 +6,7 @@ import (
"time"
)
func buildTestDomain() (VirDomain, VirConnection) {
func buildTestDomain() (*VirDomain, *VirConnection) {
conn := buildTestConnection()
dom, err := conn.DomainDefineXML(`<domain type="test">
<name>` + time.Now().String() + `</name>
......@@ -21,7 +21,7 @@ func buildTestDomain() (VirDomain, VirConnection) {
return dom, conn
}
func buildSMPTestDomain() (VirDomain, VirConnection) {
func buildSMPTestDomain() (*VirDomain, *VirConnection) {
conn := buildTestConnection()
dom, err := conn.DomainDefineXML(`<domain type="test">
<name>` + time.Now().String() + `</name>
......@@ -37,7 +37,7 @@ func buildSMPTestDomain() (VirDomain, VirConnection) {
return dom, conn
}
func buildTransientTestDomain() (VirDomain, VirConnection) {
func buildTransientTestDomain() (*VirDomain, *VirConnection) {
conn := buildTestConnection()
dom, err := conn.DomainCreateXML(`<domain type="test">
<name>`+time.Now().String()+`</name>
......@@ -603,7 +603,7 @@ func TestDomainScreenshot(t *testing.T) {
t.Error(err)
return
}
stream, err := NewVirStream(&conn, 0)
stream, err := NewVirStream(conn, 0)
if err != nil {
t.Fatalf("failed to create new stream: %s", err)
}
......
......@@ -10,7 +10,7 @@ import (
"time"
)
func buildTestQEMUConnection() VirConnection {
func buildTestQEMUConnection() *VirConnection {
conn, err := NewVirConnection("qemu:///system")
if err != nil {
panic(err)
......@@ -18,7 +18,7 @@ func buildTestQEMUConnection() VirConnection {
return conn
}
func buildTestQEMUDomain() (VirDomain, VirConnection) {
func buildTestQEMUDomain() (*VirDomain, *VirConnection) {
conn := buildTestQEMUConnection()
dom, err := conn.DomainDefineXML(`<domain type="qemu">
<name>libvirt-go-test-` + strings.Replace(time.Now().String(), " ", "_", -1) + `</name>
......@@ -212,7 +212,7 @@ func TestDomainCreateWithFlags(t *testing.T) {
}
}
func defineTestLxcDomain(conn VirConnection, title string) (VirDomain, error) {
func defineTestLxcDomain(conn *VirConnection, title string) (*VirDomain, error) {
if title == "" {
title = time.Now().String()
}
......@@ -1165,7 +1165,7 @@ func TestStorageVolUploadDownload(t *testing.T) {
// write above data to the vol
// 1. create a stream
stream, err := NewVirStream(&conn, 0)
stream, err := NewVirStream(conn, 0)
if err != nil {
t.Fatal(err)
}
......@@ -1191,7 +1191,7 @@ func TestStorageVolUploadDownload(t *testing.T) {
// read back the data
// 1. create a stream
downStream, err := NewVirStream(&conn, 0)
downStream, err := NewVirStream(conn, 0)
if err != nil {
t.Fatal(err)
}
......
......@@ -6,7 +6,7 @@ import (
"testing"
)
func buildTestInterface(mac string) (VirInterface, VirConnection) {
func buildTestInterface(mac string) (*VirInterface, *VirConnection) {
conn := buildTestConnection()
xml := `<interface type='ethernet' name='ethTest0'><mac address='` + mac + `'/></interface>`
iface, err := conn.InterfaceDefineXML(xml, 0)
......
......@@ -22,7 +22,7 @@ func networkXML(netName string) string {
</network>`
}
func buildTestNetwork(netName string) (VirNetwork, VirConnection) {
func buildTestNetwork(netName string) (*VirNetwork, *VirConnection) {
conn := buildTestConnection()
networkXML := networkXML(netName)
net, err := conn.NetworkDefineXML(networkXML)
......
......@@ -126,15 +126,13 @@ func (p *VirStoragePool) GetAutostart() (bool, error) {
}
}
func (p *VirStoragePool) GetInfo() (VirStoragePoolInfo, error) {
pi := VirStoragePoolInfo{}
func (p *VirStoragePool) GetInfo() (*VirStoragePoolInfo, error) {
var ptr C.virStoragePoolInfo
result := C.virStoragePoolGetInfo(p.ptr, (*C.virStoragePoolInfo)(unsafe.Pointer(&ptr)))
if result == -1 {
return pi, GetLastError()
return nil, GetLastError()
}
pi.ptr = ptr
return pi, nil
return &VirStoragePoolInfo{ptr: ptr}, nil
}
func (p *VirStoragePool) GetName() (string, error) {
......@@ -244,34 +242,34 @@ func (i *VirStoragePoolInfo) GetAvailableInBytes() uint64 {
return uint64(i.ptr.available)
}
func (p *VirStoragePool) StorageVolCreateXML(xmlConfig string, flags uint32) (VirStorageVol, error) {
func (p *VirStoragePool) StorageVolCreateXML(xmlConfig string, flags uint32) (*VirStorageVol, 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 VirStorageVol{}, GetLastError()
return nil, GetLastError()
}
return VirStorageVol{ptr: ptr}, nil
return &VirStorageVol{ptr: ptr}, nil
}
func (p *VirStoragePool) StorageVolCreateXMLFrom(xmlConfig string, clonevol VirStorageVol, flags uint32) (VirStorageVol, error) {
func (p *VirStoragePool) StorageVolCreateXMLFrom(xmlConfig string, clonevol *VirStorageVol, flags uint32) (*VirStorageVol, 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 VirStorageVol{}, GetLastError()
return nil, GetLastError()
}
return VirStorageVol{ptr: ptr}, nil
return &VirStorageVol{ptr: ptr}, nil
}
func (p *VirStoragePool) LookupStorageVolByName(name string) (VirStorageVol, error) {
func (p *VirStoragePool) LookupStorageVolByName(name string) (*VirStorageVol, error) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
ptr := C.virStorageVolLookupByName(p.ptr, cName)
if ptr == nil {
return VirStorageVol{}, GetLastError()
return nil, GetLastError()
}
return VirStorageVol{ptr: ptr}, nil
return &VirStorageVol{ptr: ptr}, nil
}
func (p *VirStoragePool) NumOfStorageVolumes() (int, error) {
......
......@@ -5,7 +5,7 @@ import (
"time"
)
func buildTestStoragePool(poolName string) (VirStoragePool, VirConnection) {
func buildTestStoragePool(poolName string) (*VirStoragePool, *VirConnection) {
conn := buildTestConnection()
var name string
if poolName == "" {
......
......@@ -90,15 +90,13 @@ func (v *VirStorageVol) Free() error {
return nil
}
func (v *VirStorageVol) GetInfo() (VirStorageVolInfo, error) {
vi := VirStorageVolInfo{}
func (v *VirStorageVol) GetInfo() (*VirStorageVolInfo, error) {
var ptr C.virStorageVolInfo
result := C.virStorageVolGetInfo(v.ptr, (*C.virStorageVolInfo)(unsafe.Pointer(&ptr)))
if result == -1 {
return vi, GetLastError()
return nil, GetLastError()
}
vi.ptr = ptr
return vi, nil
return &VirStorageVolInfo{ptr: ptr}, nil
}
func (i *VirStorageVolInfo) GetType() VirStorageVolType {
......@@ -188,10 +186,10 @@ func (v *VirStorageVol) Download(stream *VirStream, offset, length uint64, flags
return nil
}
func (v *VirStorageVol) LookupPoolByVolume() (VirStoragePool, error) {
func (v *VirStorageVol) LookupPoolByVolume() (*VirStoragePool, error) {
poolPtr := C.virStoragePoolLookupByVolume(v.ptr)
if poolPtr == nil {
return VirStoragePool{}, GetLastError()
return nil, GetLastError()
}
return VirStoragePool{ptr: poolPtr}, nil
return &VirStoragePool{ptr: poolPtr}, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment