getClientForVM returns the appropriate API client for a VM. In group mode, it returns the client for the VM's source profile. In single-profile mode, it returns the main client.
(vm *api.VM)
| 622 | // In group mode, it returns the client for the VM's source profile. |
| 623 | // In single-profile mode, it returns the main client. |
| 624 | func (a *App) getClientForVM(vm *api.VM) (*api.Client, error) { |
| 625 | conn := a.snapConn() |
| 626 | if conn.isGroupMode { |
| 627 | if vm.SourceProfile == "" { |
| 628 | return nil, fmt.Errorf("source profile not set for VM %s in group mode", vm.Name) |
| 629 | } |
| 630 | |
| 631 | profileClient, exists := conn.groupManager.GetClient(vm.SourceProfile) |
| 632 | if !exists { |
| 633 | return nil, fmt.Errorf("profile '%s' not found in group manager", vm.SourceProfile) |
| 634 | } |
| 635 | |
| 636 | status, err := profileClient.GetStatus() |
| 637 | if status != api.ProfileStatusConnected { |
| 638 | return nil, fmt.Errorf("profile '%s' is not connected: %v (error: %v)", vm.SourceProfile, status, err) |
| 639 | } |
| 640 | |
| 641 | return profileClient.Client, nil |
| 642 | } |
| 643 | return conn.client, nil |
| 644 | } |
| 645 | |
| 646 | // getClientForNode returns the appropriate API client for a Node. |
| 647 | // In group mode, it returns the client for the Node's source profile. |
no test coverage detected