Skip to content

Commit

Permalink
Merge pull request #928 from seokho-son/main
Browse files Browse the repository at this point in the history
Remove control action parameters from get mcis
  • Loading branch information
seokho-son authored Nov 3, 2021
2 parents 3c7612d + 50893e7 commit 5c31fac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.
59 changes: 15 additions & 44 deletions src/api/rest/server/mcis/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,15 @@ type JSONResult struct {
// Annotation for API documention Need to be revised.

// RestGetMcis godoc
// @Summary Get MCIS, Action to MCIS (status, suspend, resume, reboot, terminate), or Get VMs' ID
// @Description Get MCIS, Action to MCIS (status, suspend, resume, reboot, terminate), or Get VMs' ID
// @Summary Get MCIS object (option: status, vmID)
// @Description Get MCIS object (option: status, vmID)
// @Tags [MCIS] Provisioning management
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param action query string false "Action to MCIS" Enums(status, suspend, resume, reboot, terminate)
// @Param option query string false "Option" Enums(id)
// @success 200 {object} JSONResult{[DEFAULT]=mcis.TbMcisInfo,[STATUS]=mcis.McisStatusInfo,[CONTROL]=common.SimpleMsg,[ID]=common.IdList} "Different return structures by the given action param"
// @Param option query string false "Option" Enums(default, id, status)
// @success 200 {object} JSONResult{[DEFAULT]=mcis.TbMcisInfo,[ID]=common.IdList,[STATUS]=mcis.McisStatusInfo} "Different return structures by the given action param"
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId} [get]
Expand All @@ -118,7 +117,6 @@ func RestGetMcis(c echo.Context) error {
nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

action := c.QueryParam("action")
option := c.QueryParam("option")

if option == "id" {
Expand All @@ -131,18 +129,7 @@ func RestGetMcis(c echo.Context) error {
}

return c.JSON(http.StatusOK, &content)
} else if action == "suspend" || action == "resume" || action == "reboot" || action == "terminate" {

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

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

} else if action == "status" {
} else if option == "status" {

result, err := mcis.GetMcisStatus(nsId, mcisId)
if err != nil {
Expand All @@ -155,9 +142,7 @@ func RestGetMcis(c echo.Context) error {
}
content.Result = result

//fmt.Printf("%+v\n", content)
common.PrintJsonPretty(content)

return c.JSON(http.StatusOK, &content)

} else {
Expand All @@ -168,10 +153,7 @@ func RestGetMcis(c echo.Context) error {
return c.JSON(http.StatusNotFound, &mapA)
}

//fmt.Printf("%+v\n", *result)
common.PrintJsonPretty(*result)
//return by string
//return c.String(http.StatusOK, keyValue.Value)
return c.JSON(http.StatusOK, result)

}
Expand Down Expand Up @@ -371,14 +353,14 @@ func RestPostMcisRecommend(c echo.Context) error {
}

// RestGetControlMcis godoc
// @Summary Control the lifecycle of MCIS
// @Description Control the lifecycle of MCIS
// @Summary Control the lifecycle of MCIS (refine, suspend, resume, reboot, terminate)
// @Description Control the lifecycle of MCIS (refine, suspend, resume, reboot, terminate)
// @Tags [MCIS] Control lifecycle
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param action query string false "Action to MCIS" Enums(status, suspend, resume, reboot, terminate, refine)
// @Param action query string true "Action to MCIS" Enums(suspend, resume, reboot, terminate, refine)
// @Success 200 {object} common.SimpleMsg
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
Expand Down Expand Up @@ -407,15 +389,15 @@ func RestGetControlMcis(c echo.Context) error {
}

// RestGetControlMcisVm godoc
// @Summary Control the lifecycle of VM
// @Description Control the lifecycle of VM
// @Summary Control the lifecycle of VM (suspend, resume, reboot, terminate)
// @Description Control the lifecycle of VM (suspend, resume, reboot, terminate)
// @Tags [MCIS] Control lifecycle
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param vmId path string true "VM ID" default(vm01)
// @Param action query string false "Action to MCIS" Enums(status, suspend, resume, reboot, terminate)
// @Param action query string true "Action to MCIS" Enums(suspend, resume, reboot, terminate)
// @Success 200 {object} common.SimpleMsg
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
Expand Down Expand Up @@ -672,8 +654,8 @@ func RestPostMcisVmGroup(c echo.Context) error {
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param vmId path string true "VM ID" default(vm01)
// @Param action query string false "Action to MCIS" Enums(status, suspend, resume, reboot, terminate)
// @success 200 {object} JSONResult{[DEFAULT]=mcis.TbVmInfo,[STATUS]=mcis.TbVmStatusInfo,[CONTROL]=common.SimpleMsg} "Different return structures by the given action param"
// @Param option query string false "Option for MCIS" Enums(default, status)
// @success 200 {object} JSONResult{[DEFAULT]=mcis.TbVmInfo,[STATUS]=mcis.TbVmStatusInfo} "Different return structures by the given option param"
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/mcis/{mcisId}/vm/{vmId} [get]
Expand All @@ -683,20 +665,9 @@ func RestGetMcisVm(c echo.Context) error {
mcisId := c.Param("mcisId")
vmId := c.Param("vmId")

action := c.QueryParam("action")

if action == "suspend" || action == "resume" || action == "reboot" || action == "terminate" {

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

mapA := map[string]string{"message": result}
return c.JSON(http.StatusOK, &mapA)
option := c.QueryParam("option")

} else if action == "status" {
if option == "status" {

result, err := mcis.CoreGetMcisVmStatus(nsId, mcisId, vmId)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/testclient/scripts/8.mcis/status-mcis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ source ../init.sh

echo "${MCISID}"

ControlCmd=status
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}?action=${ControlCmd} | jq ''
GetMCISOption=status
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}?option=${GetMCISOption} | jq ''

echo -e "${BOLD}"
echo -e "Table: All VMs in the MCIS : ${MCISID}"

echo -e "${NC} ${BLUE} ${BOLD}"
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}?action=${ControlCmd} |
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}?option=${GetMCISOption} |
jq '.status | .vm | sort_by(.id)' |
jq -r '(["VM-ID","Status","PublicIP","PrivateIP","CloudType","CloudRegion","CreatedTime"] | (., map(length*"-"))), (.[] | [.id, .status, .publicIp, .privateIp, .location.cloudType, .location.nativeRegion, .createdTime]) | @tsv' |
column -t
Expand Down

0 comments on commit 5c31fac

Please sign in to comment.