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

Method ConnectToVM

internal/vnc/service.go:65–89  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
65func (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.
92func (s *Service) ConnectToNode(nodeName string) error {

Callers

nothing calls this directly

Calls 5

openBrowserFunction · 0.85
GenerateVNCURLMethod · 0.80
InfoMethod · 0.65
ErrorMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected