fix(region): filter zone region by read only (#24950)

This commit is contained in:
屈轩
2026-06-02 11:15:20 +08:00
committed by GitHub
parent b8835bb333
commit 69d3a2d894
5 changed files with 40 additions and 0 deletions
+1
View File
@@ -39,6 +39,7 @@ func init() {
Usable *bool `help:"List regions where networks are usable"`
UsableVpc *bool `help:"List regions where VPC are usable"`
Service string `help:"List regions which service has available skus" choices:"dbinstances|servers|elasticcaches"`
ReadOnly *bool `help:"List regions with read only account"`
City string `help:"List regions in the specified city"`
+8
View File
@@ -132,6 +132,10 @@ type CloudregionListInput struct {
// 按虚拟机数量排序
// pattern:asc|desc
OrderByGuestCount string `json:"order_by_guest_count"`
// 过滤有只读账号的区域
// example: true
ReadOnly *bool `json:"read_only"`
}
type ZoneListInput struct {
@@ -148,6 +152,10 @@ type ZoneListInput struct {
// 过滤提供特定服务的可用区
Service string `json:"service"`
// 过滤有只读账号的可用区
// example: true
ReadOnly *bool `json:"read_only"`
Location []string `json:"location"`
Contacts []string `json:"contacts"`
+14
View File
@@ -964,6 +964,20 @@ func (manager *SCloudregionManager) ListItemFilter(
}
}
if query.ReadOnly != nil {
sq := CloudaccountManager.Query("provider").Equals("read_only", *query.ReadOnly).SubQuery()
if *query.ReadOnly {
q = q.In("provider", sq)
} else {
q = q.Filter(
sqlchemy.OR(
sqlchemy.In(q.Field("provider"), sq),
sqlchemy.Equals(q.Field("provider"), api.CLOUD_PROVIDER_ONECLOUD),
),
)
}
}
cityStr := query.City
if cityStr == "Other" {
q = q.IsNullOrEmpty("city")
+16
View File
@@ -816,6 +816,22 @@ func (manager *SZoneManager) ListItemFilter(
q = q.In("cloudregion_id", subq.SubQuery())
}
if query.ReadOnly != nil {
sq := CloudaccountManager.Query("provider").Equals("read_only", *query.ReadOnly).SubQuery()
regions := CloudregionManager.Query("id")
if *query.ReadOnly {
regions = regions.In("provider", sq)
} else {
regions = regions.Filter(
sqlchemy.OR(
sqlchemy.In(regions.Field("provider"), sq),
sqlchemy.Equals(regions.Field("provider"), api.CLOUD_PROVIDER_ONECLOUD),
),
)
}
q = q.In("cloudregion_id", regions.SubQuery())
}
q, err = managedResourceFilterByRegion(ctx, q, query.RegionalFilterListInput, "", nil)
if len(query.Location) > 0 {
+1
View File
@@ -26,6 +26,7 @@ type ZoneListOptions struct {
City string `help:"Filter zone by city of cloudregions"`
Usable *bool `help:"List all zones where networks are usable"`
UsableVpc *bool `help:"List all zones where vpc are usable"`
ReadOnly *bool `help:"List all zones with read only account"`
OrderByWires string
OrderByHosts string