-
Notifications
You must be signed in to change notification settings - Fork 50
/
snapshot.go
95 lines (84 loc) · 2.24 KB
/
snapshot.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
88
89
90
91
92
93
94
95
package libvirt
/*
#cgo LDFLAGS: -lvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include <stdlib.h>
*/
import "C"
import (
"unsafe"
)
type VirDomainSnapshot struct {
ptr C.virDomainSnapshotPtr
}
func (s *VirDomainSnapshot) Free() error {
if result := C.virDomainSnapshotFree(s.ptr); result != 0 {
return GetLastError()
}
return nil
}
func (s *VirDomainSnapshot) Delete(flags uint32) error {
result := C.virDomainSnapshotDelete(s.ptr, C.uint(flags))
if result != 0 {
return GetLastError()
}
return nil
}
func (s *VirDomainSnapshot) RevertToSnapshot(flags uint32) error {
result := C.virDomainRevertToSnapshot(s.ptr, C.uint(flags))
if result != 0 {
return GetLastError()
}
return nil
}
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 VirDomainSnapshot{ptr: result}, nil
}
func (d *VirDomain) Save(destFile string) error {
cPath := C.CString(destFile)
defer C.free(unsafe.Pointer(cPath))
result := C.virDomainSave(d.ptr, cPath)
if result == -1 {
return GetLastError()
}
return nil
}
func (d *VirDomain) SaveFlags(destFile string, destXml string, flags uint32) error {
cDestFile := C.CString(destFile)
cDestXml := C.CString(destXml)
defer C.free(unsafe.Pointer(cDestXml))
defer C.free(unsafe.Pointer(cDestFile))
result := C.virDomainSaveFlags(d.ptr, cDestFile, cDestXml, C.uint(flags))
if result == -1 {
return GetLastError()
}
return nil
}
func (conn VirConnection) Restore(srcFile string) error {
cPath := C.CString(srcFile)
defer C.free(unsafe.Pointer(cPath))
if result := C.virDomainRestore(conn.ptr, cPath); result == -1 {
return GetLastError()
}
return nil
}
func (conn VirConnection) RestoreFlags(srcFile, xmlConf string, flags uint32) error {
cPath := C.CString(srcFile)
defer C.free(unsafe.Pointer(cPath))
var cXmlConf *C.char
if xmlConf != "" {
cXmlConf = C.CString(xmlConf)
defer C.free(unsafe.Pointer(cXmlConf))
}
if result := C.virDomainRestoreFlags(conn.ptr, cPath, cXmlConf, C.uint(flags)); result == -1 {
return GetLastError()
}
return nil
}