mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): filter vpcs by zone
This commit is contained in:
@@ -62,6 +62,9 @@ type VpcListInput struct {
|
||||
UsableResourceListInput
|
||||
UsableVpcResourceListInput
|
||||
|
||||
// 过滤vpc底下有指定zone的ip子网
|
||||
ZoneId string `json:"zone_id"`
|
||||
|
||||
// filter by globalvpc
|
||||
Globalvpc string `json:"globalvpc"`
|
||||
|
||||
|
||||
@@ -1146,6 +1146,28 @@ func (manager *SVpcManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
if len(query.ZoneId) > 0 {
|
||||
zoneObj, err := validators.ValidateModel(userCred, ZoneManager, &query.ZoneId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region, err := zoneObj.(*SZone).GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get zone %s region", zoneObj.GetName())
|
||||
}
|
||||
q = q.Equals("cloudregion_id", region.Id)
|
||||
wires := WireManager.Query().SubQuery()
|
||||
networks := NetworkManager.Query().SubQuery()
|
||||
sq := wires.Query(wires.Field("vpc_id")).Join(networks, sqlchemy.Equals(wires.Field("id"), networks.Field("wire_id"))).Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.Equals(wires.Field("zone_id"), query.ZoneId),
|
||||
sqlchemy.IsNullOrEmpty(wires.Field("zone_id")),
|
||||
),
|
||||
)
|
||||
q = q.In("id", sq.SubQuery())
|
||||
|
||||
}
|
||||
|
||||
if query.IsDefault != nil {
|
||||
if *query.IsDefault {
|
||||
q = q.IsTrue("is_default")
|
||||
|
||||
@@ -29,6 +29,7 @@ type VpcListOptions struct {
|
||||
DnsZoneId string `help:"Filter by DnsZone"`
|
||||
InterVpcNetworkId string `help:"Filter by InterVpcNetwork"`
|
||||
ExternalAccessMode string `help:"Filter by external access mode" choices:"distgw|eip|eip-distgw"`
|
||||
ZoneId string `help:"Filter by zone which has networks"`
|
||||
}
|
||||
|
||||
func (opts *VpcListOptions) GetContextId() string {
|
||||
|
||||
Reference in New Issue
Block a user