diff --git a/conf/cloud_conf.yaml b/conf/cloud_conf.yaml new file mode 100644 index 000000000..21984b51c --- /dev/null +++ b/conf/cloud_conf.yaml @@ -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 diff --git a/src/core/common/config.go b/src/core/common/config.go index d6dd01f39..7444073cf 100644 --- a/src/core/common/config.go +++ b/src/core/common/config.go @@ -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"` diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index 03ee03b4d..b5e97b095 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -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. @@ -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 + ".") diff --git a/src/main.go b/src/main.go index a649e3bf6..66fe3f04f 100644 --- a/src/main.go +++ b/src/main.go @@ -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" @@ -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 @@ -176,5 +200,7 @@ func main() { wg.Done() }() + fmt.Println("RuntimeConf: ", common.RuntimeConf.Cloud) + wg.Wait() }