Merge pull request #8447 from ioito/hotfix/qx-rds-fix

fix: sync rds account host info
This commit is contained in:
Zexi Li
2020-10-23 18:04:05 +08:00
committed by GitHub
6 changed files with 46 additions and 14 deletions
+4
View File
@@ -78,6 +78,10 @@ type DBInstanceCreateInput struct {
// 包年包月时间周期
Duration string `json:"duration"`
// 是否自动续费(仅包年包月时生效)
// default: false
AutoRenew bool `json:"auto_renew"`
// swagger:ignore
ExpiredAt time.Time `json:"expired_at"`
+4
View File
@@ -42,6 +42,8 @@ type SCapabilities struct {
DisabledBrands []string `json:",allowempty"`
ComputeEngineBrands []string `json:",allowempty"`
DisabledComputeEngineBrands []string `json:",allowempty"`
RdsEngineBrands []string `json:",allowempty"`
DisabledRdsEngineBrands []string `json:",allowempty"`
CloudIdBrands []string `json:",allowempty"`
DisabledCloudIdBrands []string `json:",allowempty"`
PublicIpBrands []string `json:",allowempty"`
@@ -260,6 +262,7 @@ func getDBInstanceInfo(region *SCloudregion, zone *SZone) map[string]map[string]
func getBrands(region *SCloudregion, zone *SZone, domainId string, capa *SCapabilities) {
capa.Brands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, "")
capa.ComputeEngineBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_COMPUTE)
capa.RdsEngineBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_RDS)
capa.NetworkManageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_NETWORK)
capa.ObjectStorageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE)
capa.CloudIdBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.True, cloudprovider.CLOUD_CAPABILITY_CLOUDID)
@@ -273,6 +276,7 @@ func getBrands(region *SCloudregion, zone *SZone, domainId string, capa *SCapabi
capa.DisabledBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, "")
capa.DisabledComputeEngineBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_COMPUTE)
capa.DisabledRdsEngineBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_RDS)
capa.DisabledNetworkManageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_NETWORK)
capa.DisabledObjectStorageBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_OBJECTSTORE)
capa.DisabledCloudIdBrands, _ = CloudaccountManager.getBrandsOfCapability(region, zone, domainId, tristate.False, cloudprovider.CLOUD_CAPABILITY_CLOUDID)
@@ -695,6 +695,7 @@ func (manager *SDBInstanceAccountManager) newFromCloudDBInstanceAccount(ctx cont
account.Name = extAccount.GetName()
account.DBInstanceId = instance.Id
account.Status = extAccount.GetStatus()
account.Host = extAccount.GetHost()
err := manager.TableSpec().Insert(ctx, &account)
if err != nil {
+13
View File
@@ -34,6 +34,7 @@ import (
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/billing"
"yunion.io/x/onecloud/pkg/util/rand"
)
@@ -1390,6 +1391,18 @@ func (self *SQcloudRegionDriver) IsDBInstanceNeedSecgroup() bool {
return true
}
func (self *SQcloudRegionDriver) IsSupportedBillingCycle(bc billing.SBillingCycle, resource string) bool {
switch resource {
case models.DBInstanceManager.KeywordPlural():
years := bc.GetYears()
months := bc.GetMonths()
if (years >= 1 && years <= 3) || (months >= 1 && months <= 12) {
return true
}
}
return false
}
func (self *SQcloudRegionDriver) ValidateCreateDBInstanceBackupData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, instance *models.SDBInstance, input api.DBInstanceBackupCreateInput) (api.DBInstanceBackupCreateInput, error) {
switch instance.Engine {
case api.DBINSTANCE_TYPE_MYSQL:
@@ -53,7 +53,6 @@ func (self *DBInstanceSyncStatusTask) SyncStatusDBInstance(ctx context.Context,
self.taskFailed(ctx, dbinstance, errors.Wrapf(err, "dbinstance.GetIDBInstance"))
return
}
status := idbinstance.GetStatus()
dbinstance.SetStatus(self.UserCred, status, "")
dbinstance.SyncAllWithCloudDBInstance(ctx, self.UserCred, dbinstance.GetCloudprovider(), idbinstance)
self.SetStageComplete(ctx, nil)
}
+23 -12
View File
@@ -729,23 +729,34 @@ func (self *SRegion) CreateMySQLDBInstance(opts *cloudprovider.SManagedDBInstanc
action := "CreateDBInstanceHour"
if opts.BillingCycle != nil {
params["Period"] = fmt.Sprintf("%d", opts.BillingCycle.GetMonths())
params["AutoRenewFlag"] = "0"
if opts.BillingCycle.AutoRenew {
params["AutoRenewFlag"] = "1"
}
action = "CreateDBInstance"
}
switch opts.Category {
case api.QCLOUD_DBINSTANCE_CATEGORY_HA, api.QCLOUD_DBINSTANCE_CATEGORY_BASIC:
params["DeviceType"] = strings.ToUpper(opts.Category)
case api.QCLOUD_DBINSTANCE_CATEGORY_FINANCE:
params["DeviceType"] = "HA"
params["ProtectMode"] = "2"
}
if len(opts.Zone1) > 0 {
params["Zone"] = opts.Zone1
}
if len(opts.Zone2) > 0 {
params["SlaveZone"] = opts.Zone2
}
if len(opts.Zone3) > 0 {
params["BackupZone"] = opts.Zone3
switch opts.Category {
case api.QCLOUD_DBINSTANCE_CATEGORY_BASIC:
params["DeviceType"] = strings.ToUpper(opts.Category)
case api.QCLOUD_DBINSTANCE_CATEGORY_HA:
params["DeviceType"] = strings.ToUpper(opts.Category)
params["DeployMode"] = "1"
if len(opts.Zone2) > 0 {
params["SlaveZone"] = opts.Zone2
}
case api.QCLOUD_DBINSTANCE_CATEGORY_FINANCE:
params["DeviceType"] = "HA"
params["ProtectMode"] = "2"
params["DeployMode"] = "1"
if len(opts.Zone2) > 0 {
params["SlaveZone"] = opts.Zone2
}
if len(opts.Zone3) > 0 {
params["BackupZone"] = opts.Zone3
}
}
params["ClientToken"] = utils.GenRequestId(20)
resp, err := self.cdbRequest(action, params)