mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10365 from rainzm/schedtag/filter
feat(region): filter schedtags from cloudprovider_id
This commit is contained in:
@@ -59,6 +59,7 @@ type SchedtagFilterListInput struct {
|
||||
type SchedtagListInput struct {
|
||||
apis.StandaloneResourceListInput
|
||||
apis.ScopedResourceBaseListInput
|
||||
CloudproviderResourceInput
|
||||
|
||||
// fitler by resource_type
|
||||
ResourceType []string `json:"resource_type"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user