Skip to content

Commit

Permalink
Merge pull request #1292 from seokho-son/main
Browse files Browse the repository at this point in the history
Add mcisFlag for register existing VMs
  • Loading branch information
seokho-son authored Feb 13, 2023
2 parents 2f69706 + 43c8a2e commit 161f3e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/api/rest/server/common/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ type RestRegisterCspNativeResourcesRequest struct {
// @Produce json
// @Param Request body RestRegisterCspNativeResourcesRequest true "Specify connectionName, NS Id, and MCIS Name""
// @Param option query string false "Option to specify resourceType" Enums(onlyVm, exceptVm)
// @Param mcisFlag query string false "Flag to show VMs in a collective MCIS form (y,n)" Enums(y, n) default(y)
// @Success 200 {object} mcis.RegisterResourceResult
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
Expand All @@ -418,8 +419,9 @@ func RestRegisterCspNativeResources(c echo.Context) error {
return err
}
option := c.QueryParam("option")
mcisFlag := c.QueryParam("mcisFlag")

content, err := mcis.RegisterCspNativeResources(u.NsId, u.ConnectionName, u.McisName, option)
content, err := mcis.RegisterCspNativeResources(u.NsId, u.ConnectionName, u.McisName, option, mcisFlag)

if err != nil {
common.CBLog.Error(err)
Expand All @@ -445,6 +447,7 @@ type RestRegisterCspNativeResourcesRequestAll struct {
// @Produce json
// @Param Request body RestRegisterCspNativeResourcesRequestAll true "Specify NS Id and MCIS Name"
// @Param option query string false "Option to specify resourceType" Enums(onlyVm, exceptVm)
// @Param mcisFlag query string false "Flag to show VMs in a collective MCIS form (y,n)" Enums(y, n) default(y)
// @Success 200 {object} mcis.RegisterResourceAllResult
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
Expand All @@ -456,8 +459,9 @@ func RestRegisterCspNativeResourcesAll(c echo.Context) error {
return err
}
option := c.QueryParam("option")
mcisFlag := c.QueryParam("mcisFlag")

content, err := mcis.RegisterCspNativeResourcesAll(u.NsId, u.McisName, option)
content, err := mcis.RegisterCspNativeResourcesAll(u.NsId, u.McisName, option, mcisFlag)

if err != nil {
common.CBLog.Error(err)
Expand Down
12 changes: 8 additions & 4 deletions src/core/mcis/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ type registerationOverview struct {
}

// RegisterCspNativeResourcesAll func registers all CSP-native resources into CB-TB
func RegisterCspNativeResourcesAll(nsId string, mcisId string, option string) (RegisterResourceAllResult, error) {
func RegisterCspNativeResourcesAll(nsId string, mcisId string, option string, mcisFlag string) (RegisterResourceAllResult, error) {
startTime := time.Now()

connectionConfigList, err := common.GetConnConfigList()
Expand Down Expand Up @@ -913,7 +913,7 @@ func RegisterCspNativeResourcesAll(nsId string, mcisId string, option string) (R

common.RandomSleep(0, 50)

registerResult, err := RegisterCspNativeResources(nsId, k.ConfigName, mcisNameForRegister, option)
registerResult, err := RegisterCspNativeResources(nsId, k.ConfigName, mcisNameForRegister, option, mcisFlag)
if err != nil {
common.CBLog.Error(err)
}
Expand Down Expand Up @@ -952,7 +952,7 @@ func RegisterCspNativeResourcesAll(nsId string, mcisId string, option string) (R
}

// RegisterCspNativeResources func registers all CSP-native resources into CB-TB
func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, option string) (RegisterResourceResult, error) {
func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, option string, mcisFlag string) (RegisterResourceResult, error) {
startTime := time.Now()

optionFlag := "register"
Expand Down Expand Up @@ -1142,8 +1142,12 @@ func RegisterCspNativeResources(nsId string, connConfig string, mcisId string, o
vm.ConnectionName = connConfig
vm.IdByCSP = r.IdByCsp
vm.Description = "Ref name: " + r.RefNameOrId + ". CSP managed VM (registered to CB-TB)"
vm.Name = vm.ConnectionName + "-" + vm.IdByCSP
vm.Name = vm.ConnectionName + "-" + r.RefNameOrId + "-" + vm.IdByCSP
vm.Name = common.ChangeIdString(vm.Name)
if mcisFlag == "n" {
// (if mcisFlag == "n") create a mcis for each vm
req.Name = vm.Name
}
vm.Label = "not defined"

vm.ImageId = "cannot retrieve"
Expand Down

0 comments on commit 161f3e8

Please sign in to comment.