the beginning of something
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
b689239cd3
commit
5fcb83a1a2
3
Makefile
3
Makefile
|
@ -7,7 +7,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE=
|
||||||
all:
|
all:
|
||||||
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||||
./virtigo --version
|
./virtigo --version
|
||||||
./virtigo --hosts farm01,farm02,farm03
|
./virtigo --hosts farm01 farm02 farm03
|
||||||
|
|
||||||
# this is for release builds using the go.mod files
|
# this is for release builds using the go.mod files
|
||||||
release-build:
|
release-build:
|
||||||
|
@ -33,4 +33,5 @@ clean:
|
||||||
git-clone:
|
git-clone:
|
||||||
go-clone --recursive --go-src --no-work go.wit.com/apps/go-clone
|
go-clone --recursive --go-src --no-work go.wit.com/apps/go-clone
|
||||||
go-clone --recursive --go-src --no-work go.wit.com/apps/virtigo
|
go-clone --recursive --go-src --no-work go.wit.com/apps/virtigo
|
||||||
|
go-clone --recursive --go-src --no-work go.wit.com/apps/gowebd
|
||||||
go-clone --recursive --go-src --no-work go.wit.com/lib/daemons/virtigod
|
go-clone --recursive --go-src --no-work go.wit.com/lib/daemons/virtigod
|
||||||
|
|
14
argv.go
14
argv.go
|
@ -6,21 +6,19 @@ package main
|
||||||
this enables command line options from other packages like 'gui' and 'log'
|
this enables command line options from other packages like 'gui' and 'log'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
Hosts []string `arg:"--hosts" help:"hosts to connect to"`
|
||||||
Uptime bool `arg:"--uptime" help:"enable port 8080 for use with uptime checks like Kuma"`
|
Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
|
||||||
Hosts []string `arg:"--hosts" help:"hosts to connect to"`
|
Port int `arg:"--port" default:"8080" help:"specify a different default port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a args) Description() string {
|
func (a args) Description() string {
|
||||||
return `
|
return `
|
||||||
virtigo will help control your cluster of hypervisiors
|
virtigo will help control your cluster of hypervisiors
|
||||||
|
|
||||||
Install:
|
go install go.wit.com/apps/virtigo@latest
|
||||||
apt install virtigo
|
|
||||||
|
|
||||||
Sources:
|
|
||||||
go-clone --recursive --no-work -go-src go.wit.com/apps/virtigo
|
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// remove '?' part and trailing '/'
|
||||||
|
func cleanURL(url string) string {
|
||||||
|
url = "/" + strings.Trim(url, "/")
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var tmp string
|
||||||
|
tmp = cleanURL(r.URL.Path)
|
||||||
|
|
||||||
|
log.Info("Got URL:", tmp)
|
||||||
|
if tmp == "/" {
|
||||||
|
fmt.Fprintln(w, "OK")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tmp == "/me" {
|
||||||
|
fmt.Fprintln(w, "OK")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if tmp == "/vms" {
|
||||||
|
s := shell.Wget("http://wilddog:2520/vms")
|
||||||
|
var bytesSplice []byte
|
||||||
|
bytesSplice = s.Bytes()
|
||||||
|
fmt.Fprintln(w, string(bytesSplice))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if tmp == "/favicon.ico" {
|
||||||
|
writeFile(w, "ipv6.png")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tmp == "/uptime" {
|
||||||
|
writeFile(w, "uptime.html")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// used for uptime monitor checking (like Kuma)
|
||||||
|
if tmp == "/uptime" {
|
||||||
|
writeFile(w, "uptime.html")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Warn("BAD URL =", tmp)
|
||||||
|
fmt.Fprintln(w, "BAD ZOOT")
|
||||||
|
// badurl(w, r.URL.String())
|
||||||
|
// fmt.Fprintln(w, "BAD", tmp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeFile(w http.ResponseWriter, filename string) {
|
||||||
|
// fmt.Fprintln(w, "GOT TEST?")
|
||||||
|
fullname := "resources/" + filename
|
||||||
|
pfile, err := resources.ReadFile(fullname)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("ERROR:", err)
|
||||||
|
// w.Write(pfile)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var repohtml string
|
||||||
|
repohtml = string(pfile)
|
||||||
|
if filename == "goReference.svg" {
|
||||||
|
w.Header().Set("Content-Type", "image/svg+xml")
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w, repohtml)
|
||||||
|
log.Println("writeFile() found internal file:", filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
// starts and sits waiting for HTTP requests
|
||||||
|
func startHTTP() {
|
||||||
|
http.HandleFunc("/", okHandler)
|
||||||
|
|
||||||
|
p := fmt.Sprintf(":%d", argv.Port)
|
||||||
|
log.Println("Running on port", p)
|
||||||
|
|
||||||
|
err := http.ListenAndServe(p, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error starting server:", err)
|
||||||
|
}
|
||||||
|
}
|
20
main.go
20
main.go
|
@ -3,23 +3,31 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "log"
|
// "log"
|
||||||
|
"embed"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.wit.com/log"
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string
|
var Version string
|
||||||
var myargs args
|
|
||||||
|
//go:embed resources/*
|
||||||
|
var resources embed.FS
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pp := arg.MustParse(&myargs)
|
pp := arg.MustParse(&argv)
|
||||||
|
|
||||||
if myargs.Uptime {
|
if ! argv.Uptime {
|
||||||
pp.WriteHelp(os.Stdout)
|
pp.WriteHelp(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("connect to cluser here", myargs.Hosts)
|
log.Info("connect to cluser here", argv.Hosts)
|
||||||
|
for i, s := range argv.Hosts {
|
||||||
|
log.Info("i, s =", i, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
startHTTP()
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 6.3 KiB |
Loading…
Reference in New Issue