GetNodeVNCShell creates a VNC shell connection for a node and returns connection details.
(nodeName string)
| 192 | |
| 193 | // GetNodeVNCShell creates a VNC shell connection for a node and returns connection details. |
| 194 | func (c *Client) GetNodeVNCShell(nodeName string) (*VNCProxyResponse, error) { |
| 195 | c.logger.Info("Creating VNC shell for node: %s", nodeName) |
| 196 | |
| 197 | // Node VNC shells don't work with API token authentication |
| 198 | if c.IsUsingTokenAuth() { |
| 199 | c.logger.Error("VNC shell not supported with API token authentication for node: %s", nodeName) |
| 200 | |
| 201 | return nil, fmt.Errorf("node VNC shells are not supported with API token authentication, please use password authentication") |
| 202 | } |
| 203 | |
| 204 | c.logger.Debug("Using password authentication for node VNC shell: %s", nodeName) |
| 205 | |
| 206 | var res map[string]interface{} |
| 207 | |
| 208 | path := fmt.Sprintf("/nodes/%s/vncshell", nodeName) |
| 209 | |
| 210 | c.logger.Debug("Node VNC shell API path: %s", path) |
| 211 | |
| 212 | // POST request with websocket=1 parameter for noVNC compatibility |
| 213 | data := map[string]interface{}{ |
| 214 | "websocket": 1, |
| 215 | } |
| 216 | |
| 217 | c.logger.Debug("Node VNC shell request data for %s: %+v", nodeName, data) |
| 218 | |
| 219 | if err := c.PostWithResponse(path, data, &res); err != nil { |
| 220 | c.logger.Error("Failed to create VNC shell for node %s: %v", nodeName, err) |
| 221 | |
| 222 | return nil, fmt.Errorf("failed to create VNC shell: %w", err) |
| 223 | } |
| 224 | |
| 225 | c.logger.Debug("Node VNC shell API response for %s: %+v", nodeName, res) |
| 226 | |
| 227 | responseData, ok := res["data"].(map[string]interface{}) |
| 228 | if !ok { |
| 229 | c.logger.Error("Unexpected VNC shell response format for node %s", nodeName) |
| 230 | |
| 231 | return nil, fmt.Errorf("unexpected VNC shell response format") |
| 232 | } |
| 233 | |
| 234 | response := &VNCProxyResponse{} |
| 235 | |
| 236 | if ticket, ok := responseData["ticket"].(string); ok { |
| 237 | response.Ticket = ticket |
| 238 | c.logger.Debug("VNC shell ticket obtained for node %s (length: %d)", nodeName, len(ticket)) |
| 239 | } |
| 240 | |
| 241 | if port, ok := responseData["port"].(string); ok { |
| 242 | response.Port = port |
| 243 | c.logger.Debug("VNC shell port for node %s: %s", nodeName, port) |
| 244 | } else if portFloat, ok := responseData["port"].(float64); ok { |
| 245 | response.Port = fmt.Sprintf("%.0f", portFloat) |
| 246 | c.logger.Debug("VNC shell port for node %s (converted from float): %s", nodeName, response.Port) |
| 247 | } |
| 248 | |
| 249 | if user, ok := responseData["user"].(string); ok { |
| 250 | response.User = user |
| 251 | c.logger.Debug("VNC shell user for node %s: %s", nodeName, user) |
no test coverage detected