set spice port

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-27 05:44:29 -05:00
parent e23c99d771
commit 065b9439a1
1 changed files with 37 additions and 0 deletions

37
spice.go Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
package virtigoxml
import (
"errors"
"fmt"
pb "go.wit.com/lib/protobuf/virtbuf"
"libvirt.org/go/libvirtxml"
)
func SetSpicePort(d *pb.Droplet, domcfg *libvirtxml.Domain) error {
if domcfg.Devices.Graphics == nil {
return errors.New("no graphics")
}
for i, g := range domcfg.Devices.Graphics {
if g.VNC != nil {
// ignore vnc settings
fmt.Printf("Ignore Graphics VNC settings: %d %+v\n", i, g)
continue
}
if g.Spice != nil {
var s *libvirtxml.DomainGraphicSpice
s = g.Spice
if s.AutoPort == "yes" {
s.AutoPort = "no"
}
s.Port = int(d.SpicePort)
fmt.Printf("setting spice port to %d\n", d.SpicePort)
continue
}
// figure out what to do with non-spice stuff
fmt.Printf("Unknown Graphics: %d %+v\n", i, g)
}
return nil
}