Skip to content

Commit

Permalink
Merge pull request #1188 from seokho-son/main
Browse files Browse the repository at this point in the history
Add yaml config feature to handle different available values for each cloud
  • Loading branch information
jihoon-seo authored Oct 4, 2022
2 parents 3b82ca8 + 886f616 commit c4512b9
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
66 changes: 66 additions & 0 deletions conf/cloud_conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cloud:
common:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "9"
threshold: "3"
aws:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "-1"
threshold: "3"
azure:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "9"
threshold: "3"
gcp:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "9"
threshold: "3"
alibaba:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "9"
threshold: "3"
tencent:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "9"
threshold: "3"
ibm:
enable: "y"
nlb:
enable: "y"
interval: "10"
timeout: "9"
threshold: "3"
openstack:
enable: "y"
nlb:
enable: "n"
interval: "10"
timeout: "9"
threshold: "3"
cloudit :
enable: "y"
nlb:
enable: "n"
interval: "10"
timeout: "9"
threshold: "3"
global:
port: 8080
34 changes: 34 additions & 0 deletions src/core/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,40 @@ import (
cbstore_utils "github.com/cloud-barista/cb-store/utils"
)

// RuntimeConf is global variable for cloud config
var RuntimeConf = RuntimeConfig{}

// RuntimeConfig is structure for global variable for cloud config
type RuntimeConfig struct {
Cloud Cloud `yaml:"cloud"`
}

// Cloud is structure for cloud settings per CSP
type Cloud struct {
Common CloudSetting `yaml:"common"`
Aws CloudSetting `yaml:"aws"`
Azure CloudSetting `yaml:"azure"`
Gcp CloudSetting `yaml:"gcp"`
Alibaba CloudSetting `yaml:"alibaba"`
Tencent CloudSetting `yaml:"tencent"`
Ibm CloudSetting `yaml:"ibm"`
Openstack CloudSetting `yaml:"openstack"`
}

// CloudSetting is structure for cloud settings per CSP in details
type CloudSetting struct {
Enable string `yaml:"enable"`
Nlb NlbSetting `yaml:"nlb"`
}

// NlbSetting is structure for NLB setting
type NlbSetting struct {
Enable string `yaml:"enable"`
Interval string `yaml:"interval"`
Timeout string `yaml:"timeout"`
Threshold string `yaml:"threshold"`
}

// swagger:request ConfigReq
type ConfigReq struct {
Name string `json:"name" example:"SPIDER_REST_URL"`
Expand Down
19 changes: 18 additions & 1 deletion src/core/mcis/nlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" example:"group"`
VmGroupId string `json:"vmGroupId" example:"group"`
VMs []string `json:"vms"`

CspID string // Optional, May be Used by Driver.
Expand Down Expand Up @@ -297,6 +297,23 @@ 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

// // TODO: update this part to assign availble values for each CSP (current code does not work)
fmt.Println("NLB available values (AWS): ", common.RuntimeConf.Cloud.Aws)
fmt.Println("NLB available values (Azure): ", common.RuntimeConf.Cloud.Azure)
// if cloud-type == aws {
// tempReq.ReqInfo.HealthChecker.Interval = common.RuntimeConf.Cloud.Aws.Nlb.Interval
// tempReq.ReqInfo.HealthChecker.Timeout = common.RuntimeConf.Cloud.Aws.Nlb.Timeout
// tempReq.ReqInfo.HealthChecker.Threshold = common.RuntimeConf.Cloud.Aws.Nlb.Threshold
// } else if cloud-type == azure {
// tempReq.ReqInfo.HealthChecker.Interval = common.RuntimeConf.Cloud.Azure.Nlb.Interval
// tempReq.ReqInfo.HealthChecker.Timeout = common.RuntimeConf.Cloud.Azure.Nlb.Timeout
// tempReq.ReqInfo.HealthChecker.Threshold = common.RuntimeConf.Cloud.Azure.Nlb.Threshold
// } else {
// tempReq.ReqInfo.HealthChecker.Interval = common.RuntimeConf.Cloud.Common.Nlb.Interval
// tempReq.ReqInfo.HealthChecker.Timeout = common.RuntimeConf.Cloud.Common.Nlb.Timeout
// tempReq.ReqInfo.HealthChecker.Threshold = common.RuntimeConf.Cloud.Common.Nlb.Threshold
// }

vmIDs, err := ListMcisGroupVms(nsId, mcisId, u.TargetGroup.VmGroupId)
if err != nil {
err := fmt.Errorf("Failed to get VMs in the VMGroup " + u.TargetGroup.VmGroupId + ".")
Expand Down
26 changes: 26 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

//_ "github.com/go-sql-driver/mysql"
_ "github.com/mattn/go-sqlite3"
"github.com/spf13/viper"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
"github.com/cloud-barista/cb-tumblebug/src/core/mcir"
Expand All @@ -36,6 +37,29 @@ import (
"xorm.io/xorm/names"
)

// init for main
func init() {
profile := "cloud_conf"
setConfig(profile)
}

// setConfig get cloud settings from a config file
func setConfig(profile string) {
viper.AddConfigPath(".")
viper.AddConfigPath("./conf/")
viper.AddConfigPath("../conf/")
viper.SetConfigName(profile)
viper.SetConfigType("yaml")
err := viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file: %w", err))
}
err = viper.Unmarshal(&common.RuntimeConf)
if err != nil {
panic(err)
}
}

// Main Body

// @title CB-Tumblebug REST API
Expand Down Expand Up @@ -176,5 +200,7 @@ func main() {
wg.Done()
}()

fmt.Println("RuntimeConf: ", common.RuntimeConf.Cloud)

wg.Wait()
}

0 comments on commit c4512b9

Please sign in to comment.