check xml domain name vs xml filename
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d09f4e25c2
commit
37a053dae9
12
xml.go
12
xml.go
|
@ -6,7 +6,9 @@ import (
|
|||
"encoding/xml"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"go.wit.com/log"
|
||||
"libvirt.org/go/libvirtxml"
|
||||
|
@ -76,6 +78,9 @@ func addDefaults(d *libvirtxml.Domain, filename string) {
|
|||
func readXml(filename string) (*libvirtxml.Domain, error) {
|
||||
log.Verbose("parse xml file:", filename)
|
||||
|
||||
hostname := filepath.Base(filename)
|
||||
hostname = strings.TrimSuffix(hostname, ".xml")
|
||||
|
||||
pfile, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
log.Println("ERROR:", err)
|
||||
|
@ -89,6 +94,13 @@ func readXml(filename string) (*libvirtxml.Domain, error) {
|
|||
log.Info("Marshal failed on file", filename, err)
|
||||
return nil, ErrorParseXML
|
||||
}
|
||||
|
||||
if domcfg.Name != hostname {
|
||||
log.Info("ERROR: domcfg.Name != name", domcfg.Name, hostname)
|
||||
log.Info("ERROR: xml filenames must match the xml name")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return domcfg, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue