2024-10-11 13:55:13 -05:00
|
|
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-12 00:17:26 -05:00
|
|
|
"embed"
|
2024-10-18 14:36:40 -05:00
|
|
|
"fmt"
|
2024-10-11 13:55:13 -05:00
|
|
|
"os"
|
2024-10-13 04:34:55 -05:00
|
|
|
"time"
|
2024-10-11 13:55:13 -05:00
|
|
|
|
|
|
|
"go.wit.com/dev/alexflint/arg"
|
2024-10-12 00:17:26 -05:00
|
|
|
"go.wit.com/log"
|
2024-10-11 13:55:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
var Version string
|
2024-10-12 00:17:26 -05:00
|
|
|
|
|
|
|
//go:embed resources/*
|
|
|
|
var resources embed.FS
|
2024-10-11 13:55:13 -05:00
|
|
|
|
|
|
|
func main() {
|
2024-10-12 00:17:26 -05:00
|
|
|
pp := arg.MustParse(&argv)
|
2024-10-11 13:55:13 -05:00
|
|
|
|
2024-10-12 10:59:11 -05:00
|
|
|
if !argv.Uptime {
|
2024-10-11 13:55:13 -05:00
|
|
|
pp.WriteHelp(os.Stdout)
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-10-12 19:44:43 -05:00
|
|
|
if argv.Daemon {
|
|
|
|
log.DaemonMode(true)
|
|
|
|
}
|
|
|
|
|
2024-10-22 16:46:39 -05:00
|
|
|
readConfigFile()
|
2024-10-13 03:04:46 -05:00
|
|
|
readDropletFile("droplets")
|
|
|
|
readHypervisorFile("hypervisor")
|
2024-10-22 16:46:39 -05:00
|
|
|
writeConfigFile()
|
2024-10-12 12:45:43 -05:00
|
|
|
|
2024-10-13 04:34:55 -05:00
|
|
|
// initialize the grid as unstable
|
|
|
|
me.unstable = time.Now()
|
|
|
|
|
2024-10-17 15:54:39 -05:00
|
|
|
log.Info("command line hypervisors:", argv.Hosts)
|
2024-10-13 03:04:46 -05:00
|
|
|
for _, name := range argv.Hosts {
|
2024-10-17 15:54:39 -05:00
|
|
|
h := findHypervisor(name)
|
|
|
|
if h != nil {
|
|
|
|
log.Info("command line hypervisor", name, "already in config file")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
h = addHypervisor(name)
|
2024-10-13 03:04:46 -05:00
|
|
|
h.Active = true
|
2024-10-12 10:59:11 -05:00
|
|
|
}
|
|
|
|
|
2024-10-13 02:23:30 -05:00
|
|
|
if argv.Start != "" {
|
|
|
|
d := findDroplet(argv.Start)
|
|
|
|
if d == nil {
|
|
|
|
log.Info("droplet is unknown:", argv.Start)
|
2024-10-18 06:00:05 -05:00
|
|
|
os.Exit(0)
|
2024-10-13 02:23:30 -05:00
|
|
|
}
|
2024-10-18 07:40:06 -05:00
|
|
|
log.Info("start droplet here:", d.Hostname)
|
2024-10-18 14:36:40 -05:00
|
|
|
domcfg := makeStandardXml(d)
|
|
|
|
|
|
|
|
fmt.Printf("Virt type %s\n", domcfg.Type)
|
|
|
|
fmt.Printf("Virt name %s\n", domcfg.Name)
|
|
|
|
fmt.Printf("Virt UUID %s\n", domcfg.UUID)
|
2024-10-18 20:22:37 -05:00
|
|
|
fmt.Printf("Virt Memory %d %s\n", domcfg.Memory.Value, domcfg.Memory.Unit)
|
|
|
|
|
|
|
|
// test add some ethernet devices
|
|
|
|
macs := getMacs(domcfg)
|
|
|
|
fmt.Printf("Virt mac addr:%s\n", macs)
|
|
|
|
|
|
|
|
// clearEthernet(domcfg)
|
|
|
|
|
|
|
|
addEthernet(domcfg, "04:44:33:11:22:11", "worldbr")
|
|
|
|
addEthernet(domcfg, "04:44:33:33:44:55", "greenbr")
|
|
|
|
|
|
|
|
// add a check here to make these unique
|
|
|
|
// setRandomMacs(domcfg)
|
|
|
|
|
|
|
|
// print out the final mac addresses
|
|
|
|
macs = getMacs(domcfg)
|
|
|
|
fmt.Printf("Virt mac addr:%s\n", macs)
|
2024-10-18 14:36:40 -05:00
|
|
|
|
|
|
|
qcow := "/home/nfs/" + d.Hostname + ".qcow2"
|
|
|
|
setSimpleDisk(domcfg, qcow)
|
|
|
|
|
|
|
|
writeoutXml(domcfg, "blahcarr")
|
2024-10-13 02:23:30 -05:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-10-12 11:54:01 -05:00
|
|
|
// start the watchdog polling for each hypervisor
|
2024-10-12 10:59:11 -05:00
|
|
|
for _, h := range me.hypers {
|
2024-10-17 15:54:39 -05:00
|
|
|
log.Info("starting polling on", h.Hostname)
|
2024-10-12 11:21:45 -05:00
|
|
|
go h.NewWatchdog()
|
2024-10-12 00:17:26 -05:00
|
|
|
}
|
|
|
|
|
2024-10-12 11:21:45 -05:00
|
|
|
// sit here
|
|
|
|
startHTTP()
|
2024-10-11 13:55:13 -05:00
|
|
|
}
|