NLP matrix algebra found 'reflect value.IsNil()'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
03eec14619
commit
34edf97565
12
config.go
12
config.go
|
@ -129,12 +129,12 @@ func writeConfigFile() {
|
|||
}
|
||||
|
||||
/*
|
||||
if me.cluster.Droplets.WriteConfigJSON() {
|
||||
os.Exit(-1)
|
||||
}
|
||||
if me.cluster.Droplets.WriteConfigTEXT() {
|
||||
os.Exit(-1)
|
||||
}
|
||||
if me.cluster.Droplets.WriteConfigJSON() {
|
||||
os.Exit(-1)
|
||||
}
|
||||
if me.cluster.Droplets.WriteConfigTEXT() {
|
||||
os.Exit(-1)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,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) {
|
||||
func dumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
|
||||
// dump type
|
||||
if domcfg.Type == "kvm" {
|
||||
domcfg.Type = ""
|
||||
|
@ -330,13 +330,21 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
|||
case "host-model":
|
||||
domcfg.CPU = nil
|
||||
case "custom":
|
||||
fmt.Printf("? CPU: %+v\n", domcfg.CPU)
|
||||
fmt.Printf("? CPU Model: %+v\n", domcfg.CPU.Model)
|
||||
domcfg.CPU = nil
|
||||
fmt.Printf("custom CPU: %+v\n", domcfg.CPU)
|
||||
fmt.Printf("custom CPU Model: %+v\n", domcfg.CPU.Model)
|
||||
// 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:
|
||||
fmt.Printf("? CPU: %+v\n", domcfg.CPU)
|
||||
fmt.Printf("? CPU Model: %+v\n", domcfg.CPU.Model)
|
||||
fmt.Printf("? CPU Mode: %+v\n", domcfg.CPU.Mode)
|
||||
fmt.Printf("unknown CPU: %+v\n", domcfg.CPU)
|
||||
fmt.Printf("unknown CPU Model: %+v\n", domcfg.CPU.Model)
|
||||
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)
|
||||
case "scsi":
|
||||
switch controller.Model {
|
||||
case "virtio-scsi":
|
||||
// fmt.Printf("IGNORE SCSI: lsilogic\n")
|
||||
case "lsilogic":
|
||||
// fmt.Printf("IGNORE SCSI: lsilogic\n")
|
||||
default:
|
||||
|
@ -625,39 +635,57 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
|
|||
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()
|
||||
if libvirtxmlDomainDevicesEmpty(*domcfg.Devices) {
|
||||
// fmt.Println("Domain Devices are empty")
|
||||
domcfg.Devices = nil
|
||||
} else {
|
||||
fmt.Println("Domain Devices are not empty")
|
||||
return warnUserOfNonStandardXML(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")
|
||||
domcfg = nil
|
||||
} else {
|
||||
fmt.Println("Domain is not yet empty")
|
||||
return warnUserOfNonStandardXML(domcfg)
|
||||
}
|
||||
|
||||
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, "", " ")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to marshal updated XML: %v\n", err)
|
||||
os.Exit(-1)
|
||||
return "", err
|
||||
}
|
||||
|
||||
final := string(updatedXML)
|
||||
if final == "" {
|
||||
// things seem pretty standard
|
||||
return
|
||||
// everything seems to have been parsed pretty standard
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Print the updated XML to verify
|
||||
log.Info("dumpNonStandardXML(domcfg) START")
|
||||
log.Info("Non-Standard XML Start")
|
||||
fmt.Println(string(updatedXML))
|
||||
log.Info("dumpNonStandardXML(domcfg) END")
|
||||
me.changed = true
|
||||
// os.Exit(-1)
|
||||
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
|
||||
|
@ -757,7 +785,7 @@ func libvirtxmlDomainEmpty(mydom libvirtxml.Domain) bool {
|
|||
|
||||
// Ensure that we are working with a 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
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
|
@ -772,6 +800,9 @@ func libvirtxmlDomainEmpty(mydom libvirtxml.Domain) bool {
|
|||
continue
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -793,9 +824,18 @@ func libvirtxmlDomainEmpty(mydom libvirtxml.Domain) bool {
|
|||
empty = false
|
||||
}
|
||||
case reflect.Ptr:
|
||||
if !value.IsValid() {
|
||||
fmt.Println("Field ptr: value:", value)
|
||||
fmt.Printf("Field ptr: %s is of type: %s\n", field, value.Kind())
|
||||
if value.IsValid() {
|
||||
if value.IsNil() {
|
||||
// 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
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue