mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-25 10:16:12 +08:00
Merge pull request #12785 from zexi/automated-cherry-pick-of-#12784-upstream-master
Automated cherry pick of #12784: fix(region): host support list by os_arch
This commit is contained in:
@@ -124,6 +124,7 @@ type HostListInput struct {
|
||||
ServerIdForNetwork string `json:"server_id_for_network"`
|
||||
// 宿主机 cpu 架构
|
||||
CpuArchitecture string `json:"cpu_architecture"`
|
||||
OsArch string `json:"os_arch"`
|
||||
|
||||
// 按虚拟机数量排序
|
||||
// enum: asc,desc
|
||||
|
||||
+20
-29
@@ -12,20 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Code generated by model-api-gen. DO NOT EDIT.
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
@@ -52,20 +38,25 @@ func (manager *SMultiArchResourceBaseManager) ListItemFilter(
|
||||
userCred mcclient.TokenCredential,
|
||||
query apis.MultiArchResourceBaseListInput,
|
||||
) (*sqlchemy.SQuery, error) {
|
||||
if len(query.OsArch) > 0 {
|
||||
if query.OsArch == apis.OS_ARCH_X86 {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.Startswith(q.Field("os_arch"), query.OsArch),
|
||||
sqlchemy.IsNullOrEmpty(q.Field("os_arch")),
|
||||
))
|
||||
} else if query.OsArch == apis.OS_ARCH_ARM {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.Startswith(q.Field("os_arch"), query.OsArch),
|
||||
sqlchemy.Equals(q.Field("os_arch"), apis.OS_ARCH_AARCH64),
|
||||
))
|
||||
} else {
|
||||
q = q.Startswith("os_arch", query.OsArch)
|
||||
}
|
||||
return ListQueryByArchitecture(q, "os_arch", query.OsArch), nil
|
||||
}
|
||||
|
||||
func ListQueryByArchitecture(q *sqlchemy.SQuery, fieldKey string, arch string) *sqlchemy.SQuery {
|
||||
if len(arch) == 0 {
|
||||
return q
|
||||
}
|
||||
return q, nil
|
||||
if arch == apis.OS_ARCH_X86 {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.Startswith(q.Field(fieldKey), arch),
|
||||
sqlchemy.IsNullOrEmpty(q.Field(fieldKey)),
|
||||
))
|
||||
} else if arch == apis.OS_ARCH_ARM {
|
||||
q = q.Filter(sqlchemy.OR(
|
||||
sqlchemy.Startswith(q.Field(fieldKey), arch),
|
||||
sqlchemy.Equals(q.Field(fieldKey), apis.OS_ARCH_AARCH64),
|
||||
))
|
||||
} else {
|
||||
q = q.Startswith(fieldKey, arch)
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
@@ -445,6 +445,9 @@ func (manager *SHostManager) ListItemFilter(
|
||||
if len(query.CpuArchitecture) > 0 {
|
||||
q = q.Equals("cpu_architecture", query.CpuArchitecture)
|
||||
}
|
||||
if len(query.OsArch) > 0 {
|
||||
q = db.ListQueryByArchitecture(q, "cpu_architecture", query.OsArch)
|
||||
}
|
||||
|
||||
// for provider onecloud
|
||||
if len(query.ServerIdForNetwork) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user