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

Remove control action parameters from get mcis #928

Merged
merged 2 commits into from
Nov 3, 2021
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
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