2022-10-08 18:32:02 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-18 18:39:45 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
2022-10-08 18:32:02 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2022-10-18 18:39:45 +08:00
|
|
|
"github.com/pkg/errors"
|
2022-10-08 18:32:02 +08:00
|
|
|
)
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary Page containers
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取容器列表分页
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.PageContainer true "request"
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/search [post]
|
2022-10-08 18:32:02 +08:00
|
|
|
func (b *BaseApi) SearchContainer(c *gin.Context) {
|
|
|
|
var req dto.PageContainer
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := containerService.Page(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Compose
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary Page composes
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取编排列表分页
|
|
|
|
// @Accept json
|
2023-02-07 18:48:32 +08:00
|
|
|
// @Param request body dto.SearchWithPage true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/compose/search [post]
|
2022-10-17 16:04:39 +08:00
|
|
|
func (b *BaseApi) SearchCompose(c *gin.Context) {
|
2023-02-07 18:48:32 +08:00
|
|
|
var req dto.SearchWithPage
|
2022-10-17 16:04:39 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := containerService.PageCompose(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-21 18:42:37 +08:00
|
|
|
// @Tags Container Compose
|
|
|
|
// @Summary Test compose
|
|
|
|
// @Description 测试 compose 是否可用
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ComposeCreate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/compose/test [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"检测 compose [name] 格式","formatEN":"check compose [name]"}
|
|
|
|
func (b *BaseApi) TestCompose(c *gin.Context) {
|
|
|
|
var req dto.ComposeCreate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
isOK, err := containerService.TestCompose(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, isOK)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Compose
|
|
|
|
// @Summary Create compose
|
|
|
|
// @Description 创建容器编排
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ComposeCreate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/compose [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建 compose [name]","formatEN":"create compose [name]"}
|
2022-10-17 16:04:39 +08:00
|
|
|
func (b *BaseApi) CreateCompose(c *gin.Context) {
|
|
|
|
var req dto.ComposeCreate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-20 18:16:26 +08:00
|
|
|
log, err := containerService.CreateCompose(req)
|
|
|
|
if err != nil {
|
2022-10-17 16:04:39 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
2023-03-20 18:16:26 +08:00
|
|
|
helper.SuccessWithData(c, log)
|
2022-10-17 16:04:39 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Compose
|
|
|
|
// @Summary Operate compose
|
|
|
|
// @Description 容器编排操作
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ComposeOperation true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/compose/operate [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name","operation"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"compose [operation] [name]","formatEN":"compose [operation] [name]"}
|
2022-10-17 16:04:39 +08:00
|
|
|
func (b *BaseApi) OperatorCompose(c *gin.Context) {
|
|
|
|
var req dto.ComposeOperation
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := containerService.ComposeOperation(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container
|
|
|
|
// @Summary Create container
|
|
|
|
// @Description 创建容器
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ContainerCreate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name","image"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建容器 [name][image]","formatEN":"create container [name][image]"}
|
2022-10-12 18:55:47 +08:00
|
|
|
func (b *BaseApi) ContainerCreate(c *gin.Context) {
|
|
|
|
var req dto.ContainerCreate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := containerService.ContainerCreate(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-05-23 19:00:06 +08:00
|
|
|
// @Tags Container
|
|
|
|
// @Summary Clean container
|
|
|
|
// @Description 容器清理
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ContainerPrune true "request"
|
|
|
|
// @Success 200 {object} dto.ContainerPruneReport
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/prune [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["pruneType"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"清理容器 [pruneType]","formatEN":"clean container [pruneType]"}
|
|
|
|
func (b *BaseApi) ContainerPrune(c *gin.Context) {
|
|
|
|
var req dto.ContainerPrune
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
report, err := containerService.Prune(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, report)
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:43:51 +08:00
|
|
|
// @Tags Container
|
|
|
|
// @Summary Clean container log
|
|
|
|
// @Description 清理容器日志
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.OperationWithName true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/clean/log [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"清理容器 [name] 日志","formatEN":"clean container [name] logs"}
|
|
|
|
func (b *BaseApi) CleanContainerLog(c *gin.Context) {
|
|
|
|
var req dto.OperationWithName
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := containerService.ContainerLogClean(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container
|
|
|
|
// @Summary Operate Container
|
|
|
|
// @Description 容器操作
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ContainerOperation true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/operate [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name","operation","newName"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"容器 [name] 执行 [operation] [newName]","formatEN":"container [operation] [name] [newName]"}
|
2022-10-08 18:32:02 +08:00
|
|
|
func (b *BaseApi) ContainerOperation(c *gin.Context) {
|
|
|
|
var req dto.ContainerOperation
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := containerService.ContainerOperation(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container
|
|
|
|
// @Summary Container stats
|
|
|
|
// @Description 容器监控信息
|
|
|
|
// @Param id path integer true "容器id"
|
|
|
|
// @Success 200 {object} dto.ContainterStats
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/stats/:id [get]
|
2022-10-13 18:24:24 +08:00
|
|
|
func (b *BaseApi) ContainerStats(c *gin.Context) {
|
|
|
|
containerID, ok := c.Params.Get("id")
|
|
|
|
if !ok {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error container id in path"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := containerService.ContainerStats(containerID)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, result)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container
|
|
|
|
// @Summary Container inspect
|
|
|
|
// @Description 容器详情
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.InspectReq true "request"
|
|
|
|
// @Success 200 {string} result
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/inspect [post]
|
2022-10-11 19:47:16 +08:00
|
|
|
func (b *BaseApi) Inspect(c *gin.Context) {
|
|
|
|
var req dto.InspectReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
2022-10-08 18:32:02 +08:00
|
|
|
return
|
|
|
|
}
|
2022-10-11 19:47:16 +08:00
|
|
|
|
|
|
|
result, err := containerService.Inspect(req)
|
2022-10-08 18:32:02 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *BaseApi) ContainerLogs(c *gin.Context) {
|
2023-06-13 23:04:12 +08:00
|
|
|
wsConn, err := upGrader.Upgrade(c.Writer, c.Request, nil)
|
|
|
|
if err != nil {
|
|
|
|
global.LOG.Errorf("gin context http handler failed, err: %v", err)
|
2022-10-08 18:32:02 +08:00
|
|
|
return
|
|
|
|
}
|
2023-06-13 23:04:12 +08:00
|
|
|
defer wsConn.Close()
|
|
|
|
|
|
|
|
container := c.Query("container")
|
|
|
|
since := c.Query("since")
|
|
|
|
follow := c.Query("follow") == "true"
|
|
|
|
tail := c.Query("tail")
|
|
|
|
|
|
|
|
if err := containerService.ContainerLogs(wsConn, container, since, tail, follow); err != nil {
|
|
|
|
_ = wsConn.WriteMessage(1, []byte(err.Error()))
|
2022-10-08 18:32:02 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2022-10-11 14:20:51 +08:00
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Network
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary Page networks
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取容器网络列表分页
|
|
|
|
// @Accept json
|
2023-02-07 18:48:32 +08:00
|
|
|
// @Param request body dto.SearchWithPage true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/network/search [post]
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) SearchNetwork(c *gin.Context) {
|
2023-02-07 18:48:32 +08:00
|
|
|
var req dto.SearchWithPage
|
2022-10-11 14:20:51 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := containerService.PageNetwork(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
2023-01-04 22:31:51 +08:00
|
|
|
|
|
|
|
// @Tags Container Network
|
|
|
|
// @Summary Delete network
|
|
|
|
// @Description 删除容器网络
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDelete true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/network/del [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["names"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"删除容器网络 [names]","formatEN":"delete container network [names]"}
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) DeleteNetwork(c *gin.Context) {
|
|
|
|
var req dto.BatchDelete
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := containerService.DeleteNetwork(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2023-01-04 22:31:51 +08:00
|
|
|
|
|
|
|
// @Tags Container Network
|
|
|
|
// @Summary Create network
|
|
|
|
// @Description 创建容器网络
|
|
|
|
// @Accept json
|
2023-05-30 15:30:57 +08:00
|
|
|
// @Param request body dto.NetworkCreate true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/network [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建容器网络 name","formatEN":"create container network [name]"}
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) CreateNetwork(c *gin.Context) {
|
2023-05-30 15:30:57 +08:00
|
|
|
var req dto.NetworkCreate
|
2022-10-11 14:20:51 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := containerService.CreateNetwork(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Volume
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary Page volumes
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取容器存储卷分页
|
|
|
|
// @Accept json
|
2023-02-07 18:48:32 +08:00
|
|
|
// @Param request body dto.SearchWithPage true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/volume/search [post]
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) SearchVolume(c *gin.Context) {
|
2023-02-07 18:48:32 +08:00
|
|
|
var req dto.SearchWithPage
|
2022-10-11 14:20:51 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := containerService.PageVolume(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
2023-01-04 22:31:51 +08:00
|
|
|
|
|
|
|
// @Tags Container Volume
|
2023-01-05 11:57:03 +08:00
|
|
|
// @Summary List volumes
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Description 获取容器存储卷列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.PageInfo true "request"
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} dto.PageResult
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/volume/search [get]
|
2022-10-12 18:55:47 +08:00
|
|
|
func (b *BaseApi) ListVolume(c *gin.Context) {
|
|
|
|
list, err := containerService.ListVolume()
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|
2023-01-04 22:31:51 +08:00
|
|
|
|
|
|
|
// @Tags Container Volume
|
|
|
|
// @Summary Delete volume
|
|
|
|
// @Description 删除容器存储卷
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDelete true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/volume/del [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["names"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"删除容器存储卷 [names]","formatEN":"delete container volume [names]"}
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) DeleteVolume(c *gin.Context) {
|
|
|
|
var req dto.BatchDelete
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := containerService.DeleteVolume(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2023-01-04 22:31:51 +08:00
|
|
|
|
|
|
|
// @Tags Container Volume
|
|
|
|
// @Summary Create volume
|
|
|
|
// @Description 创建容器存储卷
|
|
|
|
// @Accept json
|
2023-05-30 15:30:57 +08:00
|
|
|
// @Param request body dto.VolumeCreate true "request"
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/volume [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建容器存储卷 [name]","formatEN":"create container volume [name]"}
|
2022-10-11 14:20:51 +08:00
|
|
|
func (b *BaseApi) CreateVolume(c *gin.Context) {
|
2023-05-30 15:30:57 +08:00
|
|
|
var req dto.VolumeCreate
|
2022-10-11 14:20:51 +08:00
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := containerService.CreateVolume(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
2022-12-06 15:05:13 +08:00
|
|
|
|
2023-01-04 22:31:51 +08:00
|
|
|
// @Tags Container Compose
|
|
|
|
// @Summary Update compose
|
|
|
|
// @Description 更新容器编排
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ComposeUpdate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /containers/compose/update [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新 compose [name]","formatEN":"update compose information [name]"}
|
2022-12-06 15:05:13 +08:00
|
|
|
func (b *BaseApi) ComposeUpdate(c *gin.Context) {
|
|
|
|
var req dto.ComposeUpdate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := containerService.ComposeUpdate(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|