diff --git a/dumpNonStandardXML.go b/dumpNonStandardXML.go index 3feba22..a7d620d 100644 --- a/dumpNonStandardXML.go +++ b/dumpNonStandardXML.go @@ -13,12 +13,14 @@ package virtigolib import ( "encoding/xml" "fmt" + "os" "go.wit.com/log" "libvirt.org/go/libvirtxml" ) func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { + var result string // dump type if domcfg.Type == "kvm" { domcfg.Type = "" @@ -188,6 +190,7 @@ func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { if domcfg.Metadata != nil { var s string s = domcfg.Metadata.XML + result += fmt.Sprintln("Not saving Domain.Metadata.XML:", s) log.Info("Not saving Domain.Metadata.XML:", s) log.Info("todo: get this from disk image") domcfg.Metadata = nil @@ -198,6 +201,7 @@ func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { if domcfg.Resource.Partition == "/machine" { domcfg.Resource = nil } else { + result += fmt.Sprintf("non-standard Domain.Resource: %+v\n", domcfg.Resource) fmt.Printf("non-standard Domain.Resource: %+v\n", domcfg.Resource) } } @@ -506,5 +510,52 @@ func DumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { domcfg.Devices.Watchdogs = nil } - return finalEmptyCheck(domcfg) + end, err := finalEmptyCheck(domcfg) + if end != "" { + result += fmt.Sprintln(end) + } + return result, err +} + +// this tries the final zero'ing out of the XML +// todo: if this fails, put the remaining XML in the protobuf file? +func finalEmptyCheck(domcfg *libvirtxml.Domain) (string, error) { + // dumpLibvirtxmlDomainNames() + if libvirtxmlDomainDevicesEmpty(*domcfg.Devices) { + // fmt.Println("Domain Devices are empty") + domcfg.Devices = nil + } else { + return warnUserOfNonStandardXML(domcfg) + } + + if libvirtxmlDomainEmpty(*domcfg) { + domcfg = nil + return warnUserOfNonStandardXML(domcfg) + } + + final, err := warnUserOfNonStandardXML(domcfg) + if err != nil { + fmt.Printf("todo: improve this libvirtXML parsing. %v\n", err) + os.Exit(-1) + } + return final, nil +} + +func warnUserOfNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { + updatedXML, err := xml.MarshalIndent(domcfg, "", " ") + if err != nil { + fmt.Printf("Failed to marshal updated XML: %v\n", err) + return "", err + } + final := string(updatedXML) + if final == "" { + // everything seems to have been parsed pretty standard + return "", nil + } + log.Info("Non-Standard XML Start") + fmt.Println(string(updatedXML)) + log.Info("Non-Standard XML End") + log.Info("") + log.Info("This XML must be removed by hand. Put this in the protobuf?") + return string(updatedXML), nil } diff --git a/libvirtxml.go b/libvirtxml.go index d8a16cb..cd40375 100644 --- a/libvirtxml.go +++ b/libvirtxml.go @@ -224,30 +224,6 @@ func setRandomMacs(domcfg *libvirtxml.Domain) { } } -// this tries the final zero'ing out of the XML -// todo: if this fails, put the remaining XML in the protobuf file? -func finalEmptyCheck(domcfg *libvirtxml.Domain) (string, error) { - // dumpLibvirtxmlDomainNames() - if libvirtxmlDomainDevicesEmpty(*domcfg.Devices) { - // fmt.Println("Domain Devices are empty") - domcfg.Devices = nil - } else { - return warnUserOfNonStandardXML(domcfg) - } - - if libvirtxmlDomainEmpty(*domcfg) { - domcfg = nil - return warnUserOfNonStandardXML(domcfg) - } - - final, err := warnUserOfNonStandardXML(domcfg) - if err != nil { - fmt.Printf("todo: improve this libvirtXML parsing. %v\n", err) - os.Exit(-1) - } - return final, nil -} - func xmlAny(a any) (string, error) { updatedXML, err := xml.MarshalIndent(a, "", " ") if err != nil { @@ -265,25 +241,6 @@ func xmlAny(a any) (string, error) { return final, nil } -func warnUserOfNonStandardXML(domcfg *libvirtxml.Domain) (string, error) { - updatedXML, err := xml.MarshalIndent(domcfg, "", " ") - if err != nil { - fmt.Printf("Failed to marshal updated XML: %v\n", err) - return "", err - } - final := string(updatedXML) - if final == "" { - // everything seems to have been parsed pretty standard - return "", nil - } - log.Info("Non-Standard XML Start") - fmt.Println(string(updatedXML)) - log.Info("Non-Standard XML End") - log.Info("") - log.Info("This XML must be removed by hand. Put this in the protobuf?") - return string(updatedXML), nil -} - // dump out all the fields in libvirtxml.DomainDeviceList func DumpLibvirtxmlDomainNames() { var domain libvirtxml.Domain