Compare commits
No commits in common. "master" and "v0.2.52" have entirely different histories.
9
Makefile
9
Makefile
|
@ -10,8 +10,8 @@ all: install
|
||||||
@echo build worked
|
@echo build worked
|
||||||
virtigo list droplets
|
virtigo list droplets
|
||||||
virtigo list droplets --on
|
virtigo list droplets --on
|
||||||
virtigo droplet show --name check.lab.wit.org
|
virtigo droplet start --name coriolis
|
||||||
virtigo droplet start --name check.lab.wit.org
|
virtigo droplet show --name coriolis
|
||||||
|
|
||||||
build: goimports vet
|
build: goimports vet
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
|
@ -92,7 +92,7 @@ redomod:
|
||||||
clean:
|
clean:
|
||||||
rm -f go.*
|
rm -f go.*
|
||||||
rm -f virtigo*
|
rm -f virtigo*
|
||||||
go-mod-clean purge
|
go-mod-clean --purge
|
||||||
|
|
||||||
# git clone the sources and all the golang dependancies into ~/go/src
|
# git clone the sources and all the golang dependancies into ~/go/src
|
||||||
# if you don't have go-clone, you can get it from http://go.wit.com/
|
# if you don't have go-clone, you can get it from http://go.wit.com/
|
||||||
|
@ -119,8 +119,7 @@ protogen:
|
||||||
cd ~/go/src/google.golang.org/protobuf/cmd/protoc-gen-go && go install
|
cd ~/go/src/google.golang.org/protobuf/cmd/protoc-gen-go && go install
|
||||||
|
|
||||||
gocui: install
|
gocui: install
|
||||||
virtigo --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so --admin
|
virtigo --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so >/tmp/forge.log 2>&1
|
||||||
# virtigo --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so --admin >/tmp/forge.log 2>&1
|
|
||||||
|
|
||||||
log:
|
log:
|
||||||
journalctl -f -xeu virtigod.service
|
journalctl -f -xeu virtigod.service
|
||||||
|
|
34
argv.go
34
argv.go
|
@ -1,11 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "go.wit.com/log"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
this parses the command line arguements
|
this parses the command line arguements
|
||||||
|
@ -20,8 +15,6 @@ type args struct {
|
||||||
Droplet *DropletCmd `arg:"subcommand:droplet" help:"send events to a droplet"`
|
Droplet *DropletCmd `arg:"subcommand:droplet" help:"send events to a droplet"`
|
||||||
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
|
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
|
||||||
Server string `arg:"env:VIRTIGO_SERVER" help:"what virtigo cluster to connect to"`
|
Server string `arg:"env:VIRTIGO_SERVER" help:"what virtigo cluster to connect to"`
|
||||||
Localhost bool `arg:"--localhost" help:"use the local libvirt"`
|
|
||||||
Daemon bool `arg:"--daemon" help:"run as a daemon"`
|
|
||||||
Verbose bool `arg:"--verbose" help:"talk more"`
|
Verbose bool `arg:"--verbose" help:"talk more"`
|
||||||
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
|
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
|
||||||
Xml []string `arg:"--libvirt" help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
|
Xml []string `arg:"--libvirt" help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
|
||||||
|
@ -79,28 +72,3 @@ func init() {
|
||||||
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
WARN = log.NewFlag("WARN", true, full, short, "bad things")
|
||||||
EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events")
|
EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
handles shell autocomplete
|
|
||||||
*/
|
|
||||||
|
|
||||||
func (a args) DoAutoComplete(argv []string) {
|
|
||||||
switch argv[0] {
|
|
||||||
case "list":
|
|
||||||
fmt.Println("droplets hypervisors")
|
|
||||||
case "droplet":
|
|
||||||
fmt.Println("start stop")
|
|
||||||
case "devel":
|
|
||||||
fmt.Println("--force")
|
|
||||||
case "master":
|
|
||||||
fmt.Println("")
|
|
||||||
case "verify":
|
|
||||||
fmt.Println("user devel master")
|
|
||||||
default:
|
|
||||||
if argv[0] == ARGNAME {
|
|
||||||
// list the subcommands here
|
|
||||||
fmt.Println("--bash list droplet")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the GPL 3.0
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
handles shell autocomplete
|
||||||
|
*/
|
||||||
|
|
||||||
|
// used for shell auto completion
|
||||||
|
// var ARGNAME string = "forge" // todo: get this from $0 ?
|
||||||
|
|
||||||
|
func deleteMatch() {
|
||||||
|
// f := forgedb.InitSimple()
|
||||||
|
fmt.Println("go.wit.com/lib/gui/repostatus todo: need to do this")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (args) doBashAuto() {
|
||||||
|
argv.doBashHelp()
|
||||||
|
switch argv.BashAuto[0] {
|
||||||
|
case "list":
|
||||||
|
fmt.Println("droplets hypervisors")
|
||||||
|
case "droplet":
|
||||||
|
fmt.Println("start stop")
|
||||||
|
case "devel":
|
||||||
|
fmt.Println("--force")
|
||||||
|
case "master":
|
||||||
|
fmt.Println("")
|
||||||
|
case "verify":
|
||||||
|
fmt.Println("user devel master")
|
||||||
|
default:
|
||||||
|
if argv.BashAuto[0] == ARGNAME {
|
||||||
|
// list the subcommands here
|
||||||
|
fmt.Println("--bash list droplet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// prints help to STDERR // TODO: move everything below this to go-args
|
||||||
|
func (args) doBashHelp() {
|
||||||
|
if argv.BashAuto[1] != "''" {
|
||||||
|
// if this is not blank, then the user has typed something
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if argv.BashAuto[0] != ARGNAME {
|
||||||
|
// if this is not the name of the command, the user already started doing something
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if argv.BashAuto[0] == ARGNAME {
|
||||||
|
me.pp.WriteHelp(os.Stderr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintln(os.Stderr, "")
|
||||||
|
fmt.Fprintln(os.Stderr, "hello world")
|
||||||
|
fmt.Fprintln(os.Stderr, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// complete -F forge --bash forge
|
||||||
|
func (args) doBash() {
|
||||||
|
fmt.Println("# add this in your bashrc:")
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash")
|
||||||
|
fmt.Println("#")
|
||||||
|
fmt.Println("# todo: can this output work/parse with:")
|
||||||
|
fmt.Println("# complete -C `" + ARGNAME + " --bash` " + ARGNAME)
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println("_" + ARGNAME + "_complete()")
|
||||||
|
fmt.Println("{")
|
||||||
|
fmt.Println(" # sets local to this func vars")
|
||||||
|
fmt.Println(" local cur prev all")
|
||||||
|
fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}")
|
||||||
|
fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}")
|
||||||
|
fmt.Println(" all=${COMP_WORDS[@]}")
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println(" # this is where we generate the go-arg output")
|
||||||
|
fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)")
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println(" # this compares the command line input from the user")
|
||||||
|
fmt.Println(" # to whatever strings we output")
|
||||||
|
fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS")
|
||||||
|
fmt.Println(" return 0")
|
||||||
|
fmt.Println("}")
|
||||||
|
fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME)
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println("# copy and paste the above into your bash shell should work")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
224
doAdminGui.go
224
doAdminGui.go
|
@ -22,14 +22,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// refresh the windows & tables the user has open
|
// refresh the windows & tables the user has open
|
||||||
func (admin *adminT) refresh() error {
|
func (admin *adminT) refresh() {
|
||||||
if argv.Verbose {
|
if argv.Verbose {
|
||||||
log.Info("virtigo scan here")
|
log.Info("virtigo scan here")
|
||||||
}
|
}
|
||||||
|
|
||||||
if admin.url == nil {
|
if admin.url == nil {
|
||||||
log.Info("admin url == nil")
|
log.Info("admin url == nil")
|
||||||
return fmt.Errorf("admin url == nil")
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := []byte(`{"message": "Hello"}`)
|
msg := []byte(`{"message": "Hello"}`)
|
||||||
|
@ -47,12 +47,12 @@ func (admin *adminT) refresh() error {
|
||||||
log.Info("/DropletsPB Error:", err)
|
log.Info("/DropletsPB Error:", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("DropletsPB Response len:", len(data))
|
fmt.Println("DropletsPB Response len:", len(data))
|
||||||
admin.cluster.Droplets = new(virtpb.Droplets)
|
admin.droplets = new(virtpb.Droplets)
|
||||||
if err := admin.cluster.Droplets.Unmarshal(data); err != nil {
|
if err := admin.droplets.Unmarshal(data); err != nil {
|
||||||
fmt.Println("droplets marshal failed", err)
|
fmt.Println("droplets marshal failed", err)
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Droplet len=", admin.cluster.Droplets.Len())
|
fmt.Println("Droplet len=", admin.droplets.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the hypervisor list
|
// update the hypervisor list
|
||||||
|
@ -60,12 +60,12 @@ func (admin *adminT) refresh() error {
|
||||||
log.Info("Error:", err)
|
log.Info("Error:", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("HypervisorsPB Response len:", len(data))
|
fmt.Println("HypervisorsPB Response len:", len(data))
|
||||||
admin.cluster.Hypervisors = new(virtpb.Hypervisors)
|
admin.hypervisors = new(virtpb.Hypervisors)
|
||||||
if err := admin.cluster.Hypervisors.Unmarshal(data); err != nil {
|
if err := admin.hypervisors.Unmarshal(data); err != nil {
|
||||||
fmt.Println("hypervisors marshal failed", err)
|
fmt.Println("hypervisors marshal failed", err)
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Hypervisors len=", admin.cluster.Hypervisors.Len())
|
fmt.Println("Hypervisors len=", admin.hypervisors.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the events list
|
// update the events list
|
||||||
|
@ -73,114 +73,22 @@ func (admin *adminT) refresh() error {
|
||||||
log.Info("Error:", err)
|
log.Info("Error:", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("EventsPB Response len:", len(data))
|
fmt.Println("EventsPB Response len:", len(data))
|
||||||
admin.cluster.Events = new(virtpb.Events)
|
admin.events = new(virtpb.Events)
|
||||||
if err := admin.cluster.Events.Unmarshal(data); err != nil {
|
if err := admin.events.Unmarshal(data); err != nil {
|
||||||
fmt.Println("events marshal failed", err)
|
fmt.Println("events marshal failed", err)
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Events len=", admin.cluster.Events.Len())
|
fmt.Println("Events len=", admin.events.Len())
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var client *http.Client
|
var client *http.Client
|
||||||
|
|
||||||
func doLocalhostAdminGui() *adminT {
|
|
||||||
admin := new(adminT)
|
|
||||||
|
|
||||||
admin.uptime = me.gwin.Group.NewLabel("uptime")
|
|
||||||
|
|
||||||
grid := me.gwin.Group.RawGrid()
|
|
||||||
|
|
||||||
grid.NewButton("show hypervisors", func() {
|
|
||||||
if admin.cluster.Hypervisors == nil {
|
|
||||||
log.Info("hypervisors not initialized")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len())
|
|
||||||
admin.hwin = newHypervisorsWindow()
|
|
||||||
admin.hwin.doStdHypervisors(admin.cluster.Hypervisors)
|
|
||||||
admin.hwin.win.Custom = func() {
|
|
||||||
log.Info("hiding table window")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
grid.NewButton("droplets", func() {
|
|
||||||
if admin.cluster.Droplets == nil {
|
|
||||||
log.Info("droplets not initialized")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
admin.dwin = newDropletsWindow(admin)
|
|
||||||
admin.dwin.win.Custom = func() {
|
|
||||||
log.Info("hiding droplet table window")
|
|
||||||
}
|
|
||||||
var found *virtpb.Droplets
|
|
||||||
found = virtpb.NewDroplets()
|
|
||||||
all := admin.cluster.Droplets.All()
|
|
||||||
for all.Scan() {
|
|
||||||
vm := all.Next()
|
|
||||||
if vm.Current.State != virtpb.DropletState_ON {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
found.Append(vm)
|
|
||||||
}
|
|
||||||
admin.dwin.doActiveDroplets(found)
|
|
||||||
})
|
|
||||||
|
|
||||||
grid.NewButton("events", func() {
|
|
||||||
if admin.cluster.Events == nil {
|
|
||||||
log.Info("events are not initialized")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Info("Events len=", admin.cluster.Events.Len())
|
|
||||||
admin.ewin = newEventsWindow()
|
|
||||||
admin.ewin.doStdEvents(admin.cluster.Events)
|
|
||||||
admin.ewin.win.Custom = func() {
|
|
||||||
log.Info("hiding table window")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
grid.NextRow()
|
|
||||||
|
|
||||||
grid.NewButton("refresh", func() {
|
|
||||||
admin.refresh()
|
|
||||||
})
|
|
||||||
|
|
||||||
return admin
|
|
||||||
}
|
|
||||||
|
|
||||||
func doAdminGui() {
|
|
||||||
// Initialize a persistent client with a custom Transport
|
|
||||||
client = &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
DisableKeepAlives: false, // Ensure Keep-Alive is enabled
|
|
||||||
},
|
|
||||||
Timeout: 10 * time.Second, // Set a reasonable timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
me.gwin = gadgets.NewGenericWindow("Virtigo: (run your cluster)", "")
|
|
||||||
me.gwin.Custom = func() {
|
|
||||||
log.Warn("Main window close")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
me.cmap = make(map[*virtpb.Cluster]*adminT)
|
|
||||||
for c := range me.clusters.IterAll() {
|
|
||||||
a := new(adminT)
|
|
||||||
me.cmap[c] = a
|
|
||||||
log.Info("found in the config file", c.URL[0])
|
|
||||||
a.makeClusterGroup(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sit here forever refreshing the GUI
|
|
||||||
for {
|
|
||||||
// admin.refresh()
|
|
||||||
log.Info("todo: refresh() protobufs here")
|
|
||||||
time.Sleep(90 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (admin *adminT) doAdminGui() {
|
func (admin *adminT) doAdminGui() {
|
||||||
|
me.myGui = gui.New()
|
||||||
|
me.myGui.InitEmbed(resources)
|
||||||
|
me.myGui.Default()
|
||||||
|
|
||||||
// Initialize a persistent client with a custom Transport
|
// Initialize a persistent client with a custom Transport
|
||||||
client = &http.Client{
|
client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
|
@ -201,30 +109,30 @@ func (admin *adminT) doAdminGui() {
|
||||||
grid := win.Group.RawGrid()
|
grid := win.Group.RawGrid()
|
||||||
|
|
||||||
grid.NewButton("show hypervisors", func() {
|
grid.NewButton("show hypervisors", func() {
|
||||||
if admin.cluster.Hypervisors == nil {
|
if admin.hypervisors == nil {
|
||||||
log.Info("hypervisors not initialized")
|
log.Info("hypervisors not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len())
|
log.Info("Hypervisors len=", admin.hypervisors.Len())
|
||||||
admin.hwin = newHypervisorsWindow()
|
admin.hwin = newHypervisorsWindow()
|
||||||
admin.hwin.doStdHypervisors(admin.cluster.Hypervisors)
|
admin.hwin.doStdHypervisors(admin.hypervisors)
|
||||||
admin.hwin.win.Custom = func() {
|
admin.hwin.win.Custom = func() {
|
||||||
log.Info("hiding table window")
|
log.Info("hiding table window")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("droplets", func() {
|
grid.NewButton("droplets", func() {
|
||||||
if admin.cluster.Droplets == nil {
|
if admin.droplets == nil {
|
||||||
log.Info("droplets not initialized")
|
log.Info("droplets not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
admin.dwin = newDropletsWindow(admin)
|
admin.dwin = newDropletsWindow()
|
||||||
admin.dwin.win.Custom = func() {
|
admin.dwin.win.Custom = func() {
|
||||||
log.Info("hiding droplet table window")
|
log.Info("hiding droplet table window")
|
||||||
}
|
}
|
||||||
var found *virtpb.Droplets
|
var found *virtpb.Droplets
|
||||||
found = virtpb.NewDroplets()
|
found = virtpb.NewDroplets()
|
||||||
all := admin.cluster.Droplets.All()
|
all := admin.droplets.All()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
vm := all.Next()
|
vm := all.Next()
|
||||||
if vm.Current.State != virtpb.DropletState_ON {
|
if vm.Current.State != virtpb.DropletState_ON {
|
||||||
|
@ -236,13 +144,13 @@ func (admin *adminT) doAdminGui() {
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("events", func() {
|
grid.NewButton("events", func() {
|
||||||
if admin.cluster.Events == nil {
|
if admin.events == nil {
|
||||||
log.Info("events are not initialized")
|
log.Info("events are not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Events len=", admin.cluster.Events.Len())
|
log.Info("Events len=", admin.events.Len())
|
||||||
admin.ewin = newEventsWindow()
|
admin.ewin = newEventsWindow()
|
||||||
admin.ewin.doStdEvents(admin.cluster.Events)
|
admin.ewin.doStdEvents(admin.events)
|
||||||
admin.ewin.win.Custom = func() {
|
admin.ewin.win.Custom = func() {
|
||||||
log.Info("hiding table window")
|
log.Info("hiding table window")
|
||||||
}
|
}
|
||||||
|
@ -255,7 +163,7 @@ func (admin *adminT) doAdminGui() {
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("test gui close", func() {
|
grid.NewButton("test gui close", func() {
|
||||||
gui.StandardExit()
|
me.myGui.Close()
|
||||||
// okExit("admin close")
|
// okExit("admin close")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -281,47 +189,36 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) {
|
||||||
badExit(err)
|
badExit(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if admin.cluster == nil {
|
group := me.gwin.Bottom.NewGroup(admin.url.Hostname())
|
||||||
admin.cluster = new(virtpb.Cluster)
|
|
||||||
admin.cluster.Name = c.Name
|
|
||||||
admin.cluster.Uuid = c.Uuid
|
|
||||||
}
|
|
||||||
|
|
||||||
name := c.GetName()
|
|
||||||
if name == "" {
|
|
||||||
name = admin.url.Hostname()
|
|
||||||
}
|
|
||||||
|
|
||||||
group := me.gwin.Bottom.NewGroup(name)
|
|
||||||
admin.uptime = group.NewLabel("uptime")
|
admin.uptime = group.NewLabel("uptime")
|
||||||
|
|
||||||
grid := group.RawGrid()
|
grid := group.RawGrid()
|
||||||
|
|
||||||
grid.NewButton("show hypervisors", func() {
|
grid.NewButton("show hypervisors", func() {
|
||||||
if admin.cluster.Hypervisors == nil {
|
if admin.hypervisors == nil {
|
||||||
log.Info("hypervisors not initialized")
|
log.Info("hypervisors not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Hypervisors len=", admin.cluster.Hypervisors.Len())
|
log.Info("Hypervisors len=", admin.hypervisors.Len())
|
||||||
admin.hwin = newHypervisorsWindow()
|
admin.hwin = newHypervisorsWindow()
|
||||||
admin.hwin.doStdHypervisors(admin.cluster.Hypervisors)
|
admin.hwin.doStdHypervisors(admin.hypervisors)
|
||||||
admin.hwin.win.Custom = func() {
|
admin.hwin.win.Custom = func() {
|
||||||
log.Info("hiding table window")
|
log.Info("hiding table window")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("droplets", func() {
|
grid.NewButton("droplets", func() {
|
||||||
if admin.cluster.Droplets == nil {
|
if admin.droplets == nil {
|
||||||
log.Info("droplets not initialized")
|
log.Info("droplets not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
admin.dwin = newDropletsWindow(admin)
|
admin.dwin = newDropletsWindow()
|
||||||
admin.dwin.win.Custom = func() {
|
admin.dwin.win.Custom = func() {
|
||||||
log.Info("hiding droplet table window")
|
log.Info("hiding droplet table window")
|
||||||
}
|
}
|
||||||
var found *virtpb.Droplets
|
var found *virtpb.Droplets
|
||||||
found = virtpb.NewDroplets()
|
found = virtpb.NewDroplets()
|
||||||
all := admin.cluster.Droplets.All()
|
all := admin.droplets.All()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
vm := all.Next()
|
vm := all.Next()
|
||||||
if vm.Current.State != virtpb.DropletState_ON {
|
if vm.Current.State != virtpb.DropletState_ON {
|
||||||
|
@ -333,29 +230,17 @@ func (admin *adminT) makeClusterGroup(c *virtpb.Cluster) {
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("events", func() {
|
grid.NewButton("events", func() {
|
||||||
if admin.cluster.Events == nil {
|
if admin.events == nil {
|
||||||
log.Info("events are not initialized")
|
log.Info("events are not initialized")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("Events len=", admin.cluster.Events.Len())
|
log.Info("Events len=", admin.events.Len())
|
||||||
admin.ewin = newEventsWindow()
|
admin.ewin = newEventsWindow()
|
||||||
admin.ewin.doStdEvents(admin.cluster.Events)
|
admin.ewin.doStdEvents(admin.events)
|
||||||
admin.ewin.win.Custom = func() {
|
admin.ewin.win.Custom = func() {
|
||||||
log.Info("hiding table window")
|
log.Info("hiding table window")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("refresh", func() {
|
|
||||||
admin.refresh()
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := admin.refresh(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
grid.NewButton("save cluster.pb", func() {
|
|
||||||
admin.cluster.ConfigSave()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func postData(url string, data []byte) ([]byte, error) {
|
func postData(url string, data []byte) ([]byte, error) {
|
||||||
|
@ -381,36 +266,3 @@ func postData(url string, data []byte) ([]byte, error) {
|
||||||
|
|
||||||
return body, nil
|
return body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (admin *adminT) postEvent(e *virtpb.Event) error {
|
|
||||||
var result *virtpb.Event
|
|
||||||
result = new(virtpb.Event)
|
|
||||||
|
|
||||||
msg, err := e.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
log.Info("postEvent() marshal() failed", err, e)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
url := admin.url.String() + "/event"
|
|
||||||
|
|
||||||
// update the droplet list
|
|
||||||
if data, err := postData(url, msg); err != nil {
|
|
||||||
log.Info("postEvent() /event Error:", err)
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
if err := result.Unmarshal(data); err != nil {
|
|
||||||
log.Println("postEvent() result marshal failed", err, "len(dat) =", len(data))
|
|
||||||
log.Println("postEvent() data =", string(data))
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
log.Println("postEvent() result marshal worked on len(dat) =", len(data))
|
|
||||||
log.Println("postEvent() result =", result.FormatTEXT())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if result.Error != "" {
|
|
||||||
return fmt.Errorf("%s", result.Error)
|
|
||||||
}
|
|
||||||
log.Printf("Event worked to %s uuid=%s\n", url, result.DropletUuid)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
154
doDaemon.go
154
doDaemon.go
|
@ -1,154 +0,0 @@
|
||||||
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
|
||||||
"go.wit.com/lib/virtigolib"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func doDaemon() error {
|
|
||||||
// set defaults
|
|
||||||
me.unstable = time.Now() // initialize the grid as unstable
|
|
||||||
me.changed = false
|
|
||||||
me.hmap = make(map[*virtpb.Hypervisor]*HyperT)
|
|
||||||
|
|
||||||
// how long a droplet can be missing until it's declared dead
|
|
||||||
me.unstableTimeout = 17 * time.Second
|
|
||||||
me.missingDropletTimeout = time.Minute // not sure the difference between these values
|
|
||||||
|
|
||||||
// how often to poll the hypervisors
|
|
||||||
me.hyperPollDelay = 5 * time.Second
|
|
||||||
|
|
||||||
// how long the cluster must be stable before new droplets can be started
|
|
||||||
me.clusterStableDuration = 37 * time.Second
|
|
||||||
|
|
||||||
me.cluster = virtpb.InitCluster()
|
|
||||||
if err := me.cluster.ConfigLoad(); err != nil {
|
|
||||||
log.Info("config load error", err)
|
|
||||||
log.Info("")
|
|
||||||
log.Info("You have never run this before")
|
|
||||||
log.Info("init example cloud here")
|
|
||||||
log.Sleep(2)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
loop := me.cluster.DropletsAll() // get the list of droplets
|
|
||||||
for loop.Scan() {
|
|
||||||
d := loop.Next()
|
|
||||||
if d == nil {
|
|
||||||
fmt.Println("d == nil")
|
|
||||||
return fmt.Errorf("d == nil")
|
|
||||||
}
|
|
||||||
fmt.Println("Droplet UUID:", d.Uuid)
|
|
||||||
if d.Current == nil {
|
|
||||||
d.Current = new(virtpb.Current)
|
|
||||||
}
|
|
||||||
d.SetState(virtpb.DropletState_OFF)
|
|
||||||
log.Info("droplet", d.Hostname)
|
|
||||||
}
|
|
||||||
hmm := "pihole.wit.com"
|
|
||||||
d := me.cluster.FindDropletByName(hmm)
|
|
||||||
if d == nil {
|
|
||||||
log.Info("did not find found droplet", hmm)
|
|
||||||
} else {
|
|
||||||
log.Info("found droplet", d.Hostname, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
var newEvents []*virtpb.Event
|
|
||||||
|
|
||||||
// sanity check the cluster & droplets
|
|
||||||
if _, _, err := ValidateDroplets(); err != nil {
|
|
||||||
log.Info("todo: add flag to ignore. for now, fix problems in the config file.")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
newe, err := ValidateDiskFilenames()
|
|
||||||
if err != nil {
|
|
||||||
log.Info(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// this is a new droplet. add it to the cluster
|
|
||||||
for _, e := range newe {
|
|
||||||
newEvents = append(newEvents, e)
|
|
||||||
}
|
|
||||||
ValidateUniqueFilenames()
|
|
||||||
|
|
||||||
for _, filename := range argv.Xml {
|
|
||||||
domcfg, err := virtigolib.ReadXml(filename)
|
|
||||||
if err != nil {
|
|
||||||
// parsing the libvirt xml file failed
|
|
||||||
log.Info("error:", filename, err)
|
|
||||||
log.Info("readXml() error", filename)
|
|
||||||
log.Info("readXml() error", err)
|
|
||||||
log.Info("libvirt XML will have to be fixed by hand")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// this is a new droplet. add it to the cluster
|
|
||||||
log.Info("Add XML Droplet here", domcfg.Name)
|
|
||||||
_, newe, err := virtigolib.AddDomainDroplet(me.cluster, domcfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Info("addDomainDroplet() error", filename)
|
|
||||||
log.Info("addDomainDroplet() error", err)
|
|
||||||
log.Info("libvirt XML will have to be fixed by hand")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, e := range newe {
|
|
||||||
newEvents = append(newEvents, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i, e := range newEvents {
|
|
||||||
log.Info(i, "Event:", e.Droplet, e.FieldName, "orig:", e.OrigVal, "new:", e.NewVal)
|
|
||||||
me.changed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if me.changed {
|
|
||||||
if err := me.cluster.ConfigSave(); err != nil {
|
|
||||||
log.Info("configsave error", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Info("XML changes saved in protobuf config")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if len(argv.Xml) != 0 {
|
|
||||||
log.Info("No XML changes found")
|
|
||||||
return fmt.Errorf("No XML changes found")
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize each hypervisor
|
|
||||||
for _, pbh := range me.cluster.H.Hypervisors {
|
|
||||||
// this is a new unknown droplet (not in the config file)
|
|
||||||
var h *HyperT
|
|
||||||
h = new(HyperT)
|
|
||||||
h.pb = pbh
|
|
||||||
h.lastDroplets = make(map[string]time.Time)
|
|
||||||
h.lastpoll = time.Now()
|
|
||||||
|
|
||||||
me.hmap[pbh] = h
|
|
||||||
me.hypers = append(me.hypers, h)
|
|
||||||
log.Log(EVENT, "config new hypervisors", h.pb.Hostname)
|
|
||||||
}
|
|
||||||
|
|
||||||
// start the watchdog polling for each hypervisor
|
|
||||||
for _, h := range me.hypers {
|
|
||||||
log.Info("starting polling on", h.pb.Hostname)
|
|
||||||
|
|
||||||
// start a watchdog on each hypervisor
|
|
||||||
go h.NewWatchdog()
|
|
||||||
}
|
|
||||||
|
|
||||||
var cloud *virtigolib.CloudManager
|
|
||||||
cloud = virtigolib.NewCloud()
|
|
||||||
found, _ := cloud.FindDropletByName("www.wit.com")
|
|
||||||
if found == nil {
|
|
||||||
log.Info("d == nil")
|
|
||||||
} else {
|
|
||||||
log.Info("d == ", found)
|
|
||||||
}
|
|
||||||
|
|
||||||
startHTTP()
|
|
||||||
return nil
|
|
||||||
}
|
|
290
doDroplet.go
290
doDroplet.go
|
@ -7,15 +7,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
"go.wit.com/lib/protobuf/virtpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -40,9 +35,6 @@ func doDroplet() (string, error) {
|
||||||
for c := range me.clusters.IterAll() {
|
for c := range me.clusters.IterAll() {
|
||||||
var err error
|
var err error
|
||||||
admin := new(adminT)
|
admin := new(adminT)
|
||||||
if admin.cluster == nil {
|
|
||||||
admin.cluster = new(virtpb.Cluster)
|
|
||||||
}
|
|
||||||
me.cmap[c] = admin
|
me.cmap[c] = admin
|
||||||
log.Info("found in the config file", c.URL[0])
|
log.Info("found in the config file", c.URL[0])
|
||||||
// a.makeClusterGroup(c)
|
// a.makeClusterGroup(c)
|
||||||
|
@ -56,15 +48,15 @@ func doDroplet() (string, error) {
|
||||||
log.Info("/DropletsPB Error:", err)
|
log.Info("/DropletsPB Error:", err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
admin.cluster.Droplets = new(virtpb.Droplets)
|
admin.droplets = new(virtpb.Droplets)
|
||||||
if err := admin.cluster.Droplets.Unmarshal(data); err != nil {
|
if err := admin.droplets.Unmarshal(data); err != nil {
|
||||||
log.Printf("DropletsPB Response len:%d\n", len(data))
|
log.Printf("DropletsPB Response len:%d\n", len(data))
|
||||||
log.Println("droplets marshal failed", err)
|
log.Println("droplets marshal failed", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("Cluster Name: %s\n", c.Name)
|
log.Printf("Cluster Name: %s\n", c.Name)
|
||||||
log.Printf("Number of Droplets: %d\n", admin.cluster.Droplets.Len())
|
log.Printf("Number of Droplets: %d\n", admin.droplets.Len())
|
||||||
|
|
||||||
if argv.Droplet.Name == "" {
|
if argv.Droplet.Name == "" {
|
||||||
return "", fmt.Errorf("--name droplet name was empty")
|
return "", fmt.Errorf("--name droplet name was empty")
|
||||||
|
@ -72,29 +64,14 @@ func doDroplet() (string, error) {
|
||||||
|
|
||||||
var found *virtpb.Droplets
|
var found *virtpb.Droplets
|
||||||
found = virtpb.NewDroplets()
|
found = virtpb.NewDroplets()
|
||||||
all := admin.cluster.Droplets.All()
|
all := admin.droplets.All()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
vm := all.Next()
|
vm := all.Next()
|
||||||
if argv.Droplet.Name == vm.Hostname {
|
if argv.Droplet.Name == vm.Hostname {
|
||||||
if argv.Droplet.Show != nil {
|
|
||||||
log.Info(vm.SprintHeader())
|
log.Info(vm.SprintHeader())
|
||||||
txt := vm.FormatTEXT()
|
txt := vm.FormatTEXT()
|
||||||
log.Info(txt)
|
log.Info(txt)
|
||||||
return "droplet status", nil
|
return "droplet found", nil
|
||||||
}
|
|
||||||
if argv.Droplet.Start != nil {
|
|
||||||
log.Info("should start droplet here")
|
|
||||||
log.Info(vm.SprintHeader())
|
|
||||||
e := new(virtpb.Event)
|
|
||||||
e.Etype = virtpb.EventType_POWERON
|
|
||||||
e.DropletUuid = vm.Uuid
|
|
||||||
|
|
||||||
if err := admin.postEvent(e); err != nil {
|
|
||||||
return "droplet start err", err
|
|
||||||
}
|
|
||||||
return "droplet start", nil
|
|
||||||
}
|
|
||||||
return "droplet found", fmt.Errorf("do what to the droplet?")
|
|
||||||
}
|
}
|
||||||
found.Append(vm)
|
found.Append(vm)
|
||||||
}
|
}
|
||||||
|
@ -102,260 +79,3 @@ func doDroplet() (string, error) {
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("droplet %s not found", argv.Droplet.Name)
|
return "", fmt.Errorf("droplet %s not found", argv.Droplet.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doEvent(e *virtpb.Event) *virtpb.Event {
|
|
||||||
result := new(virtpb.Event)
|
|
||||||
if e.Etype == virtpb.EventType_POWERON {
|
|
||||||
log.Println("power on droplet on local cluster here", e.DropletUuid)
|
|
||||||
result.State = virtpb.Event_DONE
|
|
||||||
rs, err := Start(e.DropletUuid)
|
|
||||||
log.Println("Start() returned", rs)
|
|
||||||
log.Println("Start() returned err", err)
|
|
||||||
if err != nil {
|
|
||||||
result.Error = fmt.Sprintf("%v", err)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.Etype == virtpb.EventType_EDIT {
|
|
||||||
log.Println("edit event", e.DropletUuid)
|
|
||||||
result.State = virtpb.Event_DONE
|
|
||||||
if e.Droplet != nil {
|
|
||||||
return updateDroplet(e.Droplet)
|
|
||||||
}
|
|
||||||
log.Println("unknown edit event")
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.Etype == virtpb.EventType_ADD {
|
|
||||||
log.Println("START ADD droplet event", e.Droplet.FormatTEXT())
|
|
||||||
if e.Droplet == nil {
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
result.DropletName = e.Droplet.Hostname
|
|
||||||
result.Error = e.Droplet.FormatTEXT() // feedback to the other side for debugging
|
|
||||||
|
|
||||||
// attempt to create the new droplet
|
|
||||||
if err := createDroplet(e.Droplet, result); err != nil {
|
|
||||||
result.Error += fmt.Sprintf("createDroplet() err: %v", err)
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
log.Println("create droplet worked", e.Droplet.FormatTEXT())
|
|
||||||
result.State = virtpb.Event_DONE
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("unknown event", e)
|
|
||||||
result.Etype = e.Etype
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateDroplet(newd *virtpb.Droplet) *virtpb.Event {
|
|
||||||
var changed bool = false
|
|
||||||
result := new(virtpb.Event)
|
|
||||||
|
|
||||||
if newd == nil {
|
|
||||||
result.Error = "updateDroplet() d == nil"
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
d := me.cluster.FindDropletByUuid(newd.Uuid)
|
|
||||||
if d == nil {
|
|
||||||
result.Error = "updateDroplet() could not find uuid"
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
log.Println("found droplet to update:", newd.Uuid, newd.Hostname, newd.Cpus, newd.Memory)
|
|
||||||
|
|
||||||
if d.Hostname != newd.Hostname && newd.Hostname != "" {
|
|
||||||
d.Hostname = newd.Hostname
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if d.Cpus != newd.Cpus && newd.Cpus > 0 {
|
|
||||||
d.Cpus = newd.Cpus
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// arbitrary check. don't make vm's with less than 64 MB of RAM
|
|
||||||
// big enough most things will load with some stdout
|
|
||||||
if d.Memory != newd.Memory && newd.Memory > (64*1024*1024) {
|
|
||||||
d.Memory = newd.Memory
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if changed {
|
|
||||||
if err := me.cluster.ConfigSave(); err != nil {
|
|
||||||
log.Info("configsave error", err)
|
|
||||||
result.Error = fmt.Sprintf("%v", err)
|
|
||||||
result.State = virtpb.Event_FAIL
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Println("nothing changed in", newd.Uuid, newd.Hostname)
|
|
||||||
}
|
|
||||||
|
|
||||||
result.State = virtpb.Event_DONE
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func createDroplet(newd *virtpb.Droplet, result *virtpb.Event) error {
|
|
||||||
if newd == nil {
|
|
||||||
return fmt.Errorf("droplet protobuf == nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if newd.Uuid == "" {
|
|
||||||
newd.Uuid = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
d := me.cluster.FindDropletByUuid(newd.Uuid)
|
|
||||||
if d != nil {
|
|
||||||
return fmt.Errorf("droplet uuid already used")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("found droplet to update:", newd.Uuid, newd.Hostname, newd.Cpus, newd.Memory)
|
|
||||||
|
|
||||||
if newd.Hostname == "" {
|
|
||||||
return fmt.Errorf("Hostname can not be blank")
|
|
||||||
}
|
|
||||||
d = me.cluster.FindDropletByName(newd.Hostname)
|
|
||||||
if d != nil {
|
|
||||||
return fmt.Errorf("hostname already defined")
|
|
||||||
}
|
|
||||||
|
|
||||||
// by default, on locally imported domains, set the preferred hypervisor!
|
|
||||||
newd.LocalOnly = "yes on: " + "farm03"
|
|
||||||
|
|
||||||
newd.PreferredHypervisor = "farm03"
|
|
||||||
newd.StartState = virtpb.DropletState_OFF
|
|
||||||
|
|
||||||
newd.Current = new(virtpb.Current)
|
|
||||||
newd.Current.State = virtpb.DropletState_OFF
|
|
||||||
|
|
||||||
// create the network
|
|
||||||
if err := createNetwork(newd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the disks
|
|
||||||
if err := createDisks(newd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// append the protobuf and save it
|
|
||||||
me.cluster.AddDroplet(newd)
|
|
||||||
if err := me.cluster.ConfigSave(); err != nil {
|
|
||||||
log.Info("configsave error", err)
|
|
||||||
return fmt.Errorf("ConfigSave() error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func findDisks(d *virtpb.Droplet) error {
|
|
||||||
log.Info("need to do this")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createDisks(d *virtpb.Droplet) error {
|
|
||||||
if d.Disks != nil {
|
|
||||||
return findDisks(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
newdisk := new(virtpb.Disk)
|
|
||||||
newdisk.Filename = d.Hostname + ".qcow2"
|
|
||||||
newdisk.Filepath = "/home/nfs2"
|
|
||||||
d.Disks = append(d.Disks, newdisk)
|
|
||||||
|
|
||||||
basefile := "/home/nfs2/base2025.wit-5.qcow2"
|
|
||||||
newfile := filepath.Join(newdisk.Filepath, newdisk.Filename)
|
|
||||||
|
|
||||||
if !shell.Exists(newdisk.Filepath) {
|
|
||||||
return fmt.Errorf("disk image path missing: %s", newdisk.Filepath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !shell.Exists(basefile) {
|
|
||||||
return fmt.Errorf("basefile %s missing", basefile)
|
|
||||||
}
|
|
||||||
|
|
||||||
if shell.Exists(newfile) {
|
|
||||||
return fmt.Errorf("disk image already exists: %s", newfile)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := []string{"dd", "bs=100M", "status=progress", "oflag=dsync", "if=" + basefile, "of=" + newfile}
|
|
||||||
result := shell.RunRealtime(cmd)
|
|
||||||
if result.Exit != 0 {
|
|
||||||
return fmt.Errorf("dd to %s failed %d\n%s\n%s", newfile, result.Exit, strings.Join(result.Stdout, "\n"), strings.Join(result.Stderr, "\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createNetwork(d *virtpb.Droplet) error {
|
|
||||||
if d.Networks != nil {
|
|
||||||
// network already done
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if len(d.Networks) > 0 {
|
|
||||||
// network already done
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
n := new(virtpb.Network)
|
|
||||||
n.Mac = getNewMac()
|
|
||||||
n.Name = "worldbr"
|
|
||||||
d.Networks = append(d.Networks, n)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getNewMac() string {
|
|
||||||
// mac address map to check for duplicates
|
|
||||||
var macs map[string]string
|
|
||||||
macs = make(map[string]string)
|
|
||||||
|
|
||||||
loop := me.cluster.DropletsAll() // get the list of droplets
|
|
||||||
for loop.Scan() {
|
|
||||||
d := loop.Next()
|
|
||||||
for _, n := range d.Networks {
|
|
||||||
// log.Println("network:", n.Mac, d.Uuid, d.Hostname)
|
|
||||||
if _, ok := macs[n.Mac]; ok {
|
|
||||||
// UUID already exists
|
|
||||||
log.Info("duplicate MAC", n.Mac, macs[n.Mac])
|
|
||||||
log.Info("duplicate MAC", n.Mac, d.Hostname)
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
macs[n.Mac] = d.Hostname
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return generateMAC(macs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateMAC(macs map[string]string) string {
|
|
||||||
prefix := []byte{0x22, 0x22, 0x22}
|
|
||||||
for {
|
|
||||||
// Generate last 3 bytes randomly
|
|
||||||
suffix := make([]byte, 3)
|
|
||||||
if _, err := rand.Read(suffix); err != nil {
|
|
||||||
log.Fatalf("Failed to generate random bytes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format full MAC address
|
|
||||||
mac := fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x",
|
|
||||||
prefix[0], prefix[1], prefix[2],
|
|
||||||
suffix[0], suffix[1], suffix[2])
|
|
||||||
|
|
||||||
// Check if MAC is already used
|
|
||||||
if _, exists := macs[mac]; !exists {
|
|
||||||
log.Println("Using new MAC:", mac)
|
|
||||||
return mac
|
|
||||||
}
|
|
||||||
log.Println("MAC already defined:", mac)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
15
doGui.go
15
doGui.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
"go.wit.com/lib/protobuf/virtpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -24,6 +25,10 @@ func debug() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func doGui() {
|
func doGui() {
|
||||||
|
me.myGui = gui.New()
|
||||||
|
me.myGui.InitEmbed(resources)
|
||||||
|
me.myGui.Default()
|
||||||
|
|
||||||
mainWindow := gadgets.NewGenericWindow("Virtigo: (inventory your cluster)", "Local Cluster Settings")
|
mainWindow := gadgets.NewGenericWindow("Virtigo: (inventory your cluster)", "Local Cluster Settings")
|
||||||
mainWindow.Custom = func() {
|
mainWindow.Custom = func() {
|
||||||
log.Warn("Main window close")
|
log.Warn("Main window close")
|
||||||
|
@ -31,6 +36,10 @@ func doGui() {
|
||||||
}
|
}
|
||||||
|
|
||||||
drawWindow(mainWindow)
|
drawWindow(mainWindow)
|
||||||
|
|
||||||
|
// sits here forever
|
||||||
|
debug()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawWindow(win *gadgets.GenericWindow) {
|
func drawWindow(win *gadgets.GenericWindow) {
|
||||||
|
@ -121,10 +130,6 @@ func drawWindow(win *gadgets.GenericWindow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUptimeGui(uptime string) {
|
func updateUptimeGui(uptime string) {
|
||||||
if me.status == nil {
|
|
||||||
// gui is not initialized
|
|
||||||
return
|
|
||||||
}
|
|
||||||
me.status.SetLabel(uptime)
|
me.status.SetLabel(uptime)
|
||||||
|
|
||||||
datestamp := time.Now().Format("2006-01-02 15:04:03")
|
datestamp := time.Now().Format("2006-01-02 15:04:03")
|
||||||
|
@ -198,7 +203,7 @@ func makeEventsWindow(pb *virtpb.Events) *gadgets.GenericWindow {
|
||||||
t := pb.NewTable("test 2")
|
t := pb.NewTable("test 2")
|
||||||
t.NewUuid()
|
t.NewUuid()
|
||||||
t.SetParent(tbox)
|
t.SetParent(tbox)
|
||||||
t.AddDropletName()
|
t.AddDroplet()
|
||||||
t.AddHypervisor()
|
t.AddHypervisor()
|
||||||
t.ShowTable()
|
t.ShowTable()
|
||||||
return win
|
return win
|
||||||
|
|
12
doList.go
12
doList.go
|
@ -29,7 +29,6 @@ func doList() {
|
||||||
for c := range me.clusters.IterAll() {
|
for c := range me.clusters.IterAll() {
|
||||||
var err error
|
var err error
|
||||||
admin := new(adminT)
|
admin := new(adminT)
|
||||||
admin.cluster = new(virtpb.Cluster)
|
|
||||||
me.cmap[c] = admin
|
me.cmap[c] = admin
|
||||||
log.Info("found in the config file", c.URL[0])
|
log.Info("found in the config file", c.URL[0])
|
||||||
// a.makeClusterGroup(c)
|
// a.makeClusterGroup(c)
|
||||||
|
@ -43,24 +42,21 @@ func doList() {
|
||||||
log.Info("/DropletsPB Error:", err)
|
log.Info("/DropletsPB Error:", err)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
admin.cluster.Droplets = new(virtpb.Droplets)
|
admin.droplets = new(virtpb.Droplets)
|
||||||
if err := admin.cluster.Droplets.Unmarshal(data); err != nil {
|
if err := admin.droplets.Unmarshal(data); err != nil {
|
||||||
log.Printf("DropletsPB Response len:%d\n", len(data))
|
log.Printf("DropletsPB Response len:%d\n", len(data))
|
||||||
log.Println("droplets marshal failed", err)
|
log.Println("droplets marshal failed", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("Cluster Name: %s\n", c.Name)
|
log.Printf("Cluster Name: %s\n", c.Name)
|
||||||
log.Printf("Number of Droplets: %d\n", admin.cluster.Droplets.Len())
|
log.Printf("Number of Droplets: %d\n", admin.droplets.Len())
|
||||||
|
|
||||||
var found *virtpb.Droplets
|
var found *virtpb.Droplets
|
||||||
found = virtpb.NewDroplets()
|
found = virtpb.NewDroplets()
|
||||||
all := admin.cluster.Droplets.All()
|
all := admin.droplets.All()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
vm := all.Next()
|
vm := all.Next()
|
||||||
if vm.Current == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if argv.List.On && (vm.Current.State == virtpb.DropletState_OFF) {
|
if argv.List.On && (vm.Current.State == virtpb.DropletState_OFF) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
7
exit.go
7
exit.go
|
@ -6,7 +6,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,13 +13,13 @@ func okExit(note string) {
|
||||||
if note != "" {
|
if note != "" {
|
||||||
log.Info(ARGNAME, "exit:", note, "ok")
|
log.Info(ARGNAME, "exit:", note, "ok")
|
||||||
}
|
}
|
||||||
gui.StandardExit()
|
me.myGui.Close()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func badExit(err error) {
|
func badExit(err error) {
|
||||||
log.Info(ARGNAME, "failed: ", err)
|
log.Info(ARGNAME, "failed: ", err)
|
||||||
gui.StandardExit()
|
me.myGui.Close()
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +27,7 @@ func exit(note string, err error) {
|
||||||
if note != "" {
|
if note != "" {
|
||||||
log.Info(ARGNAME, "exit:", note, "ok")
|
log.Info(ARGNAME, "exit:", note, "ok")
|
||||||
}
|
}
|
||||||
gui.StandardExit()
|
me.myGui.Close()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
38
http.go
38
http.go
|
@ -21,8 +21,8 @@ func cleanURL(url string) string {
|
||||||
func okHandler(w http.ResponseWriter, r *http.Request) {
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var route string
|
var route string
|
||||||
route = cleanURL(r.URL.Path)
|
route = cleanURL(r.URL.Path)
|
||||||
// log.HttpMode(w)
|
log.HttpMode(w)
|
||||||
// defer log.HttpMode(nil)
|
defer log.HttpMode(nil)
|
||||||
|
|
||||||
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,7 +31,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
if route == "/uptime" {
|
if route == "/uptime" {
|
||||||
ok, s := uptimeCheck()
|
ok, s := uptimeCheck()
|
||||||
fmt.Fprintln(w, s)
|
fmt.Fprint(w, s)
|
||||||
// log.Info(s)
|
// log.Info(s)
|
||||||
updateUptimeGui(s)
|
updateUptimeGui(s)
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -70,24 +70,26 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/event" {
|
if route == "/start" {
|
||||||
var e *virtpb.Event
|
hostname := r.URL.Query().Get("hostname")
|
||||||
e = new(virtpb.Event)
|
if hostname == "" {
|
||||||
if err := e.Unmarshal(msg); err != nil {
|
log.Warn("start failed. hostname is blank", cleanURL(r.URL.Path))
|
||||||
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
|
|
||||||
log.Info("error =", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("/event proto.Unmarshal() worked on msg len", len(msg), "hostname =", e.DropletUuid)
|
log.Warn("hostname is", hostname)
|
||||||
result := doEvent(e)
|
|
||||||
data, err := result.Marshal()
|
// log.Warn("Handling URL:", tmp, "start droplet", start)
|
||||||
if err != nil {
|
result, err := Start(hostname)
|
||||||
log.Info("/event marshal failed", err, "len(data) =", len(data))
|
if err == nil {
|
||||||
fmt.Fprintln(w, "/event failed", err)
|
log.Info(result)
|
||||||
return
|
log.Info(hostname, "started output ok")
|
||||||
|
log.Info(hostname, "need to parse the output here")
|
||||||
|
log.Info(hostname, "todo: switch to protobuf here")
|
||||||
|
} else {
|
||||||
|
log.Info(result)
|
||||||
|
log.Info(err)
|
||||||
|
log.Info(hostname, "start failed")
|
||||||
}
|
}
|
||||||
w.Write(data)
|
|
||||||
// fmt.Fprintln("droplet marshal failed", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
174
main.go
174
main.go
|
@ -4,14 +4,17 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/lib/gui/prep"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
"go.wit.com/lib/protobuf/virtpb"
|
||||||
|
"go.wit.com/lib/virtigolib"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,10 +29,18 @@ var resources embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
me = new(virtigoT)
|
me = new(virtigoT)
|
||||||
prep.Bash(ARGNAME, argv.DoAutoComplete) // this line should be: prep.Bash(argv)
|
gui.InitArg()
|
||||||
me.myGui = prep.Gui() // prepares the GUI package for go-args
|
|
||||||
me.pp = arg.MustParse(&argv)
|
me.pp = arg.MustParse(&argv)
|
||||||
|
|
||||||
|
if argv.Bash {
|
||||||
|
argv.doBash()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if len(argv.BashAuto) != 0 {
|
||||||
|
argv.doBashAuto()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if me.pp == nil {
|
if me.pp == nil {
|
||||||
me.pp.WriteHelp(os.Stdout)
|
me.pp.WriteHelp(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -56,23 +67,22 @@ func main() {
|
||||||
exit(doDroplet())
|
exit(doDroplet())
|
||||||
}
|
}
|
||||||
|
|
||||||
me.myGui.Start() // loads the GUI toolkit
|
|
||||||
|
|
||||||
if argv.Admin {
|
if argv.Admin {
|
||||||
err := me.clusters.ConfigLoad()
|
err := me.clusters.ConfigLoad()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badExit(err)
|
badExit(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
doAdminGui()
|
me.admin = new(adminT)
|
||||||
|
me.admin.doAdminGui()
|
||||||
okExit("admin close")
|
okExit("admin close")
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Server != "" {
|
if argv.Server != "" {
|
||||||
log.Info("start admin interface")
|
log.Info("start admin interface")
|
||||||
admin := new(adminT)
|
me.admin = new(adminT)
|
||||||
var err error
|
var err error
|
||||||
admin.url, err = url.Parse(argv.Server)
|
me.admin.url, err = url.Parse(argv.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badExit(err)
|
badExit(err)
|
||||||
}
|
}
|
||||||
|
@ -88,17 +98,149 @@ func main() {
|
||||||
badExit(err)
|
badExit(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
admin.doAdminGui()
|
me.admin.doAdminGui()
|
||||||
okExit("admin close")
|
okExit("admin close")
|
||||||
}
|
}
|
||||||
|
os.Exit(-1)
|
||||||
|
|
||||||
if argv.Daemon {
|
// set defaults
|
||||||
if err := doDaemon(); err != nil {
|
me.unstable = time.Now() // initialize the grid as unstable
|
||||||
badExit(err)
|
me.changed = false
|
||||||
}
|
me.hmap = make(map[*virtpb.Hypervisor]*HyperT)
|
||||||
okExit("")
|
|
||||||
|
// how long a droplet can be missing until it's declared dead
|
||||||
|
me.unstableTimeout = 17 * time.Second
|
||||||
|
me.missingDropletTimeout = time.Minute // not sure the difference between these values
|
||||||
|
|
||||||
|
// how often to poll the hypervisors
|
||||||
|
me.hyperPollDelay = 5 * time.Second
|
||||||
|
|
||||||
|
// how long the cluster must be stable before new droplets can be started
|
||||||
|
me.clusterStableDuration = 37 * time.Second
|
||||||
|
|
||||||
|
me.cluster = virtpb.InitCluster()
|
||||||
|
if err := me.cluster.ConfigLoad(); err != nil {
|
||||||
|
log.Info("config load error", err)
|
||||||
|
log.Info("")
|
||||||
|
log.Info("You have never run this before")
|
||||||
|
log.Info("init example cloud here")
|
||||||
|
log.Sleep(2)
|
||||||
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
doGui() // start making our forge GUI
|
loop := me.cluster.DropletsAll() // get the list of droplets
|
||||||
startHTTP() // sit here forever
|
for loop.Scan() {
|
||||||
|
d := loop.Next()
|
||||||
|
if d == nil {
|
||||||
|
fmt.Println("d == nil")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
fmt.Println("Droplet UUID:", d.Uuid)
|
||||||
|
if d.Current == nil {
|
||||||
|
d.Current = new(virtpb.Current)
|
||||||
|
}
|
||||||
|
d.SetState(virtpb.DropletState_OFF)
|
||||||
|
log.Info("droplet", d.Hostname)
|
||||||
|
}
|
||||||
|
hmm := "pihole.wit.com"
|
||||||
|
d := me.cluster.FindDropletByName(hmm)
|
||||||
|
if d == nil {
|
||||||
|
log.Info("did not find found droplet", hmm)
|
||||||
|
} else {
|
||||||
|
log.Info("found droplet", d.Hostname, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
var newEvents []*virtpb.Event
|
||||||
|
|
||||||
|
// sanity check the cluster & droplets
|
||||||
|
if _, _, err := ValidateDroplets(); err != nil {
|
||||||
|
log.Info("todo: add flag to ignore. for now, fix problems in the config file.")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
newe, err := ValidateDiskFilenames()
|
||||||
|
if err != nil {
|
||||||
|
log.Info(err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
// this is a new droplet. add it to the cluster
|
||||||
|
for _, e := range newe {
|
||||||
|
newEvents = append(newEvents, e)
|
||||||
|
}
|
||||||
|
ValidateUniqueFilenames()
|
||||||
|
|
||||||
|
for _, filename := range argv.Xml {
|
||||||
|
domcfg, err := virtigolib.ReadXml(filename)
|
||||||
|
if err != nil {
|
||||||
|
// parsing the libvirt xml file failed
|
||||||
|
log.Info("error:", filename, err)
|
||||||
|
log.Info("readXml() error", filename)
|
||||||
|
log.Info("readXml() error", err)
|
||||||
|
log.Info("libvirt XML will have to be fixed by hand")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
// this is a new droplet. add it to the cluster
|
||||||
|
log.Info("Add XML Droplet here", domcfg.Name)
|
||||||
|
_, newe, err := virtigolib.AddDomainDroplet(me.cluster, domcfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("addDomainDroplet() error", filename)
|
||||||
|
log.Info("addDomainDroplet() error", err)
|
||||||
|
log.Info("libvirt XML will have to be fixed by hand")
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
for _, e := range newe {
|
||||||
|
newEvents = append(newEvents, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, e := range newEvents {
|
||||||
|
log.Info(i, "Event:", e.Droplet, e.FieldName, "orig:", e.OrigVal, "new:", e.NewVal)
|
||||||
|
me.changed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if me.changed {
|
||||||
|
if err := me.cluster.ConfigSave(); err != nil {
|
||||||
|
log.Info("configsave error", err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
log.Info("XML changes saved in protobuf config")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if len(argv.Xml) != 0 {
|
||||||
|
log.Info("No XML changes found")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize each hypervisor
|
||||||
|
for _, pbh := range me.cluster.H.Hypervisors {
|
||||||
|
// this is a new unknown droplet (not in the config file)
|
||||||
|
var h *HyperT
|
||||||
|
h = new(HyperT)
|
||||||
|
h.pb = pbh
|
||||||
|
h.lastDroplets = make(map[string]time.Time)
|
||||||
|
h.lastpoll = time.Now()
|
||||||
|
|
||||||
|
me.hmap[pbh] = h
|
||||||
|
me.hypers = append(me.hypers, h)
|
||||||
|
log.Log(EVENT, "config new hypervisors", h.pb.Hostname)
|
||||||
|
}
|
||||||
|
|
||||||
|
// start the watchdog polling for each hypervisor
|
||||||
|
for _, h := range me.hypers {
|
||||||
|
log.Info("starting polling on", h.pb.Hostname)
|
||||||
|
|
||||||
|
// start a watchdog on each hypervisor
|
||||||
|
go h.NewWatchdog()
|
||||||
|
}
|
||||||
|
|
||||||
|
var cloud *virtigolib.CloudManager
|
||||||
|
cloud = virtigolib.NewCloud()
|
||||||
|
found, _ := cloud.FindDropletByName("www.wit.com")
|
||||||
|
if found == nil {
|
||||||
|
log.Info("d == nil")
|
||||||
|
} else {
|
||||||
|
log.Info("d == ", found)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sit here
|
||||||
|
go startHTTP()
|
||||||
|
doGui()
|
||||||
}
|
}
|
||||||
|
|
20
start.go
20
start.go
|
@ -29,7 +29,7 @@ func isClusterStable() (string, error) {
|
||||||
|
|
||||||
// for now, because sometimes this should write to stdout and
|
// for now, because sometimes this should write to stdout and
|
||||||
// sometimes to http socket, it returns a string
|
// sometimes to http socket, it returns a string
|
||||||
func Start(id string) (string, error) {
|
func Start(name string) (string, error) {
|
||||||
var result string
|
var result string
|
||||||
|
|
||||||
if s, err := isClusterStable(); err != nil {
|
if s, err := isClusterStable(); err != nil {
|
||||||
|
@ -38,9 +38,9 @@ func Start(id string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup the droplet by name
|
// lookup the droplet by name
|
||||||
d := me.cluster.FindDropletByUuid(id)
|
d := me.cluster.FindDropletByName(name)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
result = "can't start unknown droplet: " + id
|
result = "can't start unknown droplet: " + name
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +51,6 @@ func Start(id string) (string, error) {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Current == nil {
|
|
||||||
d.Current = new(virtpb.Current)
|
|
||||||
}
|
|
||||||
|
|
||||||
// is the droplet already on?
|
// is the droplet already on?
|
||||||
if d.Current.State == virtpb.DropletState_ON {
|
if d.Current.State == virtpb.DropletState_ON {
|
||||||
result = "EVENT start droplet " + d.Hostname + " is already ON"
|
result = "EVENT start droplet " + d.Hostname + " is already ON"
|
||||||
|
@ -70,12 +66,12 @@ func Start(id string) (string, error) {
|
||||||
if ok {
|
if ok {
|
||||||
return result + b, nil
|
return result + b, nil
|
||||||
}
|
}
|
||||||
return result + b, errors.New("start " + d.Hostname + " on hypervisor " + h.pb.Hostname)
|
return result + b, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip hypervisors marked inactive
|
// skip hypervisors marked inactive
|
||||||
if h.pb.Active != true {
|
if h.pb.Active != true {
|
||||||
result += fmt.Sprintln("hypervisor is inactive:", d.Hostname, "for", h.pb.Hostname, h.pb.Active)
|
result += fmt.Sprintln("hypervisor is inactive:", name, "for", h.pb.Hostname, h.pb.Active)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +82,10 @@ func Start(id string) (string, error) {
|
||||||
if ok {
|
if ok {
|
||||||
return result + b, nil
|
return result + b, nil
|
||||||
}
|
}
|
||||||
return result + b, errors.New("start " + d.Hostname + " on hypervisor " + h.pb.Hostname)
|
return result + b, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
result += fmt.Sprintln("hypervisor ready:", d.Hostname, "for", h.pb.Hostname, h.pb.Active)
|
result += fmt.Sprintln("hypervisor ready:", name, "for", h.pb.Hostname, h.pb.Active)
|
||||||
pool = append(pool, h)
|
pool = append(pool, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,5 +106,5 @@ func Start(id string) (string, error) {
|
||||||
if ok {
|
if ok {
|
||||||
return result + output, nil
|
return result + output, nil
|
||||||
}
|
}
|
||||||
return result + output, errors.New("start " + d.Hostname + " on hypervisor " + h.pb.Hostname)
|
return result + output, errors.New("start " + name + " on hypervisor " + h.pb.Hostname)
|
||||||
}
|
}
|
||||||
|
|
13
structs.go
13
structs.go
|
@ -7,7 +7,6 @@ import (
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/gui/prep"
|
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
"go.wit.com/lib/protobuf/virtpb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +25,8 @@ func (b *virtigoT) Enable() {
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type virtigoT struct {
|
type virtigoT struct {
|
||||||
pp *arg.Parser // go-arg parser
|
pp *arg.Parser // go-arg parser
|
||||||
myGui *prep.GuiPrep // the gui toolkit handle
|
cluster *virtpb.OldCluster // basic cluster settings
|
||||||
|
myGui *gui.Node // the gui toolkit handle
|
||||||
e *virtpb.Events // virt protobuf events
|
e *virtpb.Events // virt protobuf events
|
||||||
hmap map[*virtpb.Hypervisor]*HyperT // map to the local struct
|
hmap map[*virtpb.Hypervisor]*HyperT // map to the local struct
|
||||||
names []string // ?
|
names []string // ?
|
||||||
|
@ -40,16 +40,17 @@ type virtigoT struct {
|
||||||
missingDropletTimeout time.Duration // how long a droplet can be missing for
|
missingDropletTimeout time.Duration // how long a droplet can be missing for
|
||||||
status *gui.Node // the cluster status
|
status *gui.Node // the cluster status
|
||||||
lastuptime *gui.Node // the last time uptime was checked by Kuma
|
lastuptime *gui.Node // the last time uptime was checked by Kuma
|
||||||
|
admin *adminT // the admin struct
|
||||||
clusters *virtpb.Clusters // clusters protobuf
|
clusters *virtpb.Clusters // clusters protobuf
|
||||||
cmap map[*virtpb.Cluster]*adminT // map to local GUI objects and the protobuf
|
cmap map[*virtpb.Cluster]*adminT // map to local GUI objects and the protobuf
|
||||||
gwin *gadgets.GenericWindow // main window
|
gwin *gadgets.GenericWindow // main window
|
||||||
cluster *virtpb.OldCluster // basic cluster settings
|
|
||||||
// admin *adminT // the admin struct
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cluster "admin" mode
|
|
||||||
type adminT struct {
|
type adminT struct {
|
||||||
cluster *virtpb.Cluster // the cluster protobuf
|
// admin mode
|
||||||
|
droplets *virtpb.Droplets // your droplets
|
||||||
|
hypervisors *virtpb.Hypervisors // yep
|
||||||
|
events *virtpb.Events // yep
|
||||||
uptime *gui.Node // the uptime message
|
uptime *gui.Node // the uptime message
|
||||||
dwin *stdDropletTableWin // the droplet window
|
dwin *stdDropletTableWin // the droplet window
|
||||||
hwin *stdHypervisorTableWin // the hypervisor window
|
hwin *stdHypervisorTableWin // the hypervisor window
|
||||||
|
|
35
validate.go
35
validate.go
|
@ -15,6 +15,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -162,6 +163,40 @@ func ValidateDiskFilenames() ([]*virtpb.Event, error) {
|
||||||
return alle, nil
|
return alle, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getNewMac() string {
|
||||||
|
// mac address map to check for duplicates
|
||||||
|
var macs map[string]string
|
||||||
|
macs = make(map[string]string)
|
||||||
|
|
||||||
|
loop := me.cluster.DropletsAll() // get the list of droplets
|
||||||
|
for loop.Scan() {
|
||||||
|
d := loop.Next()
|
||||||
|
for _, n := range d.Networks {
|
||||||
|
// log.Println("network:", n.Mac, d.Uuid, d.Hostname)
|
||||||
|
if _, ok := macs[n.Mac]; ok {
|
||||||
|
// UUID already exists
|
||||||
|
log.Info("duplicate MAC", n.Mac, macs[n.Mac])
|
||||||
|
log.Info("duplicate MAC", n.Mac, d.Hostname)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
macs[n.Mac] = d.Hostname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var i int = 9
|
||||||
|
var mac string
|
||||||
|
for {
|
||||||
|
mac = fmt.Sprintf("22:22:22:22:22:%02d", i)
|
||||||
|
if _, ok := macs[mac]; ok {
|
||||||
|
log.Info("MAC already defined", mac, macs[mac])
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.Info("using new MAC:", mac)
|
||||||
|
return mac
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// consistancy check. run on a regular basis
|
// consistancy check. run on a regular basis
|
||||||
//
|
//
|
||||||
// runs on startup. dies if there are duplicates
|
// runs on startup. dies if there are duplicates
|
||||||
|
|
|
@ -31,3 +31,25 @@ func createWindow() *gadgets.GenericWindow {
|
||||||
|
|
||||||
return createWindow
|
return createWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func editDropletWindow() *gadgets.GenericWindow {
|
||||||
|
editDropletWindow := gadgets.NewGenericWindow("Create Droplet", "settings")
|
||||||
|
editDropletWindow.Custom = func() {
|
||||||
|
log.Warn("create window close")
|
||||||
|
}
|
||||||
|
|
||||||
|
grid := editDropletWindow.Group.RawGrid()
|
||||||
|
|
||||||
|
gadgets.NewBasicEntry(grid, "memory")
|
||||||
|
grid.NextRow()
|
||||||
|
|
||||||
|
grid.NewLabel("name")
|
||||||
|
grid.NewTextbox("something")
|
||||||
|
grid.NextRow()
|
||||||
|
|
||||||
|
grid.NewButton("Start", func() {
|
||||||
|
log.Info("make a box")
|
||||||
|
})
|
||||||
|
|
||||||
|
return editDropletWindow
|
||||||
|
}
|
||||||
|
|
|
@ -1,121 +0,0 @@
|
||||||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
||||||
// Use of this source code is governed by the GPL 3.0
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
// An app to submit patches for the 30 GO GUI repos
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"go.wit.com/gui"
|
|
||||||
"go.wit.com/lib/gadgets"
|
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (admin *adminT) createDropletWindow() *gadgets.GenericWindow {
|
|
||||||
d := new(virtpb.Droplet)
|
|
||||||
|
|
||||||
win := gadgets.NewGenericWindow("Create Droplet "+d.Hostname, "settings")
|
|
||||||
win.Custom = func() {
|
|
||||||
log.Warn("edit window close")
|
|
||||||
}
|
|
||||||
|
|
||||||
grid := win.Group.RawGrid()
|
|
||||||
|
|
||||||
var save *gui.Node
|
|
||||||
|
|
||||||
grid.NewLabel("name")
|
|
||||||
name := grid.NewTextbox("new2.wit.com")
|
|
||||||
d.Hostname = "new2.wit.com"
|
|
||||||
name.SetText(d.Hostname)
|
|
||||||
name.Custom = func() {
|
|
||||||
if d.Hostname == name.String() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.Hostname = name.String()
|
|
||||||
log.Info("changed droplet name to", d.Hostname)
|
|
||||||
save.Enable()
|
|
||||||
}
|
|
||||||
grid.NextRow()
|
|
||||||
|
|
||||||
mem := gadgets.NewBasicEntry(grid, "memory (GB)")
|
|
||||||
mem.SetText("16")
|
|
||||||
d.Memory = int64(16 * 1024 * 2024 * 1024)
|
|
||||||
grid.NextRow()
|
|
||||||
mem.Custom = func() {
|
|
||||||
newmem, err := strconv.Atoi(mem.String())
|
|
||||||
if err != nil {
|
|
||||||
log.Info("mem value error", mem.String(), err)
|
|
||||||
mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if newmem < 1 {
|
|
||||||
log.Info("mem can not be < 1")
|
|
||||||
mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.Memory = int64(newmem * (1024 * 2024 * 1024))
|
|
||||||
log.Info("changed mem value. new val =", d.Memory)
|
|
||||||
|
|
||||||
save.Enable()
|
|
||||||
}
|
|
||||||
grid.NextRow() // each entry is on it's own row
|
|
||||||
|
|
||||||
cpus := gadgets.NewBasicEntry(grid, "cpus")
|
|
||||||
cpus.SetText("4")
|
|
||||||
d.Cpus = int64(4)
|
|
||||||
cpus.Custom = func() {
|
|
||||||
newcpu, err := strconv.Atoi(cpus.String())
|
|
||||||
if err != nil {
|
|
||||||
log.Info("cpus value error", cpus.String(), err)
|
|
||||||
cpus.SetText(fmt.Sprintf("%d", d.Cpus))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if newcpu < 1 {
|
|
||||||
log.Info("cpus can not be < 1")
|
|
||||||
cpus.SetText(fmt.Sprintf("%d", d.Cpus))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.Cpus = int64(newcpu)
|
|
||||||
log.Info("changed cpus value. new val =", d.Cpus)
|
|
||||||
|
|
||||||
save.Enable()
|
|
||||||
}
|
|
||||||
grid.NextRow() // each entry is on it's own row
|
|
||||||
|
|
||||||
/*
|
|
||||||
save = grid.NewButton("postEvent() EDIT", func() {
|
|
||||||
log.Info("save droplet changes here")
|
|
||||||
|
|
||||||
e := new(virtpb.Event)
|
|
||||||
e.Etype = virtpb.EventType_EDIT
|
|
||||||
e.Droplet = d
|
|
||||||
|
|
||||||
if err := admin.postEvent(e); err != nil {
|
|
||||||
log.Info("event edit err", err)
|
|
||||||
} else {
|
|
||||||
log.Info("admin.postEvent() worked (?)")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
save = grid.NewButton("Create", func() {
|
|
||||||
log.Info("save droplet changes here")
|
|
||||||
|
|
||||||
e := new(virtpb.Event)
|
|
||||||
e.Etype = virtpb.EventType_ADD
|
|
||||||
e.Droplet = d
|
|
||||||
|
|
||||||
if err := admin.postEvent(e); err != nil {
|
|
||||||
log.Info("event edit err", err)
|
|
||||||
} else {
|
|
||||||
log.Info("admin.postEvent() worked (?)")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// save.Disable()
|
|
||||||
return win
|
|
||||||
}
|
|
|
@ -1,125 +0,0 @@
|
||||||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
||||||
// Use of this source code is governed by the GPL 3.0
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
// An app to submit patches for the 30 GO GUI repos
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"go.wit.com/gui"
|
|
||||||
"go.wit.com/lib/gadgets"
|
|
||||||
"go.wit.com/lib/protobuf/virtpb"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (admin *adminT) editDropletWindow(d *virtpb.Droplet) *gadgets.GenericWindow {
|
|
||||||
win := gadgets.NewGenericWindow("Edit Droplet "+d.Hostname, "settings")
|
|
||||||
win.Custom = func() {
|
|
||||||
log.Warn("edit window close")
|
|
||||||
}
|
|
||||||
|
|
||||||
grid := win.Group.RawGrid()
|
|
||||||
|
|
||||||
var save *gui.Node
|
|
||||||
|
|
||||||
grid.NewLabel("name")
|
|
||||||
name := grid.NewTextbox("something")
|
|
||||||
name.SetText(d.Hostname)
|
|
||||||
name.Custom = func() {
|
|
||||||
if d.Hostname == name.String() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.Hostname = name.String()
|
|
||||||
log.Info("changed droplet name to", d.Hostname)
|
|
||||||
save.Enable()
|
|
||||||
}
|
|
||||||
grid.NextRow()
|
|
||||||
|
|
||||||
mem := gadgets.NewBasicEntry(grid, "memory (GB)")
|
|
||||||
mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
|
|
||||||
grid.NextRow()
|
|
||||||
mem.Custom = func() {
|
|
||||||
newmem, err := strconv.Atoi(mem.String())
|
|
||||||
if err != nil {
|
|
||||||
log.Info("mem value error", mem.String(), err)
|
|
||||||
mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if newmem < 1 {
|
|
||||||
log.Info("mem can not be < 1")
|
|
||||||
mem.SetText(fmt.Sprintf("%d", d.Memory/(1024*1024*1024)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.Memory = int64(newmem * (1024 * 2024 * 1024))
|
|
||||||
log.Info("changed mem value. new val =", d.Memory)
|
|
||||||
|
|
||||||
save.Enable()
|
|
||||||
}
|
|
||||||
|
|
||||||
cpus := gadgets.NewBasicEntry(grid, "cpus")
|
|
||||||
cpus.SetText(fmt.Sprintf("%d", d.Cpus))
|
|
||||||
grid.NextRow()
|
|
||||||
cpus.Custom = func() {
|
|
||||||
newcpu, err := strconv.Atoi(cpus.String())
|
|
||||||
if err != nil {
|
|
||||||
log.Info("cpus value error", cpus.String(), err)
|
|
||||||
cpus.SetText(fmt.Sprintf("%d", d.Cpus))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if newcpu < 1 {
|
|
||||||
log.Info("cpus can not be < 1")
|
|
||||||
cpus.SetText(fmt.Sprintf("%d", d.Cpus))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.Cpus = int64(newcpu)
|
|
||||||
log.Info("changed cpus value. new val =", d.Cpus)
|
|
||||||
|
|
||||||
save.Enable()
|
|
||||||
}
|
|
||||||
|
|
||||||
grid.NewLabel("hypervisor")
|
|
||||||
hyper := grid.NewDropdown()
|
|
||||||
hyper.AddText("farm03")
|
|
||||||
hyper.AddText("farm04")
|
|
||||||
hyper.AddText("farm05")
|
|
||||||
if d.Current != nil {
|
|
||||||
hyper.SetText(d.Current.Hypervisor)
|
|
||||||
} else {
|
|
||||||
hyper.SetText("farm03")
|
|
||||||
}
|
|
||||||
grid.NextRow()
|
|
||||||
|
|
||||||
grid.NewButton("Start", func() {
|
|
||||||
log.Info("make a box")
|
|
||||||
})
|
|
||||||
|
|
||||||
save = grid.NewButton("save", func() {
|
|
||||||
log.Info("save droplet changes here")
|
|
||||||
|
|
||||||
e := new(virtpb.Event)
|
|
||||||
e.Etype = virtpb.EventType_EDIT
|
|
||||||
e.Droplet = d
|
|
||||||
/*
|
|
||||||
e.Droplet = new(virtpb.Droplet)
|
|
||||||
e.Droplet.Uuid = d.Uuid
|
|
||||||
e.Droplet.Cpus = 4
|
|
||||||
e.Droplet.Memory = 8 * (1024 * 1024 * 1024)
|
|
||||||
e.Droplet.Hostname = name.String()
|
|
||||||
*/
|
|
||||||
|
|
||||||
if err := admin.postEvent(e); err != nil {
|
|
||||||
log.Info("event edit err", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
save.Disable()
|
|
||||||
|
|
||||||
grid.NewButton("dump", func() {
|
|
||||||
t := d.FormatTEXT()
|
|
||||||
log.Info(t)
|
|
||||||
})
|
|
||||||
|
|
||||||
return win
|
|
||||||
}
|
|
|
@ -23,7 +23,6 @@ type stdDropletTableWin struct {
|
||||||
TB *virtpb.DropletsTable // the gui table buffer
|
TB *virtpb.DropletsTable // the gui table buffer
|
||||||
update bool // if the window should be updated
|
update bool // if the window should be updated
|
||||||
Close func() // this function is called when the window is closed
|
Close func() // this function is called when the window is closed
|
||||||
admin *adminT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *stdDropletTableWin) Toggle() {
|
func (w *stdDropletTableWin) Toggle() {
|
||||||
|
@ -36,9 +35,8 @@ func (w *stdDropletTableWin) Toggle() {
|
||||||
w.win.Toggle()
|
w.win.Toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDropletsWindow(admin *adminT) *stdDropletTableWin {
|
func newDropletsWindow() *stdDropletTableWin {
|
||||||
dwin := new(stdDropletTableWin)
|
dwin := new(stdDropletTableWin)
|
||||||
dwin.admin = admin
|
|
||||||
dwin.win = gadgets.NewGenericWindow("virtigo current droplets", "Options")
|
dwin.win = gadgets.NewGenericWindow("virtigo current droplets", "Options")
|
||||||
dwin.win.Custom = func() {
|
dwin.win.Custom = func() {
|
||||||
log.Info("test delete window here")
|
log.Info("test delete window here")
|
||||||
|
@ -48,7 +46,7 @@ func newDropletsWindow(admin *adminT) *stdDropletTableWin {
|
||||||
grid.NewButton("Active", func() {
|
grid.NewButton("Active", func() {
|
||||||
var found *virtpb.Droplets
|
var found *virtpb.Droplets
|
||||||
found = virtpb.NewDroplets()
|
found = virtpb.NewDroplets()
|
||||||
all := admin.cluster.Droplets.All()
|
all := me.admin.droplets.All()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
vm := all.Next()
|
vm := all.Next()
|
||||||
if vm.Current.State != virtpb.DropletState_ON {
|
if vm.Current.State != virtpb.DropletState_ON {
|
||||||
|
@ -62,7 +60,7 @@ func newDropletsWindow(admin *adminT) *stdDropletTableWin {
|
||||||
grid.NewButton("Inactive", func() {
|
grid.NewButton("Inactive", func() {
|
||||||
var found *virtpb.Droplets
|
var found *virtpb.Droplets
|
||||||
found = virtpb.NewDroplets()
|
found = virtpb.NewDroplets()
|
||||||
all := admin.cluster.Droplets.All()
|
all := me.admin.droplets.All()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
vm := all.Next()
|
vm := all.Next()
|
||||||
if vm.Current.State == virtpb.DropletState_ON {
|
if vm.Current.State == virtpb.DropletState_ON {
|
||||||
|
@ -73,16 +71,65 @@ func newDropletsWindow(admin *adminT) *stdDropletTableWin {
|
||||||
dwin.doInactiveDroplets(found)
|
dwin.doInactiveDroplets(found)
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NewButton("Create", func() {
|
|
||||||
log.Info("create droplet here")
|
|
||||||
admin.createDropletWindow()
|
|
||||||
})
|
|
||||||
|
|
||||||
// make a box at the bottom of the window for the protobuf table
|
// make a box at the bottom of the window for the protobuf table
|
||||||
dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX")
|
dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX")
|
||||||
return dwin
|
return dwin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
func makeWindownDropletsPB(pb *virtpb.Droplets) *stdDropletTableWin {
|
||||||
|
dwin := new(stdDropletTableWin)
|
||||||
|
dwin.win = gadgets.NewGenericWindow("virtigo current droplets", "")
|
||||||
|
dwin.win.Custom = func() {
|
||||||
|
log.Info("test delete window here")
|
||||||
|
}
|
||||||
|
|
||||||
|
// make a box at the bottom of the window for the protobuf table
|
||||||
|
dwin.box = dwin.win.Bottom.Box().SetProgName("TBOX")
|
||||||
|
|
||||||
|
dwin.doDropletsTable(pb)
|
||||||
|
|
||||||
|
return dwin
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
func (dwin *stdDropletTableWin) doDropletsTable(currentDroplets *virtpb.Droplets) {
|
||||||
|
dwin.Lock()
|
||||||
|
defer dwin.Unlock()
|
||||||
|
if dwin.TB != nil {
|
||||||
|
dwin.TB.Delete()
|
||||||
|
dwin.TB = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// display the protobuf
|
||||||
|
dwin.TB = addDropletsPB(dwin.box, currentDroplets)
|
||||||
|
f := func(e *virtpb.Droplet) {
|
||||||
|
log.Info("Triggered. do something here", e.Hostname)
|
||||||
|
// m.Enabled = true
|
||||||
|
}
|
||||||
|
dwin.TB.Custom(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addDropletsPB(tbox *gui.Node, pb *virtpb.Droplets) *virtpb.DropletsTable {
|
||||||
|
t := pb.NewTable("DropletsPB")
|
||||||
|
t.NewUuid()
|
||||||
|
t.SetParent(tbox)
|
||||||
|
|
||||||
|
vp := t.AddButtonFunc("start", func(p *virtpb.Droplet) string {
|
||||||
|
return "poweron"
|
||||||
|
})
|
||||||
|
vp.Custom = func(d *virtpb.Droplet) {
|
||||||
|
log.Info("power on the droplet here:", d.Hostname)
|
||||||
|
}
|
||||||
|
t.AddHostname()
|
||||||
|
t.AddMemory()
|
||||||
|
t.AddCpus()
|
||||||
|
t.ShowTable()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// default window for active running droplets
|
// default window for active running droplets
|
||||||
func (dw *stdDropletTableWin) doInactiveDroplets(pb *virtpb.Droplets) {
|
func (dw *stdDropletTableWin) doInactiveDroplets(pb *virtpb.Droplets) {
|
||||||
dw.Lock()
|
dw.Lock()
|
||||||
|
@ -100,37 +147,32 @@ func (dw *stdDropletTableWin) doInactiveDroplets(pb *virtpb.Droplets) {
|
||||||
t.NewUuid()
|
t.NewUuid()
|
||||||
t.SetParent(dw.box)
|
t.SetParent(dw.box)
|
||||||
|
|
||||||
dropedit := t.AddButtonFunc("Edit", func(d *virtpb.Droplet) string {
|
// pick the columns
|
||||||
return "edit"
|
// t.AddHostname()
|
||||||
})
|
|
||||||
dropedit.Custom = func(d *virtpb.Droplet) {
|
|
||||||
log.Info("edit droplet here", d.Hostname)
|
|
||||||
dw.admin.editDropletWindow(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
dropon := t.AddButtonFunc("Start", func(d *virtpb.Droplet) string {
|
dropon := t.AddButtonFunc("Start", func(d *virtpb.Droplet) string {
|
||||||
return "poweron"
|
return "poweron"
|
||||||
})
|
})
|
||||||
dropon.Custom = func(d *virtpb.Droplet) {
|
dropon.Custom = func(d *virtpb.Droplet) {
|
||||||
log.Info("start droplet here", d.Hostname)
|
log.Info("start droplet here", d.Hostname)
|
||||||
log.Info("should start droplet here")
|
|
||||||
log.Info(d.SprintHeader())
|
|
||||||
e := new(virtpb.Event)
|
|
||||||
e.Etype = virtpb.EventType_POWERON
|
|
||||||
e.DropletUuid = d.Uuid
|
|
||||||
|
|
||||||
if err := dw.admin.postEvent(e); err != nil {
|
|
||||||
log.Info("droplet start err", err)
|
|
||||||
}
|
}
|
||||||
}
|
/*
|
||||||
|
t.AddHostname()
|
||||||
|
t.AddStringFunc("location", func(d *virtpb.Droplet) string {
|
||||||
|
return d.Current.Hypervisor
|
||||||
|
})
|
||||||
|
*/
|
||||||
vp := t.AddButtonFunc("Verify Config", func(p *virtpb.Droplet) string {
|
vp := t.AddButtonFunc("Verify Config", func(p *virtpb.Droplet) string {
|
||||||
return p.Hostname
|
return p.Hostname
|
||||||
})
|
})
|
||||||
vp.Custom = func(d *virtpb.Droplet) {
|
vp.Custom = func(d *virtpb.Droplet) {
|
||||||
log.Info("open config window", d.Hostname)
|
log.Info("open config window", d.Hostname)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
t.AddHostname()
|
||||||
|
t.AddStringFunc("location", func(d *virtpb.Droplet) string {
|
||||||
|
return d.Current.Hypervisor
|
||||||
|
})
|
||||||
|
*/
|
||||||
t.AddMemory()
|
t.AddMemory()
|
||||||
t.AddCpus()
|
t.AddCpus()
|
||||||
|
|
||||||
|
@ -178,15 +220,7 @@ func (dw *stdDropletTableWin) doActiveDroplets(pb *virtpb.Droplets) {
|
||||||
log.Info("data", string(data), "err =", err)
|
log.Info("data", string(data), "err =", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.AddHostname()
|
t.AddHostname()
|
||||||
vp := t.AddButtonFunc("Hostname", func(p *virtpb.Droplet) string {
|
|
||||||
return p.Hostname
|
|
||||||
})
|
|
||||||
vp.Custom = func(d *virtpb.Droplet) {
|
|
||||||
log.Info("edit droplet here", d.Hostname)
|
|
||||||
dw.admin.editDropletWindow(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.AddStringFunc("location", func(d *virtpb.Droplet) string {
|
t.AddStringFunc("location", func(d *virtpb.Droplet) string {
|
||||||
return d.Current.Hypervisor
|
return d.Current.Hypervisor
|
||||||
})
|
})
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (dw *stdEventTableWin) doStdEvents(pb *virtpb.Events) {
|
||||||
t.SetParent(dw.box)
|
t.SetParent(dw.box)
|
||||||
|
|
||||||
// pick the columns
|
// pick the columns
|
||||||
t.AddDropletName()
|
t.AddDroplet()
|
||||||
t.AddDropletUuid()
|
t.AddDropletUuid()
|
||||||
t.AddHypervisor()
|
t.AddHypervisor()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue