more mac and filename stats

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-18 09:05:39 -05:00
parent bdb262e9a0
commit 789a5ada40
1 changed files with 35 additions and 25 deletions

60
xml.go
View File

@ -28,29 +28,8 @@ func makeStandardXml(d *DropletT) {
qcow := "/home/nfs2/" + d.Hostname + ".qcow2"
simpleDisk(domcfg, qcow)
// domcfg.Memory = 3333
// fmt.Printf("Virt Devices %s\n", domcfg.Devices.Disks)
// log.Spew(domcfg.Devices)
// fmt.Printf("Virt Devices %s\n", domcfg.DiskDriver)
// log.Info("DISKS")
// log.Info("DISKS")
// log.Info("")
// structure DomainDeviceList shows what can be done as a range
/*
for i, x := range domcfg.Devices.Disks {
// Create a new DomainDiskSourceFile struct
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)
}
*/
// setMacs(domcfg, "33:44:33:11:22:11", "worldbr")
randomMacs(domcfg)
xmldoc, err := domcfg.Marshal()
@ -59,8 +38,6 @@ func makeStandardXml(d *DropletT) {
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)
@ -137,3 +114,36 @@ func showMacs(domcfg *libvirtxml.Domain) []string {
}
return macs
}
func setMacs(domcfg *libvirtxml.Domain, mac string, brname string) {
// Clear out the existing disks (if any)
domcfg.Devices.Interfaces = nil
// Define a new disk with "mynew.qcow2"
newNet := libvirtxml.DomainInterface{
MAC: &libvirtxml.DomainInterfaceMAC{
Address: mac,
},
Target: &libvirtxml.DomainInterfaceTarget{
Dev: brname,
},
}
// Add the new disk to the domain configuration
domcfg.Devices.Interfaces = append(domcfg.Devices.Interfaces, newNet)
}
func randomMacs(domcfg *libvirtxml.Domain) {
for i, x := range domcfg.Devices.Interfaces {
// Create a new DomainDiskInterfaces struct
newMac := &libvirtxml.DomainInterfaceMAC{
Address: "aa:bb:cc:dd:ee:ff", // make sure this is unique
}
// Assign it to the disk's source
domcfg.Devices.Interfaces[i].MAC = newMac
// fmt.Printf("Disk Source %s\n", name)
fmt.Printf("mac addr %s\n", x.MAC)
}
}