1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
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"
func CreateVmBox(gw *GuiWindow, vm *pb.Event_VM) {
log.Println("CreateVmBox() START")
log.Println("CreateVmBox() vm.Name =", vm.Name)
log.Println("CreateVmBox() gw =", gw)
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
log.Println("CreateVmBox() vbox =", vbox)
log.Println("CreateVmBox() box.UiBox =", box.UiBox)
box.UiBox = vbox
log.Println("CreateVmBox() box.W =", box.W)
box.W = gw
log.Println("CreateVmBox() gw.BoxMap =", gw.BoxMap)
gw.BoxMap[vm.Name] = box
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)
a := CreateButton(box, nil, vm, "Power On", "POWERON", nil)
hboxButtons.Append(a.B, false)
a = CreateButton(box, nil, vm, "Power Off", "POWEROFF", nil)
hboxButtons.Append(a.B, false)
a = CreateButton(box, nil, vm, "Destroy", "DESTROY", nil)
hboxButtons.Append(a.B, false)
a = CreateButton(box, nil, vm, "ping", "PING", runPingClick)
hboxButtons.Append(a.B, false)
a = CreateButton(box, nil, vm, "Console", "XTERM", runTestExecClick)
hboxButtons.Append(a.B, false)
a = CreateButton(box, nil, vm, "Save", "SAVE", nil)
hboxButtons.Append(a.B, false)
a = CreateButton(box, nil, vm, "Done", "DONE", nil)
hboxButtons.Append(a.B, false)
AddBoxToTab(vm.Name, gw.UiTab, vbox)
}
func createAddVmBox(gw *GuiWindow, b *GuiButton) {
log.Println("createAddVmBox() START")
name := "(" + b.Account.Nick + ")"
var box *GuiBox
box = new(GuiBox)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
box.UiBox = vbox
box.W = gw
gw.BoxMap["ADD VM" + name] = box
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)
var newb GuiButton
newb.Action = "CREATE"
newb.VM = b.VM
newb.Account = b.Account
hostname.B = &newb
memory.B = &newb
disk.B = &newb
hboxButtons.Append(AddButton(&newb, "Add Virtual Machine"), false)
a := CreateButton(box, nil, nil, "Cancel", "CLOSE", nil)
hboxButtons.Append(a.B, false)
AddBoxToTab(name, gw.UiTab, vbox)
}
//
// 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
}
|