From 47da51e04e544d377eef3dd07c1d3ccc3380f551 Mon Sep 17 00:00:00 2001 From: rainzm Date: Fri, 6 Aug 2021 15:41:49 +0800 Subject: [PATCH] feat(region): add host_type filter for listing wires --- pkg/apis/compute/wire.go | 3 ++- pkg/compute/models/wires.go | 6 ++++++ pkg/mcclient/options/wire.go | 9 +++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/apis/compute/wire.go b/pkg/apis/compute/wire.go index 70b376c92f..c87fd79de4 100644 --- a/pkg/apis/compute/wire.go +++ b/pkg/apis/compute/wire.go @@ -90,7 +90,8 @@ type WireListInput struct { HostResourceInput - Bandwidth *int `json:"bandwidth"` + Bandwidth *int `json:"bandwidth"` + HostType string `json:"host_type"` } type WireMergeInput struct { diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index 23e34b3dc7..274459a6ea 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -1306,6 +1306,12 @@ func (manager *SWireManager) ListItemFilter( sq := HostwireManager.Query("wire_id").Equals("host_id", hostObj.GetId()) q = q.Filter(sqlchemy.In(q.Field("id"), sq.SubQuery())) } + if len(query.HostType) > 0 { + hs := HostManager.Query("id").Equals("host_type", query.HostType).SubQuery() + sq := HostwireManager.Query("wire_id") + sq = sq.Join(hs, sqlchemy.Equals(sq.Field("host_id"), hs.Field("id"))) + q = q.Filter(sqlchemy.In(q.Field("id"), sq.SubQuery())) + } if query.Bandwidth != nil { q = q.Equals("bandwidth", *query.Bandwidth) diff --git a/pkg/mcclient/options/wire.go b/pkg/mcclient/options/wire.go index a14051afd0..95b5a94d51 100644 --- a/pkg/mcclient/options/wire.go +++ b/pkg/mcclient/options/wire.go @@ -21,10 +21,11 @@ type WireListOptions struct { Bandwidth *int `help:"List wires by bandwidth"` - Region string `help:"List wires in region"` - Zone string `help:"list wires in zone" json:"-"` - Vpc string `help:"List wires in vpc"` - Host string `help:"List wires attached to a host"` + Region string `help:"List wires in region"` + Zone string `help:"list wires in zone" json:"-"` + Vpc string `help:"List wires in vpc"` + Host string `help:"List wires attached to a host"` + HostType string `help:"List wires attached to host with HostType"` } func (wo *WireListOptions) GetContextId() string {