diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 2c6069ce3e..f878585374 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -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为指定值的主机 diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 2ea4655f7d..459503d300 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -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()