// RestoreDomain restores a domain saved to disk by Save().
func (conn Connection) RestoreDomain(from string, xml string, flags DomainSaveFlag) error {
	cFrom := C.CString(from)
	defer C.free(unsafe.Pointer(cFrom))

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

	conn.log.Printf("restoring domain from file %v (flags = %v)...\n", from, flags)
	cRet := C.virDomainRestoreFlags(conn.virConnect, cFrom, cXML, C.uint(flags))
	ret := int32(cRet)

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

	conn.log.Println("domain restored")

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