Skip to content

Commit

Permalink
Add GetCSPResourceName for Ladybug's CMKS
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Aug 17, 2022
1 parent 4aa6215 commit ba0dfb5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api-runtime/common-runtime/CCMCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5765,3 +5765,32 @@ func setVMUserIIDwithSystemId(connectionName string, nlbName string, healthInfo
return nil
}

func GetCSPResourceName(connectionName string, rsType string, nameID string) (string, error) {
cblog.Info("call GetCSPResourceName()")

// check empty and trim user inputs
connectionName, err := EmptyCheckAndTrim("connectionName", connectionName)
if err != nil {
cblog.Error(err)
return "", err
}

nameID, err = EmptyCheckAndTrim("nameID", nameID)
if err != nil {
cblog.Error(err)
return "", err
}

keySPLock.RLock(connectionName, nameID)
defer keySPLock.RUnlock(connectionName, nameID)

// (1) get IID(NameId)
iidInfo, err := iidRWLock.GetIID(iidm.IIDSGROUP, connectionName, rsType, cres.IID{nameID, ""})
if err != nil {
cblog.Error(err)
return "", err
}

// (2) get DriverNameId and return it
return getDriverIID(iidInfo.IId).NameId, nil
}
5 changes: 5 additions & 0 deletions api-runtime/rest-runtime/CBSpiderRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ func RunServer() {
{"GET", "/allnlb", ListAllNLB},
{"DELETE", "/cspnlb/:Id", DeleteCSPNLB},


//-------------------------------------------------------------------//
//----------Additional Info
{"GET", "/cspresourcename/:Name", GetCSPResourceName},

//-------------------------------------------------------------------//
//----------SPLock Info
{"GET", "/splockinfo", GetAllSPLockInfo},
Expand Down
34 changes: 34 additions & 0 deletions api-runtime/rest-runtime/CCMRest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2302,3 +2302,37 @@ func GetAllSPLockInfo(c echo.Context) error {
return c.JSON(http.StatusOK, &jsonResult)
}


func GetCSPResourceName(c echo.Context) error {
cblog.Info("call GetCSPResourceName()")

var req struct {
ConnectionName string
ResourceType string
}

if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}

// To support for Get-Query Param Type API
if req.ConnectionName == "" {
req.ConnectionName = c.QueryParam("ConnectionName")
}
if req.ResourceType == "" {
req.ResourceType = c.QueryParam("ResourceType")
}

// Call common-runtime API
result, err := cmrt.GetCSPResourceName(req.ConnectionName, req.ResourceType, c.Param("Name"))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}

var resultInfo struct {
Name string
}
resultInfo.Name = string(result)

return c.JSON(http.StatusOK, &resultInfo)
}

0 comments on commit ba0dfb5

Please sign in to comment.