bdb7d54505
- 新增SSH密钥库管理(集中托管私钥、自动指纹识别) - 新增模板中心(24个预置模板,7大分类,一键创建Playbook) - 新增文件分发功能(内容/文件双模式,权限设置) - 新增系统信息接口(版本/主机数/运行时间) - 主机支持密码/SSH密钥双认证方式 - 全新暗色玻璃拟态UI(侧边栏导航、SSE实时日志流) - 修复UpdateHost ID丢失bug - 添加.gitignore排除敏感数据
161 lines
5.7 KiB
Go
161 lines
5.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"` // SSH密钥名称或路径
|
|
AuthType string `json:"auth_type,omitempty"` // password 或 sshkey
|
|
Groups []string `json:"groups"`
|
|
Vars map[string]string `json:"vars,omitempty"`
|
|
Status string `json:"status"`
|
|
OS string `json:"os,omitempty"`
|
|
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"`
|
|
}
|
|
|
|
// 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"`
|
|
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"`
|
|
SkipTags []string `json:"skip_tags,omitempty"`
|
|
Verbose string `json:"verbose,omitempty"`
|
|
Diff bool `json:"diff,omitempty"`
|
|
Check bool `json:"check,omitempty"`
|
|
Become *bool `json:"become,omitempty"`
|
|
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"`
|
|
}
|
|
|
|
// SSHKey SSH密钥
|
|
type SSHKey struct {
|
|
Name string `json:"name"`
|
|
Fingerprint string `json:"fingerprint,omitempty"`
|
|
Path string `json:"path"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// SSHKeyCreateRequest 创建SSH密钥请求
|
|
type SSHKeyCreateRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
PrivateKey string `json:"private_key" binding:"required"`
|
|
}
|
|
|
|
// FileDistributeRequest 文件分发请求
|
|
type FileDistributeRequest struct {
|
|
Hosts []string `json:"hosts" binding:"required"`
|
|
Content string `json:"content"` // 文件内容(与SourceFile二选一)
|
|
SourceFile string `json:"source_file"` // 服务器上的源文件路径
|
|
DestPath string `json:"dest_path" binding:"required"` // 目标路径
|
|
Owner string `json:"owner"`
|
|
Group string `json:"group"`
|
|
Mode string `json:"mode"` // 如 0644
|
|
}
|
|
|
|
// SystemInfo 系统信息
|
|
type SystemInfo struct {
|
|
Version string `json:"version"`
|
|
AnsiblePath string `json:"ansible_path"`
|
|
AnsibleVer string `json:"ansible_version"`
|
|
Hostname string `json:"hostname"`
|
|
OS string `json:"os"`
|
|
Arch string `json:"arch"`
|
|
HostCount int `json:"host_count"`
|
|
GroupCount int `json:"group_count"`
|
|
PlaybookCount int `json:"playbook_count"`
|
|
TaskCount int `json:"task_count"`
|
|
Uptime string `json:"uptime"`
|
|
}
|