mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9727 from ioito/hotfix/qx-rds-list-with-secgroups
fix(region): rds list with secgorups info
This commit is contained in:
@@ -294,6 +294,8 @@ type DBInstanceDetails struct {
|
||||
|
||||
SDBInstance
|
||||
|
||||
Secgroups []apis.StandaloneShortDesc `json:"secgroups"`
|
||||
|
||||
// 安全组名称
|
||||
// example: Default
|
||||
Secgroup string `json:"secgroup"`
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
@@ -537,6 +538,7 @@ func (manager *SDBInstanceManager) FetchCustomizeColumns(
|
||||
manRows := manager.SManagedResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
regRows := manager.SCloudregionResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
rdsIds := make([]string, len(rows))
|
||||
vpcIds := make([]string, len(rows))
|
||||
zone1Ids := make([]string, len(rows))
|
||||
zone2Ids := make([]string, len(rows))
|
||||
@@ -548,6 +550,7 @@ func (manager *SDBInstanceManager) FetchCustomizeColumns(
|
||||
CloudregionResourceInfo: regRows[i],
|
||||
}
|
||||
instance := objs[i].(*SDBInstance)
|
||||
rdsIds[i] = instance.Id
|
||||
vpcIds[i] = instance.VpcId
|
||||
zone1Ids[i] = instance.Zone1
|
||||
zone2Ids[i] = instance.Zone2
|
||||
@@ -569,6 +572,42 @@ func (manager *SDBInstanceManager) FetchCustomizeColumns(
|
||||
}
|
||||
}
|
||||
|
||||
q := SecurityGroupManager.Query()
|
||||
ownerId, queryScope, err := db.FetchCheckQueryOwnerScope(ctx, userCred, query, SecurityGroupManager, policy.PolicyActionList, true)
|
||||
if err != nil {
|
||||
log.Errorf("FetchCheckQueryOwnerScope error: %v", err)
|
||||
return rows
|
||||
}
|
||||
secgroups := SecurityGroupManager.FilterByOwner(q, ownerId, queryScope).SubQuery()
|
||||
rdssecgroups := DBInstanceSecgroupManager.Query().SubQuery()
|
||||
|
||||
secQ := rdssecgroups.Query(rdssecgroups.Field("dbinstance_id"), rdssecgroups.Field("secgroup_id"), secgroups.Field("name").Label("secgroup_name")).Join(secgroups, sqlchemy.Equals(rdssecgroups.Field("secgroup_id"), secgroups.Field("id"))).Filter(sqlchemy.In(rdssecgroups.Field("dbinstance_id"), rdsIds))
|
||||
|
||||
type sRdsSecgroupInfo struct {
|
||||
DBInstanceId string `json:"dbinstance_id"`
|
||||
SecgroupName string
|
||||
SecgroupId string
|
||||
}
|
||||
rsgs := []sRdsSecgroupInfo{}
|
||||
err = secQ.All(&rsgs)
|
||||
if err != nil {
|
||||
log.Errorf("secQ.All error: %v", err)
|
||||
return rows
|
||||
}
|
||||
|
||||
ret := make(map[string][]apis.StandaloneShortDesc)
|
||||
for i := range rsgs {
|
||||
rsg, ok := ret[rsgs[i].DBInstanceId]
|
||||
if !ok {
|
||||
rsg = make([]apis.StandaloneShortDesc, 0)
|
||||
}
|
||||
rsg = append(rsg, apis.StandaloneShortDesc{
|
||||
Id: rsgs[i].SecgroupId,
|
||||
Name: rsgs[i].SecgroupName,
|
||||
})
|
||||
ret[rsgs[i].DBInstanceId] = rsg
|
||||
}
|
||||
|
||||
zone1, err := db.FetchIdNameMap2(ZoneManager, zone1Ids)
|
||||
if err != nil {
|
||||
return rows
|
||||
@@ -588,6 +627,7 @@ func (manager *SDBInstanceManager) FetchCustomizeColumns(
|
||||
rows[i].Zone1Name = zone1[zone1Ids[i]]
|
||||
rows[i].Zone2Name = zone2[zone2Ids[i]]
|
||||
rows[i].Zone3Name = zone3[zone3Ids[i]]
|
||||
rows[i].Secgroups, _ = ret[rdsIds[i]]
|
||||
}
|
||||
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user