finds disks and puts dirs in the protobuf cluster
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
61b954ecca
commit
7320fceb8d
18
Makefile
18
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.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)
|
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
|
||||||
|
|
||||||
all:
|
all: build
|
||||||
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
|
||||||
./virtigo --version
|
./virtigo --version
|
||||||
./virtigo --help
|
./virtigo --help
|
||||||
|
|
||||||
|
build:
|
||||||
|
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
xml-add:
|
xml-add:
|
||||||
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true
|
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true
|
||||||
|
|
||||||
start-uptime.wit.com:
|
xml-add-save:
|
||||||
rm /tmp/blahcarr.xml
|
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true --save
|
||||||
./virtigo --start uptime.wit.com
|
|
||||||
|
|
||||||
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=git.wit.org
|
||||||
curl --silent http://localhost:8080/start?start=go.wit.com
|
curl --silent http://localhost:8080/start?start=go.wit.com
|
||||||
curl --silent http://localhost:8080/start?start=rdate.wit.com
|
curl --silent http://localhost:8080/start?start=rdate.wit.com
|
||||||
|
|
28
change.go
28
change.go
|
@ -85,6 +85,34 @@ func NewChangeEvent(d *pb.Droplet, fname string, origval any, newval any) *pb.Ev
|
||||||
return e
|
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
|
// update the droplet memory
|
||||||
func (d *DropletT) SetMemory(b int64) *pb.Event {
|
func (d *DropletT) SetMemory(b int64) *pb.Event {
|
||||||
oldm := pb.HumanFormatBytes(d.pb.Memory)
|
oldm := pb.HumanFormatBytes(d.pb.Memory)
|
||||||
|
|
2
main.go
2
main.go
|
@ -106,7 +106,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if argv.Start != "" {
|
if argv.Start != "" {
|
||||||
makeDroplet(argv.Start)
|
startDropletXml(argv.Start)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
start.go
51
start.go
|
@ -5,14 +5,16 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"libvirt.org/go/libvirtxml"
|
"libvirt.org/go/libvirtxml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeDroplet(start string) {
|
// generate the XML for 'virsh create'
|
||||||
tmp := findDroplet(start)
|
func startDropletXml(start string) {
|
||||||
d := tmp.pb
|
meDrop := findDroplet(start)
|
||||||
|
d := meDrop.pb
|
||||||
if d == nil {
|
if d == nil {
|
||||||
log.Info("droplet is unknown:", start)
|
log.Info("droplet is unknown:", start)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -21,8 +23,8 @@ func makeDroplet(start string) {
|
||||||
domcfg := &libvirtxml.Domain{}
|
domcfg := &libvirtxml.Domain{}
|
||||||
|
|
||||||
addDefaultXml(domcfg, "standard.x86")
|
addDefaultXml(domcfg, "standard.x86")
|
||||||
addDefaultXml(domcfg, "memory")
|
// addDefaultXml(domcfg, "memory")
|
||||||
addDefaultXml(domcfg, "network")
|
// addDefaultXml(domcfg, "network")
|
||||||
addDefaultXml(domcfg, "spice")
|
addDefaultXml(domcfg, "spice")
|
||||||
addDefaultXml(domcfg, "qcow")
|
addDefaultXml(domcfg, "qcow")
|
||||||
|
|
||||||
|
@ -33,6 +35,12 @@ func makeDroplet(start string) {
|
||||||
var i uint
|
var i uint
|
||||||
i = uint(d.Memory / (1024 * 1024))
|
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.Value = i
|
||||||
domcfg.Memory.Unit = "MiB"
|
domcfg.Memory.Unit = "MiB"
|
||||||
|
|
||||||
|
@ -48,8 +56,35 @@ func makeDroplet(start string) {
|
||||||
// add a check here to make these unique
|
// add a check here to make these unique
|
||||||
// setRandomMacs(domcfg)
|
// setRandomMacs(domcfg)
|
||||||
|
|
||||||
qcow := "/home/nfs/" + d.Hostname + ".qcow2"
|
for _, disk := range d.Disks {
|
||||||
setSimpleDisk(domcfg, qcow)
|
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 ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ type virtigoT struct {
|
||||||
killcount int
|
killcount int
|
||||||
unstable time.Time // the last time the cluster was incorrect
|
unstable time.Time // the last time the cluster was incorrect
|
||||||
changed bool
|
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
|
// the stuff that is needed for a hypervisor
|
||||||
|
|
15
validate.go
15
validate.go
|
@ -37,9 +37,11 @@ func checkUniqueMac(mac string) bool {
|
||||||
return true
|
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
|
var found bool = false
|
||||||
for _, d := range me.dirs {
|
var e *pb.Event
|
||||||
|
for _, d := range me.cluster.Dirs {
|
||||||
if d == dir {
|
if d == dir {
|
||||||
// found dir
|
// found dir
|
||||||
found = true
|
found = true
|
||||||
|
@ -47,8 +49,13 @@ func addClusterFilepath(dir string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
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
|
// returns the droplet using a filename
|
||||||
|
@ -106,6 +113,7 @@ func checkUniqueFilenames() bool {
|
||||||
for _, d := range me.cluster.Droplets {
|
for _, d := range me.cluster.Droplets {
|
||||||
for _, disk := range d.Disks {
|
for _, disk := range d.Disks {
|
||||||
filename := disk.Filename
|
filename := disk.Filename
|
||||||
|
addClusterFilepath(disk.Filepath)
|
||||||
if _, ok := disks[filename]; ok {
|
if _, ok := disks[filename]; ok {
|
||||||
/*
|
/*
|
||||||
if argv.IgnDisk {
|
if argv.IgnDisk {
|
||||||
|
@ -135,6 +143,7 @@ func checkDiskFilenames() []*pb.Event {
|
||||||
filename := disk.Filename
|
filename := disk.Filename
|
||||||
filebase := filepath.Base(filename)
|
filebase := filepath.Base(filename)
|
||||||
dir := filepath.Dir(filename)
|
dir := filepath.Dir(filename)
|
||||||
|
addClusterFilepath(dir)
|
||||||
if disk.Filename != filebase {
|
if disk.Filename != filebase {
|
||||||
// update filename
|
// update filename
|
||||||
e := NewChangeEvent(d, "Disk.Filename", disk.Filename, filebase)
|
e := NewChangeEvent(d, "Disk.Filename", disk.Filename, filebase)
|
||||||
|
|
Loading…
Reference in New Issue