summaryrefslogtreecommitdiff
path: root/xml.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-18 14:36:40 -0500
committerJeff Carr <[email protected]>2024-10-18 14:36:40 -0500
commit8ad58db1cfeeffeb1837301c1165d42c0d4188ce (patch)
tree0dff2166e7db5e8e750f3e81a9b7770d7bb2b1a8 /xml.go
parent789a5ada40e598123c3fc972d104b1cfae5d49e4 (diff)
xml file does virsh create
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'xml.go')
-rw-r--r--xml.go24
1 files changed, 10 insertions, 14 deletions
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{