more xml fixes

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-25 06:41:22 -05:00
parent a4c54d6483
commit 9528d4c0fb
3 changed files with 23 additions and 12 deletions

View File

@ -159,7 +159,7 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) error {
e, err = updateNetwork(d, domcfg) e, err = updateNetwork(d, domcfg)
if err != nil { if err != nil {
log.Info("updateNetwork() failed") log.Info("updateNetwork() failed", err)
return errors.New("updateNetwork() failed") return errors.New("updateNetwork() failed")
} }
if e != nil { if e != nil {
@ -240,16 +240,22 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) (*pb.Event, error) {
// log.Info("Interface:", iface.Target, "MAC Address:", iface.MAC.Address) // log.Info("Interface:", iface.Target, "MAC Address:", iface.MAC.Address)
// fmt.Printf("source: %+v\n", iface.Source) // fmt.Printf("source: %+v\n", iface.Source)
hwaddr = iface.MAC.Address hwaddr = iface.MAC.Address
} else {
fmt.Printf("iface: %+v\n", iface)
fmt.Printf("Interface Target: %+v, MAC Address not available\n", iface.Target)
return nil, errors.New("network XML does not have a MAC Address")
} }
if iface.Source != nil { if iface.Source == nil {
if iface.Source.Bridge != nil { fmt.Printf("non-standard network: %+v\n", iface)
brname = iface.Source.Bridge.Bridge return nil, errors.New("non-standard network")
} }
}
if iface.Source.Bridge == nil {
fmt.Printf("non-standard network: %+v\n", iface)
return nil, errors.New("bridge is blank nil and no mac address")
}
if iface.Source.Bridge.Bridge == "" {
return nil, errors.New("bridge is blank and no mac address")
}
// log.Info("network has bridge:", iface.Source.Bridge.Bridge)
brname = iface.Source.Bridge.Bridge
hwaddr = "generate"
macs[hwaddr] = brname macs[hwaddr] = brname
} }

View File

@ -32,7 +32,7 @@ func convertToAnypb(x any) *anypb.Any {
a, _ = anypb.New(wrapperspb.Bool(x.(bool))) a, _ = anypb.New(wrapperspb.Bool(x.(bool)))
return a return a
default: default:
log.Error(errors.New("Set() unknown type"), "v =", v, "x =", x) log.Error(errors.New("convertToAnypb() unknown type"), "v =", v, "x =", x)
return nil return nil
} }
return nil return nil
@ -46,13 +46,16 @@ func convertToString(x any) string {
return x.(string) return x.(string)
case int: case int:
return fmt.Sprintf("%d", x.(int64)) return fmt.Sprintf("%d", x.(int64))
case uint:
return fmt.Sprintf("%d", x.(uint))
case bool: case bool:
if x.(bool) { if x.(bool) {
return "true" return "true"
} }
return "false" return "false"
default: default:
log.Error(errors.New("Set() unknown type"), "v =", v, "x =", x) log.Info("convertToSTring() unknown type", v)
log.Error(errors.New("convertToSTring() unknown type"), "v =", v, "x =", x)
return "" return ""
} }
return "" return ""

View File

@ -76,12 +76,14 @@ func main() {
_, err := addDomainDroplet(domcfg) _, err := addDomainDroplet(domcfg)
if err != nil { if err != nil {
ok = false ok = false
log.Info("addDomainDroplet() failed", err) log.Info("addDomainDroplet() error", filename)
log.Info("addDomainDroplet() error", err)
} }
} else { } else {
// this droplet is already here // this droplet is already here
err := updateDroplet(d, domcfg) err := updateDroplet(d, domcfg)
if err != nil { if err != nil {
log.Info("updateDroplet() error", filename)
log.Info("updateDroplet() error", d.pb.Hostname, err) log.Info("updateDroplet() error", d.pb.Hostname, err)
ok = false ok = false
} }