stepping through init on a window with state
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
c59247824f
commit
f6f5bdba4e
|
@ -9,53 +9,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var NOW log.LogFlag
|
var NOW log.LogFlag
|
||||||
|
var INFO log.LogFlag
|
||||||
var NET log.LogFlag
|
var NET log.LogFlag
|
||||||
var DNS log.LogFlag
|
var DNS log.LogFlag
|
||||||
var PROC log.LogFlag
|
var PROC log.LogFlag
|
||||||
var SPEW log.LogFlag
|
var SPEW log.LogFlag
|
||||||
|
var WARN log.LogFlag
|
||||||
var CHANGE log.LogFlag
|
var CHANGE log.LogFlag
|
||||||
var STATUS log.LogFlag
|
var STATUS log.LogFlag
|
||||||
|
|
||||||
func init() {
|
func myreg(f *log.LogFlag, b bool, name string, desc string) {
|
||||||
NOW.B = false
|
f.B = b
|
||||||
NOW.Name = "NOW"
|
f.Subsystem = "go.wit.com/control-panels/dns/linuxstatus"
|
||||||
NOW.Subsystem = "cpdns"
|
f.Short = "linux"
|
||||||
NOW.Desc = "temp debugging stuff"
|
f.Desc = desc
|
||||||
NOW.Register()
|
f.Name = name
|
||||||
|
f.Register()
|
||||||
NET.B = false
|
}
|
||||||
NET.Name = "NET"
|
|
||||||
NET.Subsystem = "cpdns"
|
func init() {
|
||||||
NET.Desc = "Network logging"
|
myreg(&NOW, true, "NOW", "temp debugging stuff")
|
||||||
NET.Register()
|
myreg(&NET, false, "NET", "Network Logging")
|
||||||
|
myreg(&DNS, false, "DNS", "dnsStatus.update()")
|
||||||
DNS.B = false
|
myreg(&PROC, false, "PROC", "/proc logging")
|
||||||
DNS.Name = "DNS"
|
myreg(&SPEW, false, "SPEW", "spew stuff")
|
||||||
DNS.Subsystem = "cpdns"
|
myreg(&WARN, true, "WARN", "bad things")
|
||||||
DNS.Desc = "dnsStatus.update()"
|
myreg(&CHANGE, true, "CHANGE", "show droplet state changes")
|
||||||
DNS.Register()
|
myreg(&STATUS, false, "STATUS", "Update() details")
|
||||||
|
|
||||||
PROC.B = false
|
|
||||||
PROC.Name = "PROC"
|
|
||||||
PROC.Subsystem = "cpdns"
|
|
||||||
PROC.Desc = "/proc logging"
|
|
||||||
PROC.Register()
|
|
||||||
|
|
||||||
SPEW.B = false
|
|
||||||
SPEW.Name = "SPEW"
|
|
||||||
SPEW.Subsystem = "cpdns"
|
|
||||||
SPEW.Desc = "spew logging"
|
|
||||||
SPEW.Register()
|
|
||||||
|
|
||||||
CHANGE.B = false
|
|
||||||
CHANGE.Name = "CHANGE"
|
|
||||||
CHANGE.Subsystem = "cpdns"
|
|
||||||
CHANGE.Desc = "show droplet state changes"
|
|
||||||
CHANGE.Register()
|
|
||||||
|
|
||||||
STATUS.B = false
|
|
||||||
STATUS.Name = "STATUS"
|
|
||||||
STATUS.Subsystem = "cpdns"
|
|
||||||
STATUS.Desc = "updateStatus()"
|
|
||||||
STATUS.Register()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,30 +3,52 @@ package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
"go.wit.com/gui/gui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (ls *LinuxStatus) Draw() {
|
||||||
|
log.Log(CHANGE, "linuxStatus.Draw() window")
|
||||||
|
if ! ls.Ready() {return}
|
||||||
|
log.Log(CHANGE, "linuxStatus.Draw() window ready =", ls.ready)
|
||||||
|
ls.window.Draw()
|
||||||
|
ls.ready = true
|
||||||
|
}
|
||||||
|
func (ls *LinuxStatus) Draw2() {
|
||||||
|
log.Log(CHANGE, "draw(ls)")
|
||||||
|
if ! ls.Ready() {return}
|
||||||
|
log.Log(CHANGE, "draw(ls) ready =", ls.ready)
|
||||||
|
draw(ls)
|
||||||
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Show() {
|
func (ls *LinuxStatus) Show() {
|
||||||
log.Log(CHANGE, "linuxStatus.Show() window")
|
log.Log(CHANGE, "linuxStatus.Show() window")
|
||||||
|
if ! ls.Ready() {return}
|
||||||
|
log.Log(CHANGE, "linuxStatus.Show() window ready =", ls.ready)
|
||||||
ls.window.Show()
|
ls.window.Show()
|
||||||
ls.hidden = false
|
ls.hidden = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Hide() {
|
func (ls *LinuxStatus) Hide() {
|
||||||
log.Log(CHANGE, "linuxStatus.Hide() window")
|
log.Log(CHANGE, "linuxStatus.Hide() window")
|
||||||
|
if ! ls.Ready() {return}
|
||||||
|
log.Log(CHANGE, "linuxStatus.Hide() window ready =", ls.ready)
|
||||||
ls.window.Hide()
|
ls.window.Hide()
|
||||||
ls.hidden = true
|
ls.hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Toggle() {
|
func (ls *LinuxStatus) Toggle() {
|
||||||
log.Log(CHANGE, "linuxStatus.Toggle() window")
|
log.Log(CHANGE, "linuxStatus.Toggle() window")
|
||||||
|
if ! ls.Ready() {return}
|
||||||
|
log.Log(CHANGE, "linuxStatus.Toggle() window ready =", ls.ready)
|
||||||
if ls.hidden {
|
if ls.hidden {
|
||||||
ls.window.Show()
|
ls.Show()
|
||||||
} else {
|
} else {
|
||||||
ls.window.Hide()
|
ls.Hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Ready() bool {
|
func (ls *LinuxStatus) Ready() bool {
|
||||||
|
log.Log(CHANGE, "Ready() ls =", ls)
|
||||||
if me == nil {return false}
|
if me == nil {return false}
|
||||||
if ls == nil {return false}
|
if ls == nil {return false}
|
||||||
if ls.window == nil {return false}
|
if ls.window == nil {return false}
|
||||||
|
@ -34,8 +56,22 @@ func (ls *LinuxStatus) Ready() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) Initialized() bool {
|
func (ls *LinuxStatus) Initialized() bool {
|
||||||
|
log.Log(CHANGE, "checking Initialized() ls =", ls)
|
||||||
if me == nil {return false}
|
if me == nil {return false}
|
||||||
if ls == nil {return false}
|
if ls == nil {return false}
|
||||||
if ls.parent == nil {return false}
|
if ls.parent == nil {return false}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ls *LinuxStatus) SetParent(p *gui.Node) {
|
||||||
|
log.Log(CHANGE, "Attempting SetParent =", p)
|
||||||
|
if me == nil {return}
|
||||||
|
if ls == nil {return}
|
||||||
|
if ls.parent == nil {
|
||||||
|
log.Log(CHANGE, "SetParent =", p)
|
||||||
|
ls.parent = p
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
log.Log(CHANGE, "SetParent was already set to =", ls.parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ func draw(ls *LinuxStatus) {
|
||||||
ls.grid.NewLabel("interfaces =")
|
ls.grid.NewLabel("interfaces =")
|
||||||
ls.Interfaces = ls.grid.NewCombobox("Interfaces")
|
ls.Interfaces = ls.grid.NewCombobox("Interfaces")
|
||||||
|
|
||||||
|
ls.speed = gadgets.NewOneLiner(ls.grid, "refresh speed =")
|
||||||
ls.speedActual = gadgets.NewOneLiner(ls.grid, "refresh speed =")
|
ls.speedActual = gadgets.NewOneLiner(ls.grid, "refresh speed =")
|
||||||
|
|
||||||
ls.grid.Margin()
|
ls.grid.Margin()
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
package linuxstatus
|
package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/shell"
|
"go.wit.com/shell"
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ func getHostname() {
|
||||||
log.Error(err, "FQDN hostname error")
|
log.Error(err, "FQDN hostname error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Warn("full hostname should be:", s)
|
log.Error(errors.New("full hostname should be: " + s))
|
||||||
|
|
||||||
dn := run("domainname")
|
dn := run("domainname")
|
||||||
if (me.domainname.Get() != dn) {
|
if (me.domainname.Get() != dn) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
func linuxLoop() {
|
func linuxLoop() {
|
||||||
me.changed = false
|
me.changed = false
|
||||||
duration := timeFunction(getHostname)
|
duration := timeFunction(getHostname)
|
||||||
log.Info("getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
log.Log(INFO, "getHostname() execution Time: ", duration, "me.changed =", me.changed)
|
||||||
|
|
||||||
duration = timeFunction(scanInterfaces)
|
duration = timeFunction(scanInterfaces)
|
||||||
log.Log(NET, "scanInterfaces() execution Time: ", duration)
|
log.Log(NET, "scanInterfaces() execution Time: ", duration)
|
||||||
|
@ -33,7 +33,7 @@ func linuxLoop() {
|
||||||
// me.IPv6.SetText(all)
|
// me.IPv6.SetText(all)
|
||||||
|
|
||||||
user, _ := user.Current()
|
user, _ := user.Current()
|
||||||
log.Println("os.Getuid =", user.Username, os.Getuid())
|
log.Log(INFO, "os.Getuid =", user.Username, os.Getuid())
|
||||||
if (me.uid != nil) {
|
if (me.uid != nil) {
|
||||||
me.uid.Set(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
me.uid.Set(user.Username + " (" + strconv.Itoa(os.Getuid()) + ")")
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ func renameInterface(i *net.Interface) {
|
||||||
func checkInterface(i net.Interface) {
|
func checkInterface(i net.Interface) {
|
||||||
val, ok := me.ifmap[i.Index]
|
val, ok := me.ifmap[i.Index]
|
||||||
if ! ok {
|
if ! ok {
|
||||||
log.Info(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
log.Log(INFO, i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
||||||
me.ifmap[i.Index] = new(IFtype)
|
me.ifmap[i.Index] = new(IFtype)
|
||||||
me.ifmap[i.Index].gone = false
|
me.ifmap[i.Index].gone = false
|
||||||
me.ifmap[i.Index].iface = &i
|
me.ifmap[i.Index].iface = &i
|
||||||
|
@ -88,7 +88,7 @@ func checkInterface(i net.Interface) {
|
||||||
me.ifmap[i.Index].gone = false
|
me.ifmap[i.Index].gone = false
|
||||||
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
||||||
if (val.iface.Name != i.Name) {
|
if (val.iface.Name != i.Name) {
|
||||||
log.Info(val.iface.Name, "has changed to it's name to", i.Name)
|
log.Log(INFO, val.iface.Name, "has changed to it's name to", i.Name)
|
||||||
me.ifmap[i.Index].iface = &i
|
me.ifmap[i.Index].iface = &i
|
||||||
me.changed = true
|
me.changed = true
|
||||||
if (me.Interfaces != nil) {
|
if (me.Interfaces != nil) {
|
||||||
|
@ -143,14 +143,14 @@ func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
||||||
ipt = "IPv6"
|
ipt = "IPv6"
|
||||||
}
|
}
|
||||||
if (t.IsReal()) {
|
if (t.IsReal()) {
|
||||||
log.Info("\tIP is Real ", ipt, i.Index, i.Name, s)
|
log.Log(INFO, "\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||||
if (t.ipv6) {
|
if (t.ipv6) {
|
||||||
ipv6s[s] = t
|
ipv6s[s] = t
|
||||||
} else {
|
} else {
|
||||||
ipv4s[s] = t
|
ipv4s[s] = t
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Info("\tIP is not Real", ipt, i.Index, i.Name, s)
|
log.Log(INFO, "\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ipv6s, ipv4s
|
return ipv6s, ipv4s
|
||||||
|
@ -192,14 +192,14 @@ func checkIP(ip *net.IPNet, i net.Interface) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (IsReal(&ip.IP)) {
|
if (IsReal(&ip.IP)) {
|
||||||
log.Info("\tIP is Real ", t, i.Index, i.Name, realip)
|
log.Log(INFO, "\tIP is Real ", t, i.Index, i.Name, realip)
|
||||||
} else {
|
} else {
|
||||||
log.Info("\tIP is not Real", t, i.Index, i.Name, realip)
|
log.Log(INFO, "\tIP is not Real", t, i.Index, i.Name, realip)
|
||||||
}
|
}
|
||||||
log.Log(NET, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
|
log.Log(NET, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
|
||||||
log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
log.Log(NET, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
||||||
log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
log.Log(NET, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
||||||
// log.Info("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
// log.Log(INFO, "HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ func scanInterfaces() {
|
||||||
log.Log(NET, SPEW, ifaces)
|
log.Log(NET, SPEW, ifaces)
|
||||||
for _, i := range ifaces {
|
for _, i := range ifaces {
|
||||||
addrs, _ := i.Addrs()
|
addrs, _ := i.Addrs()
|
||||||
// log.Info("range ifaces = ", i)
|
// log.Log(INFO, "range ifaces = ", i)
|
||||||
checkInterface(i)
|
checkInterface(i)
|
||||||
log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index)
|
log.Log(NET, "*net.Interface.Name = ", i.Name, i.Index)
|
||||||
log.Log(NET, SPEW, i)
|
log.Log(NET, SPEW, i)
|
||||||
|
|
|
@ -9,29 +9,31 @@ import (
|
||||||
|
|
||||||
func New() *LinuxStatus {
|
func New() *LinuxStatus {
|
||||||
if me != nil {
|
if me != nil {
|
||||||
log.Warn("You have done New() twice. You can only do this once")
|
log.Log(WARN, "You have done New() twice. You can only do this once")
|
||||||
return me
|
return me
|
||||||
}
|
}
|
||||||
me = &LinuxStatus {
|
me = &LinuxStatus {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
ready: false,
|
ready: false,
|
||||||
}
|
}
|
||||||
|
me.ifmap = make(map[int]*IFtype)
|
||||||
|
me.ipmap = make(map[string]*IPtype)
|
||||||
|
|
||||||
return me
|
return me
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) InitWindow() {
|
func (ls *LinuxStatus) InitWindow() {
|
||||||
if ! ls.Initialized() {
|
if ! ls.Initialized() {
|
||||||
log.Warn("LinuxStatus() is not initalized yet (no parent for the window?)")
|
log.Log(WARN, "not initalized yet (no parent for the window?)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ls.window != nil {
|
if ls.window != nil {
|
||||||
log.Warn("You already have a window")
|
log.Log(WARN, "You already have a window")
|
||||||
ls.ready = true
|
ls.ready = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ls.ready = true
|
log.Log(WARN, "Creating the Window")
|
||||||
log.Warn("Creating the Window")
|
|
||||||
ls.window = gadgets.NewBasicWindow(ls.parent, "Linux OS Details")
|
ls.window = gadgets.NewBasicWindow(ls.parent, "Linux OS Details")
|
||||||
|
ls.ready = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ type LinuxStatus struct {
|
||||||
IPv6 *gadgets.OneLiner
|
IPv6 *gadgets.OneLiner
|
||||||
workingIPv6 *gadgets.OneLiner
|
workingIPv6 *gadgets.OneLiner
|
||||||
Interfaces *gui.Node
|
Interfaces *gui.Node
|
||||||
|
speed *gadgets.OneLiner
|
||||||
speedActual *gadgets.OneLiner
|
speedActual *gadgets.OneLiner
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,40 @@
|
||||||
package linuxstatus
|
package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ls *LinuxStatus) Update() {
|
func (ls *LinuxStatus) Update() {
|
||||||
log.Info("linuxStatus() Update() START")
|
if ! ls.Ready() {
|
||||||
if ls == nil {
|
log.Warn("can't update yet. ready is false")
|
||||||
log.Error(errors.New("linuxStatus() Update() ls == nil"))
|
log.Error(errors.New("Update() is not ready yet"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Log(INFO, "Update() START")
|
||||||
duration := timeFunction(func () {
|
duration := timeFunction(func () {
|
||||||
linuxLoop()
|
linuxLoop()
|
||||||
})
|
})
|
||||||
|
ls.SetSpeed(duration)
|
||||||
|
log.Info("linuxStatus() Update() END")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls *LinuxStatus) SetSpeed(duration time.Duration) {
|
||||||
s := fmt.Sprint(duration)
|
s := fmt.Sprint(duration)
|
||||||
|
if ls.speedActual == nil {
|
||||||
|
log.Warn("can't actually warn")
|
||||||
|
return
|
||||||
|
}
|
||||||
ls.speedActual.Set(s)
|
ls.speedActual.Set(s)
|
||||||
|
|
||||||
if (duration > 500 * time.Millisecond ) {
|
if (duration > 500 * time.Millisecond ) {
|
||||||
// ls.speed, "SLOW")
|
ls.speed.Set("SLOW")
|
||||||
} else if (duration > 100 * time.Millisecond ) {
|
} else if (duration > 100 * time.Millisecond ) {
|
||||||
// ls.speed, "OK")
|
ls.speed.Set("OK")
|
||||||
} else {
|
} else {
|
||||||
// ls.speed, "FAST")
|
ls.speed.Set("FAST")
|
||||||
}
|
}
|
||||||
log.Info("linuxStatus() Update() END")
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue