Initialize registers the plugin's node-level action.
(ctx context.Context, app *components.App, registrar components.PluginRegistrar)
| 43 | |
| 44 | // Initialize registers the plugin's node-level action. |
| 45 | func (p *Plugin) Initialize(ctx context.Context, app *components.App, registrar components.PluginRegistrar) error { |
| 46 | p.app = app |
| 47 | |
| 48 | // Get configuration from app |
| 49 | config := commandrunner.DefaultConfig() |
| 50 | // TODO: Load config from app.Config.Plugins.CommandRunner when config structure is added |
| 51 | config.Enabled = true // For now, enable if plugin is loaded |
| 52 | p.timeout = config.Timeout |
| 53 | |
| 54 | // Create SSH client |
| 55 | appConfig := app.Config() |
| 56 | sshClient := buildSSHClient(appConfig, nil, config.Timeout) |
| 57 | |
| 58 | // Create API client adapter for guest agent commands |
| 59 | apiClient := commandrunner.NewAPIClientAdapter(app.Client()) |
| 60 | |
| 61 | // Create command runner |
| 62 | // Pass the full app which implements the UIApp interface |
| 63 | runner, err := commandrunner.NewPlugin(config, sshClient, apiClient, app) |
| 64 | if err != nil { |
| 65 | return fmt.Errorf("failed to initialize command runner: %w", err) |
| 66 | } |
| 67 | |
| 68 | p.runner = runner |
| 69 | |
| 70 | // Register node action |
| 71 | registrar.RegisterNodeAction(components.NodeAction{ |
| 72 | ID: "commandrunner.run_command", |
| 73 | Label: "Run Command", |
| 74 | Shortcut: 'C', // 'C' for command |
| 75 | IsAvailable: func(node *api.Node) bool { |
| 76 | return node != nil && node.Online |
| 77 | }, |
| 78 | Handler: p.handleRunCommand, |
| 79 | }) |
| 80 | |
| 81 | // Register guest action for containers |
| 82 | registrar.RegisterGuestAction(components.GuestAction{ |
| 83 | ID: "commandrunner.run_container_command", |
| 84 | Label: "Run Command", |
| 85 | Shortcut: 'C', // 'C' for command (same as host) |
| 86 | IsAvailable: func(node *api.Node, guest *api.VM) bool { |
| 87 | // Only available for LXC containers on online nodes |
| 88 | return node != nil && node.Online && guest != nil && guest.Type == "lxc" |
| 89 | }, |
| 90 | Handler: p.handleRunContainerCommand, |
| 91 | }) |
| 92 | |
| 93 | // Register guest action for QEMU VMs with guest agent |
| 94 | registrar.RegisterGuestAction(components.GuestAction{ |
| 95 | ID: "commandrunner.run_vm_command", |
| 96 | Label: "Run Command", |
| 97 | Shortcut: 'C', // 'C' for command (same as host and container) |
| 98 | IsAvailable: func(node *api.Node, guest *api.VM) bool { |
| 99 | // Only available for QEMU VMs with guest agent enabled and running |
| 100 | return node != nil && node.Online && guest != nil && |
| 101 | guest.Type == "qemu" && guest.AgentEnabled && guest.AgentRunning |
| 102 | }, |
nothing calls this directly
no test coverage detected