mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix: filter schedtags by zones (#23744)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -69,6 +69,9 @@ type SchedtagListInput struct {
|
||||
Type string `json:"type" yunion-deprecated-by:"resource_type"`
|
||||
|
||||
DefaultStrategy []string `json:"default_strategy"`
|
||||
|
||||
// filter by zone_id
|
||||
ZoneId []string `json:"zone_id"`
|
||||
}
|
||||
|
||||
type SchedtagDetails struct {
|
||||
|
||||
@@ -220,6 +220,40 @@ func (manager *SSchedtagManager) ListItemFilter(
|
||||
q = q.Join(hostSchedtagSubq, sqlchemy.Equals(q.Field("id"), hostSchedtagSubq.Field("schedtag_id")))
|
||||
}
|
||||
|
||||
if len(query.ZoneId) > 0 {
|
||||
var err error
|
||||
|
||||
storagesQ := StorageManager.Query("id")
|
||||
storagesQ, err = StorageManager.SZoneResourceBaseManager.ListItemFilter(ctx, storagesQ, userCred, api.ZonalFilterListInput{ZonalFilterListBase: api.ZonalFilterListBase{ZoneIds: query.ZoneId}})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "StorageManager.SZoneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
storagesSubQ := storagesQ.SubQuery()
|
||||
storageSchedtagQ := StorageschedtagManager.Query("schedtag_id")
|
||||
storageSchedtagQ = storageSchedtagQ.Join(storagesSubQ, sqlchemy.Equals(storageSchedtagQ.Field("storage_id"), storagesSubQ.Field("id")))
|
||||
|
||||
networksQ := NetworkManager.Query("id")
|
||||
networksQ, err = NetworkManager.SWireResourceBaseManager.ListItemFilter(ctx, networksQ, userCred, api.WireFilterListInput{ZonalFilterListBase: api.ZonalFilterListBase{ZoneIds: query.ZoneId}})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NetworkManager.SWireResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
networksSubQ := networksQ.SubQuery()
|
||||
networkSchedtagQ := NetworkschedtagManager.Query("schedtag_id")
|
||||
networkSchedtagQ = networkSchedtagQ.Join(networksSubQ, sqlchemy.Equals(networkSchedtagQ.Field("network_id"), networksSubQ.Field("id")))
|
||||
|
||||
hostQ := HostManager.Query("id")
|
||||
hostQ, err = HostManager.SZoneResourceBaseManager.ListItemFilter(ctx, hostQ, userCred, api.ZonalFilterListInput{ZonalFilterListBase: api.ZonalFilterListBase{ZoneIds: query.ZoneId}})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "HostManager.SZoneResourceBaseManager.ListItemFilter")
|
||||
}
|
||||
hostSubQ := hostQ.SubQuery()
|
||||
hostSchedtagQ := HostschedtagManager.Query("schedtag_id")
|
||||
hostSchedtagQ = hostSchedtagQ.Join(hostSubQ, sqlchemy.Equals(hostSchedtagQ.Field("host_id"), hostSubQ.Field("id")))
|
||||
|
||||
unionSchedtagQ := sqlchemy.Union(storageSchedtagQ, networkSchedtagQ, hostSchedtagQ).Query().SubQuery()
|
||||
q = q.In("id", unionSchedtagQ)
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,9 @@ func (o SchedtagSetOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
type SchedtagListOptions struct {
|
||||
baseoptions.BaseListOptions
|
||||
Type string `help:"Filter by resource type"`
|
||||
CloudproviderId string `help:"Filter by cloudprovider id"`
|
||||
Type string `help:"Filter by resource type"`
|
||||
CloudproviderId string `help:"Filter by cloudprovider id"`
|
||||
ZoneId []string `help:"Filter by zone id"`
|
||||
}
|
||||
|
||||
func (o SchedtagListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
@@ -72,7 +73,9 @@ func (o SchedtagListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
if len(o.CloudproviderId) > 0 {
|
||||
params.Add(jsonutils.NewString(o.CloudproviderId), "cloudprovider_id")
|
||||
}
|
||||
|
||||
if len(o.ZoneId) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(o.ZoneId), "zone_id")
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user