update memory, cpus and maybe mac addr work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-23 05:07:42 -05:00
parent 9f92891db4
commit bdb72e5682
1 changed files with 29 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import (
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
pb "go.wit.com/lib/protobuf/virtbuf"
)
func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
@ -66,8 +67,8 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) bool {
return false
}
if updateMemory(d, domcfg) {
// updateMemory failed
if ! updateMemory(d, domcfg) {
log.Info("updateMemory() failed")
ok = false
}
@ -84,13 +85,14 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) bool {
ok = false
}
if updateNetwork(d, domcfg) {
// updateNetwork failed
if ! updateNetwork(d, domcfg) {
log.Info("updateNetwork() failed")
ok = false
}
return ok
}
// returns false if something went wrong
func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
if (d == nil) || (domcfg == nil) {
return false
@ -104,14 +106,14 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
d.pb.Memory = m
me.changed = true
fmt.Printf("Memory changed %d, %d %s\n", d.pb.Memory, domcfg.Memory.Value, domcfg.Memory.Unit)
return true
}
return false
return true
}
fmt.Println("Unknown Memory Unit", domcfg.Memory.Unit)
return true
return false
}
// returns false if something went wrong
func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) bool {
if (d == nil) || (domcfg == nil) {
return false
@ -123,15 +125,32 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) bool {
if iface.MAC != nil {
// iface.MAC.Address = "aa:bb:aa:bb:aa:ff"
// fmt.Printf("MAC Address: %+v\n", iface.MAC)
// fmt.Printf("Interface: %s, MAC Address: %s\n", iface.Target.Dev, iface.MAC.Address)
// log.Info("Interface:", iface.Target, "MAC Address:", iface.MAC.Address)
// fmt.Printf("source: %+v\n", iface.Source)
macs = append(macs, iface.MAC.Address)
} else {
fmt.Printf("Interface: %s, MAC Address: not available\n", iface.Target.Dev)
}
}
// for _, iface := range domcfg.Devices.Interfaces {
for _, mac := range macs {
var found bool = false
for i, eth := range d.pb.Networks {
if eth.Mac == mac {
log.Info("OKAY. FOUND ETH:", i, eth.Mac, eth.Name)
found = true
}
}
if !found {
var eth *pb.Network
eth = new(pb.Network)
eth.Mac = mac
eth.Name = "worldbr"
d.pb.Networks = append(d.pb.Networks, eth)
me.changed = true
}
}
log.Info("mac addrs:", macs)
return false
return true
}