summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-26 01:02:09 -0500
committerJeff Carr <[email protected]>2024-10-26 01:02:09 -0500
commit7320fceb8d8cf6ed32dd139fb91667ed3b84c4f2 (patch)
tree04c00324dbe201a312bab12592e8a9101bc38d55
parent61b954ecca1ab059167311b527e3102b3f9acd40 (diff)
finds disks and puts dirs in the protobuf cluster
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--Makefile16
-rw-r--r--change.go28
-rw-r--r--main.go2
-rw-r--r--start.go51
-rw-r--r--structs.go2
-rw-r--r--validate.go15
6 files changed, 96 insertions, 18 deletions
diff --git a/Makefile b/Makefile
index cef9e5c..e956b67 100644
--- a/Makefile
+++ b/Makefile
@@ -4,19 +4,25 @@ VERSION = $(shell git describe --tags)
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
-all:
- GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
+all: build
./virtigo --version
./virtigo --help
+build:
+ GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
+
xml-add:
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true
-start-uptime.wit.com:
- rm /tmp/blahcarr.xml
+xml-add-save:
+ ./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true --save
+
+start-uptime.wit.com: build
+ rm -f /tmp/blahcarr.xml /tmp/uptime.wit.com.xml
./virtigo --start uptime.wit.com
+ ./virtigo --libvirt /tmp/uptime.wit.com.xml
-start-all-droplets:
+old-start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org
curl --silent http://localhost:8080/start?start=go.wit.com
curl --silent http://localhost:8080/start?start=rdate.wit.com
diff --git a/change.go b/change.go
index a4aef5f..2a36a4f 100644
--- a/change.go
+++ b/change.go
@@ -85,6 +85,34 @@ func NewChangeEvent(d *pb.Droplet, fname string, origval any, newval any) *pb.Ev
return e
}
+// work in progress
+func NewAddEvent(a any, fname string, newval any) *pb.Event {
+ var e *pb.Event
+ e = new(pb.Event)
+
+ switch v := a.(type) {
+ case *pb.Droplet:
+ var d *pb.Droplet
+ d = a.(*pb.Droplet)
+ e.Droplet = d.Hostname
+ case *pb.Cluster:
+ e.Droplet = "Cluster"
+ case nil:
+ e.Droplet = "<nil>"
+ default:
+ log.Info("newAddEvent() unknown type", v)
+ e.Droplet = "on something somewhere"
+ }
+
+ e.NewVal = convertToString(newval)
+ e.FieldName = fname
+
+ now := time.Now()
+ e.Start = timestamppb.New(now)
+
+ return e
+}
+
// update the droplet memory
func (d *DropletT) SetMemory(b int64) *pb.Event {
oldm := pb.HumanFormatBytes(d.pb.Memory)
diff --git a/main.go b/main.go
index 3250887..4168e0c 100644
--- a/main.go
+++ b/main.go
@@ -106,7 +106,7 @@ func main() {
}
if argv.Start != "" {
- makeDroplet(argv.Start)
+ startDropletXml(argv.Start)
os.Exit(0)
}
diff --git a/start.go b/start.go
index 3cd319b..b682926 100644
--- a/start.go
+++ b/start.go
@@ -5,14 +5,16 @@ package main
import (
"fmt"
"os"
+ "path/filepath"
"go.wit.com/log"
"libvirt.org/go/libvirtxml"
)
-func makeDroplet(start string) {
- tmp := findDroplet(start)
- d := tmp.pb
+// generate the XML for 'virsh create'
+func startDropletXml(start string) {
+ meDrop := findDroplet(start)
+ d := meDrop.pb
if d == nil {
log.Info("droplet is unknown:", start)
os.Exit(0)
@@ -21,8 +23,8 @@ func makeDroplet(start string) {
domcfg := &libvirtxml.Domain{}
addDefaultXml(domcfg, "standard.x86")
- addDefaultXml(domcfg, "memory")
- addDefaultXml(domcfg, "network")
+ // addDefaultXml(domcfg, "memory")
+ // addDefaultXml(domcfg, "network")
addDefaultXml(domcfg, "spice")
addDefaultXml(domcfg, "qcow")
@@ -33,6 +35,12 @@ func makeDroplet(start string) {
var i uint
i = uint(d.Memory / (1024 * 1024))
+ // var tmp string
+ // tmp = domcfg.VCPU
+ domcfg.VCPU = new(libvirtxml.DomainVCPU)
+ domcfg.VCPU.Value = uint(d.Cpus)
+
+ domcfg.Memory = new(libvirtxml.DomainMemory)
domcfg.Memory.Value = i
domcfg.Memory.Unit = "MiB"
@@ -48,8 +56,35 @@ func makeDroplet(start string) {
// add a check here to make these unique
// setRandomMacs(domcfg)
- qcow := "/home/nfs/" + d.Hostname + ".qcow2"
- setSimpleDisk(domcfg, qcow)
+ for _, disk := range d.Disks {
+ fullname := findDisk(disk.Filename)
+ if fullname == "" {
+ log.Info("can not find disk", d.Hostname, "dir", disk.Filepath, "filename", disk.Filename)
+ } else {
+ // qcow := "/home/nfs/" + d.Hostname + ".qcow2"
+ setSimpleDisk(domcfg, fullname)
+ }
+ }
- writeoutXml(domcfg, "blahcarr")
+ writeoutXml(domcfg, d.Hostname)
+ os.Exit(-1)
+}
+
+func findDisk(filename string) string {
+ for _, dirname := range me.cluster.Dirs {
+ // log.Info("look in dir", dirname)
+ var count int
+ newdir, _ := os.ReadDir(dirname)
+ for _, file := range newdir {
+ count += 1
+ if file.Name() == filename {
+ log.Info("Found file", filename, "in", dirname)
+ return filepath.Join(dirname, file.Name())
+ }
+ }
+ if count == 0 {
+ log.Info("Warning? dirname", dirname, "was empty. Not mounted?")
+ }
+ }
+ return ""
}
diff --git a/structs.go b/structs.go
index 45f303e..7232eec 100644
--- a/structs.go
+++ b/structs.go
@@ -30,7 +30,7 @@ type virtigoT struct {
killcount int
unstable time.Time // the last time the cluster was incorrect
changed bool
- dirs []string // all the paths too search for a qcow image
+ // dirs []string // all the paths too search for a qcow image
}
// the stuff that is needed for a hypervisor
diff --git a/validate.go b/validate.go
index 4e0dabe..2668e9f 100644
--- a/validate.go
+++ b/validate.go
@@ -37,9 +37,11 @@ func checkUniqueMac(mac string) bool {
return true
}
-func addClusterFilepath(dir string) {
+// records all the known paths. this should go in the protobuf
+func addClusterFilepath(dir string) *pb.Event {
var found bool = false
- for _, d := range me.dirs {
+ var e *pb.Event
+ for _, d := range me.cluster.Dirs {
if d == dir {
// found dir
found = true
@@ -47,8 +49,13 @@ func addClusterFilepath(dir string) {
}
}
if !found {
- me.dirs = append(me.dirs, dir)
+ if dir != "." {
+ // make a new Add Event
+ e = NewAddEvent(nil, "Add Cluster Directory", dir)
+ me.cluster.Dirs = append(me.cluster.Dirs, dir)
+ }
}
+ return e
}
// returns the droplet using a filename
@@ -106,6 +113,7 @@ func checkUniqueFilenames() bool {
for _, d := range me.cluster.Droplets {
for _, disk := range d.Disks {
filename := disk.Filename
+ addClusterFilepath(disk.Filepath)
if _, ok := disks[filename]; ok {
/*
if argv.IgnDisk {
@@ -135,6 +143,7 @@ func checkDiskFilenames() []*pb.Event {
filename := disk.Filename
filebase := filepath.Base(filename)
dir := filepath.Dir(filename)
+ addClusterFilepath(dir)
if disk.Filename != filebase {
// update filename
e := NewChangeEvent(d, "Disk.Filename", disk.Filename, filebase)