Merge pull request #10365 from rainzm/schedtag/filter

feat(region): filter schedtags from cloudprovider_id
This commit is contained in:
Zexi Li
2021-03-11 11:36:54 +08:00
committed by GitHub
3 changed files with 13 additions and 1 deletions
+1
View File
@@ -59,6 +59,7 @@ type SchedtagFilterListInput struct {
type SchedtagListInput struct {
apis.StandaloneResourceListInput
apis.ScopedResourceBaseListInput
CloudproviderResourceInput
// fitler by resource_type
ResourceType []string `json:"resource_type"`
+7
View File
@@ -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
}
+5 -1
View File
@@ -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
}