diff --git a/pkg/apis/compute/network.go b/pkg/apis/compute/network.go index 4f91a12f10..f8f4059a07 100644 --- a/pkg/apis/compute/network.go +++ b/pkg/apis/compute/network.go @@ -78,6 +78,9 @@ type NetworkListInput struct { UsableResourceListInput + // filter by route table which associate with it + RouteTableId string `json:"route_table_id"` + // description: Exact matching ip address in network. // example: 10.168.222.1 Ip string `json:"ip"` diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index 8eb5ec556d..454b425b84 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -2057,6 +2057,11 @@ func (manager *SNetworkManager) ListItemFilter( return nil, errors.Wrap(err, "SWireResourceBaseManager.ListItemFilter") } + if len(input.RouteTableId) > 0 { + sq := RouteTableAssociationManager.Query("associated_resource_id").Equals("route_table_id", input.RouteTableId).Equals("association_type", string(cloudprovider.RouteTableAssociaToSubnet)) + q = q.In("id", sq.SubQuery()) + } + if input.Usable != nil && *input.Usable { regions := CloudregionManager.Query("id").Equals("status", api.CLOUD_REGION_STATUS_INSERVER) zones := ZoneManager.Query("id").Equals("status", api.ZONE_ENABLE).In("cloudregion_id", regions) diff --git a/pkg/mcclient/options/network.go b/pkg/mcclient/options/network.go index 97a0753d9a..7360f3b5d6 100644 --- a/pkg/mcclient/options/network.go +++ b/pkg/mcclient/options/network.go @@ -44,8 +44,9 @@ type NetworkListOptions struct { GuestIpStart []string `help:"search by guest_ip_start"` GuestIpEnd []string `help:"search by guest_ip_end"` - BgpType []string `help:"filter by bgp_type"` - HostType string `help:"filter by host_type"` + BgpType []string `help:"filter by bgp_type"` + HostType string `help:"filter by host_type"` + RouteTableId string `help:"Filter by RouteTable"` } func (opts *NetworkListOptions) GetContextId() string {