add drain function

This commit is contained in:
yanmingfan
2018-06-12 14:24:01 +08:00
parent 2e5e364088
commit 06ed882f13
2 changed files with 98 additions and 1 deletions

View File

@@ -19,6 +19,8 @@ package nodes
import (
"github.com/emicklei/go-restful"
"net/http"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/pkg/filter/route"
"kubesphere.io/kubesphere/pkg/models"
@@ -32,6 +34,10 @@ func Register(ws *restful.WebService, subPath string) {
ws.Route(ws.GET(subPath+"/{nodename}").To(handleSingleNode).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
ws.Route(ws.POST(subPath+"/{nodename}/drainage").To(handleDrainNode).Filter(route.RouteLogging)).
Consumes(restful.MIME_JSON, restful.MIME_XML).
Produces(restful.MIME_JSON)
}
func handleNodes(request *restful.Request, response *restful.Response) {
@@ -60,3 +66,21 @@ func handleSingleNode(request *restful.Request, response *restful.Response) {
response.WriteAsJson(resultNode)
}
func handleDrainNode(request *restful.Request, response *restful.Response) {
nodeName := request.PathParameter("nodename")
result, err := models.DrainNode(nodeName)
if err != nil {
response.WriteHeaderAndEntity(http.StatusInternalServerError, constants.MessageResponse{Message: err.Error()})
} else {
response.WriteAsJson(result)
}
}