-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Region/Zone server module and REST API to CB-Spider Server
- Loading branch information
1 parent
0cc452f
commit f6541dd
Showing
3 changed files
with
285 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Cloud Control Manager's Rest Runtime of CB-Spider. | ||
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project. | ||
// The CB-Spider Mission is to connect all the clouds with a single interface. | ||
// | ||
// * Cloud-Barista: https://github.com/cloud-barista | ||
// | ||
// by CB-Spider Team, 2023.09. | ||
|
||
package commonruntime | ||
|
||
import ( | ||
ccm "github.com/cloud-barista/cb-spider/cloud-control-manager" | ||
cres "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources" | ||
) | ||
|
||
// ================ RegionZone Handler | ||
func ListRegionZone(connectionName string) ([]*cres.RegionZoneInfo, error) { | ||
cblog.Info("call ListRegionZone()") | ||
|
||
// check empty and trim user inputs | ||
connectionName, err := EmptyCheckAndTrim("connectionName", connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
cldConn, err := ccm.GetCloudConnection(connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
handler, err := cldConn.CreateRegionZoneHandler() | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
infoList, err := handler.ListRegionZone() | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
if infoList == nil || len(infoList) <= 0 { | ||
infoList = []*cres.RegionZoneInfo{} | ||
} | ||
|
||
return infoList, nil | ||
} | ||
|
||
func GetRegionZone(connectionName string, nameID string) (*cres.RegionZoneInfo, error) { | ||
cblog.Info("call GetRegionZone()") | ||
|
||
// check empty and trim user inputs | ||
connectionName, err := EmptyCheckAndTrim("connectionName", connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
nameID, err = EmptyCheckAndTrim("nameID", nameID) | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
cldConn, err := ccm.GetCloudConnection(connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
handler, err := cldConn.CreateRegionZoneHandler() | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
info, err := handler.GetRegionZone(nameID) | ||
if err != nil { | ||
cblog.Error(err) | ||
return nil, err | ||
} | ||
|
||
return &info, nil | ||
} | ||
|
||
func ListOrgRegion(connectionName string) (string, error) { | ||
cblog.Info("call ListOrgRegion()") | ||
|
||
// check empty and trim user inputs | ||
connectionName, err := EmptyCheckAndTrim("connectionName", connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
cldConn, err := ccm.GetCloudConnection(connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
handler, err := cldConn.CreateRegionZoneHandler() | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
infoList, err := handler.ListOrgRegion() | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
return infoList, nil | ||
} | ||
|
||
func ListOrgZone(connectionName string) (string, error) { | ||
cblog.Info("call GetOrgRegionZone()") | ||
|
||
// check empty and trim user inputs | ||
connectionName, err := EmptyCheckAndTrim("connectionName", connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
cldConn, err := ccm.GetCloudConnection(connectionName) | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
handler, err := cldConn.CreateRegionZoneHandler() | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
info, err := handler.ListOrgZone() | ||
if err != nil { | ||
cblog.Error(err) | ||
return "", err | ||
} | ||
|
||
return info, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Cloud Control Manager's Rest Runtime of CB-Spider. | ||
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project. | ||
// The CB-Spider Mission is to connect all the clouds with a single interface. | ||
// | ||
// * Cloud-Barista: https://github.com/cloud-barista | ||
// | ||
// by CB-Spider Team, 2023.09. | ||
|
||
package restruntime | ||
|
||
import ( | ||
"net/http" | ||
|
||
cmrt "github.com/cloud-barista/cb-spider/api-runtime/common-runtime" | ||
cres "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// ================ RegionZone Handler | ||
func ListRegionZone(c echo.Context) error { | ||
cblog.Info("call ListRegionZone()") | ||
|
||
var req struct { | ||
ConnectionName 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") | ||
} | ||
|
||
// Call common-runtime API | ||
result, err := cmrt.ListRegionZone(req.ConnectionName) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
var jsonResult struct { | ||
Result []*cres.RegionZoneInfo `json:"regionzone"` | ||
} | ||
jsonResult.Result = result | ||
return c.JSON(http.StatusOK, &jsonResult) | ||
} | ||
|
||
func GetRegionZone(c echo.Context) error { | ||
cblog.Info("call GetRegionZone()") | ||
|
||
var req struct { | ||
ConnectionName 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") | ||
} | ||
|
||
// Call common-runtime API | ||
result, err := cmrt.GetRegionZone(req.ConnectionName, c.Param("Name")) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.JSON(http.StatusOK, result) | ||
} | ||
|
||
func ListOrgRegion(c echo.Context) error { | ||
cblog.Info("call ListOrgRegion()") | ||
|
||
var req struct { | ||
ConnectionName 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") | ||
} | ||
|
||
// Call common-runtime API | ||
result, err := cmrt.ListOrgRegion(req.ConnectionName) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.String(http.StatusOK, result) | ||
} | ||
|
||
func ListOrgZone(c echo.Context) error { | ||
cblog.Info("call ListOrgZone()") | ||
|
||
var req struct { | ||
ConnectionName 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") | ||
} | ||
|
||
// Call common-runtime API | ||
result, err := cmrt.ListOrgZone(req.ConnectionName) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, err.Error()) | ||
} | ||
|
||
return c.String(http.StatusOK, result) | ||
} |