1
1
package v1
2
2
3
3
import (
4
+ "net/http"
5
+
4
6
"github.com/IceWhaleTech/CasaOS/model"
5
7
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
6
8
"github.com/IceWhaleTech/CasaOS/service"
7
9
"github.com/gin-gonic/gin"
8
10
"github.com/shirou/gopsutil/v3/disk"
9
- "net/http"
10
- "strconv"
11
11
)
12
12
13
13
// @Summary 获取磁盘列表
@@ -59,7 +59,7 @@ func GetPlugInDisk(c *gin.Context) {
59
59
c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS ), Data : lst })
60
60
}
61
61
62
- // @Summary 获取磁盘列表
62
+ // @Summary get disk list
63
63
// @Produce application/json
64
64
// @Accept application/json
65
65
// @Tags disk
@@ -76,12 +76,12 @@ func GetPlugInDisks(c *gin.Context) {
76
76
c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS ), Data : result })
77
77
}
78
78
79
- // @Summary 磁盘详情
79
+ // @Summary disk detail
80
80
// @Produce application/json
81
81
// @Accept application/json
82
82
// @Tags disk
83
83
// @Security ApiKeyAuth
84
- // @Param path query string true "要获取的磁盘详情 例如 /dev/sda"
84
+ // @Param path query string true "for example /dev/sda"
85
85
// @Success 200 {string} string "ok"
86
86
// @Router /disk/info [get]
87
87
func GetDiskInfo (c * gin.Context ) {
@@ -93,7 +93,7 @@ func GetDiskInfo(c *gin.Context) {
93
93
c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS ), Data : m })
94
94
}
95
95
96
- // @Summary 磁盘详情
96
+ // @Summary format disk
97
97
// @Produce application/json
98
98
// @Accept multipart/form-data
99
99
// @Tags disk
@@ -109,15 +109,9 @@ func FormatDisk(c *gin.Context) {
109
109
if len (path ) == 0 || len (t ) == 0 {
110
110
c .JSON (http .StatusOK , model.Result {Success : oasis_err .INVALID_PARAMS , Message : oasis_err .GetMsg (oasis_err .INVALID_PARAMS )})
111
111
}
112
-
113
- //删除挂载点
114
- service .MyService .Disk ().UmountPointAndRemoveDir (path )
115
-
116
112
//格式化磁盘
117
113
service .MyService .Disk ().FormatDisk (path , t )
118
114
119
- //重新挂载
120
-
121
115
c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS )})
122
116
}
123
117
@@ -154,25 +148,43 @@ func RemovePartition(c *gin.Context) {
154
148
c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS )})
155
149
}
156
150
157
- // @Summary 添加分区
151
+ // @Summary serial number
158
152
// @Produce application/json
159
153
// @Accept multipart/form-data
160
154
// @Tags disk
161
155
// @Security ApiKeyAuth
162
156
// @Param path formData string true "磁盘路径 例如/dev/sda"
163
- // @Param size formData string true "需要分区容量大小(MB)"
164
- // @Param num formData string true "磁盘符号"
157
+ // @Param serial formData string true "serial"
165
158
// @Success 200 {string} string "ok"
166
159
// @Router /disk/addpart [post]
167
160
func AddPartition (c * gin.Context ) {
168
161
path := c .PostForm ("path" )
169
- size , _ := strconv .Atoi (c .DefaultPostForm ("size" , "0" ))
170
- num := c .DefaultPostForm ("num" , "9" )
171
- if len (path ) == 0 {
162
+ serial := c .PostForm ("serial" )
163
+ if len (path ) == 0 || len (serial ) == 0 {
172
164
c .JSON (http .StatusOK , model.Result {Success : oasis_err .INVALID_PARAMS , Message : oasis_err .GetMsg (oasis_err .INVALID_PARAMS )})
165
+ return
173
166
}
167
+ service .MyService .Disk ().AddPartition (path )
168
+ c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS )})
169
+ }
170
+
171
+ func PostMountDisk (c * gin.Context ) {
172
+ // for example: path=/dev/sda1
173
+ path := c .PostForm ("path" )
174
+ //执行挂载目录
175
+ service .MyService .Disk ().MountDisk (path , "volume" )
176
+ //添加到数据库
177
+
178
+ c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS )})
179
+ }
180
+
181
+ func DeleteUmountDisk (c * gin.Context ) {
182
+
183
+ // for example: path=/dev/sda1
184
+ path := c .PostForm ("path" )
185
+ service .MyService .Disk ().UmountPointAndRemoveDir (path )
186
+
187
+ //删除数据库记录
174
188
175
- //size*1024*1024/512
176
- service .MyService .Disk ().AddPartition (path , num , uint64 (size * 1024 * 2 ))
177
189
c .JSON (http .StatusOK , model.Result {Success : oasis_err .SUCCESS , Message : oasis_err .GetMsg (oasis_err .SUCCESS )})
178
190
}
0 commit comments