From 65fe82df8d9e0eb59a2fb0a24e6525c1a260e08a Mon Sep 17 00:00:00 2001 From: Seokho Son Date: Mon, 25 Sep 2023 19:08:50 +0900 Subject: [PATCH] Add set get bastion node API --- src/api/rest/server/mcis/remoteCommand.go | 56 +++++++++++++++++++++++ src/api/rest/server/server.go | 3 ++ 2 files changed, 59 insertions(+) diff --git a/src/api/rest/server/mcis/remoteCommand.go b/src/api/rest/server/mcis/remoteCommand.go index e52665ef3..1d744ac32 100644 --- a/src/api/rest/server/mcis/remoteCommand.go +++ b/src/api/rest/server/mcis/remoteCommand.go @@ -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) +} diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 62628c97f..98daa07cb 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -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)