From 7991e83475ec78b4a9cda02f34edf5843492a3f6 Mon Sep 17 00:00:00 2001 From: Yunkon Kim Date: Wed, 14 Aug 2024 14:22:29 +0900 Subject: [PATCH] Add API drafts to enhance network features --- src/api/rest/docs/docs.go | 85 ++++++++++++++++++++++++++ src/api/rest/docs/swagger.json | 85 ++++++++++++++++++++++++++ src/api/rest/docs/swagger.yaml | 59 ++++++++++++++++++ src/api/rest/server/mcis/manageInfo.go | 71 +++++++++++++++++++++ src/api/rest/server/server.go | 2 + src/core/mcir/vnet.go | 12 +++- src/core/mcis/provisioning.go | 3 + 7 files changed, 314 insertions(+), 3 deletions(-) diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index efb57b771..9b1227a96 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -4574,6 +4574,60 @@ const docTemplate = `{ } } }, + "/ns/{nsId}/mcis/{mcisId}/vnet": { + "get": { + "description": "Get vNets in specified MCIS (not yet implemented)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra service] MCIS Provisioning management" + ], + "summary": "Get vNets in specified MCIS (not yet implemented)", + "operationId": "RestGetMcisVNets", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.RestGetMcisVnetsResponse" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/mcis/{mcisId}/vpn/{vpnId}": { "get": { "description": "Get resource info of a site-to-site VPN (Currently, GCP-AWS is supported)", @@ -10782,6 +10836,9 @@ const docTemplate = `{ }, "name": { "type": "string" + }, + "zone": { + "type": "string" } } }, @@ -11667,6 +11724,29 @@ const docTemplate = `{ } } }, + "mcis.RestGetMcisVnetsResponse": { + "type": "object", + "properties": { + "cidrBlock": { + "type": "string" + }, + "description": { + "type": "string" + }, + "mcisId": { + "type": "string" + }, + "nsId": { + "type": "string" + }, + "vNet": { + "type": "array", + "items": { + "$ref": "#/definitions/mcir.TbVNetInfo" + } + } + } + }, "mcis.SpiderImageType": { "type": "string", "enum": [ @@ -12364,6 +12444,11 @@ const docTemplate = `{ "vm" ], "properties": { + "cidrBlock": { + "description": "CidrBlock is a logical address block for the MCIS and is subnetted for vNets and subnets", + "type": "string", + "example": "10.10.0.0/16" + }, "description": { "type": "string", "example": "Made in CB-TB" diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index b94c3ee2b..5a2db3d9b 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -4567,6 +4567,60 @@ } } }, + "/ns/{nsId}/mcis/{mcisId}/vnet": { + "get": { + "description": "Get vNets in specified MCIS (not yet implemented)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra service] MCIS Provisioning management" + ], + "summary": "Get vNets in specified MCIS (not yet implemented)", + "operationId": "RestGetMcisVNets", + "parameters": [ + { + "type": "string", + "default": "ns01", + "description": "Namespace ID", + "name": "nsId", + "in": "path", + "required": true + }, + { + "type": "string", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.RestGetMcisVnetsResponse" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/mcis/{mcisId}/vpn/{vpnId}": { "get": { "description": "Get resource info of a site-to-site VPN (Currently, GCP-AWS is supported)", @@ -10775,6 +10829,9 @@ }, "name": { "type": "string" + }, + "zone": { + "type": "string" } } }, @@ -11660,6 +11717,29 @@ } } }, + "mcis.RestGetMcisVnetsResponse": { + "type": "object", + "properties": { + "cidrBlock": { + "type": "string" + }, + "description": { + "type": "string" + }, + "mcisId": { + "type": "string" + }, + "nsId": { + "type": "string" + }, + "vNet": { + "type": "array", + "items": { + "$ref": "#/definitions/mcir.TbVNetInfo" + } + } + } + }, "mcis.SpiderImageType": { "type": "string", "enum": [ @@ -12357,6 +12437,11 @@ "vm" ], "properties": { + "cidrBlock": { + "description": "CidrBlock is a logical address block for the MCIS and is subnetted for vNets and subnets", + "type": "string", + "example": "10.10.0.0/16" + }, "description": { "type": "string", "example": "Made in CB-TB" diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index be9962704..be3219098 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -1195,6 +1195,8 @@ definitions: type: array name: type: string + zone: + type: string required: - ipv4_CIDR - name @@ -1799,6 +1801,21 @@ definitions: host: type: string type: object + mcis.RestGetMcisVnetsResponse: + properties: + cidrBlock: + type: string + description: + type: string + mcisId: + type: string + nsId: + type: string + vNet: + items: + $ref: '#/definitions/mcir.TbVNetInfo' + type: array + type: object mcis.SpiderImageType: enum: - PublicImage @@ -2297,6 +2314,11 @@ definitions: - TbK8sNodeGroupDeleting mcis.TbMcisDynamicReq: properties: + cidrBlock: + description: CidrBlock is a logical address block for the MCIS and is subnetted + for vNets and subnets + example: 10.10.0.0/16 + type: string description: example: Made in CB-TB type: string @@ -6340,6 +6362,43 @@ paths: summary: Create VM Dynamically and add it to MCIS tags: - '[Infra service] MCIS Provisioning management' + /ns/{nsId}/mcis/{mcisId}/vnet: + get: + consumes: + - application/json + description: Get vNets in specified MCIS (not yet implemented) + operationId: RestGetMcisVNets + parameters: + - default: ns01 + description: Namespace ID + in: path + name: nsId + required: true + type: string + - default: mcis01 + description: MCIS ID + in: path + name: mcisId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mcis.RestGetMcisVnetsResponse' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Get vNets in specified MCIS (not yet implemented) + tags: + - '[Infra service] MCIS Provisioning management' /ns/{nsId}/mcis/{mcisId}/vpn/{vpnId}: get: consumes: diff --git a/src/api/rest/server/mcis/manageInfo.go b/src/api/rest/server/mcis/manageInfo.go index 76aec451f..e6bf661ac 100644 --- a/src/api/rest/server/mcis/manageInfo.go +++ b/src/api/rest/server/mcis/manageInfo.go @@ -19,6 +19,7 @@ import ( "net/http" "github.com/cloud-barista/cb-tumblebug/src/core/common" + "github.com/cloud-barista/cb-tumblebug/src/core/mcir" "github.com/cloud-barista/cb-tumblebug/src/core/mcis" "github.com/labstack/echo/v4" "github.com/rs/zerolog/log" @@ -392,3 +393,73 @@ func RestGetMcisGroupIds(c echo.Context) error { content.IdList, err = mcis.ListSubGroupId(nsId, mcisId) return common.EndRequestWithLog(c, reqID, err, content) } + +type RestGetMcisVnetsResponse struct { + NsId string `json:"nsId"` + McisId string `json:"mcisId"` + Description string `json:"description"` + CidrBlock string `json:"cidrBlock"` + VNet []mcir.TbVNetInfo `json:"vNet"` +} + +// RestGetMcisVNets godoc +// @ID RestGetMcisVNets +// @Summary (To be implemented) Get vNets in specified MCIS +// @Description (To be implemented) Get vNets in specified MCIS +// @Tags [Infra service] 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) +// @success 200 {object} RestGetMcisVnetsResponse +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /ns/{nsId}/mcis/{mcisId}/vnet [get] +func RestGetMcisVNets(c echo.Context) error { + + nsId := c.Param("nsId") + if nsId == "" { + return c.JSON(http.StatusBadRequest, "NS ID is required") + } + mcisId := c.Param("mcisId") + if mcisId == "" { + return c.JSON(http.StatusBadRequest, "MCIS ID is required") + } + + dummbyVnets := []mcir.TbVNetInfo{} + for i := 0; i < 3; i++ { + dummyVnet := mcir.TbVNetInfo{ + Id: "mock-vnet-01", + Name: "mock-vnet-01", + ConnectionName: "mock-conn-name", + CidrBlock: "192.168.0.0/24", + SubnetInfoList: []mcir.TbSubnetInfo{ + { + Id: "mock-subnet-01", + Name: "mock-subnet-01", + IPv4_CIDR: "", + KeyValueList: []common.KeyValue{}, + Description: "not yet implemented", + }, + }, + CspVNetId: "mock-csp-vnet-id", + CspVNetName: "mock-csp-vnet-name", + Status: "mock-status", + KeyValueList: []common.KeyValue{}, + AssociatedObjectList: []string{}, + IsAutoGenerated: false, + SystemLabel: "mock-managed in" + mcisId, + } + dummbyVnets = append(dummbyVnets, dummyVnet) + } + + dummyRes := RestGetMcisVnetsResponse{ + NsId: nsId, + McisId: mcisId, + Description: "mock-description", + CidrBlock: "192.168.0.0./16", + VNet: dummbyVnets, + } + + return c.JSON(http.StatusOK, dummyRes) +} diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 7d61e1794..b42aeea08 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -311,6 +311,8 @@ func RunServer(port string) { g.DELETE("/:nsId/mcis/:mcisId/vm/:vmId", rest_mcis.RestDelMcisVm) //g.DELETE("/:nsId/mcis/:mcisId/vm", rest_mcis.RestDelAllMcisVm) + g.GET("/:nsId/mcis/:mcisId/vnet", rest_mcis.RestGetMcisVNets) + //g.POST("/:nsId/mcis/recommend", rest_mcis.RestPostMcisRecommend) g.GET("/:nsId/control/mcis/:mcisId", rest_mcis.RestGetControlMcis) diff --git a/src/core/mcir/vnet.go b/src/core/mcir/vnet.go index 4ddb80b58..e4ec208ab 100644 --- a/src/core/mcir/vnet.go +++ b/src/core/mcir/vnet.go @@ -59,13 +59,18 @@ type SpiderVPCInfo struct { IId common.IID // {NameId, SystemId} IPv4_CIDR string SubnetInfoList []SpiderSubnetInfo - KeyValueList []common.KeyValue + + TagList []common.KeyValue + KeyValueList []common.KeyValue } // SpiderSubnetInfo is a struct to handle subnet information from the CB-Spider's REST API response type SpiderSubnetInfo struct { - IId common.IID // {NameId, SystemId} - IPv4_CIDR string + IId common.IID // {NameId, SystemId} + Zone string // Target Zone Name + IPv4_CIDR string + + TagList []common.KeyValue KeyValueList []common.KeyValue } @@ -119,6 +124,7 @@ type TbSubnetReq struct { // Tumblebug Name string `validate:"required"` IdFromCsp string IPv4_CIDR string `validate:"required"` + Zone string `json:"zone,omitempty"` KeyValueList []common.KeyValue Description string } diff --git a/src/core/mcis/provisioning.go b/src/core/mcis/provisioning.go index 4ece74b01..692ee23f9 100644 --- a/src/core/mcis/provisioning.go +++ b/src/core/mcis/provisioning.go @@ -212,6 +212,9 @@ type TbMcisDynamicReq struct { // SystemLabel is for describing the mcis in a keyword (any string can be used) for special System purpose SystemLabel string `json:"systemLabel" example:"" default:""` + // CidrBlock is a logical address block for the MCIS and is subnetted for vNets and subnets + CidrBlock string `json:"cidrBlock,omitempty" example:"10.10.0.0/16" ` + Description string `json:"description" example:"Made in CB-TB"` Vm []TbVmDynamicReq `json:"vm" validate:"required"`