update memory, cpus and maybe mac addr work
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
9f92891db4
commit
bdb72e5682
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"libvirt.org/go/libvirtxml"
|
"libvirt.org/go/libvirtxml"
|
||||||
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
|
func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
|
||||||
|
@ -66,8 +67,8 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if updateMemory(d, domcfg) {
|
if ! updateMemory(d, domcfg) {
|
||||||
// updateMemory failed
|
log.Info("updateMemory() failed")
|
||||||
ok = false
|
ok = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +85,14 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
ok = false
|
ok = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if updateNetwork(d, domcfg) {
|
if ! updateNetwork(d, domcfg) {
|
||||||
// updateNetwork failed
|
log.Info("updateNetwork() failed")
|
||||||
ok = false
|
ok = false
|
||||||
}
|
}
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns false if something went wrong
|
||||||
func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
if (d == nil) || (domcfg == nil) {
|
if (d == nil) || (domcfg == nil) {
|
||||||
return false
|
return false
|
||||||
|
@ -104,14 +106,14 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
d.pb.Memory = m
|
d.pb.Memory = m
|
||||||
me.changed = true
|
me.changed = true
|
||||||
fmt.Printf("Memory changed %d, %d %s\n", d.pb.Memory, domcfg.Memory.Value, domcfg.Memory.Unit)
|
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)
|
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 {
|
func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
if (d == nil) || (domcfg == nil) {
|
if (d == nil) || (domcfg == nil) {
|
||||||
return false
|
return false
|
||||||
|
@ -123,15 +125,32 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) bool {
|
||||||
if iface.MAC != nil {
|
if iface.MAC != nil {
|
||||||
// iface.MAC.Address = "aa:bb:aa:bb:aa:ff"
|
// iface.MAC.Address = "aa:bb:aa:bb:aa:ff"
|
||||||
// fmt.Printf("MAC Address: %+v\n", iface.MAC)
|
// 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)
|
macs = append(macs, iface.MAC.Address)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Interface: %s, MAC Address: not available\n", iface.Target.Dev)
|
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)
|
log.Info("mac addrs:", macs)
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue