Skip to content

Commit

Permalink
Merge branch 'master' of github.com:yby654/cb-spider
Browse files Browse the repository at this point in the history
  • Loading branch information
yby654 committed Jul 29, 2024
2 parents 9342c5e + fd37bfc commit fc5a5d3
Show file tree
Hide file tree
Showing 157 changed files with 13,447 additions and 2,613 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/conf/ /root/go/sr

COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/cb-spider /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/

COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/images/cb-spider-circle-logo.png /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/images/
COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/images/ /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/images/

COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/html/ /root/go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-runtime/admin-web/html/

Expand All @@ -52,10 +52,8 @@ COPY --from=builder /go/src/github.com/cloud-barista/cb-spider/api-runtime/rest-
ENV CBSPIDER_ROOT /root/go/src/github.com/cloud-barista/cb-spider
ENV CBLOG_ROOT /root/go/src/github.com/cloud-barista/cb-spider
ENV PLUGIN_SW OFF
ENV MEERKAT OFF

ENTRYPOINT [ "/root/go/src/github.com/cloud-barista/cb-spider/api-runtime/cb-spider" ]

EXPOSE 1024
EXPOSE 2048
EXPOSE 4096
146 changes: 146 additions & 0 deletions api-runtime/common-runtime/TagManager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// 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, 2024.07.

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"
)

//================ Tag Handler

// AddTag adds a tag to a resource.
func AddTag(connectionName string, resType cres.RSType, resIID cres.IID, tag cres.KeyValue) (cres.KeyValue, error) {
cblog.Info("call AddTag()")

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

cldConn, err := ccm.GetCloudConnection(connectionName)
if err != nil {
cblog.Error(err)
return cres.KeyValue{}, err
}

handler, err := cldConn.CreateTagHandler()
if err != nil {
cblog.Error(err)
return cres.KeyValue{}, err
}

return handler.AddTag(resType, resIID, tag)
}

// ListTag lists all tags of a resource.
func ListTag(connectionName string, resType cres.RSType, resIID cres.IID) ([]cres.KeyValue, error) {
cblog.Info("call ListTag()")

// 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.CreateTagHandler()
if err != nil {
cblog.Error(err)
return nil, err
}

return handler.ListTag(resType, resIID)
}

// GetTag gets a specific tag of a resource.
func GetTag(connectionName string, resType cres.RSType, resIID cres.IID, key string) (cres.KeyValue, error) {
cblog.Info("call GetTag()")

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

cldConn, err := ccm.GetCloudConnection(connectionName)
if err != nil {
cblog.Error(err)
return cres.KeyValue{}, err
}

handler, err := cldConn.CreateTagHandler()
if err != nil {
cblog.Error(err)
return cres.KeyValue{}, err
}

return handler.GetTag(resType, resIID, key)
}

// RemoveTag removes a specific tag from a resource.
func RemoveTag(connectionName string, resType cres.RSType, resIID cres.IID, key string) (bool, error) {
cblog.Info("call RemoveTag()")

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

cldConn, err := ccm.GetCloudConnection(connectionName)
if err != nil {
cblog.Error(err)
return false, err
}

handler, err := cldConn.CreateTagHandler()
if err != nil {
cblog.Error(err)
return false, err
}

return handler.RemoveTag(resType, resIID, key)
}

// FindTag finds tags by key or value.
func FindTag(connectionName string, resType cres.RSType, keyword string) ([]*cres.TagInfo, error) {
cblog.Info("call FindTag()")

// 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.CreateTagHandler()
if err != nil {
cblog.Error(err)
return nil, err
}

return handler.FindTag(resType, keyword)
}
73 changes: 56 additions & 17 deletions api-runtime/common-runtime/VMManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ func ListVMStatus(connectionName string, rsType string) ([]*cres.VMStatusInfo, e
return infoList, nil
}

// (2) get VMStatusInfo List with iidInoList
// (2) get VMStatusInfo List with iidInfoList
infoList2 := []*cres.VMStatusInfo{}
for _, iidInfo := range iidInfoList {

Expand All @@ -1373,17 +1373,36 @@ func ListVMStatus(connectionName string, rsType string) ([]*cres.VMStatusInfo, e
*/

// 2. get CSP:VMStatus(SystemId)
statusInfo, err := handler.GetVMStatus(getDriverIID(cres.IID{NameId: iidInfo.NameId, SystemId: iidInfo.SystemId}))
if err != nil {
//vmSPLock.RUnlock(connectionName, iidInfo.IId.NameId)
if checkNotFoundError(err) {
cblog.Info(err)
continue
var statusInfo cres.VMStatus
driverIID := getDriverIID(cres.IID{NameId: iidInfo.NameId, SystemId: iidInfo.SystemId})

// need to wait for https://github.com/cloud-barista/cb-spider/pull/1244#issuecomment-2253741979
waiter := NewWaiter(3, 60) // 3 seconds sleep, 60 seconds timeout

for {
statusInfo, err = handler.GetVMStatus(driverIID)
if statusInfo == cres.NotExist {
err = fmt.Errorf("Not Found %s", driverIID.SystemId)
}
if err != nil {
if checkNotFoundError(err) {
statusInfo = cres.NotExist
break
}
cblog.Error(err)
return nil, err
}

if statusInfo == cres.Creating || statusInfo == cres.Running || statusInfo == cres.Suspending || statusInfo == cres.Suspended ||
statusInfo == cres.Resuming || statusInfo == cres.Rebooting || statusInfo == cres.Terminating || statusInfo == cres.Terminated ||
statusInfo == cres.NotExist || statusInfo == cres.Failed {
break
}

if !waiter.Wait() {
return nil, fmt.Errorf("Unable to provide current VM status for VM '%s'. Timeout after %v seconds", iidInfo.NameId, waiter.Timeout)
}
cblog.Error(err)
return nil, err
}
//vmSPLock.RUnlock(connectionName, iidInfo.IId.NameId)

infoList2 = append(infoList2, &cres.VMStatusInfo{IId: getUserIID(cres.IID{NameId: iidInfo.NameId, SystemId: iidInfo.SystemId}), VmStatus: statusInfo})
}
Expand Down Expand Up @@ -1433,14 +1452,34 @@ func GetVMStatus(connectionName string, rsType string, nameID string) (cres.VMSt
return "", err
}

// (2) get CSP:VMStatus(SystemId)
info, err := handler.GetVMStatus(getDriverIID(cres.IID{NameId: iidInfo.NameId, SystemId: iidInfo.SystemId}))
if err != nil {
cblog.Error(err)
return "", err
}
driverIID := getDriverIID(cres.IID{NameId: iidInfo.NameId, SystemId: iidInfo.SystemId})

return info, nil
// need to wait for https://github.com/cloud-barista/cb-spider/pull/1244#issuecomment-2253741979
waiter := NewWaiter(3, 60) // 3 seconds sleep, 60 seconds timeout

for {
info, err := handler.GetVMStatus(driverIID)
if info == cres.NotExist {
err = fmt.Errorf("Not Found %s", driverIID.SystemId)
}
if err != nil {
if checkNotFoundError(err) {
return "", err
}
cblog.Error(err)
return "", err
}

if info == cres.Creating || info == cres.Running || info == cres.Suspending || info == cres.Suspended ||
info == cres.Resuming || info == cres.Rebooting || info == cres.Terminating || info == cres.Terminated ||
info == cres.NotExist || info == cres.Failed {
return info, nil
}

if !waiter.Wait() {
return "", fmt.Errorf("Unable to provide current VM status for VM '%s'. Timeout after %v seconds", nameID, waiter.Timeout)
}
}
}

// (1) get IID(NameId)
Expand Down
21 changes: 20 additions & 1 deletion api-runtime/rest-runtime/CBSpiderRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package restruntime
import (
"crypto/subtle"
"fmt"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -434,6 +435,12 @@ func RunServer() {
{"GET", "/countcluster", CountAllClusters},
{"GET", "/countcluster/:ConnectionName", CountClustersByConnection},

//----------Tag Handler
{"POST", "/tag", AddTag},
{"GET", "/tag", ListTag},
{"GET", "/tag/:Name", GetTag},
{"DELETE", "/tag/:Name", RemoveTag},

//----------Destory All Resources in a Connection
{"DELETE", "/destroy", Destroy},

Expand All @@ -459,12 +466,24 @@ func RunServer() {
{"GET", "/adminweb/top", aw.Top},
{"GET", "/adminweb/log", aw.Log},

{"GET", "/adminweb2", aw.MainPage},
{"GET", "/adminweb2/", aw.MainPage},
{"GET", "/adminweb/left_menu", aw.LeftMenu},
{"GET", "/adminweb/body_frame", aw.BodyFrame},

{"GET", "/adminweb/dashboard", aw.Dashboard},

{"GET", "/adminweb/driver", aw.Driver},
{"GET", "/adminweb2/driver", aw.DriverManagement},

{"GET", "/adminweb/credential", aw.Credential},
{"GET", "/adminweb2/credential", aw.CredentialManagement},

{"GET", "/adminweb/region", aw.Region},
{"GET", "/adminweb2/region", aw.RegionManagement},

{"GET", "/adminweb/connectionconfig", aw.Connectionconfig},
{"GET", "/adminweb2/connectionconfig", aw.ConnectionManagement},

{"GET", "/adminweb/dashboard", aw.Dashboard},

Expand Down Expand Up @@ -568,7 +587,7 @@ func ApiServer(routes []route) {
}

// for spider logo
e.File("/spider/adminweb/images/logo.png", cbspiderRoot+"/api-runtime/rest-runtime/admin-web/images/cb-spider-circle-logo.png")
e.Static("/spider/adminweb/images", filepath.Join(cbspiderRoot, "api-runtime/rest-runtime/admin-web/images"))

// for admin-web
e.File("/spider/adminweb/html/priceinfo-filter-gen.html", cbspiderRoot+"/api-runtime/rest-runtime/admin-web/html/priceinfo-filter-gen.html")
Expand Down
Loading

0 comments on commit fc5a5d3

Please sign in to comment.