diff --git a/pkg/apis/compute/schedtag.go b/pkg/apis/compute/schedtag.go index d326c64f95..3e877ca280 100644 --- a/pkg/apis/compute/schedtag.go +++ b/pkg/apis/compute/schedtag.go @@ -59,6 +59,7 @@ type SchedtagFilterListInput struct { type SchedtagListInput struct { apis.StandaloneResourceListInput apis.ScopedResourceBaseListInput + CloudproviderResourceInput // fitler by resource_type ResourceType []string `json:"resource_type"` diff --git a/pkg/compute/models/schedtags.go b/pkg/compute/models/schedtags.go index a3db5765f0..a65dafd4b0 100644 --- a/pkg/compute/models/schedtags.go +++ b/pkg/compute/models/schedtags.go @@ -219,6 +219,13 @@ func (manager *SSchedtagManager) ListItemFilter( q = q.In("default_strategy", query.DefaultStrategy) } + if len(query.CloudproviderId) > 0 { + hostSubq := HostManager.Query("id").Equals("manager_id", query.CloudproviderId).SubQuery() + hostSchedtagQ := HostschedtagManager.Query("schedtag_id") + hostSchedtagSubq := hostSchedtagQ.Join(hostSubq, sqlchemy.Equals(hostSchedtagQ.Field("host_id"), hostSubq.Field("id"))).SubQuery() + q = q.Join(hostSchedtagSubq, sqlchemy.Equals(q.Field("id"), hostSchedtagSubq.Field("schedtag_id"))) + } + return q, nil } diff --git a/pkg/mcclient/options/schedtags.go b/pkg/mcclient/options/schedtags.go index f471a31354..657e839d77 100644 --- a/pkg/mcclient/options/schedtags.go +++ b/pkg/mcclient/options/schedtags.go @@ -55,7 +55,8 @@ func (o SchedtagSetOptions) Params() (jsonutils.JSONObject, error) { type SchedtagListOptions struct { BaseListOptions - Type string `help:"Filter by resource type"` + Type string `help:"Filter by resource type"` + CloudproviderId string `help:"Filter by cloudprovider id"` } func (o SchedtagListOptions) Params() (jsonutils.JSONObject, error) { @@ -67,6 +68,9 @@ func (o SchedtagListOptions) Params() (jsonutils.JSONObject, error) { if len(o.Type) > 0 { params.Add(jsonutils.NewString(o.Type), "resource_type") } + if len(o.CloudproviderId) > 0 { + params.Add(jsonutils.NewString(o.CloudproviderId), "cloudprovider_id") + } return params, nil }