Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yaml config feature to handle different available values for each cloud #1188

Merged
merged 3 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
// }
Comment on lines +300 to +315
Copy link
Member

@jihoon-seo jihoon-seo Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드가 작동해야 할 것 같은데 왜 안되는걸까요.. ㅎㅎ 🤔

[예상 로직]

  1. 사용자가 "Create NLB" REST API 호출 시에 interval, timeout, threshold 전부/일부를 명시했다면
    → 해당 값을 사용
  2. 사용자가 "Create NLB" REST API 호출 시에 명시하지 않은 interval, timeout, threshold 에 대해서는
    YAML에 있는 (기본)값을 사용

이렇게 하면 좋을까요? 😊


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()
}