Merge branch 'devel'
This commit is contained in:
commit
952457ad02
|
@ -51,19 +51,33 @@ func makeCloudInfoBox(gw *gui.GuiWindow) {
|
|||
log.Println("makeCloudInfoBox() END")
|
||||
}
|
||||
|
||||
func createAccount(gw *gui.GuiWindow) {
|
||||
// func createAccount(gw *gui.GuiWindow) {
|
||||
func initWindow(gw *gui.GuiWindow, name string, axis int) *gui.GuiBox {
|
||||
window := gui.Data.WindowMap[name]
|
||||
if (window != nil) {
|
||||
box := window.BoxMap["MAINBOX"]
|
||||
log.Println("initWindow() tab already exists name =", name)
|
||||
gui.ErrorWindow(box.Window, "Create Window Error", "Window " + name + " already exists")
|
||||
return nil
|
||||
}
|
||||
|
||||
// window := gui.Data.WindowMap["createAccount"]
|
||||
// if (window != nil) {
|
||||
// box := window.BoxMap["MAINBOX"]
|
||||
// log.Println("createAccount tab already exists")
|
||||
// gui.MessageWindow(box.Window, "createAccount", "New account tab already exists")
|
||||
// return
|
||||
// }
|
||||
// if there is not an account, then go to 'make account'
|
||||
gw = gui.InitGuiWindow("createAccount", gw)
|
||||
newWindow := gui.InitGuiWindow("createAccount", gw)
|
||||
|
||||
box := gui.HardBox(gw, gui.Yaxis, "Create New Account")
|
||||
var box *gui.GuiBox
|
||||
if (axis == gui.Xaxis) {
|
||||
box = gui.HardBox(newWindow, gui.Xaxis, name)
|
||||
} else {
|
||||
box = gui.HardBox(newWindow, gui.Yaxis, name)
|
||||
}
|
||||
return box
|
||||
}
|
||||
|
||||
func createAccount(gw *gui.GuiWindow) {
|
||||
box := initWindow(gw, "Create New Account", gui.Yaxis)
|
||||
if (box == nil) { return }
|
||||
|
||||
gw = box.Window
|
||||
|
||||
// make a place for someone to enter their subdomain
|
||||
hardXbox := gui.HardBox(gw, gui.Xaxis, "subdomain test")
|
||||
|
@ -95,7 +109,7 @@ func addSubdomainClick(b *gui.GuiButton) {
|
|||
acc.Username = "jcarr@wit.com"
|
||||
acc.Email = "jcarr@wit.com"
|
||||
acc.Password = "badpass"
|
||||
acc.URL = "http://stackapi-api1.stackapi.customers.dev.wit.com:4000/"
|
||||
acc.URL = "http://stackapi-api1.stackapi.customers.wprod.wit.com:4000/"
|
||||
config.Accounts = append(config.Accounts, acc)
|
||||
|
||||
makeCloudInfoBox(b.Box.Window)
|
||||
|
@ -120,8 +134,7 @@ func generateSubdomain(b *gui.GuiButton) {
|
|||
}
|
||||
// subdomain.SetText("cust00013.wit.dev")
|
||||
|
||||
// curl -vv -X POST -H "X-Wit-Auth: $TOKEN" 'http://stackapi-api1.stackapi.customers.wit.com:4000/vms/toby?count=1&cpu=2&ram=512&disk=25'
|
||||
txt := gui.SetText(b.Box, "SUBDOMAIN", "http://stackapi-api1.stackapi.customers.wit.com:4000/vms/jcarr")
|
||||
txt := gui.SetText(b.Box, "SUBDOMAIN", "yourname.customers.wprod.wit.com")
|
||||
log.Println("generateSubdomain subdomain = ", txt)
|
||||
log.Println("generateSubdomain END")
|
||||
}
|
|
@ -45,8 +45,7 @@ func mainMouseClick(b *gui.GuiButton) {
|
|||
}
|
||||
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
||||
|
||||
var gw *gui.GuiWindow
|
||||
gw = b.Box.Window
|
||||
gw := b.Box.Window
|
||||
|
||||
if (gw == nil) {
|
||||
log.Println("\tTHIS BUTTON IS BROKEN gw = nil")
|
||||
|
@ -92,8 +91,7 @@ func showAccountClick(b *gui.GuiButton) {
|
|||
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
|
||||
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
||||
|
||||
var gw *gui.GuiWindow
|
||||
gw = b.Box.Window
|
||||
gw := b.Box.Window
|
||||
|
||||
event := pb.MakeGetEvent()
|
||||
event.Account = values.Account
|
||||
|
@ -148,9 +146,6 @@ func createVmClick(b *gui.GuiButton) {
|
|||
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
|
||||
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
||||
|
||||
// var gw *gui.GuiWindow
|
||||
// gw = b.Box.Window
|
||||
|
||||
log.Println("\tTRIGGER CREATE VM")
|
||||
State = "CREATE"
|
||||
event := pb.MakeAddVmEvent()
|
||||
|
|
12
gui-debug.go
12
gui-debug.go
|
@ -19,16 +19,16 @@ func debugClick(b *gui.GuiButton) {
|
|||
gw := b.Box.Window
|
||||
|
||||
// if there is not an account, then go to 'make account'
|
||||
gw = gui.InitGuiWindow("debugClick", gw)
|
||||
|
||||
log.Println("debugClick() AddGenericBox() START")
|
||||
box := gui.HardBox(gw, gui.Yaxis, "debugging")
|
||||
log.Println("debugClick() AddGenericBox() END box =", box)
|
||||
// gw = gui.InitGuiWindow("debugClick", gw)
|
||||
box := initWindow(gw, "Debugging", gui.Yaxis)
|
||||
if (box == nil) { return }
|
||||
log.Println("debugClick() initWindow() END")
|
||||
|
||||
makeButton(box, nil, nil, "empty", "SUBDOMAIN", nil)
|
||||
gui.HorizontalBreak(box)
|
||||
makeButton(box, nil, nil, "Create Subdomain Account", "ADD", addSubdomainClick)
|
||||
hardXbox := gui.HardBox(gw, gui.Xaxis, "subdomain test")
|
||||
|
||||
hardXbox := gui.HardBox(box.Window, gui.Xaxis, "subdomain test")
|
||||
Ybox1 := gui.NewBox(hardXbox, gui.Yaxis, "subdomain Y test")
|
||||
Xbox1 := gui.NewBox(Ybox1, gui.Xaxis, "subdomain Y test")
|
||||
makeButton(Xbox1, nil, nil, "ping", "SUBDOMAIN", runPingClick)
|
||||
|
|
|
@ -75,22 +75,5 @@ func splashClick(b *gui.GuiButton) {
|
|||
|
||||
gw.UiTab.Delete(0) // does this make things more or less stable or neither?
|
||||
createAccount(gw)
|
||||
/*
|
||||
|
||||
box := gui.HardBox(gw, gui.Yaxis, "Create New Account")
|
||||
|
||||
// make a place for someone to enter their subdomain
|
||||
hardXbox := gui.HardBox(gw, gui.Xaxis, "subdomain test")
|
||||
makeButton(hardXbox, nil, nil, "Generate a Subdomain", "SUBDOMAIN", generateSubdomain)
|
||||
gui.NewLabel(hardXbox, "")
|
||||
|
||||
gui.AddEntry(box, "SUBDOMAIN")
|
||||
// gui.HorizontalBreak(box)
|
||||
|
||||
hardXbox1 := gui.HardBox(gw, gui.Xaxis, "subdomain test")
|
||||
makeButton(hardXbox1, nil, nil, "Create Account", "ADD", addSubdomainClick)
|
||||
gui.NewLabel(hardXbox, "")
|
||||
|
||||
*/
|
||||
log.Println("splashClick() END")
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
run:
|
||||
go build
|
||||
./test4
|
|
@ -0,0 +1,220 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
This simply parses the command line arguments using the default golang
|
||||
package called 'flag'. This can be used as a simple template to parse
|
||||
command line arguments in other programs.
|
||||
|
||||
It puts everything in a 'config' Protobuf which I think is a good
|
||||
wrapper around the 'flags' package and doesn't need a whole mess of
|
||||
global variables
|
||||
*/
|
||||
|
||||
import "log"
|
||||
import "os"
|
||||
import "os/user"
|
||||
import "flag"
|
||||
import "fmt"
|
||||
import "runtime"
|
||||
import "io/ioutil"
|
||||
import "strings"
|
||||
|
||||
import "github.com/golang/protobuf/jsonpb"
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
|
||||
import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
var config *pb.Config
|
||||
|
||||
// This loads the config file and marshals it into the
|
||||
// config protocol buffer definition.
|
||||
// Then it is very easy to pass all the config options
|
||||
// around and the re-write that JSON file when the GUI
|
||||
// exits
|
||||
func loadConfigFile() {
|
||||
// look up the user information
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
onExit(err)
|
||||
}
|
||||
spew.Dump(user)
|
||||
|
||||
filename := ""
|
||||
// TODO: confirm this is correct for MacOS and Windows
|
||||
if runtime.GOOS == "linux" {
|
||||
log.Println("loadConfigFile() OS: Linux")
|
||||
filename = user.HomeDir + "/.config/cloud-control-panel.json"
|
||||
} else if runtime.GOOS == "windows" {
|
||||
log.Println("loadConfigFile() OS: Windows")
|
||||
filename = user.HomeDir + "\\cloud-control-panel.json"
|
||||
} else {
|
||||
log.Println("loadConfigFile() OS: " + runtime.GOOS)
|
||||
filename = user.HomeDir + "/.cloud-control-panel.json"
|
||||
}
|
||||
|
||||
tmp := loadConfigFromFilename(filename)
|
||||
config = &tmp
|
||||
|
||||
config.Filename = filename
|
||||
}
|
||||
|
||||
var customUsage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
|
||||
fmt.Println("")
|
||||
fmt.Println("EXAMPLES:")
|
||||
fmt.Println("")
|
||||
fmt.Println(os.Args[0] + " --hostname test.hostname.wit.com")
|
||||
fmt.Println("")
|
||||
}
|
||||
var defaultconfig *bool
|
||||
|
||||
func parseFlags() {
|
||||
var hostname string
|
||||
|
||||
// always override the debugging flag from the command line
|
||||
var debug *bool
|
||||
var debugtable *bool
|
||||
|
||||
flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname")
|
||||
|
||||
height := flag.Int ("height", 0, "Height of the Window")
|
||||
width := flag.Int ("width", 0, "Width of the Window")
|
||||
debug = flag.Bool("debug", false, "Enable debugging")
|
||||
defaultconfig = flag.Bool("defaultconfig", false, "Use the default config file")
|
||||
debugtable = flag.Bool("debugtable", false, "Enable GUI table debugging")
|
||||
|
||||
// Set the output if something fails to stdout rather than stderr
|
||||
flag.CommandLine.SetOutput(os.Stdout)
|
||||
|
||||
flag.Usage = customUsage
|
||||
flag.Parse()
|
||||
|
||||
if flag.Parsed() {
|
||||
log.Println("flag.Parse() worked")
|
||||
} else {
|
||||
log.Println("flag.Parse() failed")
|
||||
onExit(nil)
|
||||
}
|
||||
|
||||
if (*width > 100) {
|
||||
log.Println("ENABLE width =", int32(*width))
|
||||
config.Width = int32(*width)
|
||||
}
|
||||
if (*height > 100) {
|
||||
log.Println("ENABLE height =", int32(*height))
|
||||
config.Height = int32(*height)
|
||||
}
|
||||
|
||||
if (hostname == "") {
|
||||
config.Hostname = hostname
|
||||
}
|
||||
|
||||
// never allow these to be set in the config file
|
||||
config.Debug = *debug
|
||||
config.Debugtable = *debugtable
|
||||
}
|
||||
|
||||
// Convert a Protobuf to JSON
|
||||
func PBtoJSON() string {
|
||||
// this makes a sample protobuf
|
||||
c := pb.MakeDefaultConfig()
|
||||
|
||||
marshaler := &jsonpb.Marshaler{}
|
||||
stuff, _ := marshaler.MarshalToString(c)
|
||||
log.Println(stuff)
|
||||
return stuff
|
||||
}
|
||||
|
||||
func writeToFile(filename string, a string) {
|
||||
f, _ := os.Create(filename)
|
||||
f.WriteString(a)
|
||||
f.Close()
|
||||
}
|
||||
|
||||
func saveConfig() {
|
||||
filename := config.Filename
|
||||
if (filename == "") {
|
||||
log.Println("NOT SAVING CONFIG FILE")
|
||||
} else {
|
||||
marshaler := &jsonpb.Marshaler{}
|
||||
stuff, _ := marshaler.MarshalToString(config)
|
||||
log.Println(stuff)
|
||||
|
||||
writeToFile(filename, stuff)
|
||||
}
|
||||
}
|
||||
|
||||
// will load the default config from within the go binary
|
||||
func loadConfigFromFilename(filename string) pb.Config {
|
||||
sets := pb.Config{}
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Println("ioutil.ReadFile() ERROR =", err)
|
||||
// This probably means this is the first time the user is opening this
|
||||
sets.Errors += 1
|
||||
sets.Crash = "err"
|
||||
sets.Counter = 1
|
||||
sets.Width = 500
|
||||
sets.Height = 500
|
||||
return sets
|
||||
}
|
||||
log.Println("ioutil.ReadFile() b =", b)
|
||||
|
||||
err = jsonpb.Unmarshal(strings.NewReader(string(b)), &sets)
|
||||
if err != nil {
|
||||
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
||||
}
|
||||
spew.Dump(sets)
|
||||
return sets
|
||||
}
|
||||
|
||||
// will load the default config from within the go binary
|
||||
func loadDefaultConfig() *pb.Config {
|
||||
log.Println("TRY TO LOAD DEFAULT CONFIG")
|
||||
// defaultConfig, _ := packrBox.FindString("protobuf-config.json")
|
||||
b, err := packrBox.FindString("cloud-control-panel.json")
|
||||
log.Println("b =", b)
|
||||
log.Println("err =", err)
|
||||
// var newpb *pb.Config
|
||||
sets := pb.Config{}
|
||||
|
||||
err = jsonpb.Unmarshal(strings.NewReader(string(b)), &sets)
|
||||
if err != nil {
|
||||
log.Println("jsonpb.Unmarshal() ERROR =", err)
|
||||
}
|
||||
spew.Dump(sets)
|
||||
return &sets
|
||||
}
|
||||
|
||||
//
|
||||
// This is what you call from main()
|
||||
//
|
||||
func parseConfig() {
|
||||
// first load the config file
|
||||
loadConfigFile()
|
||||
|
||||
// override the config file from the command line
|
||||
parseFlags()
|
||||
|
||||
log.Println("config.width", config.Width)
|
||||
log.Println("config.height", config.Height)
|
||||
log.Println("config.debug", config.Debug)
|
||||
|
||||
// check that the config parsing worked
|
||||
for key, foo := range config.Accounts {
|
||||
log.Println("account = ", key, foo)
|
||||
log.Println("Accounts[key] = ", config.Accounts[key])
|
||||
}
|
||||
if (config.Accounts == nil) {
|
||||
log.Println("loadConfigFile() config.Accounts == nil")
|
||||
log.Println("If debugging is on, should load default config here")
|
||||
if (*defaultconfig == true) {
|
||||
log.Println("Debugging is on, loading debug config accounts")
|
||||
tmp := loadDefaultConfig()
|
||||
config.Accounts = tmp.Accounts
|
||||
log.Println("loadConfigFile() config.Accounts =", config.Accounts)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
package main
|
||||
|
||||
import "log"
|
||||
import "os"
|
||||
import "time"
|
||||
// import "reflect"
|
||||
|
||||
// this is the king of dns libraries
|
||||
// import "github.com/miekg/dns"
|
||||
|
||||
import "git.wit.com/wit/gui"
|
||||
import pb "git.wit.com/wit/witProtobuf"
|
||||
// import "git.wit.com/jcarr/dnssecsocket"
|
||||
|
||||
import "github.com/gobuffalo/packr"
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
var GITCOMMIT string // this is passed in as an ldflag
|
||||
var GOVERSION string // this is passed in as an ldflag
|
||||
var BUILDTIME string // this is passed in as an ldflag
|
||||
var VERSION string // this is passed in as an ldflag
|
||||
|
||||
var State string // used as a State machine
|
||||
|
||||
type myButtonInfo struct {
|
||||
Account *pb.Account // associated with what account?
|
||||
Accounts []*pb.Account // associated with what account?
|
||||
VM *pb.Event_VM // associated with which VM?
|
||||
Custom func (*gui.GuiButton)
|
||||
ADD func (*gui.GuiButton)
|
||||
Name string
|
||||
Action string
|
||||
}
|
||||
|
||||
var packrBox packr.Box
|
||||
|
||||
func onExit(err error) {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func main() {
|
||||
packrBox = packr.NewBox("./resources")
|
||||
|
||||
parseConfig()
|
||||
|
||||
go gui.WatchGUI()
|
||||
|
||||
config.Hostname = "localhost"
|
||||
config.IPv6 = "notvalid"
|
||||
|
||||
gui.Data.MouseClick = func (*gui.GuiButton) {
|
||||
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
||||
}
|
||||
|
||||
gui.Config.Width = int(config.Width)
|
||||
gui.Config.Height = int(config.Height)
|
||||
|
||||
gui.Config.Debug = config.Debug
|
||||
gui.Config.DebugTable = config.Debugtable
|
||||
log.Println("gui.Config.Debug = ", gui.Config.Debug)
|
||||
log.Println("gui.Config.DebugTable = ", gui.Config.DebugTable)
|
||||
|
||||
go gui.StartNewWindow(false, "test4", showBox)
|
||||
time.Sleep(time.Second * 2)
|
||||
gui.StartNewWindow(false, "test5", showBox)
|
||||
}
|
||||
|
||||
func showBox(gw *gui.GuiWindow) *gui.GuiBox {
|
||||
log.Println("ShowSplashBox() START")
|
||||
|
||||
box := gui.HardBox(gw, gui.Yaxis, "Cloud Accounts")
|
||||
|
||||
log.Println("showBox() START GW IS NOW: gw =", gw)
|
||||
log.Println("showBox() box =", box)
|
||||
|
||||
gui.NewLabel(box, "Hostname:")
|
||||
makeButton(box, nil, nil, "EMPTY", "SUBDOMAIN", nil)
|
||||
makeButton(box, nil, nil, "List all windows & tabs", "SUBDOMAIN", func (*gui.GuiButton) {
|
||||
log.Println("showBox() gui.DumpBoxes()")
|
||||
gui.DumpBoxes()
|
||||
})
|
||||
|
||||
return box
|
||||
}
|
||||
|
||||
// stores the fields we want to map into our private structure 'values'
|
||||
func makeGuiButtonValues(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
||||
name string, action string, custom func(*gui.GuiButton)) *myButtonInfo {
|
||||
val := &myButtonInfo{}
|
||||
val.Account = a
|
||||
val.Accounts = config.Accounts
|
||||
val.VM = vm
|
||||
val.Custom = custom
|
||||
val.Name = "jcarr"
|
||||
val.Action = action
|
||||
return val
|
||||
}
|
||||
|
||||
func makeButton(box *gui.GuiBox, a *pb.Account, vm *pb.Event_VM,
|
||||
name string, action string, custom func(*gui.GuiButton)) *gui.GuiButton {
|
||||
val := makeGuiButtonValues(box, a, vm, name, action, custom)
|
||||
return gui.CreateButton(box, custom, name, val)
|
||||
}
|
Loading…
Reference in New Issue