Documentation
¶
Index ¶
- func PerformOnHosts(hosts []ssh.ClientInfo, ...) map[string]CommandResult
- type Command
- func (c *Command) Cancel() error
- func (c *Command) CreatedAt() time.Time
- func (c *Command) ID() string
- func (c *Command) SetStatusForTest(status CommandStatus)
- func (c *Command) SimulateCancellationForTest()
- func (c *Command) Start() error
- func (c *Command) Status() CommandStatus
- func (c *Command) ToListItem() *CommandListItem
- func (c *Command) ToState() *CommandState
- type CommandListItem
- type CommandResult
- type CommandState
- type CommandStatus
- type MockRunner
- func (m *MockRunner) CancelAllCommands()
- func (m *MockRunner) CreateCommand(commandStr string, hosts []ssh.ClientInfo) *Command
- func (m *MockRunner) GetCommand(commandID string) (*Command, error)
- func (m *MockRunner) GetMostRecentCommand() (*Command, error)
- func (m *MockRunner) ListCommands() []*Command
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PerformOnHosts ¶
func PerformOnHosts(hosts []ssh.ClientInfo, command func(host ssh.ClientInfo, sshClient *ssh.Client) (string, error)) map[string]CommandResult
PerformOnHosts performs the command on all hosts in parallel
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a background command
func (*Command) SetStatusForTest ¶
func (c *Command) SetStatusForTest(status CommandStatus)
SetStatusForTest is a helper method for testing to set the command status This should only be used in tests
func (*Command) SimulateCancellationForTest ¶
func (c *Command) SimulateCancellationForTest()
SimulateCancellationForTest simulates the cancellation process for testing This sets the command to cancelled status after Cancel() is called
func (*Command) Status ¶
func (c *Command) Status() CommandStatus
Status returns the command's current status
func (*Command) ToListItem ¶
func (c *Command) ToListItem() *CommandListItem
ToListItem returns a summary of the command without results (for listing)
func (*Command) ToState ¶
func (c *Command) ToState() *CommandState
ToState returns a safe copy of the command state for serialization
type CommandListItem ¶
type CommandListItem struct {
ID string `json:"id"`
Status CommandStatus `json:"status"`
Command string `json:"command"`
Hosts []utils.HostIdentifier `json:"hosts"`
CreatedAt time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
EndedAt *time.Time `json:"ended_at,omitempty"`
}
CommandListItem represents a summary of a command for listing (without results)
type CommandResult ¶
type CommandResult struct {
Host string `json:"host"`
Result string `json:"result"`
Err error `json:"error"`
}
CommandResult is a single result on that host
func (CommandResult) MarshalJSON ¶
func (cr CommandResult) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling to properly handle the error field
type CommandState ¶
type CommandState struct {
ID string `json:"id"`
Status CommandStatus `json:"status"`
Command string `json:"command"`
Hosts []utils.HostIdentifier `json:"hosts"`
Results map[string]CommandResult `json:"results"`
CreatedAt time.Time `json:"created_at"`
StartedAt *time.Time `json:"started_at,omitempty"`
EndedAt *time.Time `json:"ended_at,omitempty"`
Error string `json:"error,omitempty"`
}
CommandState represents the serializable state of a Command
type CommandStatus ¶
type CommandStatus string
CommandStatus represents the current state of a command
const ( CommandStatusPending CommandStatus = "pending" CommandStatusRunning CommandStatus = "running" CommandStatusCompleted CommandStatus = "completed" CommandStatusFailed CommandStatus = "failed" CommandStatusCancelled CommandStatus = "cancelled" )
type MockRunner ¶
type MockRunner struct {
Commands map[string]*Command
CreateCommandFunc func(commandStr string, hosts []ssh.ClientInfo) *Command
GetCommandFunc func(commandID string) (*Command, error)
GetMostRecentFunc func() (*Command, error)
ListCommandsFunc func() []*Command
CancelAllFunc func()
}
MockRunner is a mock implementation of Runner for testing purposes
func (*MockRunner) CancelAllCommands ¶
func (m *MockRunner) CancelAllCommands()
CancelAllCommands cancels all running commands (mock implementation)
func (*MockRunner) CreateCommand ¶
func (m *MockRunner) CreateCommand(commandStr string, hosts []ssh.ClientInfo) *Command
CreateCommand creates a new command (mock implementation)
func (*MockRunner) GetCommand ¶
func (m *MockRunner) GetCommand(commandID string) (*Command, error)
GetCommand retrieves a command by ID (mock implementation)
func (*MockRunner) GetMostRecentCommand ¶
func (m *MockRunner) GetMostRecentCommand() (*Command, error)
GetMostRecentCommand returns the most recently created command (mock implementation)
func (*MockRunner) ListCommands ¶
func (m *MockRunner) ListCommands() []*Command
ListCommands returns all commands (mock implementation)