mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(region): filter zone region by read only (#24950)
This commit is contained in:
@@ -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"`
|
||||
|
||||
|
||||
@@ -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"`
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user