-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.go
57 lines (46 loc) · 1006 Bytes
/
core.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
package govirt
// #cgo pkg-config: libvirt
// #include <stdlib.h>
// #include <libvirt/libvirt.h>
import "C"
import "unsafe"
import "errors"
// Represents a libvirt node.
// Exposes methods for controlling the hypervisor.
type Node struct {
Url string
conn Connection
}
type Connection struct {
Pointer C.virConnectPtr
}
type Domain struct {
}
type Network struct {
}
type StorageVol struct {
}
type StoragePool struct {
}
func (p *Node) Connect() error {
cUrl := C.CString(p.Url)
defer C.free(unsafe.Pointer(cUrl))
conn := C.virConnectOpenAuth(cUrl, C.virConnectAuthPtrDefault, 0) // TODO: Implement alias override
if conn == nil {
return errors.New("Unable to establish connection")
}
p.conn = Connection{conn}
return nil
}
func (p *Node) Disconnect() int {
if p.conn.Pointer != nil {
return int(C.virConnectClose(p.conn.Pointer))
}
return -1
}
func Connect(url string) (Node, error) {
var retval Node
retval = Node{Url: url}
err := retval.Connect()
return retval, err
}