From 8ad58db1cfeeffeb1837301c1165d42c0d4188ce Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 18 Oct 2024 14:36:40 -0500 Subject: [PATCH] xml file does virsh create Signed-off-by: Jeff Carr --- main.go | 15 ++++++++++++++- resources/xml/spice.xml | 2 +- resources/xml/standard.x86.xml | 4 ---- xml.go | 24 ++++++++++-------------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index ce4823a..fd06cf6 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ package main import ( "embed" + "fmt" "os" "time" @@ -52,7 +53,19 @@ func main() { os.Exit(0) } log.Info("start droplet here:", d.Hostname) - makeStandardXml(d) + domcfg := makeStandardXml(d) + + 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) + + qcow := "/home/nfs/" + d.Hostname + ".qcow2" + setSimpleDisk(domcfg, qcow) + // setMacs(domcfg, "33:44:33:11:22:11", "worldbr") + setRandomMacs(domcfg) + + writeoutXml(domcfg, "blahcarr") os.Exit(0) } diff --git a/resources/xml/spice.xml b/resources/xml/spice.xml index 07a27a2..651e6ac 100644 --- a/resources/xml/spice.xml +++ b/resources/xml/spice.xml @@ -1,6 +1,6 @@ - + diff --git a/resources/xml/standard.x86.xml b/resources/xml/standard.x86.xml index 7256cbc..412d2cd 100644 --- a/resources/xml/standard.x86.xml +++ b/resources/xml/standard.x86.xml @@ -143,10 +143,6 @@
- - - -
diff --git a/xml.go b/xml.go index b44040e..37cc01e 100644 --- a/xml.go +++ b/xml.go @@ -10,7 +10,7 @@ import ( "libvirt.org/go/libvirtxml" ) -func makeStandardXml(d *DropletT) { +func makeStandardXml(d *DropletT) *libvirtxml.Domain { log.Info("create new xml file for:", d.Hostname) domcfg := &libvirtxml.Domain{} @@ -21,28 +21,24 @@ func makeStandardXml(d *DropletT) { addDefaults(domcfg, "qcow") addDefaults(domcfg, d.Hostname) - 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) - - qcow := "/home/nfs2/" + d.Hostname + ".qcow2" - simpleDisk(domcfg, qcow) - // setMacs(domcfg, "33:44:33:11:22:11", "worldbr") - randomMacs(domcfg) + return domcfg +} +func writeoutXml(domcfg *libvirtxml.Domain, filename string) bool { xmldoc, err := domcfg.Marshal() if err != nil { fmt.Println("can't make xml file error:\n", err) - return + return false } - outfile := "/tmp/" + d.Hostname + ".xml" + outfile := "/tmp/" + filename + ".xml" regfile, _ := os.OpenFile(outfile, os.O_RDWR|os.O_CREATE, 0666) fmt.Fprintln(regfile, xmldoc) log.Info("File is in", outfile) + regfile.Close() + return true } func setDiskFilename(domcfg *libvirtxml.Domain, filename string) { @@ -75,7 +71,7 @@ func addDefaults(d *libvirtxml.Domain, filename string) { } } -func simpleDisk(domcfg *libvirtxml.Domain, filename string) { +func setSimpleDisk(domcfg *libvirtxml.Domain, filename string) { // Clear out the existing disks (if any) domcfg.Devices.Disks = nil @@ -133,7 +129,7 @@ func setMacs(domcfg *libvirtxml.Domain, mac string, brname string) { domcfg.Devices.Interfaces = append(domcfg.Devices.Interfaces, newNet) } -func randomMacs(domcfg *libvirtxml.Domain) { +func setRandomMacs(domcfg *libvirtxml.Domain) { for i, x := range domcfg.Devices.Interfaces { // Create a new DomainDiskInterfaces struct newMac := &libvirtxml.DomainInterfaceMAC{