當前位置: 首頁>>代碼示例>>Golang>>正文


Golang VirConnection.DefineXML方法代碼示例

本文整理匯總了Golang中dmzhang/catkeeper/libvirt.VirConnection.DefineXML方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirConnection.DefineXML方法的具體用法?Golang VirConnection.DefineXML怎麽用?Golang VirConnection.DefineXML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dmzhang/catkeeper/libvirt.VirConnection的用法示例。


在下文中一共展示了VirConnection.DefineXML方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: VmInstall


//.........這裏部分代碼省略.........
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer stream.Free()

	//Upload to remote
	reportStatus(ch, "sending linuxVolume")
	if err := SendLocalToRemote(stream, linuxVolume, linuxContent); err != nil {
		reportFail(ch, err.Error())
		return
	}

	reportStatus(ch, "sending initrd")
	if err := SendLocalToRemote(stream, initrdVolume, initrdContent); err != nil {
		reportFail(ch, err.Error())
		return
	}

	// create image
	reportStatus(ch, "creating remote imaging...")
	dataPool, err := conn.StoragePoolLookupByName("default")
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer dataPool.Free()

	//var imageSize uint64 = 8589934592 //8G

	realImageName := vmname + ".img"
	imageVolume, err := createVolume(dataPool, Storage{Name: realImageName, Size: imageSize, Type: "qcow2"})

	if err != nil {
		reportFail(ch, err.Error())
		return
	}

	defer imageVolume.Free()
	imagePath, _ := imageVolume.GetPath()

	log.Println("Create remote VirtualMachine")
	reportStatus(ch, "Create remote VirtualMachine")

	// create boot xml
	var xml string
	// add autoyast
	var installArg string
	if len(autoyast) > 0 {
		installArg = url + " autoyast=" + autoyast
	} else {
		installArg = url
	}

	domain := Domain{Name: vmname, Kernel: linuxPath, Initrd: initrdPath, Image: imagePath, Install: installArg}
	if xml, err = domain.Encode(); err != nil {
		reportFail(ch, err.Error())
		return
	}

	// create booting vm
	bootingDomain, err := conn.CreateXML(xml)
	if err != nil {
		reportFail(ch, err.Error())
		return
	}
	defer bootingDomain.Free()

	// get xml from remote
	// create new defined xml
	if xml, err = bootingDomain.GetXMLDesc(); err != nil {
		reportFail(ch, err.Error())
		return
	}

	/* change xml a bit using regex lines, I do not want to parse the xml file
	* 1. change os section to boot from hd
	* 2. change destory section
	 */
	/* (?s) is used to let . match newline(\n) */
	osSection := regexp.MustCompile("(?s)<os>.*</os>")
	onBoot := regexp.MustCompile("(?s)<on_reboot>.*</on_reboot>")
	onCrash := regexp.MustCompile("(?s)<on_crash>.*</on_crash>")

	xml = osSection.ReplaceAllString(xml, OSSECTION)
	xml = onBoot.ReplaceAllString(xml, ONBOOT)
	xml = onCrash.ReplaceAllString(xml, ONCRASH)

	newPersistentDomain, err := conn.DefineXML(xml)
	if err != nil {
		reportFail(ch, err.Error())
		return
	}

	log.Println(newPersistentDomain)
	defer newPersistentDomain.Free()

	reportSuccess(ch)

}
開發者ID:hopkings2008,項目名稱:catkeeper,代碼行數:101,代碼來源:vminstall.go


注:本文中的dmzhang/catkeeper/libvirt.VirConnection.DefineXML方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。