2019-05-29 09:24:40 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "log"
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
import "github.com/andlabs/ui"
|
|
|
|
import _ "github.com/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
|
|
|
|
import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-05-31 22:14:15 -05:00
|
|
|
/*
|
2019-05-30 10:52:28 -05:00
|
|
|
func AddVmConfigureTab(wm *GuiWindow, name string, pbVM *pb.Event_VM) {
|
2019-05-31 22:14:15 -05:00
|
|
|
CreateVmBox(wm, pbVM)
|
2019-05-29 09:24:40 -05:00
|
|
|
}
|
2019-05-31 22:14:15 -05:00
|
|
|
*/
|
2019-05-29 09:24:40 -05:00
|
|
|
|
2019-05-31 22:14:15 -05:00
|
|
|
func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
|
2019-05-29 09:24:40 -05:00
|
|
|
log.Println("CreateVmBox() START")
|
2019-05-31 22:14:15 -05:00
|
|
|
log.Println("CreateVmBox() vm.Name =", vm.Name)
|
|
|
|
log.Println("CreateVmBox() gw =", gw)
|
2019-05-31 19:37:53 -05:00
|
|
|
|
|
|
|
var gb *GuiBox
|
|
|
|
gb = new(GuiBox)
|
|
|
|
|
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
2019-05-31 22:14:15 -05:00
|
|
|
log.Println("CreateVmBox() vbox =", vbox)
|
|
|
|
log.Println("CreateVmBox() gb.UiBox =", gb.UiBox)
|
2019-05-31 19:37:53 -05:00
|
|
|
gb.UiBox = vbox
|
2019-05-31 22:14:15 -05:00
|
|
|
log.Println("CreateVmBox() gb.W =", gb.W)
|
2019-05-31 19:37:53 -05:00
|
|
|
gb.W = gw
|
2019-05-31 22:14:15 -05:00
|
|
|
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
|
2019-05-31 19:37:53 -05:00
|
|
|
gw.BoxMap[vm.Name] = gb
|
|
|
|
|
|
|
|
// gw.UiTab.Append(vm.Name, vbox)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
spew.Dump(vm)
|
|
|
|
if (Data.Debug) {
|
|
|
|
spew.Dump(vm)
|
|
|
|
}
|
|
|
|
|
|
|
|
hboxAccount := ui.NewHorizontalBox()
|
|
|
|
hboxAccount.SetPadded(true)
|
|
|
|
vbox.Append(hboxAccount, false)
|
|
|
|
|
|
|
|
// Add hostname entry box
|
|
|
|
makeEntryVbox(hboxAccount, "hostname:", vm.Hostname, true, "Hostname")
|
|
|
|
makeEntryVbox(hboxAccount, "IPv6:", vm.IPv6, true, "IPv6")
|
|
|
|
makeEntryVbox(hboxAccount, "RAM:", fmt.Sprintf("%d",vm.Memory), true, "Memory")
|
|
|
|
makeEntryVbox(hboxAccount, "CPU:", fmt.Sprintf("%d",vm.Cpus), true, "Cpus")
|
|
|
|
makeEntryVbox(hboxAccount, "Disk (GB):",fmt.Sprintf("%d",vm.Disk), true, "Disk")
|
|
|
|
makeEntryVbox(hboxAccount, "OS Image:", vm.BaseImage, true, "BaseImage")
|
|
|
|
|
|
|
|
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
|
|
|
|
|
|
hboxButtons := ui.NewHorizontalBox()
|
|
|
|
hboxButtons.SetPadded(true)
|
|
|
|
vbox.Append(hboxButtons, false)
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
a := CreateButton(gb, nil, vm, "Power On", "POWERON", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(gb, nil, vm, "Power Off", "POWEROFF", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(gb, nil, vm, "Destroy", "DESTROY", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(gb, nil, vm, "ping", "PING", runPingClick)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(gb, nil, vm, "Console", "XTERM", runTestExecClick)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(gb, nil, vm, "Save", "SAVE", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-31 19:37:53 -05:00
|
|
|
a = CreateButton(gb, nil, vm, "Done", "DONE", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-29 09:24:40 -05:00
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
AddBoxToTab(vm.Name, gw.UiTab, vbox)
|
2019-05-29 09:24:40 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 22:14:15 -05:00
|
|
|
func createAddVmBox(gw *GuiWindow, b *GuiButton) {
|
2019-05-29 09:24:40 -05:00
|
|
|
log.Println("createAddVmBox() START")
|
2019-05-31 22:14:15 -05:00
|
|
|
name := "(" + b.Account.Nick + ")"
|
2019-05-31 19:37:53 -05:00
|
|
|
|
|
|
|
var gb *GuiBox
|
|
|
|
gb = new(GuiBox)
|
|
|
|
|
2019-05-29 09:24:40 -05:00
|
|
|
vbox := ui.NewVerticalBox()
|
|
|
|
vbox.SetPadded(true)
|
2019-05-31 19:37:53 -05:00
|
|
|
gb.UiBox = vbox
|
|
|
|
gb.W = gw
|
2019-05-31 22:14:15 -05:00
|
|
|
gw.BoxMap["ADD VM" + name] = gb
|
2019-05-29 09:24:40 -05:00
|
|
|
|
|
|
|
hbox := ui.NewHorizontalBox()
|
|
|
|
hbox.SetPadded(true)
|
|
|
|
vbox.Append(hbox, false)
|
|
|
|
|
|
|
|
// Add hostname entry box
|
|
|
|
hostname := makeEntryHbox(vbox, "Hostname:", "testhost", true, "Hostname")
|
|
|
|
memory := makeEntryHbox(vbox, "Memory:", "512", true, "Memory")
|
|
|
|
disk := makeEntryHbox(vbox, "Disk:", "20", true, "Disk")
|
|
|
|
|
|
|
|
log.Println("createAddVmBox() hostname, memory, disk =", hostname, memory, disk)
|
|
|
|
|
|
|
|
vbox.Append(ui.NewHorizontalSeparator(), false)
|
|
|
|
|
|
|
|
hboxButtons := ui.NewHorizontalBox()
|
|
|
|
hboxButtons.SetPadded(true)
|
|
|
|
vbox.Append(hboxButtons, false)
|
|
|
|
|
2019-05-30 10:55:54 -05:00
|
|
|
var newb GuiButton
|
2019-05-29 09:24:40 -05:00
|
|
|
newb.Action = "CREATE"
|
|
|
|
newb.VM = b.VM
|
|
|
|
newb.Account = b.Account
|
2019-05-31 19:37:53 -05:00
|
|
|
newb.T = gw.UiTab
|
2019-05-29 09:24:40 -05:00
|
|
|
hostname.B = &newb
|
|
|
|
memory.B = &newb
|
|
|
|
disk.B = &newb
|
|
|
|
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
|
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
a := CreateButton(gb, nil, nil, "Cancel", "CLOSE", nil)
|
2019-05-30 13:41:23 -05:00
|
|
|
hboxButtons.Append(a.B, false)
|
2019-05-29 09:24:40 -05:00
|
|
|
|
2019-05-31 19:37:53 -05:00
|
|
|
AddBoxToTab(name, gw.UiTab, vbox)
|
2019-05-29 09:24:40 -05:00
|
|
|
}
|
2019-05-31 22:46:41 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// THIS IS THE STANDARD VM DISPLAY TABLE
|
|
|
|
// This maps the 'human' indexed cells in the table
|
|
|
|
// to the machine's andlabs/libui values. That way
|
|
|
|
// if you want to work against column 4, then you
|
|
|
|
// can just reference 4 instead of the internal number
|
|
|
|
// which could be anything since TEXTCOLOR, TEXT, BG, etc
|
|
|
|
// fields use between 1 and 3 values internally
|
|
|
|
//
|
|
|
|
func AddVmsTab(gw *GuiWindow, name string, count int, a *pb.Account) *TableData {
|
|
|
|
var parts []TableColumnData
|
|
|
|
|
|
|
|
human := 0
|
|
|
|
|
|
|
|
tmp := TableColumnData{}
|
|
|
|
tmp.CellType = "BG"
|
|
|
|
tmp.Heading = "background"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "name"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "hostname"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "IPv6"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "cpus"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "TEXTCOLOR"
|
|
|
|
tmp.Heading = "memory"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
tmp = TableColumnData{}
|
|
|
|
tmp.CellType = "BUTTON"
|
|
|
|
tmp.Heading = "Details"
|
|
|
|
tmp.Index = human
|
|
|
|
parts = append(parts, tmp)
|
|
|
|
human += 1
|
|
|
|
|
|
|
|
mh := AddTableTab(gw, name, count, parts, a)
|
|
|
|
// mh :=
|
|
|
|
return mh
|
|
|
|
}
|