diff --git a/src/core/mcis/nlb.go b/src/core/mcis/nlb.go index ae011b268..beaf01732 100644 --- a/src/core/mcis/nlb.go +++ b/src/core/mcis/nlb.go @@ -18,6 +18,7 @@ import ( "encoding/json" "fmt" "os" + "reflect" "strconv" "strings" "time" @@ -370,44 +371,19 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf cloudType := connConfig.ProviderName - valuesFromYaml := TbNLBHealthCheckerInfo{} + // Convert cloud type to field name (e.g., AWS to Aws, OPENSTACK to Openstack) + lowercase := strings.ToLower(cloudType) + fieldName := strings.ToUpper(string(lowercase[0])) + lowercase[1:] - switch cloudType { - case "AWS": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Aws.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Aws.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Aws.Nlb.Threshold) - case "AZURE": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Azure.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Azure.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Azure.Nlb.Threshold) - case "GCP": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Gcp.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Gcp.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Gcp.Nlb.Threshold) - case "ALIBABA": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Alibaba.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Alibaba.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Alibaba.Nlb.Threshold) - case "TENCENT": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Tencent.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Tencent.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Tencent.Nlb.Threshold) - case "IBM": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Ibm.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Ibm.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Ibm.Nlb.Threshold) - case "OPENSTACK": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Openstack.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Openstack.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Openstack.Nlb.Threshold) - case "CLOUDIT": - valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Cloudit.Nlb.Interval) - valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Cloudit.Nlb.Timeout) - valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Cloudit.Nlb.Threshold) - default: + // Get cloud setting with field name + cloudSetting := reflect.ValueOf(&common.RuntimeConf.Cloud).Elem().FieldByName(fieldName).Interface().(common.CloudSetting) + + // Set nlb health checker info + valuesFromYaml := TbNLBHealthCheckerInfo{} + valuesFromYaml.Interval, _ = strconv.Atoi(cloudSetting.Nlb.Interval) + valuesFromYaml.Timeout, _ = strconv.Atoi(cloudSetting.Nlb.Timeout) + valuesFromYaml.Threshold, _ = strconv.Atoi(cloudSetting.Nlb.Threshold) - } if u.HealthChecker.Interval == "default" || u.HealthChecker.Interval == "" { tempReq.ReqInfo.HealthChecker.Interval = strconv.Itoa(valuesFromYaml.Interval)