コード例 #1
0
ファイル: domain.go プロジェクト: firebitsbr/libvirt-golang
// Save suspends a domain and save its memory contents to a file on disk. After
// the call, if successful, the domain is not listed as running anymore (this
// ends the life of a transient domain). Use Restore() to restore a domain
// after saving.
func (dom Domain) Save(to string, xml string, flags DomainSaveFlag) error {
	cTo := C.CString(to)
	defer C.free(unsafe.Pointer(cTo))

	var cXML *C.char
	if xml != "" {
		cXML = C.CString(xml)
		defer C.free(unsafe.Pointer(cXML))
	} else {
		cXML = nil
	}

	dom.log.Printf("saving domain's memory to file %v (flags = %v)...\n", to, flags)
	cRet := C.virDomainSaveFlags(dom.virDomain, cTo, cXML, C.uint(flags))
	ret := int32(cRet)

	if ret == -1 {
		err := LastError()
		dom.log.Printf("an error occurred: %v\n", err)
		return err
	}

	dom.log.Println("domain saved")

	return nil
}
コード例 #2
0
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 errors.New(GetLastError())
	}
	return nil
}