writes out xml that works with virsh

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 04:36:05 -05:00
parent fd85215d57
commit 7b83c8e7db
2 changed files with 10 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import (
"libvirt.org/go/libvirtxml"
)
/*
func makeStandardXml(hostname string) *libvirtxml.Domain {
log.Info("create new xml file for:", hostname)
domcfg := &libvirtxml.Domain{}
@ -26,6 +27,7 @@ func makeStandardXml(hostname string) *libvirtxml.Domain {
return domcfg
}
*/
func writeoutXml(domcfg *libvirtxml.Domain, filename string) bool {
xmldoc, err := domcfg.Marshal()
@ -59,7 +61,7 @@ func setDiskFilename(domcfg *libvirtxml.Domain, filename string) {
}
}
func addDefaultXml(d *libvirtxml.Domain, filename string) {
func AddDefaultXml(d *libvirtxml.Domain, filename string) error {
/*
fullname := "resources/xml/" + filename + ".xml"
pfile, err := resources.ReadFile(fullname)
@ -72,11 +74,11 @@ func addDefaultXml(d *libvirtxml.Domain, filename string) {
err := d.Unmarshal(filename)
if err != nil {
log.Info("Marshal failed on file", filename)
return
}
return err
}
func readXml(filename string) (*libvirtxml.Domain, error) {
func ReadXml(filename string) (*libvirtxml.Domain, error) {
log.Verbose("parse xml file:", filename)
hostname := filepath.Base(filename)
@ -241,7 +243,7 @@ func setRandomMacs(domcfg *libvirtxml.Domain) {
// that is "standard". This is just a way to double check that
// there might be something interesting in a VM
// 'standard' here means what I think is standard
func dumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
// dump type
if domcfg.Type == "kvm" {
domcfg.Type = ""
@ -762,7 +764,7 @@ func warnUserOfNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
}
// dump out all the fields in libvirtxml.DomainDeviceList
func dumpLibvirtxmlDomainNames() {
func DumpLibvirtxmlDomainNames() {
var domain libvirtxml.Domain
t := reflect.TypeOf(domain)

View File

@ -14,7 +14,8 @@ import (
)
// generate the XML for 'virsh create'
func startDropletXml(d *pb.Droplet) {
func StartDropletXml(d *pb.Droplet, domcfg *libvirtxml.Domain, hostname string) {
/*
if d == nil {
log.Info("droplet is nil")
os.Exit(0)
@ -27,6 +28,7 @@ func startDropletXml(d *pb.Droplet) {
// addDefaultXml(domcfg, "network")
addDefaultXml(domcfg, "spice")
addDefaultXml(domcfg, "qcow")
*/
domcfg.Type = "kvm"
domcfg.Name = d.Hostname