mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
support search ip
This commit is contained in:
@@ -58,6 +58,9 @@ type ServerListInput struct {
|
||||
// enum: asc,desc
|
||||
// OrderByDisk string `json:"order_by_disk"`
|
||||
|
||||
// 根据ip查找机器
|
||||
IpAddr string `json:"ip_addr"`
|
||||
|
||||
// 列出可以挂载指定EIP的主机
|
||||
UsableServerForEip string `json:"usable_server_for_eip"`
|
||||
|
||||
|
||||
@@ -355,6 +355,17 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
q = q.In("host_id", sq)
|
||||
}
|
||||
|
||||
if len(query.IpAddr) > 0 {
|
||||
gn := GuestnetworkManager.Query("guest_id").Contains("ip_addr", query.IpAddr).SubQuery()
|
||||
guestEip := ElasticipManager.Query("associate_id").Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER).Contains("ip_addr", query.IpAddr).SubQuery()
|
||||
q = q.LeftJoin(gn, sqlchemy.Equals(q.Field("id"), gn.Field("guest_id")))
|
||||
q = q.LeftJoin(guestEip, sqlchemy.Equals(q.Field("id"), guestEip.Field("associate_id")))
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.IsNotNull(gn.Field("guest_id")),
|
||||
sqlchemy.IsNotNull(guestEip.Field("associate_id")),
|
||||
))
|
||||
}
|
||||
|
||||
diskFilter := query.AttachableServersForDisk
|
||||
if len(diskFilter) > 0 {
|
||||
diskI, _ := DiskManager.FetchByIdOrName(userCred, diskFilter)
|
||||
|
||||
@@ -52,6 +52,7 @@ type ServerListOptions struct {
|
||||
WithoutUserMeta *bool `help:"Show Servers without user metadata"`
|
||||
Group string `help:"Instance Group ID or Name"`
|
||||
HostSn string `help:"Host SN"`
|
||||
IpAddr string `help:"Fileter by ip"`
|
||||
|
||||
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