// Copyright 2024 WIT.COM Inc Licensed GPL 3.0 package main import ( "fmt" "os" "go.wit.com/log" "libvirt.org/go/libvirtxml" ) func makeXml(d *DropletT) { log.Info("create new xml file for:", d.Hostname) domcfg := &libvirtxml.Domain{} addDefaults(domcfg, d.Hostname) addDefaults(domcfg, "standard.x86") addDefaults(domcfg, "memory") addDefaults(domcfg, "network") addDefaults(domcfg, "spice") addDefaults(domcfg, "qcow") fmt.Printf("Virt type %s\n", domcfg.Type) fmt.Printf("Virt name %s\n", domcfg.Name) fmt.Printf("Virt UUID %s\n", domcfg.UUID) fmt.Printf("Virt Memory %s\n", domcfg.Memory) xmldoc, err := domcfg.Marshal() if err != nil { fmt.Println("can't make xml file error:\n", err) return } // fmt.Printf("Virt type %s\n", xmldoc) outfile := "/tmp/" + d.Hostname + ".xml" regfile, _ := os.OpenFile(outfile, os.O_RDWR|os.O_CREATE, 0666) fmt.Fprintln(regfile, xmldoc) log.Info("File is in", outfile) } func addDefaults(d *libvirtxml.Domain, filename string) { fullname := "resources/xml/" + filename + ".xml" pfile, err := resources.ReadFile(fullname) if err != nil { log.Println("ERROR:", err) return } err = d.Unmarshal(string(pfile)) if err != nil { log.Info("Marshal failed on file", filename) return } }