[libvirt] [PATCH console-proxy 1/6] Adapt to API change for dom.Devices.Graphics
Philipp Hahn
hahn at univention.de
Fri Nov 15 13:05:12 UTC 2019
Follow
> commit 4772b681e87a8d0dcee011b8e43813e851e4f934
> Author: Daniel P. Berrange <berrange at redhat.com>
> Date: Fri Nov 24 16:15:30 2017 +0000
>
> Add remaining graphics configuration options
Signed-off-by: Philipp Hahn <hahn at univention.de>
---
cmd/virtconsoleresolveradm/cmd/enable.go | 6 ++----
pkg/resolver/server.go | 26 ++++++++++++++++--------
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/cmd/virtconsoleresolveradm/cmd/enable.go b/cmd/virtconsoleresolveradm/cmd/enable.go
index 04ca80b..dd95e9e 100644
--- a/cmd/virtconsoleresolveradm/cmd/enable.go
+++ b/cmd/virtconsoleresolveradm/cmd/enable.go
@@ -164,15 +164,13 @@ func doEnable(cmd *cobra.Command, args []string) {
meta = &resolver.ConsoleServerProxyMetadata{}
for _, graphics := range domcfg.Devices.Graphics {
- switch graphics.Type {
- case "spice":
+ if graphics.Spice != nil {
meta.Consoles = append(meta.Consoles,
createConsole("spice", 0, conn, domname, domuuid))
- case "vnc":
+ } else if graphics.VNC != nil {
meta.Consoles = append(meta.Consoles,
createConsole("vnc", 0, conn, domname, domuuid))
}
-
}
for idx, chardev := range domcfg.Devices.Serials {
diff --git a/pkg/resolver/server.go b/pkg/resolver/server.go
index 115d75d..eefdad7 100644
--- a/pkg/resolver/server.go
+++ b/pkg/resolver/server.go
@@ -86,13 +86,19 @@ type ConsoleServer struct {
const tokenpath = "/consoleresolver/token/"
+func isListenAddress(listen string) bool {
+ return listen != "" && listen != "0.0.0.0" && listen != "::"
+}
+
func getListener(dom libvirtxml.Domain, gtype string, insecure bool, consoleHost, defaultHost string) (string, error) {
if dom.Devices == nil {
return "", errors.New("No devices present")
}
for _, graphics := range dom.Devices.Graphics {
- if graphics.Type != gtype {
+ if gtype == "vnc" && graphics.VNC != nil {
+ } else if gtype == "spice" && graphics.Spice != nil {
+ } else {
continue
}
@@ -100,21 +106,25 @@ func getListener(dom libvirtxml.Domain, gtype string, insecure bool, consoleHost
if consoleHost != "" {
host = consoleHost
} else {
- if graphics.Listen != "" && graphics.Listen != "0.0.0.0" && graphics.Listen != "::" {
- host = graphics.Listen
+ if graphics.VNC != nil && isListenAddress(graphics.VNC.Listen) {
+ host = graphics.VNC.Listen
+ } else if graphics.Spice != nil && isListenAddress(graphics.Spice.Listen) {
+ host = graphics.Spice.Listen
} else {
host = defaultHost
}
}
var port int
- if graphics.Type == "spice" && !insecure {
- port = graphics.TLSPort
- } else {
- port = graphics.Port
+ if graphics.Spice != nil && !insecure {
+ port = graphics.Spice.TLSPort
+ } else if graphics.Spice != nil {
+ port = graphics.Spice.Port
+ } else if graphics.VNC != nil {
+ port = graphics.VNC.Port
}
glog.V(1).Infof("Got port %d\n", port)
- if graphics.Port == 0 || graphics.Port == -1 {
+ if port == 0 || port == -1 {
return "", errors.New("Missing port for graphics")
}
--
2.20.1
More information about the libvir-list
mailing list