2024-10-30 02:28:53 -05:00
|
|
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"os"
|
2024-10-30 09:14:20 -05:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2024-10-30 02:28:53 -05:00
|
|
|
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
2024-10-30 07:52:44 -05:00
|
|
|
"go.wit.com/log"
|
2024-10-30 02:28:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var Version string
|
|
|
|
|
|
|
|
//go:embed resources/*
|
|
|
|
var resources embed.FS
|
|
|
|
|
2024-10-30 09:14:20 -05:00
|
|
|
var urlbase string = "http://localhost:8080"
|
|
|
|
|
2024-10-30 02:28:53 -05:00
|
|
|
func main() {
|
|
|
|
var pp *arg.Parser
|
|
|
|
pp = arg.MustParse(&argv)
|
|
|
|
|
|
|
|
if pp == nil {
|
|
|
|
pp.WriteHelp(os.Stdout)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2024-10-30 07:52:44 -05:00
|
|
|
if argv.Dump != nil {
|
|
|
|
if argv.Dump.Droplets {
|
2024-10-30 11:01:03 -05:00
|
|
|
dumpDroplets(false)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if argv.Dump.DropletsFull {
|
|
|
|
dumpStdout("/dumpdropletsfull")
|
|
|
|
dumpDroplets(true)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if argv.Dump.Uptime {
|
|
|
|
dumpStdout("/uptime")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if argv.Dump.Hypervisors {
|
|
|
|
dumpStdout("/dumphypervisors")
|
2024-10-30 07:52:44 -05:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
log.Info("dump something here")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2024-10-31 14:16:07 -05:00
|
|
|
|
2024-10-30 07:52:44 -05:00
|
|
|
if argv.Create != nil {
|
2024-10-30 09:14:20 -05:00
|
|
|
dir := filepath.Dir(argv.Create.Filename)
|
|
|
|
filename := filepath.Base(argv.Create.Filename)
|
|
|
|
if err := createFilename(dir, filename); err != nil {
|
|
|
|
log.Info("create failed", err)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2024-10-30 18:10:55 -05:00
|
|
|
log.Info("virtigoctl create end")
|
2024-10-30 07:52:44 -05:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2024-10-31 14:16:07 -05:00
|
|
|
|
2024-10-30 07:52:44 -05:00
|
|
|
if argv.Start != nil {
|
|
|
|
log.Info("start the vm's here:", argv.Start)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2024-10-31 14:16:07 -05:00
|
|
|
|
|
|
|
if argv.Import != nil {
|
2024-11-01 00:42:02 -05:00
|
|
|
if argv.Import.DomainName == "" {
|
|
|
|
pp.WriteHelp(os.Stdout)
|
|
|
|
log.DaemonMode(true)
|
|
|
|
log.Info("Example:")
|
|
|
|
log.Info("")
|
|
|
|
log.Info(" virtigoctl import --domain grafana # will look for an existing libvirt domain")
|
|
|
|
log.Info("")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
log.Info("\n\nshould import here", argv.Start, "\n")
|
2024-10-31 14:16:07 -05:00
|
|
|
log.Info("import", argv.Import.Host, argv.Import.DomainName)
|
2024-11-16 05:22:41 -06:00
|
|
|
url := "/import?domainName=" + argv.Import.DomainName
|
2024-11-01 12:50:03 -05:00
|
|
|
if argv.Import.Force {
|
|
|
|
url += "&force=true"
|
|
|
|
}
|
2024-11-01 00:42:02 -05:00
|
|
|
dumpStdout(url)
|
2024-10-31 14:16:07 -05:00
|
|
|
}
|
2024-10-30 02:28:53 -05:00
|
|
|
}
|
2024-10-30 09:14:20 -05:00
|
|
|
|
2024-10-30 11:01:03 -05:00
|
|
|
func dumpDroplets(full bool) error {
|
2024-10-30 09:14:20 -05:00
|
|
|
log.DaemonMode(true)
|
|
|
|
log.Info("dump droplets here ==", argv.Dump.Droplets)
|
2024-10-30 11:01:03 -05:00
|
|
|
var url string
|
|
|
|
if full {
|
|
|
|
url = urlbase + "/dumpdropletsfull"
|
|
|
|
} else {
|
|
|
|
url = urlbase + "/dumpdroplets"
|
|
|
|
}
|
2024-10-30 09:14:20 -05:00
|
|
|
body, err := httpPost(url, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("httpPost() failed:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
test := strings.TrimSpace(string(body))
|
|
|
|
// log.Info("virtigo returned body:", test)
|
|
|
|
for _, line := range strings.Split(test, "\n") {
|
|
|
|
log.Info("GOT:", line)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-10-30 11:01:03 -05:00
|
|
|
func dumpStdout(route string) error {
|
|
|
|
log.DaemonMode(true)
|
|
|
|
url := urlbase + route
|
|
|
|
log.Info("dump url here ==", url)
|
|
|
|
body, err := httpPost(url, nil)
|
2024-10-30 09:14:20 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Info("httpPost() failed:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
test := strings.TrimSpace(string(body))
|
|
|
|
for _, line := range strings.Split(test, "\n") {
|
|
|
|
log.Info("GOT:", line)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|