diff --git a/argv.go b/argv.go index 7c584b9..52b2c49 100644 --- a/argv.go +++ b/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 { diff --git a/configfiles.go b/configfiles.go index e038f70..df56e83 100644 --- a/configfiles.go +++ b/configfiles.go @@ -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 diff --git a/main.go b/main.go index f9aec8a..48ab2c6 100644 --- a/main.go +++ b/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() diff --git a/structs.go b/structs.go index 0cf0176..0b08b25 100644 --- a/structs.go +++ b/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 } diff --git a/xml.go b/xml.go index 04c3076..1f0da87 100644 --- a/xml.go +++ b/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