summaryrefslogtreecommitdiff
path: root/xml.go
diff options
context:
space:
mode:
Diffstat (limited to 'xml.go')
-rw-r--r--xml.go60
1 files changed, 35 insertions, 25 deletions
diff --git a/xml.go b/xml.go
index 75e95b2..b44040e 100644
--- a/xml.go
+++ b/xml.go
@@ -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)
+ }
+}