Documentation
¶
Index ¶
- func ExampleStackUpExecute_Base64()
- func ExampleStackUpExecute_MultipleCommands()
- func ExampleStackUpExecute_WithLocalDataPath()
- func ExampleStackUpExecute_WithScript()
- func ExampleStackUpExecute_YAML()
- type AsyncExecuteClient
- func (c *AsyncExecuteClient) AsyncExecute(ctx context.Context, req *AsyncExecuteRequest) (*AsyncExecuteResponse, error)
- func (c *AsyncExecuteClient) GetResult(ctx context.Context, taskIDs []string, onlyCurrentController bool) (*GetResultResponse, error)
- func (c *AsyncExecuteClient) GetSingleResult(ctx context.Context, taskID string, onlyCurrentController bool) (*AsyncTaskResult, error)
- func (c *AsyncExecuteClient) StackUpExecute(ctx context.Context, req *StackUpExecuteRequest) (*StackUpExecuteResponse, error)
- func (c *AsyncExecuteClient) SyncExecute(ctx context.Context, req *AsyncExecuteRequest, opts *SyncExecuteOptions) (*AsyncTaskResult, error)
- type AsyncExecuteClientConfig
- type AsyncExecuteRequest
- type AsyncExecuteResponse
- type AsyncTaskResult
- type Client
- func (c *Client) CreateDeployment(req models.DeploymentRequest) (*models.Deployment, error)
- func (c *Client) GetControllerStatus() (*models.ControllerStatus, error)
- func (c *Client) GetDeployment(deploymentID string) (*models.Deployment, error)
- func (c *Client) GetPackageLogs(agentCode, packageName string, count int) ([]string, error)
- func (c *Client) ListAgents(filter map[string]string, page, pageSize int) (*models.AgentsResponse, error)
- func (c *Client) ListDeployments() ([]models.Deployment, error)
- func (c *Client) StartPackage(agentCode, packageName string) error
- func (c *Client) StopPackage(agentCode, packageName string) error
- type CommandResult
- type ConfigDriver
- type ErrorDetail
- type ErrorType
- type ExecutionResult
- type GetResultRequest
- type GetResultResponse
- type StackUpCommandResult
- type StackUpExecuteRequest
- type StackUpExecuteResponse
- type SyncExecuteOptions
- type TaskInfo
- type TaskStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleStackUpExecute_Base64 ¶
func ExampleStackUpExecute_Base64()
ExampleStackUpExecute_Base64 使用 Base64 编码配置执行 StackUp
func ExampleStackUpExecute_MultipleCommands ¶
func ExampleStackUpExecute_MultipleCommands()
ExampleStackUpExecute_MultipleCommands 执行多个命令
func ExampleStackUpExecute_WithLocalDataPath ¶
func ExampleStackUpExecute_WithLocalDataPath()
ExampleStackUpExecute_WithLocalDataPath 使用本地数据路径执行 StackUp
func ExampleStackUpExecute_WithScript ¶
func ExampleStackUpExecute_WithScript()
ExampleStackUpExecute_WithScript 使用脚本执行 StackUp
func ExampleStackUpExecute_YAML ¶
func ExampleStackUpExecute_YAML()
ExampleStackUpExecute_YAML 使用 YAML 配置执行 StackUp
Types ¶
type AsyncExecuteClient ¶
type AsyncExecuteClient struct {
// contains filtered or unexported fields
}
AsyncExecuteClient SDK 客户端
func NewAsyncExecuteClient ¶
func NewAsyncExecuteClient(config *AsyncExecuteClientConfig) *AsyncExecuteClient
NewAsyncExecuteClient 创建新的 SDK 客户端
func (*AsyncExecuteClient) AsyncExecute ¶
func (c *AsyncExecuteClient) AsyncExecute(ctx context.Context, req *AsyncExecuteRequest) (*AsyncExecuteResponse, error)
AsyncExecute 异步执行命令(提交任务,不等待结果)
func (*AsyncExecuteClient) GetResult ¶
func (c *AsyncExecuteClient) GetResult(ctx context.Context, taskIDs []string, onlyCurrentController bool) (*GetResultResponse, error)
GetResult 查询任务结果(支持批量查询)
func (*AsyncExecuteClient) GetSingleResult ¶
func (c *AsyncExecuteClient) GetSingleResult(ctx context.Context, taskID string, onlyCurrentController bool) (*AsyncTaskResult, error)
GetSingleResult 查询单个任务结果(便捷方法)
func (*AsyncExecuteClient) StackUpExecute ¶
func (c *AsyncExecuteClient) StackUpExecute(ctx context.Context, req *StackUpExecuteRequest) (*StackUpExecuteResponse, error)
StackUpExecute 执行 StackUp 命令 接收一个 YAML 格式的配置文件,解析后执行其中的命令
func (*AsyncExecuteClient) SyncExecute ¶
func (c *AsyncExecuteClient) SyncExecute(ctx context.Context, req *AsyncExecuteRequest, opts *SyncExecuteOptions) (*AsyncTaskResult, error)
SyncExecute 同步执行命令(提交任务并等待结果) 简洁实现:使用简单的轮询循环,逻辑清晰
type AsyncExecuteClientConfig ¶
type AsyncExecuteClientConfig struct {
BaseURL string // API 基础 URL,例如 "http://localhost:8081"
HTTPClient *http.Client // 自定义 HTTP 客户端(可选)
DefaultTimeout time.Duration // 默认请求超时时间
PollInterval time.Duration // 轮询间隔(同步调用时使用)
MaxPollDuration time.Duration // 最大轮询时间(同步调用时使用)
MaxPollAttempts int // 最大轮询次数(同步调用时使用)
}
AsyncExecuteClientConfig SDK 客户端配置
func DefaultAsyncExecuteClientConfig ¶
func DefaultAsyncExecuteClientConfig(baseURL string) *AsyncExecuteClientConfig
DefaultAsyncExecuteClientConfig 返回默认配置
type AsyncExecuteRequest ¶
type AsyncExecuteRequest struct {
ID string `json:"id"`
RemoteInfo structs.L2DeviceRemoteInfo `json:"remote_info"`
Commands []string `json:"commands,omitempty"`
Script string `json:"script,omitempty"`
ScriptPath string `json:"script_path,omitempty"`
Background bool `json:"background,omitempty"`
Timeout int `json:"timeout,omitempty"`
}
AsyncExecuteRequest 异步执行请求
type AsyncExecuteResponse ¶
type AsyncExecuteResponse struct {
Success bool `json:"success,omitempty"`
TaskID string `json:"id"` // API 返回的字段是 "id"
Status string `json:"status"`
Message string `json:"message"`
TaskInfo TaskInfo `json:"task_info"`
}
AsyncExecuteResponse 异步执行响应
type AsyncTaskResult ¶
type AsyncTaskResult struct {
Status TaskStatus `json:"status"`
TaskInfo TaskInfo `json:"task_info"`
StartTime time.Time `json:"start_time"`
EndTime *time.Time `json:"end_time,omitempty"`
Duration *int64 `json:"duration,omitempty"`
Result *ExecutionResult `json:"result,omitempty"`
Error *ErrorDetail `json:"error,omitempty"`
Message string `json:"message,omitempty"`
}
AsyncTaskResult 异步任务结果
func (*AsyncTaskResult) GetCombinedError ¶
func (r *AsyncTaskResult) GetCombinedError() string
GetCombinedError 获取合并后的错误输出
func (*AsyncTaskResult) GetCombinedOutput ¶
func (r *AsyncTaskResult) GetCombinedOutput() string
GetCombinedOutput 获取合并后的输出(兼容旧版本)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CreateDeployment ¶
func (c *Client) CreateDeployment(req models.DeploymentRequest) (*models.Deployment, error)
CreateDeployment creates a new deployment
func (*Client) GetControllerStatus ¶
func (c *Client) GetControllerStatus() (*models.ControllerStatus, error)
func (*Client) GetDeployment ¶
func (c *Client) GetDeployment(deploymentID string) (*models.Deployment, error)
GetDeployment retrieves a deployment by its ID
func (*Client) GetPackageLogs ¶
GetPackageLogs retrieves logs for a specific package on a specific agent
func (*Client) ListAgents ¶
func (*Client) ListDeployments ¶
func (c *Client) ListDeployments() ([]models.Deployment, error)
ListDeployments retrieves a list of all deployments
func (*Client) StartPackage ¶
StartPackage starts a package on a specific agent
func (*Client) StopPackage ¶
StopPackage stops a package on a specific agent
type CommandResult ¶
type CommandResult struct {
Index int `json:"index"`
Command string `json:"command"`
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Duration int64 `json:"duration,omitempty"`
ExecutedAt time.Time `json:"executed_at"`
}
CommandResult 单个命令的执行结果
type ConfigDriver ¶
type ConfigDriver struct {
keys.Keys
EtcdEndpoints []string
EtcdUsername string
EtcdPassword string
}
func NewConfigDriver ¶
func NewConfigDriver(base, area string, endpoints []string) *ConfigDriver
func NewConfigDriverWithAuth ¶
func NewConfigDriverWithAuth(base, area string, endpoints []string, username, password string) *ConfigDriver
type ErrorDetail ¶
type ErrorDetail struct {
Type ErrorType `json:"type"`
Code string `json:"code,omitempty"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
}
ErrorDetail 错误详情
type ExecutionResult ¶
type ExecutionResult struct {
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
OutputSize int64 `json:"output_size"`
CommandResults []CommandResult `json:"command_results,omitempty"`
}
ExecutionResult 执行结果详情
type GetResultRequest ¶
type GetResultRequest struct {
TaskIDs []string `json:"task_ids"`
OnlyCurrentController bool `json:"only_current,omitempty"`
}
GetResultRequest 查询结果请求
type GetResultResponse ¶
type GetResultResponse struct {
Results map[string]*AsyncTaskResult `json:"results"`
Errors map[string]string `json:"errors,omitempty"`
}
GetResultResponse 查询结果响应
type StackUpCommandResult ¶
type StackUpCommandResult struct {
Index int `json:"index"` // 命令索引(从1开始)
Command string `json:"command"` // 执行的命令
Key string `json:"key"` // 命令的 key/name
Output string `json:"output"` // 命令输出
Msg string `json:"msg"` // 消息
Status string `json:"status"` // 状态:"true" 表示有错误,"false" 表示成功
}
StackUpCommandResult 单个命令的执行结果
type StackUpExecuteRequest ¶
type StackUpExecuteRequest struct {
RemoteInfo structs.L2DeviceRemoteInfo `json:"remote_info"` // 设备连接信息
Config string `json:"config"` // YAML 格式的配置文件(可以是 base64 编码或原始字符串)
ConfigType string `json:"config_type,omitempty"` // "yaml" 或 "base64",默认为 "yaml"
LocalDataPath string `json:"local_data_path,omitempty"` // 本地数据路径(可选)
}
StackUpExecuteRequest StackUp 执行请求
type StackUpExecuteResponse ¶
type StackUpExecuteResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Results []StackUpCommandResult `json:"results,omitempty"`
Error string `json:"error,omitempty"`
}
StackUpExecuteResponse StackUp 执行响应
type SyncExecuteOptions ¶
type SyncExecuteOptions struct {
PollInterval time.Duration // 轮询间隔,默认使用 AsyncExecuteClientConfig 中的值
MaxPollDuration time.Duration // 最大轮询时间,默认使用 AsyncExecuteClientConfig 中的值
MaxPollAttempts int // 最大轮询次数,默认使用 AsyncExecuteClientConfig 中的值
OnStatusUpdate func(status TaskStatus, result *AsyncTaskResult) // 状态更新回调(可选)
}
SyncExecuteOptions 同步执行选项
type TaskInfo ¶
type TaskInfo struct {
ID string `json:"id"`
ControllerID string `json:"controller_id"`
DeviceIP string `json:"device_ip"`
DevicePort int `json:"device_port"`
Username string `json:"username"`
CommandType string `json:"command_type"`
Background bool `json:"background"`
Timeout int `json:"timeout"`
CreatedAt time.Time `json:"created_at"`
}
TaskInfo 任务信息
type TaskStatus ¶
type TaskStatus string
TaskStatus 任务状态
const ( TaskStatusPending TaskStatus = "pending" // 待执行 TaskStatusRunning TaskStatus = "running" // 执行中 TaskStatusCompleted TaskStatus = "completed" // 已完成 TaskStatusFailed TaskStatus = "failed" // 执行失败 TaskStatusTimeout TaskStatus = "timeout" // 执行超时 TaskStatusCancelled TaskStatus = "cancelled" // 已取消 )