finds disks and puts dirs in the protobuf cluster

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 01:02:09 -05:00
parent 61b954ecca
commit 7320fceb8d
6 changed files with 97 additions and 19 deletions

View File

@ -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
./virtigo --start uptime.wit.com
xml-add-save:
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true --save
start-all-droplets:
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
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

View File

@ -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)

View File

@ -106,7 +106,7 @@ func main() {
}
if argv.Start != "" {
makeDroplet(argv.Start)
startDropletXml(argv.Start)
os.Exit(0)
}

View File

@ -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 ""
}

View File

@ -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

View File

@ -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)