mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9154 from wanyaoqi/feature/wyq/add-filter-server-type
feat(region): add list filter server type
This commit is contained in:
@@ -42,6 +42,11 @@ type ServerListInput struct {
|
||||
Baremetal *bool `json:"baremetal"`
|
||||
// 只列出GPU主机
|
||||
Gpu *bool `json:"gpu"`
|
||||
// 只列出还有备份机的主机
|
||||
Backup *bool `json:"bakcup"`
|
||||
// 列出指定类型的主机
|
||||
// enum: normal,gpu,backup
|
||||
ServerType string `json:"server_type"`
|
||||
// 列出管理安全组为指定安全组的主机
|
||||
AdminSecgroup string `json:"admin_security"`
|
||||
// 列出Hypervisor为指定值的主机
|
||||
|
||||
@@ -413,6 +413,28 @@ func (manager *SGuestManager) ListItemFilter(
|
||||
q = q.NotIn("id", sq)
|
||||
}
|
||||
}
|
||||
if len(query.ServerType) > 0 {
|
||||
var trueVal, falseVal = true, false
|
||||
switch query.ServerType {
|
||||
case "normal":
|
||||
query.Gpu = nil
|
||||
query.Backup = nil
|
||||
case "gpu":
|
||||
query.Gpu = &trueVal
|
||||
query.Backup = &falseVal
|
||||
case "backup":
|
||||
query.Gpu = &falseVal
|
||||
query.Backup = &trueVal
|
||||
default:
|
||||
return nil, httperrors.NewInputParameterError("unknown server type %s", query.ServerType)
|
||||
}
|
||||
}
|
||||
|
||||
if query.Backup != nil {
|
||||
if *query.Backup {
|
||||
q = q.IsNotEmpty("backup_host_id")
|
||||
}
|
||||
}
|
||||
|
||||
if query.Gpu != nil {
|
||||
isodev := IsolatedDeviceManager.Query().SubQuery()
|
||||
|
||||
Reference in New Issue
Block a user