simple ethernet mac settings
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
8a2502c61b
commit
70a506bc59
20
main.go
20
main.go
|
@ -58,12 +58,26 @@ func main() {
|
|||
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)
|
||||
fmt.Printf("Virt Memory %d %s\n", domcfg.Memory.Value, domcfg.Memory.Unit)
|
||||
|
||||
// test add some ethernet devices
|
||||
macs := getMacs(domcfg)
|
||||
fmt.Printf("Virt mac addr:%s\n", macs)
|
||||
|
||||
// clearEthernet(domcfg)
|
||||
|
||||
addEthernet(domcfg, "04:44:33:11:22:11", "worldbr")
|
||||
addEthernet(domcfg, "04:44:33:33:44:55", "greenbr")
|
||||
|
||||
// add a check here to make these unique
|
||||
// setRandomMacs(domcfg)
|
||||
|
||||
// print out the final mac addresses
|
||||
macs = getMacs(domcfg)
|
||||
fmt.Printf("Virt mac addr:%s\n", macs)
|
||||
|
||||
qcow := "/home/nfs/" + d.Hostname + ".qcow2"
|
||||
setSimpleDisk(domcfg, qcow)
|
||||
// setMacs(domcfg, "33:44:33:11:22:11", "worldbr")
|
||||
setRandomMacs(domcfg)
|
||||
|
||||
writeoutXml(domcfg, "blahcarr")
|
||||
os.Exit(0)
|
||||
|
|
15
xml.go
15
xml.go
|
@ -97,12 +97,14 @@ func setSimpleDisk(domcfg *libvirtxml.Domain, filename string) {
|
|||
domcfg.Devices.Disks = append(domcfg.Devices.Disks, newDisk)
|
||||
}
|
||||
|
||||
func showMacs(domcfg *libvirtxml.Domain) []string {
|
||||
func getMacs(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)
|
||||
// iface.MAC.Address = "aa:bb:aa:bb:aa:ff"
|
||||
fmt.Printf("MAC Address: %+v\n", iface.MAC)
|
||||
// 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)
|
||||
|
@ -111,10 +113,14 @@ func showMacs(domcfg *libvirtxml.Domain) []string {
|
|||
return macs
|
||||
}
|
||||
|
||||
func setMacs(domcfg *libvirtxml.Domain, mac string, brname string) {
|
||||
// removes all the ethernet interfaces
|
||||
func clearEthernet(domcfg *libvirtxml.Domain) {
|
||||
// Clear out the existing disks (if any)
|
||||
domcfg.Devices.Interfaces = nil
|
||||
}
|
||||
|
||||
// add a new ethernet interface with mac assigned to bridge name
|
||||
func addEthernet(domcfg *libvirtxml.Domain, mac string, brname string) {
|
||||
// Define a new disk with "mynew.qcow2"
|
||||
newNet := libvirtxml.DomainInterface{
|
||||
MAC: &libvirtxml.DomainInterfaceMAC{
|
||||
|
@ -140,6 +146,7 @@ func setRandomMacs(domcfg *libvirtxml.Domain) {
|
|||
domcfg.Devices.Interfaces[i].MAC = newMac
|
||||
|
||||
// fmt.Printf("Disk Source %s\n", name)
|
||||
fmt.Printf("mac addr %s\n", x.MAC)
|
||||
// fmt.Printf("mac addr %+v\n", x.MAC)
|
||||
fmt.Printf("mac addr %s\n", x.MAC.Address)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue