network is maybe correct as virtio. pci needed?

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 02:31:52 -05:00
parent 7320fceb8d
commit f42091a2ce
5 changed files with 67 additions and 6 deletions

View File

@ -17,10 +17,10 @@ xml-add:
xml-add-save: xml-add-save:
./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true --save ./virtigo --libvirt ~/libvirt/*.xml --xml-ignore-disk=true --save
start-uptime.wit.com: build start-pihole.wit.com: build
rm -f /tmp/blahcarr.xml /tmp/uptime.wit.com.xml rm -f /tmp/blahcarr.xml /tmp/pihole.wit.com.xml
./virtigo --start uptime.wit.com ./virtigo --start pihole.wit.com
./virtigo --libvirt /tmp/uptime.wit.com.xml ./virtigo --libvirt /tmp/pihole.wit.com.xml
old-start-all-droplets: old-start-all-droplets:
curl --silent http://localhost:8080/start?start=git.wit.org curl --silent http://localhost:8080/start?start=git.wit.org

View File

@ -173,14 +173,23 @@ func clearEthernet(domcfg *libvirtxml.Domain) {
// add a new ethernet interface with mac assigned to bridge name // add a new ethernet interface with mac assigned to bridge name
func addEthernet(domcfg *libvirtxml.Domain, mac string, brname string) { func addEthernet(domcfg *libvirtxml.Domain, mac string, brname string) {
// Define a new disk with "mynew.qcow2" // 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{ newNet := libvirtxml.DomainInterface{
MAC: &libvirtxml.DomainInterfaceMAC{ MAC: &libvirtxml.DomainInterfaceMAC{
Address: mac, Address: mac,
}, },
Source: &libvirtxml.DomainInterfaceSource{
Bridge: ib,
},
Model: &libvirtxml.DomainInterfaceModel{
Type: "virtio",
},
Target: &libvirtxml.DomainInterfaceTarget{ Target: &libvirtxml.DomainInterfaceTarget{
Dev: brname,
}, },
} }
@ -759,6 +768,22 @@ func dumpLibvirtxmlDomainNames() {
field := t.Field(i) field := t.Field(i)
fmt.Println("DomainInterface:", field.Name) 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 // dump out all the fields in libvirtxml.DomainDeviceList

6
network.xml Normal file
View File

@ -0,0 +1,6 @@
<interface type='bridge'>
<mac address='52:54:00:fb:7e:b1'/>
<source bridge='worldbr'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>

View File

@ -112,3 +112,21 @@ DomainInterface: ROM
DomainInterface: ACPI DomainInterface: ACPI
DomainInterface: Alias DomainInterface: Alias
DomainInterface: Address 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

View File

@ -49,8 +49,19 @@ func startDropletXml(start string) {
// addEthernet(domcfg, "04:44:33:11:22:11", "worldbr") // addEthernet(domcfg, "04:44:33:11:22:11", "worldbr")
// addEthernet(domcfg, "04:44:33:33:44:55", "greenbr") // addEthernet(domcfg, "04:44:33:33:44:55", "greenbr")
var count int = 0
for _, n := range d.Networks { for _, n := range d.Networks {
log.Info("add network", d.Hostname, "mac addr", n.Mac, "interface", n.Name) 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 // add a check here to make these unique
@ -60,6 +71,7 @@ func startDropletXml(start string) {
fullname := findDisk(disk.Filename) fullname := findDisk(disk.Filename)
if fullname == "" { if fullname == "" {
log.Info("can not find disk", d.Hostname, "dir", disk.Filepath, "filename", disk.Filename) log.Info("can not find disk", d.Hostname, "dir", disk.Filepath, "filename", disk.Filename)
os.Exit(-1)
} else { } else {
// qcow := "/home/nfs/" + d.Hostname + ".qcow2" // qcow := "/home/nfs/" + d.Hostname + ".qcow2"
setSimpleDisk(domcfg, fullname) setSimpleDisk(domcfg, fullname)