NLP matrix algebra found 'reflect value.IsNil()'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
03eec14619
commit
34edf97565
|
@ -208,7 +208,7 @@ func setRandomMacs(domcfg *libvirtxml.Domain) {
|
||||||
// that is "standard". This is just a way to double check that
|
// that is "standard". This is just a way to double check that
|
||||||
// there might be something interesting in a VM
|
// there might be something interesting in a VM
|
||||||
// 'standard' here means what I think is standard
|
// 'standard' here means what I think is standard
|
||||||
func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
func dumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
|
||||||
// dump type
|
// dump type
|
||||||
if domcfg.Type == "kvm" {
|
if domcfg.Type == "kvm" {
|
||||||
domcfg.Type = ""
|
domcfg.Type = ""
|
||||||
|
@ -330,13 +330,21 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
||||||
case "host-model":
|
case "host-model":
|
||||||
domcfg.CPU = nil
|
domcfg.CPU = nil
|
||||||
case "custom":
|
case "custom":
|
||||||
fmt.Printf("? CPU: %+v\n", domcfg.CPU)
|
fmt.Printf("custom CPU: %+v\n", domcfg.CPU)
|
||||||
fmt.Printf("? CPU Model: %+v\n", domcfg.CPU.Model)
|
fmt.Printf("custom CPU Model: %+v\n", domcfg.CPU.Model)
|
||||||
domcfg.CPU = nil
|
// domcfg.CPU = nil
|
||||||
|
updatedXML, _ := xml.MarshalIndent(domcfg.CPU, "", " ")
|
||||||
|
log.Info("Non-Standard XML Start")
|
||||||
|
fmt.Println(string(updatedXML))
|
||||||
|
log.Info("Non-Standard XML End")
|
||||||
default:
|
default:
|
||||||
fmt.Printf("? CPU: %+v\n", domcfg.CPU)
|
fmt.Printf("unknown CPU: %+v\n", domcfg.CPU)
|
||||||
fmt.Printf("? CPU Model: %+v\n", domcfg.CPU.Model)
|
fmt.Printf("unknown CPU Model: %+v\n", domcfg.CPU.Model)
|
||||||
fmt.Printf("? CPU Mode: %+v\n", domcfg.CPU.Mode)
|
fmt.Printf("unknown CPU Mode: %+v\n", domcfg.CPU.Mode)
|
||||||
|
updatedXML, _ := xml.MarshalIndent(domcfg.CPU, "", " ")
|
||||||
|
log.Info("Non-Standard XML Start")
|
||||||
|
fmt.Println(string(updatedXML))
|
||||||
|
log.Info("Non-Standard XML End")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +436,8 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
||||||
// fmt.Printf("SATA: %+v\n", controller)
|
// fmt.Printf("SATA: %+v\n", controller)
|
||||||
case "scsi":
|
case "scsi":
|
||||||
switch controller.Model {
|
switch controller.Model {
|
||||||
|
case "virtio-scsi":
|
||||||
|
// fmt.Printf("IGNORE SCSI: lsilogic\n")
|
||||||
case "lsilogic":
|
case "lsilogic":
|
||||||
// fmt.Printf("IGNORE SCSI: lsilogic\n")
|
// fmt.Printf("IGNORE SCSI: lsilogic\n")
|
||||||
default:
|
default:
|
||||||
|
@ -625,39 +635,57 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
||||||
domcfg.Devices.Videos = nil
|
domcfg.Devices.Videos = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return finalEmptyCheck(domcfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()
|
// dumpLibvirtxmlDomainNames()
|
||||||
if libvirtxmlDomainDevicesEmpty(*domcfg.Devices) {
|
if libvirtxmlDomainDevicesEmpty(*domcfg.Devices) {
|
||||||
// fmt.Println("Domain Devices are empty")
|
// fmt.Println("Domain Devices are empty")
|
||||||
domcfg.Devices = nil
|
domcfg.Devices = nil
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Domain Devices are not empty")
|
return warnUserOfNonStandardXML(domcfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if libvirtxmlDomainEmpty(*domcfg) {
|
if libvirtxmlDomainEmpty(*domcfg) {
|
||||||
|
log.Info("CPU THIS SHOULD NEVER HAPPEN")
|
||||||
|
log.Info("CPU THIS SHOULD NEVER HAPPEN")
|
||||||
|
log.Info("CPU THIS SHOULD NEVER HAPPEN")
|
||||||
// fmt.Println("Domain Devices are empty")
|
// fmt.Println("Domain Devices are empty")
|
||||||
domcfg = nil
|
domcfg = nil
|
||||||
} else {
|
return warnUserOfNonStandardXML(domcfg)
|
||||||
fmt.Println("Domain is not yet empty")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final, err := warnUserOfNonStandardXML(domcfg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("todo: improve this libvirtXML parsing. %v\n", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
if final != "" {
|
||||||
|
me.changed = true
|
||||||
|
}
|
||||||
|
return final, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func warnUserOfNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
|
||||||
updatedXML, err := xml.MarshalIndent(domcfg, "", " ")
|
updatedXML, err := xml.MarshalIndent(domcfg, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to marshal updated XML: %v\n", err)
|
fmt.Printf("Failed to marshal updated XML: %v\n", err)
|
||||||
os.Exit(-1)
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
final := string(updatedXML)
|
final := string(updatedXML)
|
||||||
if final == "" {
|
if final == "" {
|
||||||
// things seem pretty standard
|
// everything seems to have been parsed pretty standard
|
||||||
return
|
return "", nil
|
||||||
}
|
}
|
||||||
|
log.Info("Non-Standard XML Start")
|
||||||
// Print the updated XML to verify
|
|
||||||
log.Info("dumpNonStandardXML(domcfg) START")
|
|
||||||
fmt.Println(string(updatedXML))
|
fmt.Println(string(updatedXML))
|
||||||
log.Info("dumpNonStandardXML(domcfg) END")
|
log.Info("Non-Standard XML End")
|
||||||
me.changed = true
|
log.Info("")
|
||||||
// os.Exit(-1)
|
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
|
// dump out all the fields in libvirtxml.DomainDeviceList
|
||||||
|
@ -757,7 +785,7 @@ func libvirtxmlDomainEmpty(mydom libvirtxml.Domain) bool {
|
||||||
|
|
||||||
// Ensure that we are working with a struct
|
// Ensure that we are working with a struct
|
||||||
if v.Kind() == reflect.Struct {
|
if v.Kind() == reflect.Struct {
|
||||||
// fmt.Println("Fields and values in libvirtxml.DomainDeviceList:")
|
fmt.Println("Fields and values in libvirtxml.DomainDeviceList:")
|
||||||
|
|
||||||
// Loop through each field in the struct
|
// Loop through each field in the struct
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
|
@ -772,6 +800,9 @@ func libvirtxmlDomainEmpty(mydom libvirtxml.Domain) bool {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (field == "IOThreads") || (field == "XMLName") {
|
if (field == "IOThreads") || (field == "XMLName") {
|
||||||
|
fmt.Printf("Field: %s is nil or invalid\n", field)
|
||||||
|
fmt.Printf("Field: %s is nil or invalid\n", field)
|
||||||
|
fmt.Printf("Field: %s is a String with value: %s\n", field, value.String())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,9 +824,18 @@ func libvirtxmlDomainEmpty(mydom libvirtxml.Domain) bool {
|
||||||
empty = false
|
empty = false
|
||||||
}
|
}
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
if !value.IsValid() {
|
if value.IsValid() {
|
||||||
fmt.Println("Field ptr: value:", value)
|
if value.IsNil() {
|
||||||
fmt.Printf("Field ptr: %s is of type: %s\n", field, value.Kind())
|
// this means the value is actually nil
|
||||||
|
} else {
|
||||||
|
// there is something still here in the libvirt XML
|
||||||
|
fmt.Printf("Field Valid? field %s is of type: %s\n", field, value.Kind())
|
||||||
|
fmt.Println("Field Valid? ptr: value:", value)
|
||||||
|
empty = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Invalid Field ptr: value:", value)
|
||||||
|
fmt.Printf("Invalid Field ptr: %s is of type: %s\n", field, value.Kind())
|
||||||
empty = false
|
empty = false
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue