MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / StartVMVNCServerWithSession

Method StartVMVNCServerWithSession

internal/vnc/server.go:62–99  ·  view source on GitHub ↗

StartVMVNCServerWithSession starts the embedded server for a VM VNC connection with session notifications.

(client *api.Client, vm *api.VM, session SessionNotifier)

Source from the content-addressed store, hash-verified

60
61// StartVMVNCServerWithSession starts the embedded server for a VM VNC connection with session notifications.
62func (s *Server) StartVMVNCServerWithSession(client *api.Client, vm *api.VM, session SessionNotifier) (string, error) {
63 s.logger.Info("Starting VM VNC server for: %s (ID: %d, Type: %s, Node: %s)", vm.Name, vm.ID, vm.Type, vm.Node)
64
65 // Create proxy configuration
66 s.logger.Debug("Creating VNC proxy configuration for VM %s", vm.Name)
67
68 config, err := CreateVMProxyConfigWithLogger(client, vm, s.logger)
69 if err != nil {
70 s.logger.Error("Failed to create VM proxy config for %s: %v", vm.Name, err)
71
72 return "", fmt.Errorf("failed to create VM proxy config: %w", err)
73 }
74
75 s.logger.Debug("VM proxy config created - Port: %s, VM Type: %s", config.Port, config.VMType)
76
77 // Create WebSocket proxy with session notifications
78 s.logger.Debug("Creating WebSocket proxy for VM %s", vm.Name)
79 s.proxy = NewWebSocketProxyWithSessionAndLogger(config, session, s.logger)
80
81 // Start HTTP server
82 s.logger.Debug("Starting HTTP server for VM %s", vm.Name)
83
84 if err := s.startHTTPServer(); err != nil {
85 s.logger.Error("Failed to start HTTP server for VM %s: %v", vm.Name, err)
86
87 return "", fmt.Errorf("failed to start HTTP server: %w", err)
88 }
89
90 // Generate noVNC URL with relative WebSocket connection for VS Code port forwarding compatibility
91 // By not specifying host and port, noVNC will use the current page's host and port (which includes VS Code forwarding)
92 vncURL := fmt.Sprintf("http://localhost:%d/vnc.html?autoconnect=true&reconnect=true&password=%s&path=vnc-proxy&resize=scale",
93 s.port, url.QueryEscape(config.Password))
94
95 s.logger.Info("VM VNC server started successfully for %s on port %d", vm.Name, s.port)
96 s.logger.Debug("VM VNC URL generated: %s", vncURL)
97
98 return vncURL, nil
99}
100
101// StartNodeVNCServer starts the embedded server for a node VNC shell connection.
102func (s *Server) StartNodeVNCServer(client *api.Client, nodeName string) (string, error) {

Callers 2

StartVMVNCServerMethod · 0.95

Calls 6

startHTTPServerMethod · 0.95
InfoMethod · 0.65
DebugMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected