mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
feat(region): add cloudcache for dnszone and secgroup details
This commit is contained in:
@@ -125,7 +125,7 @@ type DnsZoneDetails struct {
|
||||
// 关联vpc数量
|
||||
VpcCount int `json:"vpc_count"`
|
||||
// Cache info
|
||||
CloudCaches []DnsZoneCacheDetails `json:"cloud_caches"`
|
||||
CloudCaches []jsonutils.JSONObject `json:"cloud_caches"`
|
||||
}
|
||||
|
||||
type DnsZoneListInput struct {
|
||||
@@ -141,7 +141,8 @@ type DnsZoneListInput struct {
|
||||
ZoneType string `json:"zone_type"`
|
||||
|
||||
// Filter dns zone By vpc
|
||||
VpcId string `json:"vpc_id"`
|
||||
VpcId string `json:"vpc_id"`
|
||||
WithCache bool `json:"with_cache"`
|
||||
}
|
||||
|
||||
type DnsZoneSyncStatusInput struct {
|
||||
|
||||
@@ -17,6 +17,7 @@ package compute
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/regutils"
|
||||
"yunion.io/x/pkg/util/secrules"
|
||||
@@ -181,6 +182,7 @@ type SecgroupListInput struct {
|
||||
RegionalFilterListInput
|
||||
|
||||
ManagedResourceListInput
|
||||
WithCache bool `json:"witch_cache"`
|
||||
}
|
||||
|
||||
type SecurityGroupCacheListInput struct {
|
||||
@@ -252,6 +254,8 @@ type SecgroupDetails struct {
|
||||
InRules []SecgroupRuleDetails `json:"in_rules"`
|
||||
// 出方向规则信息
|
||||
OutRules []SecgroupRuleDetails `json:"out_rules"`
|
||||
|
||||
CloudCaches []jsonutils.JSONObject `json:"cloud_caches"`
|
||||
}
|
||||
|
||||
type SecurityGroupResourceInfo struct {
|
||||
|
||||
@@ -309,7 +309,27 @@ func (manager *SDnsZoneManager) FetchCustomizeColumns(
|
||||
for i := range caches {
|
||||
objs[i] = &caches[i]
|
||||
}
|
||||
rows[i].CloudCaches = DnsZoneCacheManager.FetchCustomizeColumns(ctx, userCred, jsonutils.NewDict(), objs, stringutils2.SSortedStrings{}, true)
|
||||
cacheDetails := DnsZoneCacheManager.FetchCustomizeColumns(ctx, userCred, jsonutils.NewDict(), objs, stringutils2.SSortedStrings{}, true)
|
||||
for i := range cacheDetails {
|
||||
jsonDict := jsonutils.Marshal(cacheDetails[i]).(*jsonutils.JSONDict)
|
||||
jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict))
|
||||
rows[i].CloudCaches = append(rows[i].CloudCaches, jsonDict)
|
||||
}
|
||||
}
|
||||
}
|
||||
withCache, _ := query.Bool("with_cache")
|
||||
if withCache {
|
||||
log.Infof("try to get caches")
|
||||
dnsZoneIds := make([]string, len(dnsZones))
|
||||
for i := range dnsZones {
|
||||
dnsZoneIds[i] = dnsZones[i].Id
|
||||
}
|
||||
cacheDetails, err := manager.GetCacheDetails(ctx, userCred, dnsZoneIds)
|
||||
if err != nil {
|
||||
log.Errorf("unable to Get cacheDetails: %v", err)
|
||||
}
|
||||
for i := range rows {
|
||||
rows[i].CloudCaches = cacheDetails[dnsZoneIds[i]]
|
||||
}
|
||||
}
|
||||
return rows
|
||||
@@ -473,6 +493,28 @@ func (self *SDnsZone) GetDnsZoneCache(accountId string) (*SDnsZoneCache, error)
|
||||
return nil, sqlchemy.ErrDuplicateEntry
|
||||
}
|
||||
|
||||
func (self *SDnsZoneManager) GetCacheDetails(ctx context.Context, userCred mcclient.TokenCredential, dnsZoneIds []string) (map[string][]jsonutils.JSONObject, error) {
|
||||
q := DnsZoneCacheManager.Query().In("dns_zone_id", dnsZoneIds)
|
||||
caches := []SDnsZoneCache{}
|
||||
err := db.FetchModelObjects(DnsZoneCacheManager, q, &caches)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
||||
}
|
||||
objs := make([]interface{}, len(caches))
|
||||
for i := range caches {
|
||||
objs[i] = &caches[i]
|
||||
}
|
||||
cacheDetails := DnsZoneCacheManager.FetchCustomizeColumns(ctx, userCred, jsonutils.NewDict(), objs, stringutils2.SSortedStrings{}, true)
|
||||
ret := make(map[string][]jsonutils.JSONObject, len(dnsZoneIds))
|
||||
for i := range cacheDetails {
|
||||
jsonDict := jsonutils.Marshal(cacheDetails[i]).(*jsonutils.JSONDict)
|
||||
jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict))
|
||||
dnsZoneId, _ := jsonDict.GetString("dns_zone_id")
|
||||
ret[dnsZoneId] = append(ret[dnsZoneId], jsonDict)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SDnsZone) GetDnsZoneCaches() ([]SDnsZoneCache, error) {
|
||||
caches := []SDnsZoneCache{}
|
||||
q := DnsZoneCacheManager.Query().Equals("dns_zone_id", self.Id)
|
||||
|
||||
@@ -373,12 +373,14 @@ func (manager *SSecurityGroupManager) FetchCustomizeColumns(
|
||||
|
||||
virtRows := manager.SSharableVirtualResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
secgroupIds := make([]string, len(objs))
|
||||
secgroups := make([]*SSecurityGroup, len(objs))
|
||||
for i := range rows {
|
||||
rows[i] = api.SecgroupDetails{
|
||||
SharableVirtualResourceDetails: virtRows[i],
|
||||
}
|
||||
secgroup := objs[i].(*SSecurityGroup)
|
||||
secgroupIds[i] = secgroup.Id
|
||||
secgroups[i] = secgroup
|
||||
}
|
||||
|
||||
caches := []SSecurityGroupCache{}
|
||||
@@ -515,7 +517,20 @@ func (manager *SSecurityGroupManager) FetchCustomizeColumns(
|
||||
rows[i].AdminGuestCnt, _ = adminGuestMaps[secgroupIds[i]]
|
||||
rows[i].SystemGuestCnt, _ = systemGuestMaps[secgroupIds[i]]
|
||||
}
|
||||
|
||||
withCache, _ := query.Bool("with_cache")
|
||||
if withCache {
|
||||
secgroupIds := make([]string, len(secgroups))
|
||||
for i := range secgroups {
|
||||
secgroupIds[i] = secgroups[i].Id
|
||||
}
|
||||
cacheDetails, err := manager.GetCacheDetails(ctx, userCred, secgroupIds)
|
||||
if err != nil {
|
||||
log.Errorf("unable to Get cacheDetails: %v", err)
|
||||
}
|
||||
for i := range rows {
|
||||
rows[i].CloudCaches = cacheDetails[secgroupIds[i]]
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
@@ -528,6 +543,28 @@ func (self *SSecurityGroup) GetExtraDetails(
|
||||
return api.SecgroupDetails{}, nil
|
||||
}
|
||||
|
||||
func (manager *SSecurityGroupManager) GetCacheDetails(ctx context.Context, userCred mcclient.TokenCredential, secgroupIds []string) (map[string][]jsonutils.JSONObject, error) {
|
||||
q := SecurityGroupCacheManager.Query().In("secgroup_id", secgroupIds)
|
||||
caches := []SSecurityGroupCache{}
|
||||
err := db.FetchModelObjects(SecurityGroupCacheManager, q, &caches)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "db.FetchModelObjects")
|
||||
}
|
||||
objs := make([]interface{}, len(caches))
|
||||
for i := range caches {
|
||||
objs[i] = &caches[i]
|
||||
}
|
||||
cacheDetails := SecurityGroupCacheManager.FetchCustomizeColumns(ctx, userCred, jsonutils.NewDict(), objs, stringutils2.SSortedStrings{}, true)
|
||||
ret := make(map[string][]jsonutils.JSONObject, len(secgroupIds))
|
||||
for i := range cacheDetails {
|
||||
jsonDict := jsonutils.Marshal(cacheDetails[i]).(*jsonutils.JSONDict)
|
||||
jsonDict.Update(jsonutils.Marshal(objs[i]).(*jsonutils.JSONDict))
|
||||
secgroupId, _ := jsonDict.GetString("secgroup_id")
|
||||
ret[secgroupId] = append(ret[secgroupId], jsonDict)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (manager *SSecurityGroupManager) ValidateCreateData(
|
||||
ctx context.Context,
|
||||
userCred mcclient.TokenCredential,
|
||||
|
||||
@@ -22,8 +22,9 @@ import (
|
||||
type SDnsZoneListOptions struct {
|
||||
BaseListOptions
|
||||
|
||||
VpcId string `help:"Filter dns zone by vpc"`
|
||||
ZoneType string `help:"Filter dns zone by zone type" choices:"PublicZone|PrivateZone"`
|
||||
VpcId string `help:"Filter dns zone by vpc"`
|
||||
ZoneType string `help:"Filter dns zone by zone type" choices:"PublicZone|PrivateZone"`
|
||||
WithCache bool `help:"Whether to bring cache information"`
|
||||
}
|
||||
|
||||
func (opts *SDnsZoneListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -37,6 +37,7 @@ type SecgroupListOptions struct {
|
||||
DBInstance string `help:"Filter secgroups bound to specified rds" json:"dbinstance"`
|
||||
Cloudregion string `help:"Filter secgroups by region"`
|
||||
Cloudaccount string `help:"Filter secgroups by account"`
|
||||
WithCache bool `help:"Whether to bring cache information"`
|
||||
}
|
||||
|
||||
func (opts *SecgroupListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user