parent
0d1b204d9e
commit
90f3213d4a
|
@ -45,8 +45,7 @@ func mainMouseClick(b *gui.GuiButton) {
|
||||||
}
|
}
|
||||||
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
log.Println("mainMouseClick() BACK IN CONTROL PANEL CODE")
|
||||||
|
|
||||||
var gw *gui.GuiWindow
|
gw := b.Box.Window
|
||||||
gw = b.Box.Window
|
|
||||||
|
|
||||||
if (gw == nil) {
|
if (gw == nil) {
|
||||||
log.Println("\tTHIS BUTTON IS BROKEN 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.Accounts =", values.Accounts)
|
||||||
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
||||||
|
|
||||||
var gw *gui.GuiWindow
|
gw := b.Box.Window
|
||||||
gw = b.Box.Window
|
|
||||||
|
|
||||||
event := pb.MakeGetEvent()
|
event := pb.MakeGetEvent()
|
||||||
event.Account = values.Account
|
event.Account = values.Account
|
||||||
|
@ -148,9 +146,6 @@ func createVmClick(b *gui.GuiButton) {
|
||||||
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
|
log.Println("\tmainMouseClick() values.Accounts =", values.Accounts)
|
||||||
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
log.Println("\tmainMouseClick() values.Name = ", values.Name)
|
||||||
|
|
||||||
// var gw *gui.GuiWindow
|
|
||||||
// gw = b.Box.Window
|
|
||||||
|
|
||||||
log.Println("\tTRIGGER CREATE VM")
|
log.Println("\tTRIGGER CREATE VM")
|
||||||
State = "CREATE"
|
State = "CREATE"
|
||||||
event := pb.MakeAddVmEvent()
|
event := pb.MakeAddVmEvent()
|
||||||
|
|
|
@ -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