Merge pull request #5413 from ioito/hotfix/qx-rds-sku-detail

fix: rds sku 返回region name
This commit is contained in:
yunion-ci-robot
2020-03-10 10:42:57 +08:00
committed by GitHub
2 changed files with 70 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compute
import "yunion.io/x/onecloud/pkg/apis"
type DBInstanceSkuDetails struct {
apis.EnabledStatusStandaloneResourceDetails
CloudregionResourceInfo
SDBInstanceSku
Zone1Name string `json:"zone1_name"`
Zone2Name string `json:"zone2_name"`
Zone3Name string `json:"zone3_name"`
}
+43
View File
@@ -32,10 +32,12 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
type SDBInstanceSkuManager struct {
db.SEnabledStatusStandaloneResourceBaseManager
SCloudregionResourceBaseManager
}
var DBInstanceSkuManager *SDBInstanceSkuManager
@@ -141,6 +143,47 @@ func (manager *SDBInstanceSkuManager) ListItemFilter(
return q, nil
}
func (manager *SDBInstanceSkuManager) FetchCustomizeColumns(
ctx context.Context,
userCred mcclient.TokenCredential,
query jsonutils.JSONObject,
objs []interface{},
fields stringutils2.SSortedStrings,
isList bool,
) []api.DBInstanceSkuDetails {
rows := make([]api.DBInstanceSkuDetails, len(objs))
enableRows := manager.SEnabledStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
regionRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
zoneIds := map[string]string{}
for i := range rows {
rows[i] = api.DBInstanceSkuDetails{
EnabledStatusStandaloneResourceDetails: enableRows[i],
CloudregionResourceInfo: regionRows[i],
}
sku := objs[i].(*SDBInstanceSku)
for _, zoneId := range []string{sku.Zone1, sku.Zone2, sku.Zone3} {
if _, ok := zoneIds[zoneId]; !ok {
zoneIds[zoneId] = ""
}
}
}
var err error
zoneIds, err = db.FetchIdNameMap(ZoneManager, zoneIds)
if err != nil {
log.Errorf("db.FetchIdNameMap fail %s", err)
return rows
}
for i := range rows {
sku := objs[i].(*SDBInstanceSku)
rows[i].Zone1Name, _ = zoneIds[sku.Zone1]
rows[i].Zone2Name, _ = zoneIds[sku.Zone2]
rows[i].Zone3Name, _ = zoneIds[sku.Zone3]
}
return rows
}
func (manager *SDBInstanceSkuManager) OrderByExtraFields(
ctx context.Context,
q *sqlchemy.SQuery,