Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set get bastion node API #1351

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/api/rest/server/mcis/remoteCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,59 @@ func RestPostCmdMcis(c echo.Context) error {
return c.JSON(http.StatusOK, content)

}

// RestSetBastionNodes godoc
// @Summary Set bastion nodes for a VM
// @Description Set bastion nodes for a VM
// @Tags [Infra service] MCIS Remote command
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param targetVmId path string true "Target VM ID" default(vm01)
// @Param bastionVmId path string true "Bastion VM ID" default(bastion01)
// @Success 200 {object} common.SimpleMsg
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId}/vm/{targetVmId}/bastion/{bastionVmId} [put]
func RestSetBastionNodes(c echo.Context) error {
nsId := c.Param("nsId")
mcisId := c.Param("mcisId")
targetVmId := c.Param("targetVmId")
bastionVmId := c.Param("bastionVmId")

message, err := mcis.SetBastionNodes(nsId, mcisId, targetVmId, bastionVmId)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

return c.JSON(http.StatusOK, map[string]string{"message": message})
}

// RestGetBastionNodes godoc
// @Summary Get bastion nodes for a VM
// @Description Get bastion nodes for a VM
// @Tags [Infra service] MCIS Remote command
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param targetVmId path string true "Target VM ID" default(vm01)
// @Success 200 {object} mcis.BastionInfo
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId}/vm/{targetVmId}/bastion [get]
func RestGetBastionNodes(c echo.Context) error {
nsId := c.Param("nsId")
mcisId := c.Param("mcisId")
targetVmId := c.Param("targetVmId")

bastionNodes, err := mcis.GetBastionNodes(nsId, mcisId, targetVmId)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

return c.JSON(http.StatusOK, bastionNodes)
}
3 changes: 3 additions & 0 deletions src/api/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ func RunServer(port string) {
g.GET("/:nsId/control/mcis/:mcisId/vm/:vmId", rest_mcis.RestGetControlMcisVm)

g.POST("/:nsId/cmd/mcis/:mcisId", rest_mcis.RestPostCmdMcis)
g.PUT("/:nsId/mcis/:mcisId/vm/:targetVmId/bastion/:bastionVmId", rest_mcis.RestSetBastionNodes)
g.GET("/:nsId/mcis/:mcisId/vm/:targetVmId/bastion", rest_mcis.RestGetBastionNodes)

g.POST("/:nsId/installBenchmarkAgent/mcis/:mcisId", rest_mcis.RestPostInstallBenchmarkAgentToMcis)
g.POST("/:nsId/benchmark/mcis/:mcisId", rest_mcis.RestGetBenchmark)
g.POST("/:nsId/benchmarkAll/mcis/:mcisId", rest_mcis.RestGetAllBenchmark)
Expand Down