things to add xml files
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
ca98c0e3c0
commit
3f2cbcb57f
1
argv.go
1
argv.go
|
@ -16,6 +16,7 @@ type args struct {
|
|||
Hosts []string `arg:"--hosts" help:"hosts to connect to"`
|
||||
Uptime bool `arg:"--uptime" default:"true" help:"allow uptime checks for things like Kuma"`
|
||||
Daemon bool `arg:"--daemon" help:"run in daemon mode"`
|
||||
Xml []string `arg:"--add-xml" help:"add libvirt xml files"`
|
||||
}
|
||||
|
||||
func (a args) Description() string {
|
||||
|
|
|
@ -12,16 +12,17 @@ import (
|
|||
)
|
||||
|
||||
var ErrorNoFile error = errors.New("missing file")
|
||||
var ErrorParse error = errors.New("invalid json")
|
||||
var ErrorParseJSON error = errors.New("invalid json")
|
||||
var ErrorParseXML error = errors.New("invalid xml")
|
||||
|
||||
// something is wrong somewhere and sometimes the
|
||||
// something is wrong somewhere and sometimes the
|
||||
// protobuf json files get written out with garbage
|
||||
func cfgfile() {
|
||||
err := readConfigFile("virtigo.json")
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
if err == ErrorParse {
|
||||
if err == ErrorParseJSON {
|
||||
os.Exit(-1)
|
||||
}
|
||||
err = readConfigFile("virtigo.json.last")
|
||||
|
@ -47,7 +48,7 @@ func readConfigFile(filename string) error {
|
|||
if err != nil {
|
||||
log.Info("read json failed", err)
|
||||
os.Exit(-1)
|
||||
return ErrorParse
|
||||
return ErrorParseJSON
|
||||
}
|
||||
|
||||
// initialize each hypervisor
|
||||
|
|
4
main.go
4
main.go
|
@ -37,6 +37,10 @@ func main() {
|
|||
|
||||
cfgfile()
|
||||
|
||||
for _, filename := range argv.Xml {
|
||||
log.Info("add xml file", filename)
|
||||
}
|
||||
|
||||
// initialize the grid as unstable
|
||||
me.unstable = time.Now()
|
||||
|
||||
|
|
12
structs.go
12
structs.go
|
@ -4,6 +4,7 @@ import (
|
|||
"time"
|
||||
|
||||
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||
"libvirt.org/go/libvirtxml"
|
||||
)
|
||||
|
||||
var me virtigoT
|
||||
|
@ -39,9 +40,10 @@ type HyperT struct {
|
|||
|
||||
// the stuff that is needed for a hypervisor
|
||||
type DropletT struct {
|
||||
pb *pb.Droplet // the Droplet protobuf
|
||||
CurrentState string // what the state of the droplet is ACTUALLY IS
|
||||
h *HyperT // the hypervisor it's currently running on
|
||||
lastpoll time.Time // the last time the droplet was seen running
|
||||
starts int // how many times a start event has been attempted
|
||||
pb *pb.Droplet // the Droplet protobuf
|
||||
xml *libvirtxml.Domain // a xml representation from libvirt
|
||||
h *HyperT // the hypervisor it's currently running on
|
||||
CurrentState string // what the state of the droplet is ACTUALLY IS
|
||||
lastpoll time.Time // the last time the droplet was seen running
|
||||
starts int // how many times a start event has been attempted
|
||||
}
|
||||
|
|
17
xml.go
17
xml.go
|
@ -71,6 +71,23 @@ func addDefaults(d *libvirtxml.Domain, filename string) {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *DropletT) readXml(filename string) error {
|
||||
log.Info("parse xml file:", filename)
|
||||
|
||||
pfile, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Println("ERROR:", err)
|
||||
return ErrorNoFile
|
||||
}
|
||||
|
||||
err = d.xml.Unmarshal(string(pfile))
|
||||
if err != nil {
|
||||
log.Info("Marshal failed on file", filename)
|
||||
return ErrorParseXML
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setSimpleDisk(domcfg *libvirtxml.Domain, filename string) {
|
||||
// Clear out the existing disks (if any)
|
||||
domcfg.Devices.Disks = nil
|
||||
|
|
Loading…
Reference in New Issue