mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #6463 from tb365/bugfix/tb-network-ip-query-fix
add fuzzy ip matching
This commit is contained in:
@@ -72,10 +72,14 @@ type NetworkListInput struct {
|
||||
|
||||
UsableResourceListInput
|
||||
|
||||
// description: search ip address in network.
|
||||
// description: Exact matching ip address in network.
|
||||
// example: 10.168.222.1
|
||||
Ip string `json:"ip"`
|
||||
|
||||
// description: Fuzzy matching ip address in network.
|
||||
// example: 10.168.222.1
|
||||
IpMatch string `json:"ip_match"`
|
||||
|
||||
IfnameHint []string `json:"ifname_hint"`
|
||||
// 起始IP地址
|
||||
GuestIpStart []string `json:"guest_ip_start"`
|
||||
|
||||
@@ -1780,8 +1780,17 @@ func (manager *SNetworkManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
ip := ""
|
||||
exactIpMatch := false
|
||||
if len(input.Ip) > 0 {
|
||||
ipIa, err := parseIpToIntArray(input.Ip)
|
||||
exactIpMatch = true
|
||||
ip = input.Ip
|
||||
} else if len(input.IpMatch) > 0 {
|
||||
ip = input.IpMatch
|
||||
}
|
||||
|
||||
if len(ip) > 0 {
|
||||
ipIa, err := parseIpToIntArray(ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1796,7 +1805,13 @@ func (manager *SNetworkManager) ListItemFilter(
|
||||
ipStart := sqlchemy.INET_ATON(q.Field("guest_ip_start"))
|
||||
ipEnd := sqlchemy.INET_ATON(q.Field("guest_ip_end"))
|
||||
|
||||
ipCondtion := sqlchemy.OR(sqlchemy.Between(ipField, ipStart, ipEnd), sqlchemy.Contains(q.Field("guest_ip_start"), input.Ip), sqlchemy.Contains(q.Field("guest_ip_end"), input.Ip))
|
||||
var ipCondtion sqlchemy.ICondition
|
||||
if exactIpMatch {
|
||||
ipCondtion = sqlchemy.Between(ipField, ipStart, ipEnd)
|
||||
} else {
|
||||
ipCondtion = sqlchemy.OR(sqlchemy.Between(ipField, ipStart, ipEnd), sqlchemy.Contains(q.Field("guest_ip_start"), ip), sqlchemy.Contains(q.Field("guest_ip_end"), ip))
|
||||
}
|
||||
|
||||
q = q.Filter(ipCondtion)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user