feat: Ansible 模板克隆 (后端 ClonePlaybook API + 前端卡片悬浮克隆按钮 + 模板管理入口)
This commit is contained in:
1 parent
2d02d63806
commit
7be277658a
4 files changed
+78
-1
No files matched your search
@@ -121,6 +121,41 @@ func (h *AnsibleHandler) DeletePlaybook(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, models.Response{Code: 200, Message: "已删除"})
|
||||
}
|
||||
|
||||
// ClonePlaybook 克隆 Playbook 为自定义模板 // Logan.Li
|
||||
// POST /api/v1/ansible/playbooks/:id/clone
|
||||
func (h *AnsibleHandler) ClonePlaybook(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
var src models.AnsiblePlaybook
|
||||
if err := h.db.First(&src, id); err.Error != nil {
|
||||
c.JSON(http.StatusNotFound, models.Response{Code: 404, Message: "Playbook 不存在"})
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Name *string `json:"name"` // 可选自定义名称
|
||||
}
|
||||
c.ShouldBindJSON(&req)
|
||||
|
||||
cloneName := src.Name + " (副本)"
|
||||
if req.Name != nil && *req.Name != "" {
|
||||
cloneName = *req.Name
|
||||
}
|
||||
|
||||
clone := models.AnsiblePlaybook{
|
||||
Name: cloneName,
|
||||
Description: src.Description,
|
||||
Content: src.Content,
|
||||
Tags: src.Tags,
|
||||
Category: src.Category,
|
||||
CreatedBy: c.GetString("username"),
|
||||
}
|
||||
if err := h.db.Create(&clone); err.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{Code: 500, Message: "克隆失败"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, models.Response{Code: 200, Data: clone})
|
||||
}
|
||||
|
||||
// BatchDeletePlaybooks 批量删除 Playbook // Logan.Li
|
||||
func (h *AnsibleHandler) BatchDeletePlaybooks(c *gin.Context) {
|
||||
var req models.IDsRequest
|
||||
|
||||
@@ -443,6 +443,7 @@ func Register(r *gin.Engine, db *gorm.DB, log *zap.Logger, cfg *config.Config, c
|
||||
ansible.DELETE("/playbooks/:id", ansibleHandler.DeletePlaybook)
|
||||
ansible.DELETE("/playbooks/batch-delete", ansibleHandler.BatchDeletePlaybooks)
|
||||
ansible.POST("/playbooks/:id/execute", ansibleHandler.ExecutePlaybook)
|
||||
ansible.POST("/playbooks/:id/clone", ansibleHandler.ClonePlaybook)
|
||||
|
||||
ansible.GET("/jobs", ansibleHandler.ListJobs)
|
||||
ansible.GET("/jobs/:id", ansibleHandler.GetJob)
|
||||
|
||||
Reference in new issue
Block a user