From f42091a2ce37f54bb8ad365b31ae2395a9af1372 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 26 Oct 2024 02:31:52 -0500 Subject: [PATCH] network is maybe correct as virtio. pci needed? Signed-off-by: Jeff Carr --- Makefile | 8 ++++---- libvirtxml.go | 29 +++++++++++++++++++++++++++-- network.xml | 6 ++++++ resources/libvirtxml.fields | 18 ++++++++++++++++++ start.go | 12 ++++++++++++ 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 network.xml diff --git a/Makefile b/Makefile index e956b67..45d10f6 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,10 @@ xml-add: xml-add-save: ./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true --save -start-uptime.wit.com: build - rm -f /tmp/blahcarr.xml /tmp/uptime.wit.com.xml - ./virtigo --start uptime.wit.com - ./virtigo --libvirt /tmp/uptime.wit.com.xml +start-pihole.wit.com: build + rm -f /tmp/blahcarr.xml /tmp/pihole.wit.com.xml + ./virtigo --start pihole.wit.com + ./virtigo --libvirt /tmp/pihole.wit.com.xml old-start-all-droplets: curl --silent http://localhost:8080/start?start=git.wit.org diff --git a/libvirtxml.go b/libvirtxml.go index b702a1c..6d8aee8 100644 --- a/libvirtxml.go +++ b/libvirtxml.go @@ -173,14 +173,23 @@ func clearEthernet(domcfg *libvirtxml.Domain) { // 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" - type DomainInterfaceType string + // type DomainInterfaceType string + + var ib *libvirtxml.DomainInterfaceSourceBridge + ib = new(libvirtxml.DomainInterfaceSourceBridge) + ib.Bridge = brname newNet := libvirtxml.DomainInterface{ MAC: &libvirtxml.DomainInterfaceMAC{ Address: mac, }, + Source: &libvirtxml.DomainInterfaceSource{ + Bridge: ib, + }, + Model: &libvirtxml.DomainInterfaceModel{ + Type: "virtio", + }, Target: &libvirtxml.DomainInterfaceTarget{ - Dev: brname, }, } @@ -759,6 +768,22 @@ func dumpLibvirtxmlDomainNames() { field := t.Field(i) fmt.Println("DomainInterface:", field.Name) } + + var isource libvirtxml.DomainInterfaceSource + listFields(isource, "libvirtxml.DomainInterfaceSource") + + var ibridge libvirtxml.DomainInterfaceSourceBridge + listFields(ibridge, "libvirtxml.DomainInterfaceSourceBridge") +} + +func listFields(a any, name string) { + t := reflect.TypeOf(a) + + fmt.Println("Fields in", name) + for i := 0; i < t.NumField(); i++ { + field := t.Field(i) + fmt.Println(name, field.Name) + } } // dump out all the fields in libvirtxml.DomainDeviceList diff --git a/network.xml b/network.xml new file mode 100644 index 0000000..9bc3172 --- /dev/null +++ b/network.xml @@ -0,0 +1,6 @@ + + + + +
+ diff --git a/resources/libvirtxml.fields b/resources/libvirtxml.fields index c77b0b0..c8bd802 100644 --- a/resources/libvirtxml.fields +++ b/resources/libvirtxml.fields @@ -112,3 +112,21 @@ DomainInterface: ROM DomainInterface: ACPI DomainInterface: Alias DomainInterface: Address +Fields in libvirtxml.DomainInterfaceSource +libvirtxml.DomainInterfaceSource User +libvirtxml.DomainInterfaceSource Ethernet +libvirtxml.DomainInterfaceSource VHostUser +libvirtxml.DomainInterfaceSource Server +libvirtxml.DomainInterfaceSource Client +libvirtxml.DomainInterfaceSource MCast +libvirtxml.DomainInterfaceSource Network +libvirtxml.DomainInterfaceSource Bridge +libvirtxml.DomainInterfaceSource Internal +libvirtxml.DomainInterfaceSource Direct +libvirtxml.DomainInterfaceSource Hostdev +libvirtxml.DomainInterfaceSource UDP +libvirtxml.DomainInterfaceSource VDPA +libvirtxml.DomainInterfaceSource Null +libvirtxml.DomainInterfaceSource VDS +Fields in libvirtxml.DomainInterfaceSourceBridge +libvirtxml.DomainInterfaceSourceBridge Bridge diff --git a/start.go b/start.go index b682926..91cca37 100644 --- a/start.go +++ b/start.go @@ -49,8 +49,19 @@ func startDropletXml(start string) { // addEthernet(domcfg, "04:44:33:11:22:11", "worldbr") // addEthernet(domcfg, "04:44:33:33:44:55", "greenbr") + var count int = 0 for _, n := range d.Networks { log.Info("add network", d.Hostname, "mac addr", n.Mac, "interface", n.Name) + if n.Name != "worldbr" { + log.Info("OVERRIDE BRIDGE WITH 'worldbr'") + } + addEthernet(domcfg, n.Mac, "worldbr") + count += 1 + } + if count == 1 { + // this is normal + } else { + log.Info("WRONG NUMBER OF ETHERNET INTERFACES:", count) } // add a check here to make these unique @@ -60,6 +71,7 @@ func startDropletXml(start string) { fullname := findDisk(disk.Filename) if fullname == "" { log.Info("can not find disk", d.Hostname, "dir", disk.Filepath, "filename", disk.Filename) + os.Exit(-1) } else { // qcow := "/home/nfs/" + d.Hostname + ".qcow2" setSimpleDisk(domcfg, fullname)