Skip to content

Commit

Permalink
Merge pull request #1244 from jihoon-seo/221031_Update_availableDataD…
Browse files Browse the repository at this point in the history
…isk_REST_API

Update `availableDataDisk` REST API
  • Loading branch information
seokho-son authored Oct 31, 2022
2 parents c9f205f + edb4cc6 commit 63027a3
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 59 deletions.
30 changes: 17 additions & 13 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2869,9 +2869,24 @@ const docTemplate = `{
],
"responses": {
"200": {
"description": "OK",
"description": "Different return structures by the given option param",
"schema": {
"$ref": "#/definitions/mcir.RestGetAvailableDataDisksResponse"
"allOf": [
{
"$ref": "#/definitions/mcir.JSONResult"
},
{
"type": "object",
"properties": {
"[DEFAULT]": {
"$ref": "#/definitions/mcir.RestGetAllDataDiskResponse"
},
"[ID]": {
"$ref": "#/definitions/common.IdList"
}
}
}
]
}
},
"404": {
Expand Down Expand Up @@ -7259,17 +7274,6 @@ const docTemplate = `{
}
}
},
"mcir.RestGetAvailableDataDisksResponse": {
"type": "object",
"properties": {
"dataDisk": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"mcir.RestLookupImageRequest": {
"type": "object",
"properties": {
Expand Down
30 changes: 17 additions & 13 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2861,9 +2861,24 @@
],
"responses": {
"200": {
"description": "OK",
"description": "Different return structures by the given option param",
"schema": {
"$ref": "#/definitions/mcir.RestGetAvailableDataDisksResponse"
"allOf": [
{
"$ref": "#/definitions/mcir.JSONResult"
},
{
"type": "object",
"properties": {
"[DEFAULT]": {
"$ref": "#/definitions/mcir.RestGetAllDataDiskResponse"
},
"[ID]": {
"$ref": "#/definitions/common.IdList"
}
}
}
]
}
},
"404": {
Expand Down Expand Up @@ -7251,17 +7266,6 @@
}
}
},
"mcir.RestGetAvailableDataDisksResponse": {
"type": "object",
"properties": {
"dataDisk": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"mcir.RestLookupImageRequest": {
"type": "object",
"properties": {
Expand Down
18 changes: 9 additions & 9 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,6 @@ definitions:
$ref: '#/definitions/mcir.TbVNetInfo'
type: array
type: object
mcir.RestGetAvailableDataDisksResponse:
properties:
dataDisk:
items:
type: string
type: array
type: object
mcir.RestLookupImageRequest:
properties:
connectionName:
Expand Down Expand Up @@ -4289,9 +4282,16 @@ paths:
- application/json
responses:
"200":
description: OK
description: Different return structures by the given option param
schema:
$ref: '#/definitions/mcir.RestGetAvailableDataDisksResponse'
allOf:
- $ref: '#/definitions/mcir.JSONResult'
- properties:
'[DEFAULT]':
$ref: '#/definitions/mcir.RestGetAllDataDiskResponse'
'[ID]':
$ref: '#/definitions/common.IdList'
type: object
"404":
description: Not Found
schema:
Expand Down
21 changes: 12 additions & 9 deletions src/api/rest/server/mcir/dataDisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ func RestDelAllDataDisk(c echo.Context) error {
return nil
}

type RestGetAvailableDataDisksResponse struct {
DataDisk []string `json:"dataDisk"`
}

// RestPutVmDataDisk godoc
// @Summary Attach/Detach available dataDisk
// @Description Attach/Detach available dataDisk
Expand Down Expand Up @@ -225,7 +221,7 @@ func RestPutVmDataDisk(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(g1-1)
// @Success 200 {object} RestGetAvailableDataDisksResponse
// @Success 200 {object} JSONResult{[DEFAULT]=RestGetAllDataDiskResponse,[ID]=common.IdList} "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}/dataDisk [get]
Expand All @@ -234,17 +230,24 @@ func RestGetVmDataDisk(c echo.Context) error {
nsId := c.Param("nsId")
mcisId := c.Param("mcisId")
vmId := c.Param("vmId")
optionFlag := c.QueryParam("option")

dataDiskIDs, err := mcis.GetAvailableDataDiskIDs(nsId, mcisId, vmId)
result, err := mcis.GetAvailableDataDisks(nsId, mcisId, vmId, optionFlag)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusNotFound, &mapA)
}

content := RestGetAvailableDataDisksResponse{
DataDisk: dataDiskIDs,
var content interface{}
if optionFlag == "id" {
content = common.IdList{
IdList: result.([]string),
}
} else {
content = RestGetAllDataDiskResponse{
DataDisk: result.([]mcir.TbDataDiskInfo),
}
}

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

}
32 changes: 18 additions & 14 deletions src/core/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ func AttachDetachDataDisk(nsId string, mcisId string, vmId string, command strin
return vm, nil
}

func GetAvailableDataDiskIDs(nsId string, mcisId string, vmId string) ([]string, error) {
func GetAvailableDataDisks(nsId string, mcisId string, vmId string, option string) (interface{}, error) {
vmKey := common.GenMcisKey(nsId, mcisId, vmId)

// Check existence of the key. If no key, no update.
Expand Down Expand Up @@ -1758,23 +1758,27 @@ func GetAvailableDataDiskIDs(nsId string, mcisId string, vmId string) ([]string,
tbDataDisks := []mcir.TbDataDiskInfo{}
json.Unmarshal(jsonString, &tbDataDisks)

idList := []string{}
if option != "id" {
return tbDataDisks, nil
} else { // option == "id"
idList := []string{}

for _, v := range tbDataDisks {
// Update Tb dataDisk object's status
newObj, err := mcir.GetResource(nsId, common.StrDataDisk, v.Id)
if err != nil {
common.CBLog.Error(err)
return nil, err
}
tempObj := newObj.(mcir.TbDataDiskInfo)
for _, v := range tbDataDisks {
// Update Tb dataDisk object's status
newObj, err := mcir.GetResource(nsId, common.StrDataDisk, v.Id)
if err != nil {
common.CBLog.Error(err)
return nil, err
}
tempObj := newObj.(mcir.TbDataDiskInfo)

if v.ConnectionName == vm.ConnectionName && tempObj.Status == "Available" {
idList = append(idList, v.Id)
if v.ConnectionName == vm.ConnectionName && tempObj.Status == "Available" {
idList = append(idList, v.Id)
}
}
}

return idList, nil
return idList, nil
}
}

// [Delete MCIS and VM object]
Expand Down
9 changes: 9 additions & 0 deletions src/testclient/scripts/11.dataDisk/available-dataDisk-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo "####################################################################"
echo "## 11. dataDisk: Get available dataDisks"
echo "####################################################################"

source ../init.sh

curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/vm/${CONN_CONFIG[$INDEX,$REGION]}-1/dataDisk?option=id | jq ''
2 changes: 1 addition & 1 deletion src/testclient/scripts/11.dataDisk/available-dataDisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ echo "####################################################################"

source ../init.sh

curl -H "${AUTH}" -sX PUT http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/vm/${CONN_CONFIG[$INDEX,$REGION]}-1/dataDisk?option=available | jq ''
curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/vm/${CONN_CONFIG[$INDEX,$REGION]}-1/dataDisk | jq ''

0 comments on commit 63027a3

Please sign in to comment.