diff options
| author | Jeff Carr <[email protected]> | 2024-10-18 09:05:39 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-18 09:05:39 -0500 |
| commit | 789a5ada40e598123c3fc972d104b1cfae5d49e4 (patch) | |
| tree | 504ee964c5d2224f3c4f74539f595ec14f6adbf7 /xml.go | |
| parent | bdb262e9a003685c2e8209595dc505dfd6110298 (diff) | |
more mac and filename stats
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'xml.go')
| -rw-r--r-- | xml.go | 60 |
1 files changed, 35 insertions, 25 deletions
@@ -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) + } +} |
