set the qcow2 filename

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-18 08:39:52 -05:00
parent bffee3265e
commit bdb262e9a0
1 changed files with 50 additions and 15 deletions

65
xml.go
View File

@ -25,26 +25,32 @@ func makeStandardXml(d *DropletT) {
fmt.Printf("Virt name %s\n", domcfg.Name) fmt.Printf("Virt name %s\n", domcfg.Name)
fmt.Printf("Virt UUID %s\n", domcfg.UUID) fmt.Printf("Virt UUID %s\n", domcfg.UUID)
fmt.Printf("Virt Memory %s\n", domcfg.Memory) fmt.Printf("Virt Memory %s\n", domcfg.Memory)
qcow := "/home/nfs2/" + d.Hostname + ".qcow2"
simpleDisk(domcfg, qcow)
// domcfg.Memory = 3333 // domcfg.Memory = 3333
fmt.Printf("Virt Devices %s\n", domcfg.Devices.Disks) // fmt.Printf("Virt Devices %s\n", domcfg.Devices.Disks)
// log.Spew(domcfg.Devices) // log.Spew(domcfg.Devices)
// fmt.Printf("Virt Devices %s\n", domcfg.DiskDriver) // fmt.Printf("Virt Devices %s\n", domcfg.DiskDriver)
log.Info("DISKS") // log.Info("DISKS")
log.Info("DISKS") // log.Info("DISKS")
log.Info("") // log.Info("")
// structure DomainDeviceList shows what can be done as a range // structure DomainDeviceList shows what can be done as a range
for i, x := range domcfg.Devices.Disks { /*
// Create a new DomainDiskSourceFile struct for i, x := range domcfg.Devices.Disks {
newSource := &libvirtxml.DomainDiskSourceFile{ // Create a new DomainDiskSourceFile struct
File: "mynew.qcow2", // Set the file name here newSource := &libvirtxml.DomainDiskSourceFile{
File: "mynew.qcow2", // Set the file name here
}
// Assign it to the disk's source
domcfg.Devices.Disks[i].Source.File = newSource
// fmt.Printf("Disk Source %s\n", name)
fmt.Printf("Disk Device %s\n", x.Source.File)
} }
*/
// Assign it to the disk's source
domcfg.Devices.Disks[i].Source.File = newSource
// fmt.Printf("Disk Source %s\n", name)
fmt.Printf("Disk Device %s\n", x.Source.File)
}
xmldoc, err := domcfg.Marshal() xmldoc, err := domcfg.Marshal()
@ -62,6 +68,21 @@ func makeStandardXml(d *DropletT) {
log.Info("File is in", outfile) log.Info("File is in", outfile)
} }
func setDiskFilename(domcfg *libvirtxml.Domain, filename string) {
for i, x := range domcfg.Devices.Disks {
// Create a new DomainDiskSourceFile struct
newSource := &libvirtxml.DomainDiskSourceFile{
File: filename, // Set the file name here
}
// Assign it to the disk's source
domcfg.Devices.Disks[i].Source.File = newSource
// fmt.Printf("Disk Source %s\n", name)
fmt.Printf("Disk Device %s\n", x.Source.File)
}
}
func addDefaults(d *libvirtxml.Domain, filename string) { func addDefaults(d *libvirtxml.Domain, filename string) {
fullname := "resources/xml/" + filename + ".xml" fullname := "resources/xml/" + filename + ".xml"
pfile, err := resources.ReadFile(fullname) pfile, err := resources.ReadFile(fullname)
@ -102,3 +123,17 @@ func simpleDisk(domcfg *libvirtxml.Domain, filename string) {
// Add the new disk to the domain configuration // Add the new disk to the domain configuration
domcfg.Devices.Disks = append(domcfg.Devices.Disks, newDisk) domcfg.Devices.Disks = append(domcfg.Devices.Disks, newDisk)
} }
func showMacs(domcfg *libvirtxml.Domain) []string {
var macs []string
// Iterate over the network interfaces and print the MAC addresses
for _, iface := range domcfg.Devices.Interfaces {
if iface.MAC != nil {
fmt.Printf("Interface: %s, MAC Address: %s\n", iface.Target.Dev, iface.MAC.Address)
macs = append(macs, iface.MAC.Address)
} else {
fmt.Printf("Interface: %s, MAC Address: not available\n", iface.Target.Dev)
}
}
return macs
}