forked from rgbkrk/libvirt-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
interface.go
87 lines (76 loc) · 1.64 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package libvirt
/*
#cgo LDFLAGS: -lvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
type VirInterface struct {
ptr C.virInterfacePtr
}
func (n *VirInterface) Create(flags uint32) error {
result := C.virInterfaceCreate(n.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (n *VirInterface) Destroy(flags uint32) error {
result := C.virInterfaceDestroy(n.ptr, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (n *VirInterface) 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 *VirInterface) GetMACString() (string, error) {
result := C.virInterfaceGetMACString(n.ptr)
if result == nil {
return "", GetLastError()
}
mac := C.GoString(result)
return mac, nil
}
func (n *VirInterface) GetName() (string, error) {
result := C.virInterfaceGetName(n.ptr)
if result == nil {
return "", GetLastError()
}
name := C.GoString(result)
return name, nil
}
func (n *VirInterface) GetXMLDesc(flags uint32) (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 *VirInterface) Undefine() error {
result := C.virInterfaceUndefine(n.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (n *VirInterface) Free() error {
if result := C.virInterfaceFree(n.ptr); result != 0 {
return GetLastError()
}
return nil
}