generate XML by droplet hostname

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-25 22:07:28 -05:00
parent 3893ac7e3d
commit 0fd0283372
5 changed files with 72 additions and 45 deletions

View File

@ -12,6 +12,10 @@ all:
xml-add:
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true
start-uptime.wit.com:
rm /tmp/blahcarr.xml
./virtigo --start uptime.wit.com
start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org
curl --silent http://localhost:8080/start?start=go.wit.com

View File

@ -19,6 +19,7 @@ type args struct {
Config string `arg:"env:VIRTIGO_HOME" help:"defaults to ~/.config/virtigo/"`
Port int `arg:"--port" default:"8080" help:"allow droplet events via http"`
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
Start string `arg:"--start" help:"start a droplet"`
}
// Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`

View File

@ -18,12 +18,12 @@ func makeStandardXml(d *DropletT) *libvirtxml.Domain {
log.Info("create new xml file for:", d.pb.Hostname)
domcfg := &libvirtxml.Domain{}
addDefaults(domcfg, "standard.x86")
addDefaults(domcfg, "memory")
addDefaults(domcfg, "network")
addDefaults(domcfg, "spice")
addDefaults(domcfg, "qcow")
addDefaults(domcfg, d.pb.Hostname)
addDefaultXml(domcfg, "standard.x86")
addDefaultXml(domcfg, "memory")
addDefaultXml(domcfg, "network")
addDefaultXml(domcfg, "spice")
addDefaultXml(domcfg, "qcow")
addDefaultXml(domcfg, d.pb.Hostname)
return domcfg
}
@ -60,7 +60,7 @@ func setDiskFilename(domcfg *libvirtxml.Domain, filename string) {
}
}
func addDefaults(d *libvirtxml.Domain, filename string) {
func addDefaultXml(d *libvirtxml.Domain, filename string) {
fullname := "resources/xml/" + filename + ".xml"
pfile, err := resources.ReadFile(fullname)
if err != nil {

43
main.go
View File

@ -4,7 +4,6 @@ package main
import (
"embed"
"fmt"
"os"
"path/filepath"
"time"
@ -106,6 +105,11 @@ func main() {
os.Exit(0)
}
if argv.Start != "" {
makeDroplet(argv.Start)
os.Exit(0)
}
// start the watchdog polling for each hypervisor
for _, h := range me.hypers {
log.Info("starting polling on", h.pb.Hostname)
@ -115,40 +119,3 @@ func main() {
// sit here
startHTTP()
}
func makeDroplet(start string) {
d := findDroplet(start)
if d == nil {
log.Info("droplet is unknown:", start)
os.Exit(0)
}
log.Info("start droplet here:", d.pb.Hostname)
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)
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)
qcow := "/home/nfs/" + d.pb.Hostname + ".qcow2"
setSimpleDisk(domcfg, qcow)
writeoutXml(domcfg, "blahcarr")
os.Exit(0)
}

55
start.go Normal file
View File

@ -0,0 +1,55 @@
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
package main
import (
"fmt"
"os"
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
)
func makeDroplet(start string) {
tmp := findDroplet(start)
d := tmp.pb
if d == nil {
log.Info("droplet is unknown:", start)
os.Exit(0)
}
log.Info("start droplet here:", d.Hostname)
domcfg := &libvirtxml.Domain{}
addDefaultXml(domcfg, "standard.x86")
addDefaultXml(domcfg, "memory")
addDefaultXml(domcfg, "network")
addDefaultXml(domcfg, "spice")
addDefaultXml(domcfg, "qcow")
domcfg.Type = "kvm"
domcfg.Name = d.Hostname
domcfg.UUID = d.Uuid
var i uint
i = uint(d.Memory / (1024 * 1024))
domcfg.Memory.Value = i
domcfg.Memory.Unit = "MiB"
fmt.Printf("Virt Memory %d %s\n", domcfg.Memory.Value, domcfg.Memory.Unit)
// addEthernet(domcfg, "04:44:33:11:22:11", "worldbr")
// addEthernet(domcfg, "04:44:33:33:44:55", "greenbr")
for _, n := range d.Networks {
log.Info("add network", d.Hostname, "mac addr", n.Mac, "interface", n.Name)
}
// add a check here to make these unique
// setRandomMacs(domcfg)
qcow := "/home/nfs/" + d.Hostname + ".qcow2"
setSimpleDisk(domcfg, qcow)
writeoutXml(domcfg, "blahcarr")
}