Skip to content

Commit

Permalink
fix: google rds regional and zonal
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jul 6, 2020
1 parent 21d67a4 commit 79d0169
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/compute/dbinstance_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const (
HUAWEI_DBINSTANCE_CATEGORY_SINGLE = "single" //单机
HUAWEI_DBINSTANCE_CATEGORY_REPLICA = "replica" //只读

//谷歌云实例类型
GOOGLE_DBINSTANCE_CATEGORY_REGIONAL = "Regional" // 高可用性(区域级)
GOOGLE_DBINSTANCE_CATEGORY_ZONAL = "Zonal" // 单个地区

//阿里云存储类型
ALIYUN_DBINSTANCE_STORAGE_TYPE_LOCAL_SSD = "local_ssd" //本地盘SSD盘
ALIYUN_DBINSTANCE_STORAGE_TYPE_CLOUD_ESSD = "cloud_essd" //ESSD云盘
Expand Down
23 changes: 20 additions & 3 deletions pkg/multicloud/google/dbinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"

billing_api "yunion.io/x/onecloud/pkg/apis/billing"
api "yunion.io/x/onecloud/pkg/apis/compute"
Expand Down Expand Up @@ -320,7 +321,12 @@ func (rds *SDBInstance) GetDiskSizeGB() int {
}

func (rds *SDBInstance) GetCategory() string {
return rds.BackendType
switch rds.Settings.AvailabilityType {
case "REGIONAL":
return api.GOOGLE_DBINSTANCE_CATEGORY_REGIONAL
default:
return api.GOOGLE_DBINSTANCE_CATEGORY_ZONAL
}
}

func (rds *SDBInstance) GetStorageType() string {
Expand Down Expand Up @@ -545,6 +551,14 @@ func (region *SRegion) CreateRds(name, databaseVersion, category, instanceType,
"dataDiskType": storageType,
"dataDiskSizeGb": diskSizeGb,
}
if utils.IsInStringArray(category, []string{api.GOOGLE_DBINSTANCE_CATEGORY_REGIONAL, api.GOOGLE_DBINSTANCE_CATEGORY_ZONAL}) {
settings["availabilityType"] = strings.ToUpper(category)
settings["backupConfiguration"] = map[string]interface{}{
"enabled": true,
"binaryLogEnabled": true,
"startTime": "19:00",
}
}
ipConfiguration := map[string]interface{}{
"ipv4Enabled": true,
}
Expand All @@ -560,10 +574,13 @@ func (region *SRegion) CreateRds(name, databaseVersion, category, instanceType,
"name": name,
"region": region.Name,
"settings": settings,
"backendType": category,
"backendType": "SECOND_GEN",
"instanceType": "CLOUD_SQL_INSTANCE",
}
if len(zoneId) > 0 {
body["gceZone"] = zoneId
settings["locationPreference"] = map[string]string{
"zone": zoneId,
}
}
if len(password) > 0 {
body["rootPassword"] = password
Expand Down

0 comments on commit 79d0169

Please sign in to comment.