133 строки
4.7 KiB
Go
133 строки
4.7 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// Host 主机信息
|
|
type Host struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
IP string `json:"ip"`
|
|
Port int `json:"port"`
|
|
Username string `json:"username"`
|
|
Password string `json:"password,omitempty"`
|
|
SSHKey string `json:"ssh_key,omitempty"`
|
|
AuthType string `json:"auth_type,omitempty"` // password 或 sshkey
|
|
Groups []string `json:"groups"`
|
|
Vars map[string]string `json:"vars,omitempty"`
|
|
Status string `json:"status"`
|
|
LastCheck time.Time `json:"last_check,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// HostGroup 主机组
|
|
type HostGroup struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Hosts []string `json:"hosts"`
|
|
HostList []Host `json:"host_list,omitempty"` // 组内主机的详细信息
|
|
Vars map[string]string `json:"vars,omitempty"`
|
|
Children []string `json:"children,omitempty"`
|
|
}
|
|
|
|
// Inventory 资产清单
|
|
type Inventory struct {
|
|
All *InventoryGroup `yaml:"all"`
|
|
Ungrouped *InventoryGroup `yaml:"ungrouped,omitempty"`
|
|
}
|
|
|
|
// InventoryGroup 资产组
|
|
type InventoryGroup struct {
|
|
Children map[string]*InventoryGroup `yaml:"children,omitempty"`
|
|
Hosts map[string]Host `yaml:"hosts,omitempty"`
|
|
Vars map[string]interface{} `yaml:"vars,omitempty"`
|
|
}
|
|
|
|
// Playbook Playbook定义
|
|
type Playbook struct {
|
|
Name string `json:"name"`
|
|
Path string `json:"path"`
|
|
Description string `json:"description"`
|
|
Variables map[string]interface{} `json:"variables,omitempty"`
|
|
Hosts string `json:"hosts"`
|
|
Tasks []Task `json:"tasks"`
|
|
}
|
|
|
|
// Task 任务定义
|
|
type Task struct {
|
|
Name string `json:"name"`
|
|
Module string `json:"module"`
|
|
Args map[string]interface{} `json:"args,omitempty"`
|
|
When string `json:"when,omitempty"`
|
|
Loop []interface{} `json:"loop,omitempty"`
|
|
LoopVar string `json:"loop_var,omitempty"`
|
|
}
|
|
|
|
// TaskExecution 任务执行记录
|
|
type TaskExecution struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Playbook string `json:"playbook"`
|
|
Hosts []string `json:"hosts"`
|
|
Status string `json:"status"` // pending, running, success, failed, cancelled
|
|
StartTime time.Time `json:"start_time"`
|
|
EndTime time.Time `json:"end_time,omitempty"`
|
|
Progress int `json:"progress"`
|
|
TotalHosts int `json:"total_hosts"`
|
|
SuccessHosts int `json:"success_hosts"`
|
|
FailedHosts int `json:"failed_hosts"`
|
|
Output string `json:"output,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// CommandRequest 命令执行请求
|
|
type CommandRequest struct {
|
|
Hosts []string `json:"hosts" binding:"required"`
|
|
Command string `json:"command" binding:"required"`
|
|
Parallel bool `json:"parallel"`
|
|
Timeout int `json:"timeout"`
|
|
}
|
|
|
|
// CommandResult 命令执行结果
|
|
type CommandResult struct {
|
|
Host string `json:"host"`
|
|
Success bool `json:"success"`
|
|
Output string `json:"output"`
|
|
Error string `json:"error,omitempty"`
|
|
ExitCode int `json:"exit_code"`
|
|
Duration int64 `json:"duration_ms"`
|
|
}
|
|
|
|
// BatchCommandResult 批量命令结果
|
|
type BatchCommandResult struct {
|
|
TaskID string `json:"task_id"`
|
|
Total int `json:"total"`
|
|
Success int `json:"success"`
|
|
Failed int `json:"failed"`
|
|
Results []CommandResult `json:"results"`
|
|
}
|
|
|
|
// PlaybookExecutionRequest Playbook执行请求
|
|
type PlaybookExecutionRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Hosts []string `json:"hosts"`
|
|
ExtraVars map[string]interface{} `json:"extra_vars"`
|
|
Tags []string `json:"tags,omitempty"` // 只执行指定tags
|
|
SkipTags []string `json:"skip_tags,omitempty"` // 跳过指定tags
|
|
Verbose string `json:"verbose,omitempty"` // v, vv, vvv, vvvv
|
|
Diff bool `json:"diff,omitempty"` // 显示文件差异
|
|
Check bool `json:"check,omitempty"` // dry-run模式
|
|
Become *bool `json:"become,omitempty"` // 是否提权,nil表示使用playbook默认
|
|
Forks int `json:"forks,omitempty"` // 并发数
|
|
Timeout int `json:"timeout,omitempty"` // 超时(秒)
|
|
ExtraArgs string `json:"extra_args,omitempty"` // 自定义额外参数
|
|
}
|
|
|
|
// LogEntry 日志条目
|
|
type LogEntry struct {
|
|
Time string `json:"time"`
|
|
Level string `json:"level"`
|
|
Host string `json:"host"`
|
|
Message string `json:"message"`
|
|
}
|