diff --git a/pkg/apis/compute/dbinstance_const.go b/pkg/apis/compute/dbinstance_const.go index c62e0b9d49..1c331d2a3f 100644 --- a/pkg/apis/compute/dbinstance_const.go +++ b/pkg/apis/compute/dbinstance_const.go @@ -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云盘 diff --git a/pkg/multicloud/google/dbinstance.go b/pkg/multicloud/google/dbinstance.go index fc70945299..d92a6edf59 100644 --- a/pkg/multicloud/google/dbinstance.go +++ b/pkg/multicloud/google/dbinstance.go @@ -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" @@ -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 { @@ -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, } @@ -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