forked from rgbkrk/libvirt-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nwfilter.go
70 lines (61 loc) · 1.46 KB
/
nwfilter.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
package libvirt
/*
#cgo LDFLAGS: -lvirt -ldl
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
type VirNWFilter struct {
ptr C.virNWFilterPtr
}
func (f *VirNWFilter) Free() error {
if result := C.virNWFilterFree(f.ptr); result != 0 {
return GetLastError()
}
return nil
}
func (f *VirNWFilter) GetName() (string, error) {
name := C.virNWFilterGetName(f.ptr)
if name == nil {
return "", GetLastError()
}
return C.GoString(name), nil
}
func (f *VirNWFilter) Undefine() error {
result := C.virNWFilterUndefine(f.ptr)
if result == -1 {
return GetLastError()
}
return nil
}
func (f *VirNWFilter) 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 *VirNWFilter) 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 *VirNWFilter) 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
}