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

Accept two commonImage input types #1571

Merged
merged 1 commit into from
May 16, 2024
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
24 changes: 15 additions & 9 deletions src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4209,7 +4209,7 @@ const docTemplate = `{
"required": true
},
{
"description": "Request body to provision MCIS dynamically",
"description": "Request body to provision MCIS dynamically. Must include commonSpec and commonImage info of each VM request.(ex: {name: mcis01,vm: [{commonImage: aws+ap-northeast-2+ubuntu22.04,commonSpec: aws+ap-northeast-2+t2.small}]} ) You can use /mcisRecommendVm and /mcisDynamicCheckRequest to get it) Check the guide: https://github.com/cloud-barista/cb-tumblebug/discussions/1570",
"name": "mcisReq",
"in": "body",
"required": true,
Expand Down Expand Up @@ -9996,16 +9996,22 @@ const docTemplate = `{
"type": "string"
}
},
"image": {
"type": "array",
"items": {
"$ref": "#/definitions/mcir.TbImageInfo"
}
},
"region": {
"$ref": "#/definitions/common.RegionDetail"
},
"spec": {
"$ref": "#/definitions/mcir.TbSpecInfo"
},
"systemMessage": {
"description": "Latest system message such as error message",
"type": "string",
"example": "Failed because ..."
},
"vmSpec": {
"$ref": "#/definitions/mcir.TbSpecInfo"
}
}
},
Expand Down Expand Up @@ -10058,11 +10064,11 @@ const docTemplate = `{
"metric": {
"type": "string",
"enum": [
"cpu",
"memory",
"cost"
"vCPU",
"memoryGiB",
"costPerHour"
],
"example": "cpu"
"example": "vCPU"
}
}
},
Expand Down Expand Up @@ -10212,7 +10218,7 @@ const docTemplate = `{
},
"example": [
"aws+ap-northeast-2+t2.small",
"gcp+us-west1+g1.small"
"gcp+us-west1+g1-small"
]
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4202,7 +4202,7 @@
"required": true
},
{
"description": "Request body to provision MCIS dynamically",
"description": "Request body to provision MCIS dynamically. Must include commonSpec and commonImage info of each VM request.(ex: {name: mcis01,vm: [{commonImage: aws+ap-northeast-2+ubuntu22.04,commonSpec: aws+ap-northeast-2+t2.small}]} ) You can use /mcisRecommendVm and /mcisDynamicCheckRequest to get it) Check the guide: https://github.com/cloud-barista/cb-tumblebug/discussions/1570",
"name": "mcisReq",
"in": "body",
"required": true,
Expand Down Expand Up @@ -9989,16 +9989,22 @@
"type": "string"
}
},
"image": {
"type": "array",
"items": {
"$ref": "#/definitions/mcir.TbImageInfo"
}
},
"region": {
"$ref": "#/definitions/common.RegionDetail"
},
"spec": {
"$ref": "#/definitions/mcir.TbSpecInfo"
},
"systemMessage": {
"description": "Latest system message such as error message",
"type": "string",
"example": "Failed because ..."
},
"vmSpec": {
"$ref": "#/definitions/mcir.TbSpecInfo"
}
}
},
Expand Down Expand Up @@ -10051,11 +10057,11 @@
"metric": {
"type": "string",
"enum": [
"cpu",
"memory",
"cost"
"vCPU",
"memoryGiB",
"costPerHour"
],
"example": "cpu"
"example": "vCPU"
}
}
},
Expand Down Expand Up @@ -10205,7 +10211,7 @@
},
"example": [
"aws+ap-northeast-2+t2.small",
"gcp+us-west1+g1.small"
"gcp+us-west1+g1-small"
]
}
}
Expand Down
24 changes: 16 additions & 8 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,14 +1242,18 @@ definitions:
items:
type: string
type: array
image:
items:
$ref: '#/definitions/mcir.TbImageInfo'
type: array
region:
$ref: '#/definitions/common.RegionDetail'
spec:
$ref: '#/definitions/mcir.TbSpecInfo'
systemMessage:
description: Latest system message such as error message
example: Failed because ...
type: string
vmSpec:
$ref: '#/definitions/mcir.TbSpecInfo'
type: object
mcis.ClusterStatus:
enum:
Expand Down Expand Up @@ -1287,10 +1291,10 @@ definitions:
type: array
metric:
enum:
- cpu
- memory
- cost
example: cpu
- vCPU
- memoryGiB
- costPerHour
example: vCPU
type: string
type: object
mcis.FilterInfo:
Expand Down Expand Up @@ -1386,7 +1390,7 @@ definitions:
description: CommonSpec is field for id of a spec in common namespace
example:
- aws+ap-northeast-2+t2.small
- gcp+us-west1+g1.small
- gcp+us-west1+g1-small
items:
type: string
type: array
Expand Down Expand Up @@ -5700,7 +5704,11 @@ paths:
name: nsId
required: true
type: string
- description: Request body to provision MCIS dynamically
- description: 'Request body to provision MCIS dynamically. Must include commonSpec
and commonImage info of each VM request.(ex: {name: mcis01,vm: [{commonImage:
aws+ap-northeast-2+ubuntu22.04,commonSpec: aws+ap-northeast-2+t2.small}]}
) You can use /mcisRecommendVm and /mcisDynamicCheckRequest to get it) Check
the guide: https://github.com/cloud-barista/cb-tumblebug/discussions/1570'
in: body
name: mcisReq
required: true
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/server/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func RestPostSystemMcis(c echo.Context) error {
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisReq body TbMcisDynamicReq true "Request body to provision MCIS dynamically"
// @Param mcisReq body TbMcisDynamicReq true "Request body to provision MCIS dynamically. Must include commonSpec and commonImage info of each VM request.(ex: {name: mcis01,vm: [{commonImage: aws+ap-northeast-2+ubuntu22.04,commonSpec: aws+ap-northeast-2+t2.small}]} ) You can use /mcisRecommendVm and /mcisDynamicCheckRequest to get it) Check the guide: https://github.com/cloud-barista/cb-tumblebug/discussions/1570"
// @Param option query string false "Option for MCIS creation" Enums(hold)
// @Success 200 {object} TbMcisInfo
// @Failure 404 {object} common.SimpleMsg
Expand Down
23 changes: 18 additions & 5 deletions src/core/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ type TbVmDynamicReq struct {
// McisConnectionConfigCandidatesReq is struct for a request to check requirements to create a new MCIS instance dynamically (with default resource option)
type McisConnectionConfigCandidatesReq struct {
// CommonSpec is field for id of a spec in common namespace
CommonSpecs []string `json:"commonSpec" validate:"required" example:"aws+ap-northeast-2+t2.small,gcp+us-west1+g1.small"`
CommonSpecs []string `json:"commonSpec" validate:"required" example:"aws+ap-northeast-2+t2.small,gcp+us-west1+g1-small"`
}

// CheckMcisDynamicReqInfo is struct to check requirements to create a new MCIS instance dynamically (with default resource option)
Expand All @@ -259,11 +259,10 @@ type CheckVmDynamicReqInfo struct {
// ConnectionConfigCandidates will provide ConnectionConfig options
ConnectionConfigCandidates []string `json:"connectionConfigCandidates" default:""`

// CommonImage is field for id of a image in common namespace
// CommonImage string `json:"commonImage" validate:"required" example:"ubuntu18.04"`
//RootDiskSize string `json:"rootDiskSize,omitempty" example:"default, 30, 42, ..."` // "default", Integer (GB): ["50", ..., "1000"]

VmSpec mcir.TbSpecInfo `json:"vmSpec" default:""`
Spec mcir.TbSpecInfo `json:"spec" default:""`
Image []mcir.TbImageInfo `json:"image" default:""`
Region common.RegionDetail `json:"region" default:""`

// Latest system message such as error message
Expand Down Expand Up @@ -1179,7 +1178,13 @@ func CheckMcisDynamicReq(req *McisConnectionConfigCandidatesReq) (*CheckMcisDyna
}
}

vmReqInfo.VmSpec = specInfo
vmReqInfo.Spec = specInfo
imageSearchKey := specInfo.ProviderName + "+" + specInfo.RegionName
availableImageList, err := mcir.SearchImage(common.SystemCommonNs, imageSearchKey)
if err != nil {
errMessage += "//Failed to search images for Spec (" + k + ")"
}
vmReqInfo.Image = availableImageList
vmReqInfo.Region = regionInfo
vmReqInfo.SystemMessage = errMessage
mcisReqInfo.ReqCheck = append(mcisReqInfo.ReqCheck, vmReqInfo)
Expand Down Expand Up @@ -1388,6 +1393,10 @@ func checkCommonResAvailable(req *TbVmDynamicReq) error {

osType := strings.ReplaceAll(k.CommonImage, " ", "")
vmReq.ImageId = mcir.GetProviderRegionZoneResourceKey(connection.ProviderName, connection.RegionDetail.RegionName, "", osType)
// incase of user provided image id completely (e.g. aws+ap-northeast-2+ubuntu22.04)
if strings.Contains(k.CommonImage, "+") {
vmReq.ImageId = k.CommonImage
}
tempInterface, err = mcir.GetResource(common.SystemCommonNs, common.StrImage, vmReq.ImageId)
if err != nil {
err := fmt.Errorf("Failed to get Image " + k.CommonImage + " from " + vmReq.ConnectionName)
Expand Down Expand Up @@ -1444,6 +1453,10 @@ func getVmReqFromDynamicReq(nsId string, req *TbVmDynamicReq) (*TbVmReq, error)
vmReq.SpecId = specInfo.Id
osType := strings.ReplaceAll(k.CommonImage, " ", "")
vmReq.ImageId = mcir.GetProviderRegionZoneResourceKey(connection.ProviderName, connection.RegionDetail.RegionName, "", osType)
// incase of user provided image id completely (e.g. aws+ap-northeast-2+ubuntu22.04)
if strings.Contains(k.CommonImage, "+") {
vmReq.ImageId = k.CommonImage
}
tempInterface, err = mcir.GetResource(common.SystemCommonNs, common.StrImage, vmReq.ImageId)
if err != nil {
err := fmt.Errorf("Failed to get the Image " + vmReq.ImageId + " from " + vmReq.ConnectionName)
Expand Down
2 changes: 1 addition & 1 deletion src/core/mcis/recommendation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type FilterInfo struct {

// FilterCondition is struct for .
type FilterCondition struct {
Metric string `json:"metric" example:"cpu" enums:"cpu,memory,cost"`
Metric string `json:"metric" example:"vCPU" enums:"vCPU,memoryGiB,costPerHour"`
Condition []Operation `json:"condition"`
}

Expand Down