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

Method GetNodeVNCShellWithWebSocket

pkg/api/node.go:265–342  ·  view source on GitHub ↗

GetNodeVNCShellWithWebSocket creates a VNC shell connection for a node with WebSocket support and one-time password.

(nodeName string)

Source from the content-addressed store, hash-verified

263
264// GetNodeVNCShellWithWebSocket creates a VNC shell connection for a node with WebSocket support and one-time password.
265func (c *Client) GetNodeVNCShellWithWebSocket(nodeName string) (*VNCProxyResponse, error) {
266 c.logger.Info("Creating VNC shell with WebSocket for node: %s", nodeName)
267
268 // Node VNC shells don't work with API token authentication
269 if c.IsUsingTokenAuth() {
270 c.logger.Error("VNC shell with WebSocket not supported with API token authentication for node: %s", nodeName)
271
272 return nil, fmt.Errorf("node VNC shells are not supported with API token authentication, please use password authentication")
273 }
274
275 c.logger.Debug("Using password authentication for node VNC shell with WebSocket: %s", nodeName)
276
277 var res map[string]interface{}
278
279 path := fmt.Sprintf("/nodes/%s/vncshell", nodeName)
280
281 c.logger.Debug("Node VNC shell WebSocket API path: %s", path)
282
283 // POST request with websocket=1 parameter for WebSocket compatibility
284 // Note: Node VNC shells don't support generate-password parameter
285 data := map[string]interface{}{
286 "websocket": 1,
287 }
288
289 c.logger.Debug("Node VNC shell WebSocket request data for %s: %+v", nodeName, data)
290
291 if err := c.PostWithResponse(path, data, &res); err != nil {
292 c.logger.Error("Failed to create VNC shell with WebSocket for node %s: %v", nodeName, err)
293
294 return nil, fmt.Errorf("failed to create VNC shell with WebSocket: %w", err)
295 }
296
297 c.logger.Debug("Node VNC shell WebSocket API response for %s: %+v", nodeName, res)
298
299 responseData, ok := res["data"].(map[string]interface{})
300 if !ok {
301 c.logger.Error("Unexpected VNC shell WebSocket response format for node %s", nodeName)
302
303 return nil, fmt.Errorf("unexpected VNC shell response format")
304 }
305
306 response := &VNCProxyResponse{}
307
308 if ticket, ok := responseData["ticket"].(string); ok {
309 response.Ticket = ticket
310 c.logger.Debug("VNC shell WebSocket ticket obtained for node %s (length: %d)", nodeName, len(ticket))
311 }
312
313 if port, ok := responseData["port"].(string); ok {
314 response.Port = port
315 c.logger.Debug("VNC shell WebSocket port for node %s: %s", nodeName, port)
316 } else if portFloat, ok := responseData["port"].(float64); ok {
317 response.Port = fmt.Sprintf("%.0f", portFloat)
318 c.logger.Debug("VNC shell WebSocket port for node %s (converted from float): %s", nodeName, response.Port)
319 }
320
321 if user, ok := responseData["user"].(string); ok {
322 response.User = user

Callers 1

Calls 5

IsUsingTokenAuthMethod · 0.95
PostWithResponseMethod · 0.95
InfoMethod · 0.65
ErrorMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected