puts the spice port in the protobuf

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-23 17:49:15 -05:00
parent 57fdc99855
commit a1593b0b88
2 changed files with 83 additions and 19 deletions

View File

@ -115,6 +115,26 @@ func updateDroplet(d *DropletT, domcfg *libvirtxml.Domain) bool {
me.changed = true
}
// update spice port
if domcfg.Devices.Graphics != nil {
for _, g := range domcfg.Devices.Graphics {
if g.Spice == nil {
continue
}
var s *libvirtxml.DomainGraphicSpice
s = g.Spice
// fmt.Printf("Spice: %d %+v %s\n", i, s, s.AutoPort)
if s.AutoPort == "yes" {
// should ignore either way
} else {
// print out, but ignore the port number
d.pb.SpicePort = int64(s.Port)
fmt.Printf("Spice Port set to = %d\n", s.Port)
me.changed = true
}
}
}
// check type
if domcfg.Type != "kvm" {
fmt.Printf("not kvm. Virt type == %s\n", domcfg.Type)
@ -139,6 +159,10 @@ func updateMemory(d *DropletT, domcfg *libvirtxml.Domain) bool {
return false
}
if domcfg.Memory == nil {
return true
}
// check memory
if domcfg.Memory.Unit == "KiB" {
var m int64
@ -185,6 +209,11 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) bool {
var macs []string
// Iterate over the network interfaces and print the MAC addresses
for _, iface := range domcfg.Devices.Interfaces {
// fmt.Printf("iface: %+v\n", iface)
// fmt.Printf("MAC: %+v\n", iface.MAC)
// fmt.Printf("Source: %+v\n", iface.Source)
// fmt.Printf("Bridge: %+v\n", iface.Source.Bridge)
// fmt.Printf("Model: %+v\n", iface.Model)
if iface.MAC != nil {
// iface.MAC.Address = "aa:bb:aa:bb:aa:ff"
// fmt.Printf("MAC Address: %+v\n", iface.MAC)

73
xml.go
View File

@ -160,6 +160,8 @@ 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
newNet := libvirtxml.DomainInterface{
MAC: &libvirtxml.DomainInterfaceMAC{
Address: mac,
@ -304,9 +306,12 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
domcfg.Memory = nil
domcfg.CurrentMemory = nil
domcfg.VCPU = nil
if domcfg.CPU.Mode == "host-model" {
switch domcfg.CPU.Mode {
case "host-passthrough":
domcfg.CPU = nil
} else {
case "host-model":
domcfg.CPU = nil
default:
fmt.Printf("? CPU Mode: %+v\n", domcfg.CPU.Mode)
}
@ -351,6 +356,7 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
case "usb":
switch controller.Model {
case "ich9-ehci1":
case "qemu-xhci":
// fmt.Printf("OK USB: %s, %d\n", controller.Model, *controller.Index)
case "ich9-uhci1":
// fmt.Printf("OK USB: %s, %d\n", controller.Model, *controller.Index)
@ -370,6 +376,9 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
// fmt.Printf("IGNORE IDE\n")
case "virtio-serial":
// fmt.Printf("IGNORE virtio-serial\n")
case "sata":
// fmt.Printf("SATA: %s, %d\n", controller.Model, *controller.Index)
// fmt.Printf("SATA: %+v\n", controller)
case "scsi":
switch controller.Model {
case "lsilogic":
@ -379,14 +388,23 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
normalPCI = false
}
case "pci":
fmt.Printf("PCI: %s, %d\n", controller.Model, *controller.Index)
// Domain:0xc0002d2760 Bus:0xc0002d2768 Slot:0xc0002d2770 Function:0xc0002d2778 MultiFunction:
pci := controller.Address.PCI
fmt.Printf("PCI: Domain: %+v Slot %d Function %d\n", *pci.Domain, *pci.Slot, *pci.Function)
normalPCI = false
keepPCI = append(keepPCI, controller)
switch controller.Model {
case "pcie-root":
// pcie-root
case "pcie-root-port":
// pcie-root
case "pcie-to-pci-bridge":
// pcie-root
default:
fmt.Printf("PCI: %s, %d\n", controller.Model, *controller.Index)
// Domain:0xc0002d2760 Bus:0xc0002d2768 Slot:0xc0002d2770 Function:0xc0002d2778 MultiFunction:
pci := controller.Address.PCI
fmt.Printf("PCI: Domain: %+v Slot %d Function %d\n", *pci.Domain, *pci.Slot, *pci.Function)
normalPCI = false
keepPCI = append(keepPCI, controller)
}
default:
fmt.Printf("? %s: %+v\n", controller.Type, controller)
fmt.Printf("? controllerType: %s: %+v\n", controller.Type, controller)
normalPCI = false
keepPCI = append(keepPCI, controller)
}
@ -419,17 +437,25 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) {
// ignore Graphics == Spice when AutoPort = 'yes'
var normalSpice bool = true
if domcfg.Devices.Graphics != nil {
for _, g := range domcfg.Devices.Graphics {
if g.Spice != nil {
// fmt.Printf("Graphics: %d %+v\n", i, g)
var s *libvirtxml.DomainGraphicSpice
s = g.Spice
// fmt.Printf("Spice: %d %+v %s\n", i, s, s.AutoPort)
if s.AutoPort != "yes" {
normalSpice = false
}
} else {
for i, g := range domcfg.Devices.Graphics {
if g.Spice == nil {
// figure out what to do with non-spice stuff
fmt.Printf("Graphics: %d %+v\n", i, g)
normalSpice = false
continue
}
// this is a spice definition, just ignore it
// because port mappings and network access will be handled
// somewhere else someday
// fmt.Printf("Graphics: %d %+v\n", i, g)
var s *libvirtxml.DomainGraphicSpice
s = g.Spice
// fmt.Printf("Spice: %d %+v %s\n", i, s, s.AutoPort)
if s.AutoPort == "yes" {
// should ignore either way
} else {
// print out, but ignore the port number
fmt.Printf("Spice Port = %d\n", s.Port)
}
}
}
@ -546,6 +572,15 @@ func dumpLibvirtxmlDomainNames() {
field := t.Field(i)
fmt.Println("DomainDeviceList:", field.Name)
}
var iface libvirtxml.DomainInterface
t = reflect.TypeOf(iface)
fmt.Println("Fields in libvirtxml.DomainInterface:")
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
fmt.Println("DomainInterface:", field.Name)
}
}
// dump out all the fields in libvirtxml.DomainDeviceList