本文整理汇总了Golang中dmzhang/catkeeper/libvirt.VirConnection.CreateXML方法的典型用法代码示例。如果您正苦于以下问题:Golang VirConnection.CreateXML方法的具体用法?Golang VirConnection.CreateXML怎么用?Golang VirConnection.CreateXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dmzhang/catkeeper/libvirt.VirConnection
的用法示例。
在下文中一共展示了VirConnection.CreateXML方法的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)
}