Merge pull request #17250 from ioito/hotfix/qx-host-filter-by-ips

fix(region): filter host by ips
This commit is contained in:
Zexi Li
2023-06-06 14:17:12 +08:00
committed by GitHub
3 changed files with 30 additions and 20 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ type HostListInput struct {
// filter by mac of any network interface
AnyMac string `json:"any_mac"`
// filter by ip of any network interface
AnyIp string `json:"any_ip"`
AnyIp []string `json:"any_ip"`
// filter storages not attached to this host
StorageNotAttached *bool `json:"storage_not_attached"`
// filter by Hypervisor
+15 -5
View File
@@ -270,14 +270,24 @@ func (manager *SHostManager) ListItemFilter(
}
}
if len(query.AnyIp) > 0 {
hn := HostnetworkManager.Query("baremetal_id").Contains("ip_addr", query.AnyIp).SubQuery()
hnQ := HostnetworkManager.Query("baremetal_id") //.Contains("ip_addr", query.AnyIp).SubQuery()
conditions := []sqlchemy.ICondition{}
for _, ip := range query.AnyIp {
conditions = append(conditions, sqlchemy.Contains(hnQ.Field("ip_addr"), ip))
}
hn := hnQ.Filter(
sqlchemy.OR(conditions...),
)
conditions = []sqlchemy.ICondition{}
for _, ip := range query.AnyIp {
conditions = append(conditions, sqlchemy.Contains(q.Field("access_ip"), ip))
conditions = append(conditions, sqlchemy.Contains(q.Field("ipmi_ip"), ip))
}
conditions = append(conditions, sqlchemy.In(q.Field("id"), hn))
q = q.Filter(sqlchemy.OR(
sqlchemy.Contains(q.Field("access_ip"), query.AnyIp),
sqlchemy.Contains(q.Field("ipmi_ip"), query.AnyIp),
sqlchemy.In(q.Field("id"), hn),
conditions...,
))
}
// var scopeQuery *sqlchemy.SSubQuery
schedTagStr := query.SchedtagId
if len(schedTagStr) > 0 {
+14 -14
View File
@@ -21,20 +21,20 @@ import (
)
type HostListOptions struct {
Schedtag string `help:"List hosts in schedtag"`
Zone string `help:"List hosts in zone"`
Region string `help:"List hosts in region"`
Wire string `help:"List hosts in wire"`
Image string `help:"List hosts cached images" json:"cachedimage"`
Storage string `help:"List hosts attached to storages"`
Baremetal string `help:"List hosts that is managed by baremetal system" choices:"true|false"`
Empty bool `help:"show empty host" json:"-"`
Occupied bool `help:"show occupid host" json:"-"`
Enabled bool `help:"Show enabled host only" json:"-"`
Disabled bool `help:"Show disabled host only" json:"-"`
HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv|aliyun|azure|qcloud|aws|huawei|ucloud|google|ctyun"`
AnyMac string `help:"Mac matches one of the host's interface"`
AnyIp string `help:"IP matches one of the host's interface"`
Schedtag string `help:"List hosts in schedtag"`
Zone string `help:"List hosts in zone"`
Region string `help:"List hosts in region"`
Wire string `help:"List hosts in wire"`
Image string `help:"List hosts cached images" json:"cachedimage"`
Storage string `help:"List hosts attached to storages"`
Baremetal string `help:"List hosts that is managed by baremetal system" choices:"true|false"`
Empty bool `help:"show empty host" json:"-"`
Occupied bool `help:"show occupid host" json:"-"`
Enabled bool `help:"Show enabled host only" json:"-"`
Disabled bool `help:"Show disabled host only" json:"-"`
HostType string `help:"Host type filter" choices:"baremetal|hypervisor|esxi|kubelet|hyperv|aliyun|azure|qcloud|aws|huawei|ucloud|google|ctyun"`
AnyMac string `help:"Mac matches one of the host's interface"`
AnyIp []string `help:"IP matches one of the host's interface"`
IsBaremetal *bool `help:"filter host list by is_baremetal=true|false"`