2019-05-11 09:53:32 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
|
|
|
|
import "github.com/golang/protobuf/proto"
|
2019-05-11 14:45:17 -05:00
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
2019-05-11 09:53:32 -05:00
|
|
|
|
2019-05-26 19:42:44 -05:00
|
|
|
import "github.com/andlabs/ui"
|
2019-05-28 19:00:56 -05:00
|
|
|
import "git.wit.com/wit/gui"
|
2019-05-26 19:42:44 -05:00
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
var mychannel chan *pb.Event
|
2019-05-23 00:33:16 -05:00
|
|
|
var currentMessage *pb.Event
|
|
|
|
|
2019-05-28 19:00:56 -05:00
|
|
|
/*
|
2019-05-23 17:11:35 -05:00
|
|
|
var windowsTextVeryLightGrey = color.RGBA{10, 10, 10, 10}
|
|
|
|
var windowsTextBlack = color.RGBA{200, 200, 200, 200}
|
2019-05-23 16:33:55 -05:00
|
|
|
var windowsTextWhite = color.RGBA{255, 255, 255, 255}
|
|
|
|
var windowsTextYellow = color.RGBA{200, 200, 0, 200}
|
|
|
|
var windowsTextRed = color.RGBA{200, 0, 0, 200}
|
|
|
|
var windowsTextBlue = color.RGBA{0, 100, 200, 100}
|
|
|
|
var windowsBgGrey = color.RGBA{100, 100, 100, 142}
|
|
|
|
var windowsBgBlack = color.RGBA{55, 55, 55, 255}
|
|
|
|
|
|
|
|
var linuxTextBlue = color.RGBA{0, 100, 200, 100}
|
|
|
|
var linuxTextBlack = color.RGBA{0, 0, 0, 0}
|
2019-05-23 16:42:35 -05:00
|
|
|
var linuxTextYellow = color.RGBA{200, 200, 0, 200}
|
|
|
|
var linuxBgMauve = color.RGBA{72, 0, 0, 142}
|
|
|
|
var linuxBgBlack = color.RGBA{55, 55, 55, 255}
|
|
|
|
var linuxBgWhite = color.RGBA{0, 0, 0, 0}
|
2019-05-28 19:00:56 -05:00
|
|
|
*/
|
2019-05-23 16:33:55 -05:00
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
func initChannel() {
|
|
|
|
mychannel = make(chan *pb.Event)
|
|
|
|
}
|
|
|
|
|
2019-05-23 20:04:00 -05:00
|
|
|
// Marshal & Unmarshal just to see if it ever fails
|
|
|
|
func addEvent(msg *pb.Event) {
|
|
|
|
data, err := proto.Marshal(msg)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Marshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata := new(pb.Event)
|
|
|
|
err = proto.Unmarshal(data, pdata)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Printf("addEvent() something fucked up happened in Unmarshal")
|
|
|
|
}
|
|
|
|
|
|
|
|
mychannel <- pdata
|
|
|
|
}
|
|
|
|
|
2019-05-11 09:53:32 -05:00
|
|
|
// func processEvents(mychannel chan *pb.Event) {
|
|
|
|
func processEvents() {
|
2019-05-26 04:58:29 -05:00
|
|
|
defer r() // a golang trick to try to not crash on certain errors
|
2019-05-11 09:53:32 -05:00
|
|
|
for {
|
2019-05-23 00:33:16 -05:00
|
|
|
currentMessage = <-mychannel
|
2019-05-26 04:19:23 -05:00
|
|
|
log.Println("processEvents() RECIEVED msg = ", currentMessage)
|
2019-05-23 00:33:16 -05:00
|
|
|
if (currentMessage.Type == pb.Event_DEMO) {
|
2019-05-12 20:36:31 -05:00
|
|
|
log.Println("processEvents() do Event DEMO")
|
2019-05-12 20:49:59 -05:00
|
|
|
} else {
|
2019-05-23 21:36:20 -05:00
|
|
|
log.Println("processEvents() NEW PROTOBUF")
|
2019-05-23 18:38:51 -05:00
|
|
|
gui.Data.State = "NEW PROTOBUF"
|
2019-05-12 20:36:31 -05:00
|
|
|
}
|
2019-05-21 20:18:59 -05:00
|
|
|
log.Println("processEvents() END on channel")
|
2019-05-11 09:53:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 12:02:47 -05:00
|
|
|
func countVMS(data *pb.Event) int {
|
|
|
|
vms := data.GetVms()
|
|
|
|
log.Println("NUMBER OF vms=", len(vms))
|
|
|
|
// os.Exit(-1)
|
|
|
|
return len(vms)
|
|
|
|
}
|
|
|
|
|
2019-05-28 19:00:56 -05:00
|
|
|
/*
|
|
|
|
func setRowValues(mh *gui.TableData, row int, vm *pb.Event_VM) {
|
|
|
|
defaultTextColor := linuxTextBlue
|
|
|
|
defaultTextYellow := linuxTextYellow
|
|
|
|
defaultTextBlack := linuxTextBlack
|
|
|
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
defaultTextColor = windowsTextRed
|
|
|
|
defaultTextBlack = windowsTextBlack
|
|
|
|
}
|
|
|
|
// if (row % 2) == 1 {
|
|
|
|
if (row == 1) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{100, 100, 100, 142} // makes the background of each other row grey
|
|
|
|
} else if (row == 2) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{0, 0, 0, 0} // makes the background of each other row grey
|
|
|
|
} else if (row == 3) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{255, 255, 255, 255} // makes the background of each other row grey
|
|
|
|
} else if (row == 4) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{255, 255, 255, 0} // makes the background of each other row grey
|
|
|
|
} else if (row == 5) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{55, 55, 55, 255} // makes the background of each other row grey
|
|
|
|
} else if (row < 10) {
|
|
|
|
mh.Rows[row].HumanData[0].Color = linuxBgMauve
|
|
|
|
} else {
|
|
|
|
mh.Rows[row].HumanData[0].Color = color.RGBA{250, 250, 250, 250}
|
|
|
|
}
|
|
|
|
mh.Rows[row].HumanData[1].Text = vm.Name
|
|
|
|
mh.Rows[row].HumanData[1].Color = defaultTextColor
|
|
|
|
mh.Rows[row].HumanData[2].Text = vm.Hostname
|
|
|
|
mh.Rows[row].HumanData[2].Color = defaultTextYellow
|
|
|
|
mh.Rows[row].HumanData[3].Text = fmt.Sprintf("%d",vm.Cpus)
|
|
|
|
mh.Rows[row].HumanData[3].Color = defaultTextColor
|
|
|
|
mh.Rows[row].HumanData[4].Text = fmt.Sprintf("%d",vm.Memory)
|
|
|
|
mh.Rows[row].HumanData[4].Color = defaultTextBlack
|
|
|
|
mh.Rows[row].HumanData[5].Text = fmt.Sprintf("%d",vm.Disk)
|
|
|
|
mh.Rows[row].HumanData[5].Color = defaultTextBlack
|
|
|
|
mh.Rows[row].HumanData[6].Text = fmt.Sprintf("Details %s",vm.Name)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-05-26 19:42:44 -05:00
|
|
|
func ReadReceivedData(data *pb.Event, mh *gui.TableData, window *ui.Window, tab *ui.Tab) {
|
2019-05-11 09:53:32 -05:00
|
|
|
msgItems := data.GetResults()
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println("ReadReceivedData() Event msgItems=", msgItems)
|
2019-05-11 09:53:32 -05:00
|
|
|
for _, item := range msgItems {
|
2019-05-11 14:45:17 -05:00
|
|
|
log.Println(item)
|
2019-05-12 14:55:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
nets := data.GetNetworks()
|
|
|
|
log.Println("ReadReceivedData() Event networks=", nets)
|
|
|
|
for _, item := range nets {
|
|
|
|
log.Println(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
vms := data.GetVms()
|
|
|
|
log.Println("ReadReceivedData() Event vms=", vms)
|
2019-05-28 19:00:56 -05:00
|
|
|
for row, vm := range vms {
|
|
|
|
setRowValues(mh, row, vm)
|
2019-05-12 23:00:55 -05:00
|
|
|
|
2019-05-26 16:48:46 -05:00
|
|
|
// create 'fake' button entries for the mouse clicks within tables
|
|
|
|
var newButtonMap gui.ButtonMap
|
|
|
|
newButtonMap.Action = "SHOW VM"
|
2019-05-28 19:00:56 -05:00
|
|
|
newButtonMap.VM = vm // set the button to this VM
|
2019-05-26 16:48:46 -05:00
|
|
|
newButtonMap.Account = data.Account
|
2019-05-26 19:42:44 -05:00
|
|
|
newButtonMap.W = window
|
|
|
|
newButtonMap.T = tab
|
2019-05-26 16:48:46 -05:00
|
|
|
gui.Data.AllButtons = append(gui.Data.AllButtons, newButtonMap)
|
|
|
|
mh.Rows[row].HumanData[6].Button = &newButtonMap
|
2019-05-28 19:00:56 -05:00
|
|
|
mh.Rows[row].HumanData[6].VM = vm
|
2019-05-26 16:48:46 -05:00
|
|
|
|
2019-05-28 19:00:56 -05:00
|
|
|
mh.Rows[row].VM = vm
|
2019-05-24 13:32:26 -05:00
|
|
|
|
2019-05-28 19:00:56 -05:00
|
|
|
log.Println("\tvm=", vm)
|
|
|
|
log.Println("\tvm.Name=", vm.Name)
|
2019-05-12 23:00:55 -05:00
|
|
|
log.Println("\tRows[row]=", mh.Rows[row])
|
|
|
|
log.Println("\tRows[row]=", row)
|
|
|
|
log.Println("\tRows[row].Name=", mh.Rows[row].Name)
|
2019-05-28 19:00:56 -05:00
|
|
|
log.Println(vm)
|
2019-05-12 17:32:38 -05:00
|
|
|
row += 1
|
|
|
|
}
|
2019-05-12 20:49:59 -05:00
|
|
|
}
|