ConnectToVM opens a VNC connection to a VM in the user's browser Note: Validation should be done using GetVMVNCStatus before calling this method.
(vm *api.VM)
| 63 | // ConnectToVM opens a VNC connection to a VM in the user's browser |
| 64 | // Note: Validation should be done using GetVMVNCStatus before calling this method. |
| 65 | func (s *Service) ConnectToVM(vm *api.VM) error { |
| 66 | s.logger.Info("Connecting to VM VNC: %s (ID: %d, Type: %s, Node: %s)", vm.Name, vm.ID, vm.Type, vm.Node) |
| 67 | |
| 68 | // Generate the VNC URL |
| 69 | vncURL, err := s.client.GenerateVNCURL(vm) |
| 70 | if err != nil { |
| 71 | s.logger.Error("Failed to generate VNC URL for VM %s: %v", vm.Name, err) |
| 72 | |
| 73 | return fmt.Errorf("failed to generate VNC URL: %w", err) |
| 74 | } |
| 75 | |
| 76 | s.logger.Debug("Generated VNC URL for VM %s: %s", vm.Name, vncURL) |
| 77 | |
| 78 | // Open the URL in the default browser |
| 79 | err = openBrowser(vncURL) |
| 80 | if err != nil { |
| 81 | s.logger.Error("Failed to open browser for VM %s VNC: %v", vm.Name, err) |
| 82 | |
| 83 | return err |
| 84 | } |
| 85 | |
| 86 | s.logger.Info("Successfully opened VNC connection for VM %s", vm.Name) |
| 87 | |
| 88 | return nil |
| 89 | } |
| 90 | |
| 91 | // ConnectToNode opens a VNC shell connection to a node in the user's browser. |
| 92 | func (s *Service) ConnectToNode(nodeName string) error { |
nothing calls this directly
no test coverage detected