From 1f3f3fca097308b17285058c201777b9d34fb19c Mon Sep 17 00:00:00 2001 From: Jihoon Seo Date: Fri, 23 Sep 2022 08:45:19 +0900 Subject: [PATCH 1/4] Modify the hierarchy of TB NLB object --- src/api/rest/docs/docs.go | 606 ++++++++---------- src/api/rest/docs/swagger.json | 606 ++++++++---------- src/api/rest/docs/swagger.yaml | 471 ++++++-------- src/api/rest/server/mcis/nlb.go | 57 +- src/api/rest/server/server.go | 19 +- src/core/mcis/nlb.go | 129 +++- .../{addVM.sh => (deprecated)-addVM.sh} | 0 .../{removeVM.sh => (deprecated)-removeVM.sh} | 0 src/testclient/scripts/10.nlb/create-NLB.sh | 6 +- src/testclient/scripts/10.nlb/delete-NLB.sh | 2 +- .../scripts/10.nlb/delete-all-NLB.sh | 2 +- src/testclient/scripts/10.nlb/get-NLB.sh | 2 +- src/testclient/scripts/10.nlb/id-list-NLB.sh | 2 +- src/testclient/scripts/10.nlb/list-NLB.sh | 2 +- src/testclient/scripts/conf.env | 4 +- 15 files changed, 879 insertions(+), 1029 deletions(-) rename src/testclient/scripts/10.nlb/{addVM.sh => (deprecated)-addVM.sh} (100%) rename src/testclient/scripts/10.nlb/{removeVM.sh => (deprecated)-removeVM.sh} (100%) diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index c5aecb26..4bb34f68 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -1885,9 +1885,9 @@ const docTemplate = `{ } } }, - "/ns/{nsId}/mcis/{mcisId}/vm": { - "post": { - "description": "Create VM in specified MCIS", + "/ns/{nsId}/mcis/{mcisId}/nlb": { + "get": { + "description": "List all NLBs or NLBs' ID", "consumes": [ "application/json" ], @@ -1895,9 +1895,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "Create VM in specified MCIS", + "summary": "List all NLBs or NLBs' ID", "parameters": [ { "type": "string", @@ -1916,83 +1916,24 @@ const docTemplate = `{ "required": true }, { - "description": "Details for an VM object", - "name": "vmReq", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.TbVmReq" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/mcis.TbVmInfo" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } - } - } - } - }, - "/ns/{nsId}/mcis/{mcisId}/vm/{vmId}": { - "get": { - "description": "Get VM in specified MCIS", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "[Infra service] MCIS Provisioning management" - ], - "summary": "Get VM in specified MCIS", - "parameters": [ - { + "enum": [ + "id" + ], "type": "string", - "default": "ns01", - "description": "Namespace ID", - "name": "nsId", - "in": "path", - "required": true + "description": "Option", + "name": "option", + "in": "query" }, { "type": "string", - "default": "mcis01", - "description": "MCIS ID", - "name": "mcisId", - "in": "path", - "required": true + "description": "Field key for filtering (ex: cspNLBName)", + "name": "filterKey", + "in": "query" }, { "type": "string", - "default": "vm01", - "description": "VM ID", - "name": "vmId", - "in": "path", - "required": true - }, - { - "enum": [ - "default", - "status" - ], - "type": "string", - "description": "Option for MCIS", - "name": "option", + "description": "Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)", + "name": "filterVal", "in": "query" } ], @@ -2008,10 +1949,10 @@ const docTemplate = `{ "type": "object", "properties": { "[DEFAULT]": { - "$ref": "#/definitions/mcis.TbVmInfo" + "$ref": "#/definitions/mcis.RestGetAllNLBResponse" }, - "[STATUS]": { - "$ref": "#/definitions/mcis.TbVmStatusInfo" + "[ID]": { + "$ref": "#/definitions/common.IdList" } } } @@ -2032,8 +1973,8 @@ const docTemplate = `{ } } }, - "delete": { - "description": "Delete VM in specified MCIS", + "post": { + "description": "Create NLB", "consumes": [ "application/json" ], @@ -2041,9 +1982,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "Delete VM in specified MCIS", + "summary": "Create NLB", "parameters": [ { "type": "string", @@ -2061,29 +2002,30 @@ const docTemplate = `{ "in": "path", "required": true }, - { - "type": "string", - "default": "vm01", - "description": "VM ID", - "name": "vmId", - "in": "path", - "required": true - }, { "enum": [ - "force" + "register" ], "type": "string", - "description": "Option for delete VM (support force delete)", + "description": "Option: [required params for register] connectionName, name, cspNLBId", "name": "option", "in": "query" + }, + { + "description": "Details of the NLB object", + "name": "nlbReq", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.TbNLBReq" + } } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.SimpleMsg" + "$ref": "#/definitions/mcis.TbNLBInfo" } }, "404": { @@ -2091,13 +2033,17 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/common.SimpleMsg" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } } } - } - }, - "/ns/{nsId}/mcis/{mcisId}/vmgroup": { - "get": { - "description": "List VMGroup IDs in a specified MCIS", + }, + "delete": { + "description": "Delete all NLBs", "consumes": [ "application/json" ], @@ -2105,9 +2051,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "List VMGroup IDs in a specified MCIS", + "summary": "Delete all NLBs", "parameters": [ { "type": "string", @@ -2124,6 +2070,13 @@ const docTemplate = `{ "name": "mcisId", "in": "path", "required": true + }, + { + "type": "string", + "default": "", + "description": "Delete resources containing matched ID-substring only", + "name": "match", + "in": "query" } ], "responses": { @@ -2138,17 +2091,13 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/common.SimpleMsg" } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } } } - }, - "post": { - "description": "Create multiple VMs by VM group in specified MCIS", + } + }, + "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}": { + "get": { + "description": "Get NLB", "consumes": [ "application/json" ], @@ -2156,9 +2105,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "Create multiple VMs by VM group in specified MCIS", + "summary": "Get NLB", "parameters": [ { "type": "string", @@ -2177,20 +2126,18 @@ const docTemplate = `{ "required": true }, { - "description": "Details for VM Group", - "name": "vmReq", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.TbVmReq" - } + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbMcisInfo" + "$ref": "#/definitions/mcis.TbNLBInfo" } }, "404": { @@ -2206,11 +2153,9 @@ const docTemplate = `{ } } } - } - }, - "/ns/{nsId}/mcis/{mcisId}/vmgroup/{vmgroupId}": { - "get": { - "description": "List VMs with a VMGroup label in a specified MCIS", + }, + "delete": { + "description": "Delete NLB", "consumes": [ "application/json" ], @@ -2218,9 +2163,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "List VMs with a VMGroup label in a specified MCIS", + "summary": "Delete NLB", "parameters": [ { "type": "string", @@ -2240,27 +2185,17 @@ const docTemplate = `{ }, { "type": "string", - "default": "group-0", - "description": "VM Group ID", - "name": "vmgroupId", + "description": "NLB ID", + "name": "nlbId", "in": "path", "required": true - }, - { - "enum": [ - "id" - ], - "type": "string", - "description": "Option", - "name": "option", - "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.IdList" + "$ref": "#/definitions/common.SimpleMsg" } }, "404": { @@ -2268,19 +2203,13 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/common.SimpleMsg" } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } } } } }, - "/ns/{nsId}/mcisDynamic": { + "/ns/{nsId}/mcis/{mcisId}/vm": { "post": { - "description": "Create MCIS Dynamically from common spec and image", + "description": "Create VM in specified MCIS", "consumes": [ "application/json" ], @@ -2290,7 +2219,7 @@ const docTemplate = `{ "tags": [ "[Infra service] MCIS Provisioning management" ], - "summary": "Create MCIS Dynamically", + "summary": "Create VM in specified MCIS", "parameters": [ { "type": "string", @@ -2301,12 +2230,20 @@ const docTemplate = `{ "required": true }, { - "description": "Details for MCIS object", - "name": "mcisReq", + "type": "string", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + }, + { + "description": "Details for an VM object", + "name": "vmReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbMcisDynamicReq" + "$ref": "#/definitions/mcis.TbVmReq" } } ], @@ -2314,7 +2251,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbMcisInfo" + "$ref": "#/definitions/mcis.TbVmInfo" } }, "404": { @@ -2332,9 +2269,9 @@ const docTemplate = `{ } } }, - "/ns/{nsId}/monitoring/install/mcis/{mcisId}": { - "post": { - "description": "Install monitoring agent (CB-Dragonfly agent) to MCIS", + "/ns/{nsId}/mcis/{mcisId}/vm/{vmId}": { + "get": { + "description": "Get VM in specified MCIS", "consumes": [ "application/json" ], @@ -2342,9 +2279,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Resource monitor (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Install monitoring agent (CB-Dragonfly agent) to MCIS", + "summary": "Get VM in specified MCIS", "parameters": [ { "type": "string", @@ -2363,20 +2300,44 @@ const docTemplate = `{ "required": true }, { - "description": "Details for an MCIS object", - "name": "mcisInfo", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.McisCmdReq" - } + "type": "string", + "default": "vm01", + "description": "VM ID", + "name": "vmId", + "in": "path", + "required": true + }, + { + "enum": [ + "default", + "status" + ], + "type": "string", + "description": "Option for MCIS", + "name": "option", + "in": "query" } ], "responses": { "200": { - "description": "OK", + "description": "Different return structures by the given option param", "schema": { - "$ref": "#/definitions/mcis.AgentInstallContentWrapper" + "allOf": [ + { + "$ref": "#/definitions/mcis.JSONResult" + }, + { + "type": "object", + "properties": { + "[DEFAULT]": { + "$ref": "#/definitions/mcis.TbVmInfo" + }, + "[STATUS]": { + "$ref": "#/definitions/mcis.TbVmStatusInfo" + } + } + } + ] } }, "404": { @@ -2392,11 +2353,9 @@ const docTemplate = `{ } } } - } - }, - "/ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric}": { - "get": { - "description": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", + }, + "delete": { + "description": "Delete VM in specified MCIS", "consumes": [ "application/json" ], @@ -2404,9 +2363,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Resource monitor (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", + "summary": "Delete VM in specified MCIS", "parameters": [ { "type": "string", @@ -2426,17 +2385,27 @@ const docTemplate = `{ }, { "type": "string", - "description": "Metric type: cpu, memory, disk, network", - "name": "metric", + "default": "vm01", + "description": "VM ID", + "name": "vmId", "in": "path", "required": true + }, + { + "enum": [ + "force" + ], + "type": "string", + "description": "Option for delete VM (support force delete)", + "name": "option", + "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.MonResultSimpleResponse" + "$ref": "#/definitions/common.SimpleMsg" } }, "404": { @@ -2444,19 +2413,13 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/common.SimpleMsg" } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } } } } }, - "/ns/{nsId}/network/mcis/{mcisId}": { - "put": { - "description": "Inject Cloud Information For Cloud Adaptive Network", + "/ns/{nsId}/mcis/{mcisId}/vmgroup": { + "get": { + "description": "List VMGroup IDs in a specified MCIS", "consumes": [ "application/json" ], @@ -2464,9 +2427,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Cloud Adaptive Network (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Inject Cloud Information For Cloud Adaptive Network", + "summary": "List VMGroup IDs in a specified MCIS", "parameters": [ { "type": "string", @@ -2483,22 +2446,13 @@ const docTemplate = `{ "name": "mcisId", "in": "path", "required": true - }, - { - "description": "Details for the network request body", - "name": "networkReq", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.NetworkReq" - } } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.AgentInstallContentWrapper" + "$ref": "#/definitions/common.IdList" } }, "404": { @@ -2516,7 +2470,7 @@ const docTemplate = `{ } }, "post": { - "description": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", + "description": "Create multiple VMs by VM group in specified MCIS", "consumes": [ "application/json" ], @@ -2524,9 +2478,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra service] MCIS Cloud Adaptive Network (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", + "summary": "Create multiple VMs by VM group in specified MCIS", "parameters": [ { "type": "string", @@ -2545,12 +2499,12 @@ const docTemplate = `{ "required": true }, { - "description": "Details for the network request body", - "name": "networkReq", + "description": "Details for VM Group", + "name": "vmReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.NetworkReq" + "$ref": "#/definitions/mcis.TbVmReq" } } ], @@ -2558,7 +2512,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.AgentInstallContentWrapper" + "$ref": "#/definitions/mcis.TbMcisInfo" } }, "404": { @@ -2576,9 +2530,9 @@ const docTemplate = `{ } } }, - "/ns/{nsId}/nlb": { + "/ns/{nsId}/mcis/{mcisId}/vmgroup/{vmgroupId}": { "get": { - "description": "List all NLBs or NLBs' ID", + "description": "List VMs with a VMGroup label in a specified MCIS", "consumes": [ "application/json" ], @@ -2586,9 +2540,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Provisioning management" ], - "summary": "List all NLBs or NLBs' ID", + "summary": "List VMs with a VMGroup label in a specified MCIS", "parameters": [ { "type": "string", @@ -2599,47 +2553,36 @@ const docTemplate = `{ "required": true }, { - "enum": [ - "id" - ], "type": "string", - "description": "Option", - "name": "option", - "in": "query" + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true }, { "type": "string", - "description": "Field key for filtering (ex: cspNLBName)", - "name": "filterKey", - "in": "query" + "default": "group-0", + "description": "VM Group ID", + "name": "vmgroupId", + "in": "path", + "required": true }, { + "enum": [ + "id" + ], "type": "string", - "description": "Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)", - "name": "filterVal", + "description": "Option", + "name": "option", "in": "query" } ], "responses": { "200": { - "description": "Different return structures by the given option param", + "description": "OK", "schema": { - "allOf": [ - { - "$ref": "#/definitions/mcis.JSONResult" - }, - { - "type": "object", - "properties": { - "[DEFAULT]": { - "$ref": "#/definitions/mcis.RestGetAllNLBResponse" - }, - "[ID]": { - "$ref": "#/definitions/common.IdList" - } - } - } - ] + "$ref": "#/definitions/common.IdList" } }, "404": { @@ -2655,9 +2598,11 @@ const docTemplate = `{ } } } - }, + } + }, + "/ns/{nsId}/mcisDynamic": { "post": { - "description": "Create NLB", + "description": "Create MCIS Dynamically from common spec and image", "consumes": [ "application/json" ], @@ -2665,9 +2610,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Provisioning management" ], - "summary": "Create NLB", + "summary": "Create MCIS Dynamically", "parameters": [ { "type": "string", @@ -2678,21 +2623,12 @@ const docTemplate = `{ "required": true }, { - "enum": [ - "register" - ], - "type": "string", - "description": "Option: [required params for register] connectionName, name, cspNLBId", - "name": "option", - "in": "query" - }, - { - "description": "Details of the NLB object", - "name": "nlbReq", + "description": "Details for MCIS object", + "name": "mcisReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbNLBReq" + "$ref": "#/definitions/mcis.TbMcisDynamicReq" } } ], @@ -2700,7 +2636,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbNLBInfo" + "$ref": "#/definitions/mcis.TbMcisInfo" } }, "404": { @@ -2716,55 +2652,11 @@ const docTemplate = `{ } } } - }, - "delete": { - "description": "Delete all NLBs", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "[Infra resource] NLB management" - ], - "summary": "Delete all NLBs", - "parameters": [ - { - "type": "string", - "default": "ns01", - "description": "Namespace ID", - "name": "nsId", - "in": "path", - "required": true - }, - { - "type": "string", - "default": "", - "description": "Delete resources containing matched ID-substring only", - "name": "match", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/common.IdList" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } - } - } } }, - "/ns/{nsId}/nlb/{nlbId}": { - "get": { - "description": "Get NLB", + "/ns/{nsId}/monitoring/install/mcis/{mcisId}": { + "post": { + "description": "Install monitoring agent (CB-Dragonfly agent) to MCIS", "consumes": [ "application/json" ], @@ -2772,9 +2664,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Resource monitor (for developer)" ], - "summary": "Get NLB", + "summary": "Install monitoring agent (CB-Dragonfly agent) to MCIS", "parameters": [ { "type": "string", @@ -2786,17 +2678,27 @@ const docTemplate = `{ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", "in": "path", "required": true + }, + { + "description": "Details for an MCIS object", + "name": "mcisInfo", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.McisCmdReq" + } } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbNLBInfo" + "$ref": "#/definitions/mcis.AgentInstallContentWrapper" } }, "404": { @@ -2812,9 +2714,11 @@ const docTemplate = `{ } } } - }, - "delete": { - "description": "Delete NLB", + } + }, + "/ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric}": { + "get": { + "description": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", "consumes": [ "application/json" ], @@ -2822,9 +2726,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Resource monitor (for developer)" ], - "summary": "Delete NLB", + "summary": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", "parameters": [ { "type": "string", @@ -2836,8 +2740,16 @@ const docTemplate = `{ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Metric type: cpu, memory, disk, network", + "name": "metric", "in": "path", "required": true } @@ -2846,7 +2758,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.SimpleMsg" + "$ref": "#/definitions/mcis.MonResultSimpleResponse" } }, "404": { @@ -2854,13 +2766,19 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/common.SimpleMsg" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } } } } }, - "/ns/{nsId}/nlb/{nlbId}/vm": { - "post": { - "description": "Add VMs to NLB", + "/ns/{nsId}/network/mcis/{mcisId}": { + "put": { + "description": "Inject Cloud Information For Cloud Adaptive Network", "consumes": [ "application/json" ], @@ -2868,9 +2786,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Cloud Adaptive Network (for developer)" ], - "summary": "Add VMs to NLB", + "summary": "Inject Cloud Information For Cloud Adaptive Network", "parameters": [ { "type": "string", @@ -2882,18 +2800,19 @@ const docTemplate = `{ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", "in": "path", "required": true }, { - "description": "VMs to add to NLB", - "name": "nlbAddRemoveVMReq", + "description": "Details for the network request body", + "name": "networkReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + "$ref": "#/definitions/mcis.NetworkReq" } } ], @@ -2901,7 +2820,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbNLBInfo" + "$ref": "#/definitions/mcis.AgentInstallContentWrapper" } }, "404": { @@ -2918,8 +2837,8 @@ const docTemplate = `{ } } }, - "delete": { - "description": "Delete VMs from NLB", + "post": { + "description": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", "consumes": [ "application/json" ], @@ -2927,9 +2846,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Cloud Adaptive Network (for developer)" ], - "summary": "Delete VMs from NLB", + "summary": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", "parameters": [ { "type": "string", @@ -2941,18 +2860,19 @@ const docTemplate = `{ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", "in": "path", "required": true }, { - "description": "VMs to add to NLB", - "name": "nlbAddRemoveVMReq", + "description": "Details for the network request body", + "name": "networkReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + "$ref": "#/definitions/mcis.NetworkReq" } } ], @@ -2960,7 +2880,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.SimpleMsg" + "$ref": "#/definitions/mcis.AgentInstallContentWrapper" } }, "404": { @@ -2968,6 +2888,12 @@ const docTemplate = `{ "schema": { "$ref": "#/definitions/common.SimpleMsg" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } } } } @@ -7895,10 +7821,6 @@ const docTemplate = `{ "$ref": "#/definitions/common.KeyValue" } }, - "mcis": { - "type": "string", - "example": "mc" - }, "port": { "description": "Listener Port or 1-65535", "type": "string", @@ -8071,14 +7993,6 @@ const docTemplate = `{ } } }, - "mcis.TbNLBAddRemoveVMReq": { - "type": "object", - "properties": { - "targetGroup": { - "$ref": "#/definitions/mcis.TBNLBTargetGroup" - } - } - }, "mcis.TbNLBInfo": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index 91e19ca1..a862a9ea 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -1877,9 +1877,9 @@ } } }, - "/ns/{nsId}/mcis/{mcisId}/vm": { - "post": { - "description": "Create VM in specified MCIS", + "/ns/{nsId}/mcis/{mcisId}/nlb": { + "get": { + "description": "List all NLBs or NLBs' ID", "consumes": [ "application/json" ], @@ -1887,9 +1887,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "Create VM in specified MCIS", + "summary": "List all NLBs or NLBs' ID", "parameters": [ { "type": "string", @@ -1908,83 +1908,24 @@ "required": true }, { - "description": "Details for an VM object", - "name": "vmReq", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.TbVmReq" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/mcis.TbVmInfo" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } - } - } - } - }, - "/ns/{nsId}/mcis/{mcisId}/vm/{vmId}": { - "get": { - "description": "Get VM in specified MCIS", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "[Infra service] MCIS Provisioning management" - ], - "summary": "Get VM in specified MCIS", - "parameters": [ - { + "enum": [ + "id" + ], "type": "string", - "default": "ns01", - "description": "Namespace ID", - "name": "nsId", - "in": "path", - "required": true + "description": "Option", + "name": "option", + "in": "query" }, { "type": "string", - "default": "mcis01", - "description": "MCIS ID", - "name": "mcisId", - "in": "path", - "required": true + "description": "Field key for filtering (ex: cspNLBName)", + "name": "filterKey", + "in": "query" }, { "type": "string", - "default": "vm01", - "description": "VM ID", - "name": "vmId", - "in": "path", - "required": true - }, - { - "enum": [ - "default", - "status" - ], - "type": "string", - "description": "Option for MCIS", - "name": "option", + "description": "Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)", + "name": "filterVal", "in": "query" } ], @@ -2000,10 +1941,10 @@ "type": "object", "properties": { "[DEFAULT]": { - "$ref": "#/definitions/mcis.TbVmInfo" + "$ref": "#/definitions/mcis.RestGetAllNLBResponse" }, - "[STATUS]": { - "$ref": "#/definitions/mcis.TbVmStatusInfo" + "[ID]": { + "$ref": "#/definitions/common.IdList" } } } @@ -2024,8 +1965,8 @@ } } }, - "delete": { - "description": "Delete VM in specified MCIS", + "post": { + "description": "Create NLB", "consumes": [ "application/json" ], @@ -2033,9 +1974,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "Delete VM in specified MCIS", + "summary": "Create NLB", "parameters": [ { "type": "string", @@ -2053,29 +1994,30 @@ "in": "path", "required": true }, - { - "type": "string", - "default": "vm01", - "description": "VM ID", - "name": "vmId", - "in": "path", - "required": true - }, { "enum": [ - "force" + "register" ], "type": "string", - "description": "Option for delete VM (support force delete)", + "description": "Option: [required params for register] connectionName, name, cspNLBId", "name": "option", "in": "query" + }, + { + "description": "Details of the NLB object", + "name": "nlbReq", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.TbNLBReq" + } } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.SimpleMsg" + "$ref": "#/definitions/mcis.TbNLBInfo" } }, "404": { @@ -2083,13 +2025,17 @@ "schema": { "$ref": "#/definitions/common.SimpleMsg" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } } } - } - }, - "/ns/{nsId}/mcis/{mcisId}/vmgroup": { - "get": { - "description": "List VMGroup IDs in a specified MCIS", + }, + "delete": { + "description": "Delete all NLBs", "consumes": [ "application/json" ], @@ -2097,9 +2043,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "List VMGroup IDs in a specified MCIS", + "summary": "Delete all NLBs", "parameters": [ { "type": "string", @@ -2116,6 +2062,13 @@ "name": "mcisId", "in": "path", "required": true + }, + { + "type": "string", + "default": "", + "description": "Delete resources containing matched ID-substring only", + "name": "match", + "in": "query" } ], "responses": { @@ -2130,17 +2083,13 @@ "schema": { "$ref": "#/definitions/common.SimpleMsg" } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } } } - }, - "post": { - "description": "Create multiple VMs by VM group in specified MCIS", + } + }, + "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}": { + "get": { + "description": "Get NLB", "consumes": [ "application/json" ], @@ -2148,9 +2097,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "Create multiple VMs by VM group in specified MCIS", + "summary": "Get NLB", "parameters": [ { "type": "string", @@ -2169,20 +2118,18 @@ "required": true }, { - "description": "Details for VM Group", - "name": "vmReq", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.TbVmReq" - } + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbMcisInfo" + "$ref": "#/definitions/mcis.TbNLBInfo" } }, "404": { @@ -2198,11 +2145,9 @@ } } } - } - }, - "/ns/{nsId}/mcis/{mcisId}/vmgroup/{vmgroupId}": { - "get": { - "description": "List VMs with a VMGroup label in a specified MCIS", + }, + "delete": { + "description": "Delete NLB", "consumes": [ "application/json" ], @@ -2210,9 +2155,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Provisioning management" + "[Infra resource] NLB management" ], - "summary": "List VMs with a VMGroup label in a specified MCIS", + "summary": "Delete NLB", "parameters": [ { "type": "string", @@ -2232,27 +2177,17 @@ }, { "type": "string", - "default": "group-0", - "description": "VM Group ID", - "name": "vmgroupId", + "description": "NLB ID", + "name": "nlbId", "in": "path", "required": true - }, - { - "enum": [ - "id" - ], - "type": "string", - "description": "Option", - "name": "option", - "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.IdList" + "$ref": "#/definitions/common.SimpleMsg" } }, "404": { @@ -2260,19 +2195,13 @@ "schema": { "$ref": "#/definitions/common.SimpleMsg" } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } } } } }, - "/ns/{nsId}/mcisDynamic": { + "/ns/{nsId}/mcis/{mcisId}/vm": { "post": { - "description": "Create MCIS Dynamically from common spec and image", + "description": "Create VM in specified MCIS", "consumes": [ "application/json" ], @@ -2282,7 +2211,7 @@ "tags": [ "[Infra service] MCIS Provisioning management" ], - "summary": "Create MCIS Dynamically", + "summary": "Create VM in specified MCIS", "parameters": [ { "type": "string", @@ -2293,12 +2222,20 @@ "required": true }, { - "description": "Details for MCIS object", - "name": "mcisReq", + "type": "string", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + }, + { + "description": "Details for an VM object", + "name": "vmReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbMcisDynamicReq" + "$ref": "#/definitions/mcis.TbVmReq" } } ], @@ -2306,7 +2243,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbMcisInfo" + "$ref": "#/definitions/mcis.TbVmInfo" } }, "404": { @@ -2324,9 +2261,9 @@ } } }, - "/ns/{nsId}/monitoring/install/mcis/{mcisId}": { - "post": { - "description": "Install monitoring agent (CB-Dragonfly agent) to MCIS", + "/ns/{nsId}/mcis/{mcisId}/vm/{vmId}": { + "get": { + "description": "Get VM in specified MCIS", "consumes": [ "application/json" ], @@ -2334,9 +2271,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Resource monitor (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Install monitoring agent (CB-Dragonfly agent) to MCIS", + "summary": "Get VM in specified MCIS", "parameters": [ { "type": "string", @@ -2355,20 +2292,44 @@ "required": true }, { - "description": "Details for an MCIS object", - "name": "mcisInfo", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.McisCmdReq" - } + "type": "string", + "default": "vm01", + "description": "VM ID", + "name": "vmId", + "in": "path", + "required": true + }, + { + "enum": [ + "default", + "status" + ], + "type": "string", + "description": "Option for MCIS", + "name": "option", + "in": "query" } ], "responses": { "200": { - "description": "OK", + "description": "Different return structures by the given option param", "schema": { - "$ref": "#/definitions/mcis.AgentInstallContentWrapper" + "allOf": [ + { + "$ref": "#/definitions/mcis.JSONResult" + }, + { + "type": "object", + "properties": { + "[DEFAULT]": { + "$ref": "#/definitions/mcis.TbVmInfo" + }, + "[STATUS]": { + "$ref": "#/definitions/mcis.TbVmStatusInfo" + } + } + } + ] } }, "404": { @@ -2384,11 +2345,9 @@ } } } - } - }, - "/ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric}": { - "get": { - "description": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", + }, + "delete": { + "description": "Delete VM in specified MCIS", "consumes": [ "application/json" ], @@ -2396,9 +2355,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Resource monitor (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", + "summary": "Delete VM in specified MCIS", "parameters": [ { "type": "string", @@ -2418,17 +2377,27 @@ }, { "type": "string", - "description": "Metric type: cpu, memory, disk, network", - "name": "metric", + "default": "vm01", + "description": "VM ID", + "name": "vmId", "in": "path", "required": true + }, + { + "enum": [ + "force" + ], + "type": "string", + "description": "Option for delete VM (support force delete)", + "name": "option", + "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.MonResultSimpleResponse" + "$ref": "#/definitions/common.SimpleMsg" } }, "404": { @@ -2436,19 +2405,13 @@ "schema": { "$ref": "#/definitions/common.SimpleMsg" } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } } } } }, - "/ns/{nsId}/network/mcis/{mcisId}": { - "put": { - "description": "Inject Cloud Information For Cloud Adaptive Network", + "/ns/{nsId}/mcis/{mcisId}/vmgroup": { + "get": { + "description": "List VMGroup IDs in a specified MCIS", "consumes": [ "application/json" ], @@ -2456,9 +2419,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Cloud Adaptive Network (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Inject Cloud Information For Cloud Adaptive Network", + "summary": "List VMGroup IDs in a specified MCIS", "parameters": [ { "type": "string", @@ -2475,22 +2438,13 @@ "name": "mcisId", "in": "path", "required": true - }, - { - "description": "Details for the network request body", - "name": "networkReq", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/mcis.NetworkReq" - } } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.AgentInstallContentWrapper" + "$ref": "#/definitions/common.IdList" } }, "404": { @@ -2508,7 +2462,7 @@ } }, "post": { - "description": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", + "description": "Create multiple VMs by VM group in specified MCIS", "consumes": [ "application/json" ], @@ -2516,9 +2470,9 @@ "application/json" ], "tags": [ - "[Infra service] MCIS Cloud Adaptive Network (for developer)" + "[Infra service] MCIS Provisioning management" ], - "summary": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", + "summary": "Create multiple VMs by VM group in specified MCIS", "parameters": [ { "type": "string", @@ -2537,12 +2491,12 @@ "required": true }, { - "description": "Details for the network request body", - "name": "networkReq", + "description": "Details for VM Group", + "name": "vmReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.NetworkReq" + "$ref": "#/definitions/mcis.TbVmReq" } } ], @@ -2550,7 +2504,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.AgentInstallContentWrapper" + "$ref": "#/definitions/mcis.TbMcisInfo" } }, "404": { @@ -2568,9 +2522,9 @@ } } }, - "/ns/{nsId}/nlb": { + "/ns/{nsId}/mcis/{mcisId}/vmgroup/{vmgroupId}": { "get": { - "description": "List all NLBs or NLBs' ID", + "description": "List VMs with a VMGroup label in a specified MCIS", "consumes": [ "application/json" ], @@ -2578,9 +2532,9 @@ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Provisioning management" ], - "summary": "List all NLBs or NLBs' ID", + "summary": "List VMs with a VMGroup label in a specified MCIS", "parameters": [ { "type": "string", @@ -2591,47 +2545,36 @@ "required": true }, { - "enum": [ - "id" - ], "type": "string", - "description": "Option", - "name": "option", - "in": "query" + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true }, { "type": "string", - "description": "Field key for filtering (ex: cspNLBName)", - "name": "filterKey", - "in": "query" + "default": "group-0", + "description": "VM Group ID", + "name": "vmgroupId", + "in": "path", + "required": true }, { + "enum": [ + "id" + ], "type": "string", - "description": "Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)", - "name": "filterVal", + "description": "Option", + "name": "option", "in": "query" } ], "responses": { "200": { - "description": "Different return structures by the given option param", + "description": "OK", "schema": { - "allOf": [ - { - "$ref": "#/definitions/mcis.JSONResult" - }, - { - "type": "object", - "properties": { - "[DEFAULT]": { - "$ref": "#/definitions/mcis.RestGetAllNLBResponse" - }, - "[ID]": { - "$ref": "#/definitions/common.IdList" - } - } - } - ] + "$ref": "#/definitions/common.IdList" } }, "404": { @@ -2647,9 +2590,11 @@ } } } - }, + } + }, + "/ns/{nsId}/mcisDynamic": { "post": { - "description": "Create NLB", + "description": "Create MCIS Dynamically from common spec and image", "consumes": [ "application/json" ], @@ -2657,9 +2602,9 @@ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Provisioning management" ], - "summary": "Create NLB", + "summary": "Create MCIS Dynamically", "parameters": [ { "type": "string", @@ -2670,21 +2615,12 @@ "required": true }, { - "enum": [ - "register" - ], - "type": "string", - "description": "Option: [required params for register] connectionName, name, cspNLBId", - "name": "option", - "in": "query" - }, - { - "description": "Details of the NLB object", - "name": "nlbReq", + "description": "Details for MCIS object", + "name": "mcisReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbNLBReq" + "$ref": "#/definitions/mcis.TbMcisDynamicReq" } } ], @@ -2692,7 +2628,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbNLBInfo" + "$ref": "#/definitions/mcis.TbMcisInfo" } }, "404": { @@ -2708,55 +2644,11 @@ } } } - }, - "delete": { - "description": "Delete all NLBs", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "[Infra resource] NLB management" - ], - "summary": "Delete all NLBs", - "parameters": [ - { - "type": "string", - "default": "ns01", - "description": "Namespace ID", - "name": "nsId", - "in": "path", - "required": true - }, - { - "type": "string", - "default": "", - "description": "Delete resources containing matched ID-substring only", - "name": "match", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/common.IdList" - } - }, - "404": { - "description": "Not Found", - "schema": { - "$ref": "#/definitions/common.SimpleMsg" - } - } - } } }, - "/ns/{nsId}/nlb/{nlbId}": { - "get": { - "description": "Get NLB", + "/ns/{nsId}/monitoring/install/mcis/{mcisId}": { + "post": { + "description": "Install monitoring agent (CB-Dragonfly agent) to MCIS", "consumes": [ "application/json" ], @@ -2764,9 +2656,9 @@ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Resource monitor (for developer)" ], - "summary": "Get NLB", + "summary": "Install monitoring agent (CB-Dragonfly agent) to MCIS", "parameters": [ { "type": "string", @@ -2778,17 +2670,27 @@ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", "in": "path", "required": true + }, + { + "description": "Details for an MCIS object", + "name": "mcisInfo", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.McisCmdReq" + } } ], "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbNLBInfo" + "$ref": "#/definitions/mcis.AgentInstallContentWrapper" } }, "404": { @@ -2804,9 +2706,11 @@ } } } - }, - "delete": { - "description": "Delete NLB", + } + }, + "/ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric}": { + "get": { + "description": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", "consumes": [ "application/json" ], @@ -2814,9 +2718,9 @@ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Resource monitor (for developer)" ], - "summary": "Delete NLB", + "summary": "Get monitoring data of specified MCIS for specified monitoring metric (cpu, memory, disk, network)", "parameters": [ { "type": "string", @@ -2828,8 +2732,16 @@ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Metric type: cpu, memory, disk, network", + "name": "metric", "in": "path", "required": true } @@ -2838,7 +2750,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.SimpleMsg" + "$ref": "#/definitions/mcis.MonResultSimpleResponse" } }, "404": { @@ -2846,13 +2758,19 @@ "schema": { "$ref": "#/definitions/common.SimpleMsg" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } } } } }, - "/ns/{nsId}/nlb/{nlbId}/vm": { - "post": { - "description": "Add VMs to NLB", + "/ns/{nsId}/network/mcis/{mcisId}": { + "put": { + "description": "Inject Cloud Information For Cloud Adaptive Network", "consumes": [ "application/json" ], @@ -2860,9 +2778,9 @@ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Cloud Adaptive Network (for developer)" ], - "summary": "Add VMs to NLB", + "summary": "Inject Cloud Information For Cloud Adaptive Network", "parameters": [ { "type": "string", @@ -2874,18 +2792,19 @@ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", "in": "path", "required": true }, { - "description": "VMs to add to NLB", - "name": "nlbAddRemoveVMReq", + "description": "Details for the network request body", + "name": "networkReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + "$ref": "#/definitions/mcis.NetworkReq" } } ], @@ -2893,7 +2812,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/mcis.TbNLBInfo" + "$ref": "#/definitions/mcis.AgentInstallContentWrapper" } }, "404": { @@ -2910,8 +2829,8 @@ } } }, - "delete": { - "description": "Delete VMs from NLB", + "post": { + "description": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", "consumes": [ "application/json" ], @@ -2919,9 +2838,9 @@ "application/json" ], "tags": [ - "[Infra resource] NLB management" + "[Infra service] MCIS Cloud Adaptive Network (for developer)" ], - "summary": "Delete VMs from NLB", + "summary": "Configure Cloud Adaptive Network (cb-network agent) to MCIS", "parameters": [ { "type": "string", @@ -2933,18 +2852,19 @@ }, { "type": "string", - "description": "NLB ID", - "name": "nlbId", + "default": "mcis01", + "description": "MCIS ID", + "name": "mcisId", "in": "path", "required": true }, { - "description": "VMs to add to NLB", - "name": "nlbAddRemoveVMReq", + "description": "Details for the network request body", + "name": "networkReq", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + "$ref": "#/definitions/mcis.NetworkReq" } } ], @@ -2952,7 +2872,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/common.SimpleMsg" + "$ref": "#/definitions/mcis.AgentInstallContentWrapper" } }, "404": { @@ -2960,6 +2880,12 @@ "schema": { "$ref": "#/definitions/common.SimpleMsg" } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } } } } @@ -7887,10 +7813,6 @@ "$ref": "#/definitions/common.KeyValue" } }, - "mcis": { - "type": "string", - "example": "mc" - }, "port": { "description": "Listener Port or 1-65535", "type": "string", @@ -8063,14 +7985,6 @@ } } }, - "mcis.TbNLBAddRemoveVMReq": { - "type": "object", - "properties": { - "targetGroup": { - "$ref": "#/definitions/mcis.TBNLBTargetGroup" - } - } - }, "mcis.TbNLBInfo": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index b1fa285e..180f7915 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -1482,9 +1482,6 @@ definitions: items: $ref: '#/definitions/common.KeyValue' type: array - mcis: - example: mc - type: string port: description: Listener Port or 1-65535 example: "22" @@ -1621,11 +1618,6 @@ definitions: - name - vm type: object - mcis.TbNLBAddRemoveVMReq: - properties: - targetGroup: - $ref: '#/definitions/mcis.TBNLBTargetGroup' - type: object mcis.TbNLBInfo: properties: associatedObjectList: @@ -3347,53 +3339,11 @@ paths: summary: 'Get MCIS object (option: status, vmID)' tags: - '[Infra service] MCIS Provisioning management' - /ns/{nsId}/mcis/{mcisId}/vm: - post: - consumes: - - application/json - description: Create VM in specified MCIS - 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 - - description: Details for an VM object - in: body - name: vmReq - required: true - schema: - $ref: '#/definitions/mcis.TbVmReq' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/mcis.TbVmInfo' - "404": - description: Not Found - schema: - $ref: '#/definitions/common.SimpleMsg' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/common.SimpleMsg' - summary: Create VM in specified MCIS - tags: - - '[Infra service] MCIS Provisioning management' - /ns/{nsId}/mcis/{mcisId}/vm/{vmId}: + /ns/{nsId}/mcis/{mcisId}/nlb: delete: consumes: - application/json - description: Delete VM in specified MCIS + description: Delete all NLBs parameters: - default: ns01 description: Namespace ID @@ -3407,17 +3357,10 @@ paths: name: mcisId required: true type: string - - default: vm01 - description: VM ID - in: path - name: vmId - required: true - type: string - - description: Option for delete VM (support force delete) - enum: - - force + - default: "" + description: Delete resources containing matched ID-substring only in: query - name: option + name: match type: string produces: - application/json @@ -3425,18 +3368,18 @@ paths: "200": description: OK schema: - $ref: '#/definitions/common.SimpleMsg' + $ref: '#/definitions/common.IdList' "404": description: Not Found schema: $ref: '#/definitions/common.SimpleMsg' - summary: Delete VM in specified MCIS + summary: Delete all NLBs tags: - - '[Infra service] MCIS Provisioning management' + - '[Infra resource] NLB management' get: consumes: - application/json - description: Get VM in specified MCIS + description: List all NLBs or NLBs' ID parameters: - default: ns01 description: Namespace ID @@ -3450,19 +3393,20 @@ paths: name: mcisId required: true type: string - - default: vm01 - description: VM ID - in: path - name: vmId - required: true - type: string - - description: Option for MCIS + - description: Option enum: - - default - - status + - id in: query name: option type: string + - description: 'Field key for filtering (ex: cspNLBName)' + in: query + name: filterKey + type: string + - description: 'Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)' + in: query + name: filterVal + type: string produces: - application/json responses: @@ -3473,9 +3417,9 @@ paths: - $ref: '#/definitions/mcis.JSONResult' - properties: '[DEFAULT]': - $ref: '#/definitions/mcis.TbVmInfo' - '[STATUS]': - $ref: '#/definitions/mcis.TbVmStatusInfo' + $ref: '#/definitions/mcis.RestGetAllNLBResponse' + '[ID]': + $ref: '#/definitions/common.IdList' type: object "404": description: Not Found @@ -3485,14 +3429,13 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Get VM in specified MCIS + summary: List all NLBs or NLBs' ID tags: - - '[Infra service] MCIS Provisioning management' - /ns/{nsId}/mcis/{mcisId}/vmgroup: - get: + - '[Infra resource] NLB management' + post: consumes: - application/json - description: List VMGroup IDs in a specified MCIS + description: Create NLB parameters: - default: ns01 description: Namespace ID @@ -3506,13 +3449,26 @@ paths: name: mcisId required: true type: string + - description: 'Option: [required params for register] connectionName, name, + cspNLBId' + enum: + - register + in: query + name: option + type: string + - description: Details of the NLB object + in: body + name: nlbReq + required: true + schema: + $ref: '#/definitions/mcis.TbNLBReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/common.IdList' + $ref: '#/definitions/mcis.TbNLBInfo' "404": description: Not Found schema: @@ -3521,13 +3477,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: List VMGroup IDs in a specified MCIS + summary: Create NLB tags: - - '[Infra service] MCIS Provisioning management' - post: + - '[Infra resource] NLB management' + /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}: + delete: consumes: - application/json - description: Create multiple VMs by VM group in specified MCIS + description: Delete NLB parameters: - default: ns01 description: Namespace ID @@ -3541,35 +3498,29 @@ paths: name: mcisId required: true type: string - - description: Details for VM Group - in: body - name: vmReq + - description: NLB ID + in: path + name: nlbId required: true - schema: - $ref: '#/definitions/mcis.TbVmReq' + type: string produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.TbMcisInfo' + $ref: '#/definitions/common.SimpleMsg' "404": description: Not Found schema: $ref: '#/definitions/common.SimpleMsg' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/common.SimpleMsg' - summary: Create multiple VMs by VM group in specified MCIS + summary: Delete NLB tags: - - '[Infra service] MCIS Provisioning management' - /ns/{nsId}/mcis/{mcisId}/vmgroup/{vmgroupId}: + - '[Infra resource] NLB management' get: consumes: - application/json - description: List VMs with a VMGroup label in a specified MCIS + description: Get NLB parameters: - default: ns01 description: Namespace ID @@ -3583,25 +3534,18 @@ paths: name: mcisId required: true type: string - - default: group-0 - description: VM Group ID + - description: NLB ID in: path - name: vmgroupId + name: nlbId required: true type: string - - description: Option - enum: - - id - in: query - name: option - type: string produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/common.IdList' + $ref: '#/definitions/mcis.TbNLBInfo' "404": description: Not Found schema: @@ -3610,14 +3554,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: List VMs with a VMGroup label in a specified MCIS + summary: Get NLB tags: - - '[Infra service] MCIS Provisioning management' - /ns/{nsId}/mcisDynamic: + - '[Infra resource] NLB management' + /ns/{nsId}/mcis/{mcisId}/vm: post: consumes: - application/json - description: Create MCIS Dynamically from common spec and image + description: Create VM in specified MCIS parameters: - default: ns01 description: Namespace ID @@ -3625,19 +3569,25 @@ paths: name: nsId required: true type: string - - description: Details for MCIS object + - default: mcis01 + description: MCIS ID + in: path + name: mcisId + required: true + type: string + - description: Details for an VM object in: body - name: mcisReq + name: vmReq required: true schema: - $ref: '#/definitions/mcis.TbMcisDynamicReq' + $ref: '#/definitions/mcis.TbVmReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.TbMcisInfo' + $ref: '#/definitions/mcis.TbVmInfo' "404": description: Not Found schema: @@ -3646,14 +3596,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Create MCIS Dynamically + summary: Create VM in specified MCIS tags: - '[Infra service] MCIS Provisioning management' - /ns/{nsId}/monitoring/install/mcis/{mcisId}: - post: + /ns/{nsId}/mcis/{mcisId}/vm/{vmId}: + delete: consumes: - application/json - description: Install monitoring agent (CB-Dragonfly agent) to MCIS + description: Delete VM in specified MCIS parameters: - default: ns01 description: Namespace ID @@ -3667,36 +3617,36 @@ paths: name: mcisId required: true type: string - - description: Details for an MCIS object - in: body - name: mcisInfo + - default: vm01 + description: VM ID + in: path + name: vmId required: true - schema: - $ref: '#/definitions/mcis.McisCmdReq' + type: string + - description: Option for delete VM (support force delete) + enum: + - force + in: query + name: option + type: string produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.AgentInstallContentWrapper' + $ref: '#/definitions/common.SimpleMsg' "404": description: Not Found schema: $ref: '#/definitions/common.SimpleMsg' - "500": - description: Internal Server Error - schema: - $ref: '#/definitions/common.SimpleMsg' - summary: Install monitoring agent (CB-Dragonfly agent) to MCIS + summary: Delete VM in specified MCIS tags: - - '[Infra service] MCIS Resource monitor (for developer)' - /ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric}: + - '[Infra service] MCIS Provisioning management' get: consumes: - application/json - description: Get monitoring data of specified MCIS for specified monitoring - metric (cpu, memory, disk, network) + description: Get VM in specified MCIS parameters: - default: ns01 description: Namespace ID @@ -3710,18 +3660,33 @@ paths: name: mcisId required: true type: string - - description: 'Metric type: cpu, memory, disk, network' + - default: vm01 + description: VM ID in: path - name: metric + name: vmId required: true type: string + - description: Option for MCIS + enum: + - default + - status + in: query + name: option + type: string produces: - application/json responses: "200": - description: OK + description: Different return structures by the given option param schema: - $ref: '#/definitions/mcis.MonResultSimpleResponse' + allOf: + - $ref: '#/definitions/mcis.JSONResult' + - properties: + '[DEFAULT]': + $ref: '#/definitions/mcis.TbVmInfo' + '[STATUS]': + $ref: '#/definitions/mcis.TbVmStatusInfo' + type: object "404": description: Not Found schema: @@ -3730,15 +3695,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Get monitoring data of specified MCIS for specified monitoring metric - (cpu, memory, disk, network) + summary: Get VM in specified MCIS tags: - - '[Infra service] MCIS Resource monitor (for developer)' - /ns/{nsId}/network/mcis/{mcisId}: - post: + - '[Infra service] MCIS Provisioning management' + /ns/{nsId}/mcis/{mcisId}/vmgroup: + get: consumes: - application/json - description: Configure Cloud Adaptive Network (cb-network agent) to MCIS + description: List VMGroup IDs in a specified MCIS parameters: - default: ns01 description: Namespace ID @@ -3752,19 +3716,13 @@ paths: name: mcisId required: true type: string - - description: Details for the network request body - in: body - name: networkReq - required: true - schema: - $ref: '#/definitions/mcis.NetworkReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.AgentInstallContentWrapper' + $ref: '#/definitions/common.IdList' "404": description: Not Found schema: @@ -3773,13 +3731,13 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Configure Cloud Adaptive Network (cb-network agent) to MCIS + summary: List VMGroup IDs in a specified MCIS tags: - - '[Infra service] MCIS Cloud Adaptive Network (for developer)' - put: + - '[Infra service] MCIS Provisioning management' + post: consumes: - application/json - description: Inject Cloud Information For Cloud Adaptive Network + description: Create multiple VMs by VM group in specified MCIS parameters: - default: ns01 description: Namespace ID @@ -3793,19 +3751,19 @@ paths: name: mcisId required: true type: string - - description: Details for the network request body + - description: Details for VM Group in: body - name: networkReq + name: vmReq required: true schema: - $ref: '#/definitions/mcis.NetworkReq' + $ref: '#/definitions/mcis.TbVmReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.AgentInstallContentWrapper' + $ref: '#/definitions/mcis.TbMcisInfo' "404": description: Not Found schema: @@ -3814,14 +3772,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Inject Cloud Information For Cloud Adaptive Network + summary: Create multiple VMs by VM group in specified MCIS tags: - - '[Infra service] MCIS Cloud Adaptive Network (for developer)' - /ns/{nsId}/nlb: - delete: + - '[Infra service] MCIS Provisioning management' + /ns/{nsId}/mcis/{mcisId}/vmgroup/{vmgroupId}: + get: consumes: - application/json - description: Delete all NLBs + description: List VMs with a VMGroup label in a specified MCIS parameters: - default: ns01 description: Namespace ID @@ -3829,34 +3787,16 @@ paths: name: nsId required: true type: string - - default: "" - description: Delete resources containing matched ID-substring only - in: query - name: match + - default: mcis01 + description: MCIS ID + in: path + name: mcisId + required: true type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/common.IdList' - "404": - description: Not Found - schema: - $ref: '#/definitions/common.SimpleMsg' - summary: Delete all NLBs - tags: - - '[Infra resource] NLB management' - get: - consumes: - - application/json - description: List all NLBs or NLBs' ID - parameters: - - default: ns01 - description: Namespace ID + - default: group-0 + description: VM Group ID in: path - name: nsId + name: vmgroupId required: true type: string - description: Option @@ -3865,28 +3805,13 @@ paths: in: query name: option type: string - - description: 'Field key for filtering (ex: cspNLBName)' - in: query - name: filterKey - type: string - - description: 'Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)' - in: query - name: filterVal - type: string produces: - application/json responses: "200": - description: Different return structures by the given option param + description: OK schema: - allOf: - - $ref: '#/definitions/mcis.JSONResult' - - properties: - '[DEFAULT]': - $ref: '#/definitions/mcis.RestGetAllNLBResponse' - '[ID]': - $ref: '#/definitions/common.IdList' - type: object + $ref: '#/definitions/common.IdList' "404": description: Not Found schema: @@ -3895,13 +3820,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: List all NLBs or NLBs' ID + summary: List VMs with a VMGroup label in a specified MCIS tags: - - '[Infra resource] NLB management' + - '[Infra service] MCIS Provisioning management' + /ns/{nsId}/mcisDynamic: post: consumes: - application/json - description: Create NLB + description: Create MCIS Dynamically from common spec and image parameters: - default: ns01 description: Namespace ID @@ -3909,26 +3835,19 @@ paths: name: nsId required: true type: string - - description: 'Option: [required params for register] connectionName, name, - cspNLBId' - enum: - - register - in: query - name: option - type: string - - description: Details of the NLB object + - description: Details for MCIS object in: body - name: nlbReq + name: mcisReq required: true schema: - $ref: '#/definitions/mcis.TbNLBReq' + $ref: '#/definitions/mcis.TbMcisDynamicReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.TbNLBInfo' + $ref: '#/definitions/mcis.TbMcisInfo' "404": description: Not Found schema: @@ -3937,14 +3856,14 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Create NLB + summary: Create MCIS Dynamically tags: - - '[Infra resource] NLB management' - /ns/{nsId}/nlb/{nlbId}: - delete: + - '[Infra service] MCIS Provisioning management' + /ns/{nsId}/monitoring/install/mcis/{mcisId}: + post: consumes: - application/json - description: Delete NLB + description: Install monitoring agent (CB-Dragonfly agent) to MCIS parameters: - default: ns01 description: Namespace ID @@ -3952,29 +3871,42 @@ paths: name: nsId required: true type: string - - description: NLB ID + - default: mcis01 + description: MCIS ID in: path - name: nlbId + name: mcisId required: true type: string + - description: Details for an MCIS object + in: body + name: mcisInfo + required: true + schema: + $ref: '#/definitions/mcis.McisCmdReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/common.SimpleMsg' + $ref: '#/definitions/mcis.AgentInstallContentWrapper' "404": description: Not Found schema: $ref: '#/definitions/common.SimpleMsg' - summary: Delete NLB + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Install monitoring agent (CB-Dragonfly agent) to MCIS tags: - - '[Infra resource] NLB management' + - '[Infra service] MCIS Resource monitor (for developer)' + /ns/{nsId}/monitoring/mcis/{mcisId}/metric/{metric}: get: consumes: - application/json - description: Get NLB + description: Get monitoring data of specified MCIS for specified monitoring + metric (cpu, memory, disk, network) parameters: - default: ns01 description: Namespace ID @@ -3982,9 +3914,15 @@ paths: name: nsId required: true type: string - - description: NLB ID + - default: mcis01 + description: MCIS ID in: path - name: nlbId + name: mcisId + required: true + type: string + - description: 'Metric type: cpu, memory, disk, network' + in: path + name: metric required: true type: string produces: @@ -3993,7 +3931,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/mcis.TbNLBInfo' + $ref: '#/definitions/mcis.MonResultSimpleResponse' "404": description: Not Found schema: @@ -4002,14 +3940,15 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Get NLB + summary: Get monitoring data of specified MCIS for specified monitoring metric + (cpu, memory, disk, network) tags: - - '[Infra resource] NLB management' - /ns/{nsId}/nlb/{nlbId}/vm: - delete: + - '[Infra service] MCIS Resource monitor (for developer)' + /ns/{nsId}/network/mcis/{mcisId}: + post: consumes: - application/json - description: Delete VMs from NLB + description: Configure Cloud Adaptive Network (cb-network agent) to MCIS parameters: - default: ns01 description: Namespace ID @@ -4017,35 +3956,40 @@ paths: name: nsId required: true type: string - - description: NLB ID + - default: mcis01 + description: MCIS ID in: path - name: nlbId + name: mcisId required: true type: string - - description: VMs to add to NLB + - description: Details for the network request body in: body - name: nlbAddRemoveVMReq + name: networkReq required: true schema: - $ref: '#/definitions/mcis.TbNLBAddRemoveVMReq' + $ref: '#/definitions/mcis.NetworkReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/common.SimpleMsg' + $ref: '#/definitions/mcis.AgentInstallContentWrapper' "404": description: Not Found schema: $ref: '#/definitions/common.SimpleMsg' - summary: Delete VMs from NLB + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Configure Cloud Adaptive Network (cb-network agent) to MCIS tags: - - '[Infra resource] NLB management' - post: + - '[Infra service] MCIS Cloud Adaptive Network (for developer)' + put: consumes: - application/json - description: Add VMs to NLB + description: Inject Cloud Information For Cloud Adaptive Network parameters: - default: ns01 description: Namespace ID @@ -4053,24 +3997,25 @@ paths: name: nsId required: true type: string - - description: NLB ID + - default: mcis01 + description: MCIS ID in: path - name: nlbId + name: mcisId required: true type: string - - description: VMs to add to NLB + - description: Details for the network request body in: body - name: nlbAddRemoveVMReq + name: networkReq required: true schema: - $ref: '#/definitions/mcis.TbNLBAddRemoveVMReq' + $ref: '#/definitions/mcis.NetworkReq' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/mcis.TbNLBInfo' + $ref: '#/definitions/mcis.AgentInstallContentWrapper' "404": description: Not Found schema: @@ -4079,9 +4024,9 @@ paths: description: Internal Server Error schema: $ref: '#/definitions/common.SimpleMsg' - summary: Add VMs to NLB + summary: Inject Cloud Information For Cloud Adaptive Network tags: - - '[Infra resource] NLB management' + - '[Infra service] MCIS Cloud Adaptive Network (for developer)' /ns/{nsId}/policy/mcis: delete: consumes: diff --git a/src/api/rest/server/mcis/nlb.go b/src/api/rest/server/mcis/nlb.go index b2d1a13e..2a839008 100644 --- a/src/api/rest/server/mcis/nlb.go +++ b/src/api/rest/server/mcis/nlb.go @@ -30,15 +30,17 @@ import ( // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param option query string false "Option: [required params for register] connectionName, name, cspNLBId" Enums(register) // @Param nlbReq body mcis.TbNLBReq true "Details of the NLB object" // @Success 200 {object} mcis.TbNLBInfo // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb [post] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb [post] func RestPostNLB(c echo.Context) error { nsId := c.Param("nsId") + mcisId := c.Param("mcisId") optionFlag := c.QueryParam("option") @@ -49,7 +51,7 @@ func RestPostNLB(c echo.Context) error { fmt.Println("[POST NLB]") - content, err := mcis.CreateNLB(nsId, u, optionFlag) + content, err := mcis.CreateNLB(nsId, mcisId, u, optionFlag) if err != nil { common.CBLog.Error(err) @@ -68,14 +70,17 @@ func RestPostNLB(c echo.Context) error { // @Tags [Infra resource] NLB management // @Accept json // @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param nlbInfo body mcis.TbNLBInfo true "Details of the NLB object" // @Success 200 {object} mcis.TbNLBInfo // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb/{nlbId} [put] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [put] */ func RestPutNLB(c echo.Context) error { - //nsId := c.Param("nsId") + // nsId := c.Param("nsId") + // mcisId := c.Param("mcisId") return nil } @@ -87,18 +92,19 @@ func RestPutNLB(c echo.Context) error { // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param nlbId path string true "NLB ID" // @Success 200 {object} mcis.TbNLBInfo // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb/{nlbId} [get] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [get] func RestGetNLB(c echo.Context) error { nsId := c.Param("nsId") - + mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") - res, err := mcis.GetNLB(nsId, resourceId) + res, err := mcis.GetNLB(nsId, mcisId, resourceId) if err != nil { mapA := map[string]string{"message": "Failed to find the NLB " + resourceId} return c.JSON(http.StatusNotFound, &mapA) @@ -119,16 +125,18 @@ type RestGetAllNLBResponse struct { // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param option query string false "Option" Enums(id) // @Param filterKey query string false "Field key for filtering (ex: cspNLBName)" // @Param filterVal query string false "Field value for filtering (ex: ns01-alibaba-ap-northeast-1-vpc)" // @Success 200 {object} JSONResult{[DEFAULT]=RestGetAllNLBResponse,[ID]=common.IdList} "Different return structures by the given option param" // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb [get] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb [get] func RestGetAllNLB(c echo.Context) error { nsId := c.Param("nsId") + mcisId := c.Param("mcisId") optionFlag := c.QueryParam("option") filterKey := c.QueryParam("filterKey") @@ -137,7 +145,7 @@ func RestGetAllNLB(c echo.Context) error { if optionFlag == "id" { content := common.IdList{} var err error - content.IdList, err = mcis.ListNLBId(nsId) + content.IdList, err = mcis.ListNLBId(nsId, mcisId) if err != nil { mapA := map[string]string{"message": "Failed to list NLBs' ID; " + err.Error()} return c.JSON(http.StatusNotFound, &mapA) @@ -146,7 +154,7 @@ func RestGetAllNLB(c echo.Context) error { return c.JSON(http.StatusOK, &content) } else { - resourceList, err := mcis.ListNLB(nsId, filterKey, filterVal) + resourceList, err := mcis.ListNLB(nsId, mcisId, filterKey, filterVal) if err != nil { mapA := map[string]string{"message": "Failed to list NLBs; " + err.Error()} return c.JSON(http.StatusNotFound, &mapA) @@ -169,19 +177,20 @@ func RestGetAllNLB(c echo.Context) error { // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param nlbId path string true "NLB ID" // @Success 200 {object} common.SimpleMsg // @Failure 404 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb/{nlbId} [delete] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId} [delete] func RestDelNLB(c echo.Context) error { nsId := c.Param("nsId") - + mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") forceFlag := c.QueryParam("force") - err := mcis.DelNLB(nsId, resourceId, forceFlag) + err := mcis.DelNLB(nsId, mcisId, resourceId, forceFlag) if err != nil { common.CBLog.Error(err) mapA := map[string]string{"message": err.Error()} @@ -199,18 +208,20 @@ func RestDelNLB(c echo.Context) error { // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param match query string false "Delete resources containing matched ID-substring only" default() // @Success 200 {object} common.IdList // @Failure 404 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb [delete] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb [delete] func RestDelAllNLB(c echo.Context) error { nsId := c.Param("nsId") + mcisId := c.Param("mcisId") forceFlag := c.QueryParam("force") subString := c.QueryParam("match") - output, err := mcis.DelAllNLB(nsId, subString, forceFlag) + output, err := mcis.DelAllNLB(nsId, mcisId, subString, forceFlag) if err != nil { common.CBLog.Error(err) mapA := map[string]string{"message": err.Error()} @@ -220,6 +231,7 @@ func RestDelAllNLB(c echo.Context) error { return c.JSON(http.StatusOK, output) } +/* REST API Deprecated // RestAddNLBVMs godoc // @Summary Add VMs to NLB // @Description Add VMs to NLB @@ -227,16 +239,17 @@ func RestDelAllNLB(c echo.Context) error { // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param nlbId path string true "NLB ID" // @Param nlbAddRemoveVMReq body mcis.TbNLBAddRemoveVMReq true "VMs to add to NLB" // @Success 200 {object} mcis.TbNLBInfo // @Failure 404 {object} common.SimpleMsg // @Failure 500 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb/{nlbId}/vm [post] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm [post] func RestAddNLBVMs(c echo.Context) error { nsId := c.Param("nsId") - + mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") u := &mcis.TbNLBAddRemoveVMReq{} @@ -246,7 +259,7 @@ func RestAddNLBVMs(c echo.Context) error { fmt.Println("[Add NLB VMs]") - content, err := mcis.AddNLBVMs(nsId, resourceId, u) + content, err := mcis.AddNLBVMs(nsId, mcisId, resourceId, u) if err != nil { common.CBLog.Error(err) @@ -263,15 +276,16 @@ func RestAddNLBVMs(c echo.Context) error { // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) // @Param nlbId path string true "NLB ID" // @Param nlbAddRemoveVMReq body mcis.TbNLBAddRemoveVMReq true "VMs to add to NLB" // @Success 200 {object} common.SimpleMsg // @Failure 404 {object} common.SimpleMsg -// @Router /ns/{nsId}/nlb/{nlbId}/vm [delete] +// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm [delete] func RestRemoveNLBVMs(c echo.Context) error { nsId := c.Param("nsId") - + mcisId := c.Param("mcisId") resourceId := c.Param("resourceId") u := &mcis.TbNLBAddRemoveVMReq{} @@ -279,7 +293,7 @@ func RestRemoveNLBVMs(c echo.Context) error { return err } - err := mcis.RemoveNLBVMs(nsId, resourceId, u) + err := mcis.RemoveNLBVMs(nsId, mcisId, resourceId, u) if err != nil { common.CBLog.Error(err) mapA := map[string]string{"message": err.Error()} @@ -289,3 +303,4 @@ func RestRemoveNLBVMs(c echo.Context) error { mapA := map[string]string{"message": "Removed VMs from the NLB " + resourceId} return c.JSON(http.StatusOK, &mapA) } +*/ diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 0c67d6b5..7c0acdea 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -224,15 +224,16 @@ func RunServer(port string) { g.PUT("/:nsId/network/mcis/:mcisId", rest_mcis.RestPutInjectCloudInformationForCloudAdaptiveNetwork) // Network Load Balancer - g.POST("/:nsId/nlb", rest_mcis.RestPostNLB) - g.GET("/:nsId/nlb/:resourceId", rest_mcis.RestGetNLB) - g.GET("/:nsId/nlb", rest_mcis.RestGetAllNLB) - // g.PUT("/:nsId/nlb/:resourceId", rest_mcis.RestPutNLB) - g.DELETE("/:nsId/nlb/:resourceId", rest_mcis.RestDelNLB) - g.DELETE("/:nsId/nlb", rest_mcis.RestDelAllNLB) - - g.POST("/:nsId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs) - g.DELETE("/:nsId/nlb/:resourceId/vm", rest_mcis.RestRemoveNLBVMs) + g.POST("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestPostNLB) + g.GET("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestGetNLB) + g.GET("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestGetAllNLB) + // g.PUT("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestPutNLB) + g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestDelNLB) + g.DELETE("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestDelAllNLB) + + // REST API Deprecated + // g.POST("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs) + // g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestRemoveNLBVMs) //MCIR Management g.POST("/:nsId/resources/image", rest_mcir.RestPostImage) diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index beed8337..9bafa65c 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -135,7 +135,6 @@ type SpiderHealthInfo struct { type TBNLBTargetGroup struct { Protocol string `json:"protocol" example:"TCP"` // TCP|HTTP|HTTPS Port string `json:"port" example:"22"` // Listener Port or 1-65535 - MCIS string `json:"mcis" example:"mc"` VMs []string `json:"vms"` CspID string // Optional, May be Used by Driver. @@ -217,7 +216,7 @@ type TbNLBAddRemoveVMReq struct { // Tumblebug } // CreateNLB accepts nlb creation request, creates and returns an TB nlb object -func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { +func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInfo, error) { fmt.Println("=========================== CreateNLB") err := common.CheckString(nsId) @@ -227,6 +226,13 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { return temp, err } + err = common.CheckString(mcisId) + if err != nil { + temp := TbNLBInfo{} + common.CBLog.Error(err) + return temp, err + } + err = validate.Struct(u) if err != nil { if _, ok := err.(*validator.InvalidValidationError); ok { @@ -239,7 +245,7 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { return temp, err } - check, err := CheckNLB(nsId, u.Name) + check, err := CheckNLB(nsId, mcisId, u.Name) if check { temp := TbNLBInfo{} @@ -280,7 +286,7 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { tempReq.ReqInfo.VMGroup.Protocol = u.TargetGroup.Protocol for _, v := range u.TargetGroup.VMs { - vm, err := GetVmObject(nsId, u.TargetGroup.MCIS, v) + vm, err := GetVmObject(nsId, mcisId, v) if err != nil { common.CBLog.Error(err) return TbNLBInfo{}, err @@ -288,10 +294,11 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { // fmt.Println("vm:") // for debug // payload, _ := json.MarshalIndent(vm, "", " ") // for debug // fmt.Print(string(payload)) // for debug + // fmt.Print("vm.CspViewVmDetail.IId.NameId: " + vm.CspViewVmDetail.IId.NameId) // for debug tempReq.ReqInfo.VMGroup.VMs = append(tempReq.ReqInfo.VMGroup.VMs, vm.CspViewVmDetail.IId.NameId) } - // fmt.Printf("u.TargetGroup.VMs: %s \n", u.TargetGroup.VMs) // for debug + // fmt.Printf("u.TargetGroup.VMs: %s \n", u.TargetGroup.VMs) // for debug // fmt.Printf("tempReq.ReqInfo.VMGroup.VMs: %s \n", tempReq.ReqInfo.VMGroup.VMs) // for debug /* for _, v := range u.VMIDList { @@ -422,7 +429,7 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { content.TargetGroup.Port = tempSpiderNLBInfo.VMGroup.Port content.TargetGroup.Protocol = tempSpiderNLBInfo.VMGroup.Protocol - content.TargetGroup.MCIS = u.TargetGroup.MCIS + // content.TargetGroup.MCIS = u.TargetGroup.MCIS content.TargetGroup.VMs = u.TargetGroup.VMs content.TargetGroup.CspID = u.TargetGroup.CspID content.TargetGroup.KeyValueList = u.TargetGroup.KeyValueList @@ -435,7 +442,7 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { // cb-store // Key := common.GenResourceKey(nsId, common.StrNLB, content.Id) - Key := GenNLBKey(nsId, content.Id) + Key := GenNLBKey(nsId, mcisId, content.Id) Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) @@ -464,7 +471,7 @@ func CreateNLB(nsId string, u *TbNLBReq, option string) (TbNLBInfo, error) { } // GetNLB returns the requested TB NLB object -func GetNLB(nsId string, resourceId string) (TbNLBInfo, error) { +func GetNLB(nsId string, mcisId string, resourceId string) (TbNLBInfo, error) { res := TbNLBInfo{} err := common.CheckString(nsId) @@ -473,12 +480,19 @@ func GetNLB(nsId string, resourceId string) (TbNLBInfo, error) { return res, err } + err = common.CheckString(mcisId) + if err != nil { + temp := TbNLBInfo{} + common.CBLog.Error(err) + return temp, err + } + err = common.CheckString(resourceId) if err != nil { common.CBLog.Error(err) return res, err } - check, err := CheckNLB(nsId, resourceId) + check, err := CheckNLB(nsId, mcisId, resourceId) if err != nil { common.CBLog.Error(err) return res, err @@ -493,7 +507,7 @@ func GetNLB(nsId string, resourceId string) (TbNLBInfo, error) { fmt.Println("[Get NLB] " + resourceId) // key := common.GenResourceKey(nsId, resourceType, resourceId) - key := GenNLBKey(nsId, resourceId) + key := GenNLBKey(nsId, mcisId, resourceId) keyValue, err := common.CBStore.Get(key) if err != nil { @@ -515,7 +529,7 @@ func GetNLB(nsId string, resourceId string) (TbNLBInfo, error) { } // CheckNLB returns the existence of the TB NLB object in bool form. -func CheckNLB(nsId string, resourceId string) (bool, error) { +func CheckNLB(nsId string, mcisId string, resourceId string) (bool, error) { // Check parameters' emptiness if nsId == "" { @@ -532,6 +546,12 @@ func CheckNLB(nsId string, resourceId string) (bool, error) { return false, err } + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return false, err + } + err = common.CheckString(resourceId) if err != nil { common.CBLog.Error(err) @@ -541,7 +561,7 @@ func CheckNLB(nsId string, resourceId string) (bool, error) { fmt.Println("[Check NLB] " + resourceId) // key := common.GenResourceKey(nsId, resourceType, resourceId) - key := GenNLBKey(nsId, resourceId) + key := GenNLBKey(nsId, mcisId, resourceId) keyValue, err := common.CBStore.Get(key) if err != nil { @@ -556,24 +576,30 @@ func CheckNLB(nsId string, resourceId string) (bool, error) { } // GenNLBKey is func to generate a key from NLB id -func GenNLBKey(nsId string, resourceId string) string { +func GenNLBKey(nsId string, mcisId string, resourceId string) string { err := common.CheckString(nsId) if err != nil { common.CBLog.Error(err) return "/invalidKey" } + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return "/invalidKey" + } + err = common.CheckString(resourceId) if err != nil { common.CBLog.Error(err) return "/invalidKey" } - return fmt.Sprintf("/ns/%s/nlb/%s", nsId, resourceId) + return fmt.Sprintf("/ns/%s/mcis/%s/nlb/%s", nsId, mcisId, resourceId) } // ListNLBId returns the list of TB NLB object IDs of given nsId -func ListNLBId(nsId string) ([]string, error) { +func ListNLBId(nsId string, mcisId string) ([]string, error) { err := common.CheckString(nsId) if err != nil { @@ -581,6 +607,12 @@ func ListNLBId(nsId string) ([]string, error) { return nil, err } + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return nil, err + } + fmt.Println("[ListNLBId] ns: " + nsId) key := "/ns/" + nsId + "/" fmt.Println(key) @@ -614,7 +646,7 @@ func ListNLBId(nsId string) ([]string, error) { } // ListNLB returns the list of TB NLB objects of given nsId -func ListNLB(nsId string, filterKey string, filterVal string) (interface{}, error) { +func ListNLB(nsId string, mcisId string, filterKey string, filterVal string) (interface{}, error) { err := common.CheckString(nsId) if err != nil { @@ -622,6 +654,12 @@ func ListNLB(nsId string, filterKey string, filterVal string) (interface{}, erro return nil, err } + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return nil, err + } + fmt.Println("[Get] NLB list") key := "/ns/" + nsId + "/nlb" fmt.Println(key) @@ -666,7 +704,7 @@ func ListNLB(nsId string, filterKey string, filterVal string) (interface{}, erro } // DelNLB deletes the TB NLB object -func DelNLB(nsId string, resourceId string, forceFlag string) error { +func DelNLB(nsId string, mcisId string, resourceId string, forceFlag string) error { err := common.CheckString(nsId) if err != nil { @@ -674,12 +712,18 @@ func DelNLB(nsId string, resourceId string, forceFlag string) error { return err } + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return err + } + err = common.CheckString(resourceId) if err != nil { common.CBLog.Error(err) return err } - check, err := CheckNLB(nsId, resourceId) + check, err := CheckNLB(nsId, mcisId, resourceId) if err != nil { common.CBLog.Error(err) @@ -692,7 +736,7 @@ func DelNLB(nsId string, resourceId string, forceFlag string) error { return err } - key := GenNLBKey(nsId, resourceId) + key := GenNLBKey(nsId, mcisId, resourceId) fmt.Println("key: " + key) keyValue, _ := common.CBStore.Get(key) @@ -832,7 +876,7 @@ func DelNLB(nsId string, resourceId string, forceFlag string) error { } // DelAllNLB deletes all TB NLB object of given nsId -func DelAllNLB(nsId string, subString string, forceFlag string) (common.IdList, error) { +func DelAllNLB(nsId string, mcisId string, subString string, forceFlag string) (common.IdList, error) { deletedResources := common.IdList{} deleteStatus := "" @@ -843,7 +887,13 @@ func DelAllNLB(nsId string, subString string, forceFlag string) (common.IdList, return deletedResources, err } - resourceIdList, err := ListNLBId(nsId) + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return deletedResources, err + } + + resourceIdList, err := ListNLBId(nsId, mcisId) if err != nil { return deletedResources, err } @@ -860,7 +910,7 @@ func DelAllNLB(nsId string, subString string, forceFlag string) (common.IdList, if subString == "" || strings.Contains(v, subString) { deleteStatus = "" - err := DelNLB(nsId, v, forceFlag) + err := DelNLB(nsId, mcisId, v, forceFlag) if err != nil { deleteStatus = err.Error() @@ -875,7 +925,7 @@ func DelAllNLB(nsId string, subString string, forceFlag string) (common.IdList, } // AddNLBVMs accepts VM addition request, adds VM to NLB, and returns an updated TB NLB object -func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInfo, error) { +func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInfo, error) { fmt.Println("=========================== AddNLBVMs") err := common.CheckString(nsId) @@ -885,6 +935,13 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf return temp, err } + err = common.CheckString(mcisId) + if err != nil { + temp := TbNLBInfo{} + common.CBLog.Error(err) + return temp, err + } + err = validate.Struct(u) if err != nil { if _, ok := err.(*validator.InvalidValidationError); ok { @@ -897,7 +954,7 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf return temp, err } - check, err := CheckNLB(nsId, resourceId) + check, err := CheckNLB(nsId, mcisId, resourceId) if !check { temp := TbNLBInfo{} @@ -925,7 +982,7 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf } */ - nlb, err := GetNLB(nsId, resourceId) + nlb, err := GetNLB(nsId, mcisId, resourceId) if err != nil { temp := TbNLBInfo{} err := fmt.Errorf("Failed to get the nlb object " + resourceId + ".") @@ -936,7 +993,7 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf tempReq.ConnectionName = nlb.ConnectionName for _, v := range u.TargetGroup.VMs { - vm, err := GetVmObject(nsId, u.TargetGroup.MCIS, v) + vm, err := GetVmObject(nsId, mcisId, v) if err != nil { common.CBLog.Error(err) return TbNLBInfo{}, err @@ -1070,7 +1127,7 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf content.TargetGroup.Port = tempSpiderNLBInfo.VMGroup.Port content.TargetGroup.Protocol = tempSpiderNLBInfo.VMGroup.Protocol - content.TargetGroup.MCIS = u.TargetGroup.MCIS // What if oldNlb.TargetGroup.MCIS != newNlb.TargetGroup.MCIS + // content.TargetGroup.MCIS = u.TargetGroup.MCIS // What if oldNlb.TargetGroup.MCIS != newNlb.TargetGroup.MCIS content.TargetGroup.CspID = u.TargetGroup.CspID content.TargetGroup.KeyValueList = u.TargetGroup.KeyValueList @@ -1080,7 +1137,7 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf // cb-store // Key := common.GenResourceKey(nsId, common.StrNLB, content.Id) - Key := GenNLBKey(nsId, content.Id) + Key := GenNLBKey(nsId, mcisId, content.Id) Val, _ := json.Marshal(content) err = common.CBStore.Put(Key, string(Val)) @@ -1109,7 +1166,7 @@ func AddNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInf } // RemoveNLBVMs accepts VM removal request, removes VMs from NLB, and returns an error if occurs. -func RemoveNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) error { +func RemoveNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveVMReq) error { fmt.Println("=========================== RemoveNLBVMs") err := common.CheckString(nsId) @@ -1119,6 +1176,12 @@ func RemoveNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) error return err } + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return err + } + err = validate.Struct(u) if err != nil { if _, ok := err.(*validator.InvalidValidationError); ok { @@ -1131,7 +1194,7 @@ func RemoveNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) error return err } - check, err := CheckNLB(nsId, resourceId) + check, err := CheckNLB(nsId, mcisId, resourceId) if !check { // temp := TbNLBInfo{} @@ -1159,7 +1222,7 @@ func RemoveNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) error } */ - nlb, err := GetNLB(nsId, resourceId) + nlb, err := GetNLB(nsId, mcisId, resourceId) if err != nil { // temp := TbNLBInfo{} err := fmt.Errorf("Failed to get the nlb object " + resourceId + ".") @@ -1172,7 +1235,7 @@ func RemoveNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) error // fmt.Printf("u.TargetGroup.VMs: %s \n", u.TargetGroup.VMs) // for debug for _, v := range u.TargetGroup.VMs { - vm, err := GetVmObject(nsId, u.TargetGroup.MCIS, v) + vm, err := GetVmObject(nsId, mcisId, v) if err != nil { common.CBLog.Error(err) return err @@ -1329,7 +1392,7 @@ func RemoveNLBVMs(nsId string, resourceId string, u *TbNLBAddRemoveVMReq) error // cb-store // Key := common.GenResourceKey(nsId, common.StrNLB, content.Id) - Key := GenNLBKey(nsId, nlb.Id) + Key := GenNLBKey(nsId, mcisId, nlb.Id) Val, _ := json.Marshal(nlb) err = common.CBStore.Put(Key, string(Val)) diff --git a/src/testclient/scripts/10.nlb/addVM.sh b/src/testclient/scripts/10.nlb/(deprecated)-addVM.sh similarity index 100% rename from src/testclient/scripts/10.nlb/addVM.sh rename to src/testclient/scripts/10.nlb/(deprecated)-addVM.sh diff --git a/src/testclient/scripts/10.nlb/removeVM.sh b/src/testclient/scripts/10.nlb/(deprecated)-removeVM.sh similarity index 100% rename from src/testclient/scripts/10.nlb/removeVM.sh rename to src/testclient/scripts/10.nlb/(deprecated)-removeVM.sh diff --git a/src/testclient/scripts/10.nlb/create-NLB.sh b/src/testclient/scripts/10.nlb/create-NLB.sh index cb414cb4..bf265b0c 100755 --- a/src/testclient/scripts/10.nlb/create-NLB.sh +++ b/src/testclient/scripts/10.nlb/create-NLB.sh @@ -4,7 +4,7 @@ function CallTB() { echo "- Create nlb in ${MCIRRegionName}" resp=$( - curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/nlb -H 'Content-Type: application/json' -d @- < Date: Fri, 23 Sep 2022 14:08:41 +0900 Subject: [PATCH 2/4] Enable 'VmGroupId' field for CreateNLB() --- src/api/rest/docs/docs.go | 141 ++++++++++++++++++ src/api/rest/docs/swagger.json | 141 ++++++++++++++++++ src/api/rest/docs/swagger.yaml | 96 ++++++++++++ src/api/rest/server/mcis/nlb.go | 8 +- src/api/rest/server/server.go | 6 +- src/core/mcis/nlb.go | 43 +++--- .../scripts/10.nlb/(deprecated)-addVM.sh | 60 -------- .../scripts/10.nlb/(deprecated)-removeVM.sh | 60 -------- src/testclient/scripts/10.nlb/create-NLB.sh | 103 ++++--------- src/testclient/scripts/10.nlb/id-list-NLB.sh | 16 +- src/testclient/scripts/10.nlb/list-NLB.sh | 16 +- src/testclient/scripts/10.nlb/test-addVM.sh | 21 +++ .../scripts/10.nlb/test-removeVM.sh | 21 +++ 13 files changed, 485 insertions(+), 247 deletions(-) delete mode 100755 src/testclient/scripts/10.nlb/(deprecated)-addVM.sh delete mode 100755 src/testclient/scripts/10.nlb/(deprecated)-removeVM.sh create mode 100755 src/testclient/scripts/10.nlb/test-addVM.sh create mode 100755 src/testclient/scripts/10.nlb/test-removeVM.sh diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index 4bb34f68..5c44d439 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -2207,6 +2207,136 @@ const docTemplate = `{ } } }, + "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm": { + "post": { + "description": "Add VMs to NLB", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] NLB management (for developer)" + ], + "summary": "Add VMs to NLB", + "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 + }, + { + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true + }, + { + "description": "VMs to add to NLB", + "name": "nlbAddRemoveVMReq", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.TbNLBInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + }, + "delete": { + "description": "Delete VMs from NLB", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] NLB management (for developer)" + ], + "summary": "Delete VMs from NLB", + "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 + }, + { + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true + }, + { + "description": "VMs to add to NLB", + "name": "nlbAddRemoveVMReq", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/mcis/{mcisId}/vm": { "post": { "description": "Create VM in specified MCIS", @@ -7831,6 +7961,9 @@ const docTemplate = `{ "type": "string", "example": "TCP" }, + "vmGroupId": { + "type": "string" + }, "vms": { "type": "array", "items": { @@ -7993,6 +8126,14 @@ const docTemplate = `{ } } }, + "mcis.TbNLBAddRemoveVMReq": { + "type": "object", + "properties": { + "targetGroup": { + "$ref": "#/definitions/mcis.TBNLBTargetGroup" + } + } + }, "mcis.TbNLBInfo": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index a862a9ea..9866139f 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -2199,6 +2199,136 @@ } } }, + "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm": { + "post": { + "description": "Add VMs to NLB", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] NLB management (for developer)" + ], + "summary": "Add VMs to NLB", + "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 + }, + { + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true + }, + { + "description": "VMs to add to NLB", + "name": "nlbAddRemoveVMReq", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.TbNLBInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + }, + "delete": { + "description": "Delete VMs from NLB", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] NLB management (for developer)" + ], + "summary": "Delete VMs from NLB", + "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 + }, + { + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true + }, + { + "description": "VMs to add to NLB", + "name": "nlbAddRemoveVMReq", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/mcis.TbNLBAddRemoveVMReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/mcis/{mcisId}/vm": { "post": { "description": "Create VM in specified MCIS", @@ -7823,6 +7953,9 @@ "type": "string", "example": "TCP" }, + "vmGroupId": { + "type": "string" + }, "vms": { "type": "array", "items": { @@ -7985,6 +8118,14 @@ } } }, + "mcis.TbNLBAddRemoveVMReq": { + "type": "object", + "properties": { + "targetGroup": { + "$ref": "#/definitions/mcis.TBNLBTargetGroup" + } + } + }, "mcis.TbNLBInfo": { "type": "object", "properties": { diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 180f7915..3ec90edd 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -1490,6 +1490,8 @@ definitions: description: TCP|HTTP|HTTPS example: TCP type: string + vmGroupId: + type: string vms: items: type: string @@ -1618,6 +1620,11 @@ definitions: - name - vm type: object + mcis.TbNLBAddRemoveVMReq: + properties: + targetGroup: + $ref: '#/definitions/mcis.TBNLBTargetGroup' + type: object mcis.TbNLBInfo: properties: associatedObjectList: @@ -3557,6 +3564,95 @@ paths: summary: Get NLB tags: - '[Infra resource] NLB management' + /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm: + delete: + consumes: + - application/json + description: Delete VMs from NLB + 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 + - description: NLB ID + in: path + name: nlbId + required: true + type: string + - description: VMs to add to NLB + in: body + name: nlbAddRemoveVMReq + required: true + schema: + $ref: '#/definitions/mcis.TbNLBAddRemoveVMReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/common.SimpleMsg' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Delete VMs from NLB + tags: + - '[Infra resource] NLB management (for developer)' + post: + consumes: + - application/json + description: Add VMs to NLB + 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 + - description: NLB ID + in: path + name: nlbId + required: true + type: string + - description: VMs to add to NLB + in: body + name: nlbAddRemoveVMReq + required: true + schema: + $ref: '#/definitions/mcis.TbNLBAddRemoveVMReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mcis.TbNLBInfo' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Add VMs to NLB + tags: + - '[Infra resource] NLB management (for developer)' /ns/{nsId}/mcis/{mcisId}/vm: post: consumes: diff --git a/src/api/rest/server/mcis/nlb.go b/src/api/rest/server/mcis/nlb.go index 2a839008..76eb4eae 100644 --- a/src/api/rest/server/mcis/nlb.go +++ b/src/api/rest/server/mcis/nlb.go @@ -231,11 +231,12 @@ func RestDelAllNLB(c echo.Context) error { return c.JSON(http.StatusOK, output) } -/* REST API Deprecated +// The REST APIs below are for dev/test only + // RestAddNLBVMs godoc // @Summary Add VMs to NLB // @Description Add VMs to NLB -// @Tags [Infra resource] NLB management +// @Tags [Infra resource] NLB management (for developer) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -272,7 +273,7 @@ func RestAddNLBVMs(c echo.Context) error { // RestRemoveNLBVMs godoc // @Summary Delete VMs from NLB // @Description Delete VMs from NLB -// @Tags [Infra resource] NLB management +// @Tags [Infra resource] NLB management (for developer) // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(ns01) @@ -303,4 +304,3 @@ func RestRemoveNLBVMs(c echo.Context) error { mapA := map[string]string{"message": "Removed VMs from the NLB " + resourceId} return c.JSON(http.StatusOK, &mapA) } -*/ diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 7c0acdea..607baa34 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -231,9 +231,9 @@ func RunServer(port string) { g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestDelNLB) g.DELETE("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestDelAllNLB) - // REST API Deprecated - // g.POST("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs) - // g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestRemoveNLBVMs) + // These REST APIs are for dev/test only + g.POST("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs) + g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestRemoveNLBVMs) //MCIR Management g.POST("/:nsId/resources/image", rest_mcir.RestPostImage) diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index 9bafa65c..38065f1b 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -133,9 +133,11 @@ type SpiderHealthInfo struct { } type TBNLBTargetGroup struct { - Protocol string `json:"protocol" example:"TCP"` // TCP|HTTP|HTTPS - Port string `json:"port" example:"22"` // Listener Port or 1-65535 - VMs []string `json:"vms"` + Protocol string `json:"protocol" example:"TCP"` // TCP|HTTP|HTTPS + Port string `json:"port" example:"22"` // Listener Port or 1-65535 + + VmGroupId string `json:"vmGroupId"` + VMs []string `json:"vms"` CspID string // Optional, May be Used by Driver. KeyValueList []common.KeyValue @@ -285,7 +287,13 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf tempReq.ReqInfo.VMGroup.Port = u.TargetGroup.Port tempReq.ReqInfo.VMGroup.Protocol = u.TargetGroup.Protocol - for _, v := range u.TargetGroup.VMs { + vmIDs, err := ListMcisGroupVms(nsId, mcisId, u.TargetGroup.VmGroupId) + if err != nil { + err := fmt.Errorf("Failed to get VMs in the VMGroup " + u.TargetGroup.VmGroupId + ".") + return TbNLBInfo{}, err + } + + for _, v := range vmIDs { vm, err := GetVmObject(nsId, mcisId, v) if err != nil { common.CBLog.Error(err) @@ -300,24 +308,6 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf // fmt.Printf("u.TargetGroup.VMs: %s \n", u.TargetGroup.VMs) // for debug // fmt.Printf("tempReq.ReqInfo.VMGroup.VMs: %s \n", tempReq.ReqInfo.VMGroup.VMs) // for debug - /* - for _, v := range u.VMIDList { - mcisId_vmId := strings.Split(v, "/") - if len(mcisId_vmId) != 2 { - err := fmt.Errorf("Cannot retrieve VM info: " + v) - common.CBLog.Error(err) - return TbNLBInfo{}, err - } - - vm, err := mcis.GetVmObject(nsId, mcisId_vmId[0], mcisId_vmId[1]) - if err != nil { - common.CBLog.Error(err) - return TbNLBInfo{}, err - } - - tempReq.ReqInfo.VMGroup = append(tempReq.ReqInfo.VMGroup, vm.IdByCSP) - } - */ var tempSpiderNLBInfo *SpiderNLBInfo @@ -429,8 +419,8 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf content.TargetGroup.Port = tempSpiderNLBInfo.VMGroup.Port content.TargetGroup.Protocol = tempSpiderNLBInfo.VMGroup.Protocol - // content.TargetGroup.MCIS = u.TargetGroup.MCIS - content.TargetGroup.VMs = u.TargetGroup.VMs + content.TargetGroup.VmGroupId = u.TargetGroup.VmGroupId + content.TargetGroup.VMs = vmIDs content.TargetGroup.CspID = u.TargetGroup.CspID content.TargetGroup.KeyValueList = u.TargetGroup.KeyValueList @@ -614,7 +604,8 @@ func ListNLBId(nsId string, mcisId string) ([]string, error) { } fmt.Println("[ListNLBId] ns: " + nsId) - key := "/ns/" + nsId + "/" + // key := "/ns/" + nsId + "/" + key := fmt.Sprintf("/ns/%s/mcis/%s/", nsId, mcisId) fmt.Println(key) keyValue, err := common.CBStore.GetList(key, true) @@ -661,7 +652,7 @@ func ListNLB(nsId string, mcisId string, filterKey string, filterVal string) (in } fmt.Println("[Get] NLB list") - key := "/ns/" + nsId + "/nlb" + key := fmt.Sprintf("/ns/%s/mcis/%s/nlb", nsId, mcisId) fmt.Println(key) keyValue, err := common.CBStore.GetList(key, true) diff --git a/src/testclient/scripts/10.nlb/(deprecated)-addVM.sh b/src/testclient/scripts/10.nlb/(deprecated)-addVM.sh deleted file mode 100755 index 5abe7bbb..00000000 --- a/src/testclient/scripts/10.nlb/(deprecated)-addVM.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -function CallTB() { - echo "- Add VM to NLB in ${MCIRRegionName}" - - resp=$( - curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/nlb/${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}/vm -H 'Content-Type: application/json' -d @- < Date: Fri, 23 Sep 2022 16:05:24 +0900 Subject: [PATCH 3/4] Add 'Get NLB health' feature --- src/api/rest/docs/docs.go | 60 ++++++ src/api/rest/docs/swagger.json | 60 ++++++ src/api/rest/docs/swagger.yaml | 41 ++++ src/api/rest/server/mcis/nlb.go | 28 +++ src/api/rest/server/server.go | 1 + src/core/mcis/nlb.go | 193 +++++++++++++++++- src/core/mcis/utility.go | 49 +++++ src/testclient/scripts/10.nlb/delete-NLB.sh | 52 +---- .../scripts/10.nlb/delete-all-NLB.sh | 26 +-- src/testclient/scripts/10.nlb/get-NLB.sh | 53 +---- src/testclient/scripts/10.nlb/health-NLB.sh | 13 ++ 11 files changed, 471 insertions(+), 105 deletions(-) create mode 100755 src/testclient/scripts/10.nlb/health-NLB.sh diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index 5c44d439..9ddf6fa5 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -2207,6 +2207,66 @@ const docTemplate = `{ } } }, + "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/healthz": { + "get": { + "description": "Get NLB Health", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] NLB management" + ], + "summary": "Get NLB Health", + "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 + }, + { + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.TbNLBInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm": { "post": { "description": "Add VMs to NLB", diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index 9866139f..ea7d2900 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -2199,6 +2199,66 @@ } } }, + "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/healthz": { + "get": { + "description": "Get NLB Health", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "[Infra resource] NLB management" + ], + "summary": "Get NLB Health", + "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 + }, + { + "type": "string", + "description": "NLB ID", + "name": "nlbId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/mcis.TbNLBInfo" + } + }, + "404": { + "description": "Not Found", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/common.SimpleMsg" + } + } + } + } + }, "/ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm": { "post": { "description": "Add VMs to NLB", diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 3ec90edd..912e16c0 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -3564,6 +3564,47 @@ paths: summary: Get NLB tags: - '[Infra resource] NLB management' + /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/healthz: + get: + consumes: + - application/json + description: Get NLB Health + 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 + - description: NLB ID + in: path + name: nlbId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/mcis.TbNLBInfo' + "404": + description: Not Found + schema: + $ref: '#/definitions/common.SimpleMsg' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/common.SimpleMsg' + summary: Get NLB Health + tags: + - '[Infra resource] NLB management' /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/vm: delete: consumes: diff --git a/src/api/rest/server/mcis/nlb.go b/src/api/rest/server/mcis/nlb.go index 76eb4eae..fb266c79 100644 --- a/src/api/rest/server/mcis/nlb.go +++ b/src/api/rest/server/mcis/nlb.go @@ -231,6 +231,34 @@ func RestDelAllNLB(c echo.Context) error { return c.JSON(http.StatusOK, output) } +// RestGetNLBHealth godoc +// @Summary Get NLB Health +// @Description Get NLB Health +// @Tags [Infra resource] NLB management +// @Accept json +// @Produce json +// @Param nsId path string true "Namespace ID" default(ns01) +// @Param mcisId path string true "MCIS ID" default(mcis01) +// @Param nlbId path string true "NLB ID" +// @Success 200 {object} mcis.TbNLBInfo +// @Failure 404 {object} common.SimpleMsg +// @Failure 500 {object} common.SimpleMsg +// @Router /ns/{nsId}/mcis/{mcisId}/nlb/{nlbId}/healthz [get] +func RestGetNLBHealth(c echo.Context) error { + + nsId := c.Param("nsId") + mcisId := c.Param("mcisId") + resourceId := c.Param("resourceId") + + res, err := mcis.GetNLBHealth(nsId, mcisId, resourceId) + if err != nil { + mapA := map[string]string{"message": "Failed to get the health info of NLB " + resourceId} + return c.JSON(http.StatusNotFound, &mapA) + } else { + return c.JSON(http.StatusOK, &res) + } +} + // The REST APIs below are for dev/test only // RestAddNLBVMs godoc diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 607baa34..ffd8b0a5 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -230,6 +230,7 @@ func RunServer(port string) { // g.PUT("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestPutNLB) g.DELETE("/:nsId/mcis/:mcisId/nlb/:resourceId", rest_mcis.RestDelNLB) g.DELETE("/:nsId/mcis/:mcisId/nlb", rest_mcis.RestDelAllNLB) + g.GET("/:nsId/mcis/:mcisId/nlb/:resourceId/healthz", rest_mcis.RestGetNLBHealth) // These REST APIs are for dev/test only g.POST("/:nsId/mcis/:mcisId/nlb/:resourceId/vm", rest_mcis.RestAddNLBVMs) diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index 38065f1b..ca535ab7 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -126,7 +126,11 @@ type NLBHealthCheckerInfo struct { KeyValueList []common.KeyValue `json:"keyValueList"` } -type SpiderHealthInfo struct { +type SpiderNLBHealthInfoWrapper struct { + Healthinfo SpiderNLBHealthInfo +} + +type SpiderNLBHealthInfo struct { AllVMs *[]common.IID HealthyVMs *[]common.IID UnHealthyVMs *[]common.IID @@ -212,6 +216,12 @@ type TbNLBInfo struct { // Tumblebug //ResourceGroupName string `json:"resourceGroupName"` } +type TbNLBHealthInfo struct { // Tumblebug + AllVMs []string + HealthyVMs []string + UnHealthyVMs []string +} + // TbNLBAddRemoveVMReq is a struct to handle 'Add/Remove VMs to/from NLB' request toward CB-Tumblebug. type TbNLBAddRemoveVMReq struct { // Tumblebug TargetGroup TBNLBTargetGroup `json:"targetGroup"` @@ -915,6 +925,187 @@ func DelAllNLB(nsId string, mcisId string, subString string, forceFlag string) ( return deletedResources, nil } +// GetNLBHealth queries the health status of NLB to CB-Spider, and returns it to user +func GetNLBHealth(nsId string, mcisId string, nlbId string) (TbNLBHealthInfo, error) { + fmt.Println("=========================== GetNLBHealth") + + err := common.CheckString(nsId) + if err != nil { + common.CBLog.Error(err) + return TbNLBHealthInfo{}, err + } + + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return TbNLBHealthInfo{}, err + } + + err = common.CheckString(nlbId) + if err != nil { + common.CBLog.Error(err) + return TbNLBHealthInfo{}, err + } + + check, err := CheckNLB(nsId, mcisId, nlbId) + + if !check { + err := fmt.Errorf("The nlb " + nlbId + " does not exist.") + return TbNLBHealthInfo{}, err + } + + if err != nil { + err := fmt.Errorf("Failed to check the existence of the nlb " + nlbId + ".") + return TbNLBHealthInfo{}, err + } + + nlb, err := GetNLB(nsId, mcisId, nlbId) + if err != nil { + err := fmt.Errorf("Failed to get the NLB " + nlbId + ".") + return TbNLBHealthInfo{}, err + } + + tempReq := common.SpiderConnectionName{} + tempReq.ConnectionName = nlb.ConnectionName + + var tempSpiderNLBHealthInfo *SpiderNLBHealthInfoWrapper + + if os.Getenv("SPIDER_CALL_METHOD") == "REST" { + + client := resty.New().SetCloseConnection(true) + client.SetAllowGetMethodPayload(true) + + // fmt.Println("tempReq:") // for debug + // payload, _ := json.MarshalIndent(tempReq, "", " ") // for debug + // fmt.Print(string(payload)) // for debug + + req := client.R(). + SetHeader("Content-Type", "application/json"). + SetBody(tempReq). + SetResult(&SpiderNLBHealthInfoWrapper{}) // or SetResult(AuthSuccess{}). + //SetError(&AuthError{}). // or SetError(AuthError{}). + + var resp *resty.Response + var err error + + var url string + url = fmt.Sprintf("%s/nlb/%s/health", common.SpiderRestUrl, nlb.CspNLBName) + resp, err = req.Get(url) + + if err != nil { + common.CBLog.Error(err) + err := fmt.Errorf("an error occurred while requesting to CB-Spider") + return TbNLBHealthInfo{}, err + } + + fmt.Println("HTTP Status code: " + strconv.Itoa(resp.StatusCode())) + switch { + case resp.StatusCode() >= 400 || resp.StatusCode() < 200: + err := fmt.Errorf(string(resp.Body())) + common.CBLog.Error(err) + return TbNLBHealthInfo{}, err + } + + tempSpiderNLBHealthInfo = resp.Result().(*SpiderNLBHealthInfoWrapper) + + } + /* + else { + + // Set CCM API + ccm := api.NewCloudResourceHandler() + err := ccm.SetConfigPath(os.Getenv("CBTUMBLEBUG_ROOT") + "/conf/grpc_conf.yaml") + if err != nil { + common.CBLog.Error("ccm failed to set config : ", err) + return TbNLBInfo{}, err + } + err = ccm.Open() + if err != nil { + common.CBLog.Error("ccm api open failed : ", err) + return TbNLBInfo{}, err + } + defer ccm.Close() + + payload, _ := json.MarshalIndent(tempReq, "", " ") + + var result string + + if option == "register" { + result, err = ccm.CreateNLB(string(payload)) + } else { + result, err = ccm.GetNLB(string(payload)) + } + + if err != nil { + common.CBLog.Error(err) + return TbNLBInfo{}, err + } + + tempSpiderNLBInfo = &SpiderNLBInfo{} + err = json.Unmarshal([]byte(result), &tempSpiderNLBInfo) + if err != nil { + common.CBLog.Error(err) + return TbNLBInfo{}, err + } + + } + */ + + result := TbNLBHealthInfo{} + + for _, v := range *tempSpiderNLBHealthInfo.Healthinfo.HealthyVMs { + vm, err := FindTbVmByCspId(nsId, mcisId, v.NameId) + if err != nil { + return TbNLBHealthInfo{}, err + } + + result.HealthyVMs = append(result.HealthyVMs, vm.Id) + } + + for _, v := range *tempSpiderNLBHealthInfo.Healthinfo.UnHealthyVMs { + vm, err := FindTbVmByCspId(nsId, mcisId, v.NameId) + if err != nil { + return TbNLBHealthInfo{}, err + } + + result.UnHealthyVMs = append(result.UnHealthyVMs, vm.Id) + } + + result.AllVMs = append(result.AllVMs, result.HealthyVMs...) + result.AllVMs = append(result.AllVMs, result.UnHealthyVMs...) + /* + // cb-store + // Key := common.GenResourceKey(nsId, common.StrNLB, content.Id) + Key := GenNLBKey(nsId, mcisId, content.Id) + Val, _ := json.Marshal(content) + + err = common.CBStore.Put(Key, string(Val)) + if err != nil { + common.CBLog.Error(err) + return content, err + } + + keyValue, err := common.CBStore.Get(Key) + if err != nil { + common.CBLog.Error(err) + err = fmt.Errorf("In CreateNLB(); CBStore.Get() returned an error.") + common.CBLog.Error(err) + // return nil, err + } + + fmt.Println("<" + keyValue.Key + "> \n" + keyValue.Value) + fmt.Println("===========================") + + result := TbNLBInfo{} + err = json.Unmarshal([]byte(keyValue.Value), &result) + if err != nil { + common.CBLog.Error(err) + } + */ + + return result, nil +} + // AddNLBVMs accepts VM addition request, adds VM to NLB, and returns an updated TB NLB object func AddNLBVMs(nsId string, mcisId string, resourceId string, u *TbNLBAddRemoveVMReq) (TbNLBInfo, error) { fmt.Println("=========================== AddNLBVMs") diff --git a/src/core/mcis/utility.go b/src/core/mcis/utility.go index 837c60c5..b63367cd 100644 --- a/src/core/mcis/utility.go +++ b/src/core/mcis/utility.go @@ -957,3 +957,52 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o return result, err } + +func FindTbVmByCspId(nsId string, mcisId string, vmIdByCsp string) (TbVmInfo, error) { + + err := common.CheckString(nsId) + if err != nil { + common.CBLog.Error(err) + return TbVmInfo{}, err + } + + err = common.CheckString(mcisId) + if err != nil { + common.CBLog.Error(err) + return TbVmInfo{}, err + } + + err = common.CheckString(vmIdByCsp) + if err != nil { + common.CBLog.Error(err) + return TbVmInfo{}, err + } + + check, err := CheckMcis(nsId, mcisId) + + if !check { + err := fmt.Errorf("The MCIS " + mcisId + " does not exist.") + return TbVmInfo{}, err + } + + if err != nil { + err := fmt.Errorf("Failed to check the existence of the MCIS " + mcisId + ".") + return TbVmInfo{}, err + } + + mcis, err := GetMcisObject(nsId, mcisId) + if err != nil { + err := fmt.Errorf("Failed to get the MCIS " + mcisId + ".") + return TbVmInfo{}, err + } + + vms := mcis.Vm + for _, v := range vms { + if v.IdByCSP == vmIdByCsp || v.CspViewVmDetail.IId.NameId == vmIdByCsp { + return v, nil + } + } + + err = fmt.Errorf("Cannot find the VM %s in %s/%s", vmIdByCsp, nsId, mcisId) + return TbVmInfo{}, err +} diff --git a/src/testclient/scripts/10.nlb/delete-NLB.sh b/src/testclient/scripts/10.nlb/delete-NLB.sh index c2eb33bb..5905884d 100755 --- a/src/testclient/scripts/10.nlb/delete-NLB.sh +++ b/src/testclient/scripts/10.nlb/delete-NLB.sh @@ -1,47 +1,13 @@ #!/bin/bash -function CallTB() { - echo "- Delete NLB in ${MCIRRegionName}" +echo "####################################################################" +echo "## 10. NLB: Delete" +echo "####################################################################" - curl -H "${AUTH}" -sX DELETE http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb/${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX} | jq '' -} +source ../init.sh -#function delete_NLB() { - - echo "####################################################################" - echo "## 10. NLB: Delete" - echo "####################################################################" - - source ../init.sh - - if [ "${INDEX}" == "0" ]; then - echo "[Parallel execution for all CSP regions]" - INDEXX=${NumCSP} - for ((cspi = 1; cspi <= INDEXX; cspi++)); do - INDEXY=${NumRegion[$cspi]} - CSP=${CSPType[$cspi]} - echo "[$cspi] $CSP details" - for ((cspj = 1; cspj <= INDEXY; cspj++)); do - echo "[$cspi,$cspj] ${RegionName[$cspi,$cspj]}" - - MCIRRegionName=${RegionName[$cspi,$cspj]} - - CallTB - - done - - done - wait - - else - echo "" - - MCIRRegionName=${CONN_CONFIG[$INDEX,$REGION]} - - CallTB - - fi - -#} - -#delete_NLB +resp=$( + curl -H "${AUTH}" -sX DELETE http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb/${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX} + ); echo ${resp} | jq '' + echo "" + # echo ["${CONN_CONFIG[$INDEX,$REGION]}-0"] # for debug diff --git a/src/testclient/scripts/10.nlb/delete-all-NLB.sh b/src/testclient/scripts/10.nlb/delete-all-NLB.sh index b8c74a56..d4497d5e 100755 --- a/src/testclient/scripts/10.nlb/delete-all-NLB.sh +++ b/src/testclient/scripts/10.nlb/delete-all-NLB.sh @@ -1,21 +1,13 @@ #!/bin/bash -function CallTB() { - echo "- Delete all NLBs" +echo "####################################################################" +echo "## 10. NLB: Delete" +echo "####################################################################" - curl -H "${AUTH}" -sX DELETE http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb | jq '' -} +source ../init.sh -#function delete_NLB() { - - echo "####################################################################" - echo "## 10. NLB: Delete" - echo "####################################################################" - - source ../init.sh - - CallTB - -#} - -#delete_NLB +resp=$( + curl -H "${AUTH}" -sX DELETE http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb + ); echo ${resp} | jq '' + echo "" + # echo ["${CONN_CONFIG[$INDEX,$REGION]}-0"] # for debug diff --git a/src/testclient/scripts/10.nlb/get-NLB.sh b/src/testclient/scripts/10.nlb/get-NLB.sh index 2d39147b..3b78529f 100755 --- a/src/testclient/scripts/10.nlb/get-NLB.sh +++ b/src/testclient/scripts/10.nlb/get-NLB.sh @@ -1,48 +1,13 @@ #!/bin/bash -function CallTB() { - echo "- Get NLB in ${MCIRRegionName}" +echo "####################################################################" +echo "## 10. NLB: Get" +echo "####################################################################" - curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb/${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX} | jq '' - echo "" -} - -#function get_NLB() { - - echo "####################################################################" - echo "## 10. NLB: Get" - echo "####################################################################" - - source ../init.sh - - if [ "${INDEX}" == "0" ]; then - echo "[Parallel execution for all CSP regions]" - INDEXX=${NumCSP} - for ((cspi = 1; cspi <= INDEXX; cspi++)); do - INDEXY=${NumRegion[$cspi]} - CSP=${CSPType[$cspi]} - echo "[$cspi] $CSP details" - for ((cspj = 1; cspj <= INDEXY; cspj++)); do - echo "[$cspi,$cspj] ${RegionName[$cspi,$cspj]}" - - MCIRRegionName=${RegionName[$cspi,$cspj]} - - CallTB +source ../init.sh - done - - done - wait - - else - echo "" - - MCIRRegionName=${CONN_CONFIG[$INDEX,$REGION]} - - CallTB - - fi - -#} - -#get_NLB +resp=$( + curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb/${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX} + ); echo ${resp} | jq '' + echo "" + # echo ["${CONN_CONFIG[$INDEX,$REGION]}-0"] # for debug diff --git a/src/testclient/scripts/10.nlb/health-NLB.sh b/src/testclient/scripts/10.nlb/health-NLB.sh new file mode 100755 index 00000000..dbad72ac --- /dev/null +++ b/src/testclient/scripts/10.nlb/health-NLB.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +echo "####################################################################" +echo "## 10. NLB: Get Health" +echo "####################################################################" + +source ../init.sh + +resp=$( + curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID}/nlb/${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}/healthz + ); echo ${resp} | jq '' + echo "" + # echo ["${CONN_CONFIG[$INDEX,$REGION]}-0"] # for debug From f82dcd46e751b29585ab8591fa04e17daefd4b17 Mon Sep 17 00:00:00 2001 From: Seokho Son Date: Sat, 24 Sep 2022 01:15:13 +0900 Subject: [PATCH 4/4] Update src/core/mcis/nlb.go --- src/core/mcis/nlb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index ca535ab7..03ee03b4 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -140,7 +140,7 @@ type TBNLBTargetGroup struct { Protocol string `json:"protocol" example:"TCP"` // TCP|HTTP|HTTPS Port string `json:"port" example:"22"` // Listener Port or 1-65535 - VmGroupId string `json:"vmGroupId"` + VmGroupId string `json:"vmGroupId" example:"group"` VMs []string `json:"vms"` CspID string // Optional, May be Used by Driver.