mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix(region): server list filter by ips
This commit is contained in:
@@ -75,7 +75,9 @@ type ServerListInput struct {
|
||||
|
||||
OrderByIp string `json:"order_by_ip"`
|
||||
// 根据ip查找机器
|
||||
IpAddr string `json:"ip_addr"`
|
||||
IpAddr string `json:"ip_addr" yunion-deprecated-by:"ip_addrs"`
|
||||
// 根据多个ip查找机器
|
||||
IpAddrs []string `json:"ip_addrs"`
|
||||
|
||||
// 列出可以挂载指定EIP的主机
|
||||
UsableServerForEip string `json:"usable_server_for_eip"`
|
||||
|
||||
@@ -374,20 +374,40 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
q = q.In("host_id", sq)
|
||||
}
|
||||
|
||||
if len(query.IpAddr) > 0 {
|
||||
if len(query.IpAddrs) > 0 {
|
||||
grpnets := GroupnetworkManager.Query().SubQuery()
|
||||
vipq := GroupguestManager.Query("guest_id")
|
||||
vipq = vipq.Join(grpnets, sqlchemy.Equals(grpnets.Field("group_id"), vipq.Field("group_id")))
|
||||
vipq = vipq.Contains("ip_addr", query.IpAddr)
|
||||
conditions := []sqlchemy.ICondition{}
|
||||
for _, ipAddr := range query.IpAddrs {
|
||||
conditions = append(conditions, sqlchemy.Contains(grpnets.Field("ip_addr"), ipAddr))
|
||||
}
|
||||
vipq = vipq.Join(grpnets, sqlchemy.Equals(grpnets.Field("group_id"), vipq.Field("group_id"))).Filter(
|
||||
sqlchemy.OR(conditions...),
|
||||
)
|
||||
|
||||
grpeips := ElasticipManager.Query().Equals("associate_type", api.EIP_ASSOCIATE_TYPE_INSTANCE_GROUP).SubQuery()
|
||||
conditions = []sqlchemy.ICondition{}
|
||||
for _, ipAddr := range query.IpAddrs {
|
||||
conditions = append(conditions, sqlchemy.Contains(grpeips.Field("ip_addr"), ipAddr))
|
||||
}
|
||||
vipeipq := GroupguestManager.Query("guest_id")
|
||||
vipeipq = vipeipq.Join(grpeips, sqlchemy.Equals(grpeips.Field("associate_id"), vipeipq.Field("group_id")))
|
||||
vipeipq = vipeipq.Contains("ip_addr", query.IpAddr)
|
||||
vipeipq = vipeipq.Join(grpeips, sqlchemy.Equals(grpeips.Field("associate_id"), vipeipq.Field("group_id"))).Filter(
|
||||
sqlchemy.OR(conditions...),
|
||||
)
|
||||
|
||||
gn := GuestnetworkManager.Query("guest_id").Contains("ip_addr", query.IpAddr)
|
||||
gnQ := GuestnetworkManager.Query("guest_id")
|
||||
conditions = []sqlchemy.ICondition{}
|
||||
for _, ipAddr := range query.IpAddrs {
|
||||
conditions = append(conditions, sqlchemy.Contains(gnQ.Field("ip_addr"), ipAddr))
|
||||
}
|
||||
gn := gnQ.Filter(sqlchemy.OR(conditions...))
|
||||
|
||||
guestEip := ElasticipManager.Query("associate_id").Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER).Contains("ip_addr", query.IpAddr)
|
||||
guestEipQ := ElasticipManager.Query("associate_id").Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER)
|
||||
conditions = []sqlchemy.ICondition{}
|
||||
for _, ipAddr := range query.IpAddrs {
|
||||
conditions = append(conditions, sqlchemy.Contains(guestEipQ.Field("ip_addr"), ipAddr))
|
||||
}
|
||||
guestEip := guestEipQ.Filter(sqlchemy.OR(conditions...))
|
||||
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.In(q.Field("id"), gn.SubQuery()),
|
||||
|
||||
@@ -33,27 +33,28 @@ import (
|
||||
var ErrEmtptyUpdate = errors.New("No valid update data")
|
||||
|
||||
type ServerListOptions struct {
|
||||
Zone string `help:"Zone ID or Name"`
|
||||
Wire string `help:"Wire ID or Name"`
|
||||
Network string `help:"Network ID or Name"`
|
||||
Disk string `help:"Disk ID or Name"`
|
||||
Host string `help:"Host ID or Name"`
|
||||
Baremetal *bool `help:"Show baremetal servers"`
|
||||
Gpu *bool `help:"Show gpu servers"`
|
||||
Secgroup string `help:"Secgroup ID or Name"`
|
||||
AdminSecgroup string `help:"AdminSecgroup ID or Name"`
|
||||
Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|container|baremetal|aliyun|azure|aws|huawei|ucloud|zstack|openstack|google|ctyun"`
|
||||
Region string `help:"Show servers in cloudregion"`
|
||||
WithEip *bool `help:"Show Servers with EIP"`
|
||||
WithoutEip *bool `help:"Show Servers without EIP"`
|
||||
OsType string `help:"OS Type" choices:"linux|windows|vmware"`
|
||||
Vpc string `help:"Vpc id or name"`
|
||||
UsableServerForEip string `help:"Eip id or name"`
|
||||
WithoutUserMeta *bool `help:"Show Servers without user metadata"`
|
||||
EipAssociable *bool `help:"Show Servers can associate with eip"`
|
||||
Group string `help:"Instance Group ID or Name"`
|
||||
HostSn string `help:"Host SN"`
|
||||
IpAddr string `help:"Fileter by ip"`
|
||||
Zone string `help:"Zone ID or Name"`
|
||||
Wire string `help:"Wire ID or Name"`
|
||||
Network string `help:"Network ID or Name"`
|
||||
Disk string `help:"Disk ID or Name"`
|
||||
Host string `help:"Host ID or Name"`
|
||||
Baremetal *bool `help:"Show baremetal servers"`
|
||||
Gpu *bool `help:"Show gpu servers"`
|
||||
Secgroup string `help:"Secgroup ID or Name"`
|
||||
AdminSecgroup string `help:"AdminSecgroup ID or Name"`
|
||||
Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|container|baremetal|aliyun|azure|aws|huawei|ucloud|zstack|openstack|google|ctyun"`
|
||||
Region string `help:"Show servers in cloudregion"`
|
||||
WithEip *bool `help:"Show Servers with EIP"`
|
||||
WithoutEip *bool `help:"Show Servers without EIP"`
|
||||
OsType string `help:"OS Type" choices:"linux|windows|vmware"`
|
||||
Vpc string `help:"Vpc id or name"`
|
||||
UsableServerForEip string `help:"Eip id or name"`
|
||||
WithoutUserMeta *bool `help:"Show Servers without user metadata"`
|
||||
EipAssociable *bool `help:"Show Servers can associate with eip"`
|
||||
Group string `help:"Instance Group ID or Name"`
|
||||
HostSn string `help:"Host SN"`
|
||||
IpAddr string `help:"Fileter by ip"`
|
||||
IpAddrs []string `help:"Fileter by ips"`
|
||||
|
||||
OrderByDisk string `help:"Order by disk size" choices:"asc|desc"`
|
||||
OrderByHost string `help:"Order by host name" choices:"asc|desc"`
|
||||
|
||||
Reference in New Issue
Block a user