Merge pull request #16962 from ioito/hotfix/qx-image-filter-by-os-archs

fix(glance): support filter image by os archs
This commit is contained in:
Zexi Li
2023-05-08 10:28:09 +08:00
committed by GitHub
6 changed files with 33 additions and 10 deletions
+5
View File
@@ -49,6 +49,11 @@ type ImageListInput struct {
// 操作系统精确匹配
OsTypePreciseMatch bool `json:"os_type_precise_match"`
// 操作系统架构, 可能值为: arm, x86 等
OsArchs []string `json:"os_archs"`
// 操作系统架构精确匹配
OsArchPreciseMatch bool `json:"os_arch_precise_match"`
// 发行版本,可能值为: CentOS, Ubuntu, Debian, ArchLinux, OpenEuler 等
Distributions []string `json:"distributions"`
// 发行版精确匹配
+5
View File
@@ -347,6 +347,11 @@ type EnabledStatusInfrasResourceBaseListInput struct {
}
type MultiArchResourceBaseListInput struct {
// 通过操作系统架构过滤
// x86会过滤出os_arch为空或os_arch=i386或以x86开头的资源
// arm会过滤出os_arch=aarch64或os_arch=aarch32或者以arm开头的资源
// 其他的输入会过滤出以输入字符开头的资源
// enmu: x86, arm
OsArch string `json:"os_arch"`
}
+2
View File
@@ -48,11 +48,13 @@ func ListQueryByArchitecture(q *sqlchemy.SQuery, fieldKey string, arch string) *
if arch == apis.OS_ARCH_X86 {
q = q.Filter(sqlchemy.OR(
sqlchemy.Startswith(q.Field(fieldKey), arch),
sqlchemy.Equals(q.Field(fieldKey), apis.OS_ARCH_I386),
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_AARCH32),
sqlchemy.Equals(q.Field(fieldKey), apis.OS_ARCH_AARCH64),
))
} else {
+12 -10
View File
@@ -411,18 +411,20 @@ func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.T
return dataImages[i].Name < dataImages[j].Name
})
out.Size = size
out.RootImage = *rootImage
out.DataImages = dataImages
// properties of root image
properties, err := ImagePropertyManager.GetProperties(rootImage.ID)
if err != nil {
return out
if rootImage != nil {
out.RootImage = *rootImage
// properties of root image
properties, err := ImagePropertyManager.GetProperties(rootImage.ID)
if err != nil {
return out
}
propJson := jsonutils.NewDict()
for k, v := range properties {
propJson.Add(jsonutils.NewString(v), k)
}
out.Properties = propJson
}
propJson := jsonutils.NewDict()
for k, v := range properties {
propJson.Add(jsonutils.NewString(v), k)
}
out.Properties = propJson
out.DisableDelete = self.Protected.Bool()
return out
}
+1
View File
@@ -1326,6 +1326,7 @@ func (manager *SImageManager) ListItemFilter(
propSq := propQ.SubQuery()
q = q.Join(propSq, sqlchemy.Equals(q.Field("id"), propSq.Field("image_id"))).Distinct()
}
propFilter([]string{api.IMAGE_OS_ARCH}, query.OsArchs, query.OsArchPreciseMatch)
propFilter([]string{api.IMAGE_OS_TYPE}, query.OsTypes, query.OsTypePreciseMatch)
propFilter([]string{api.IMAGE_OS_DISTRO, "distro"}, query.Distributions, query.DistributionPreciseMatch)
+8
View File
@@ -32,6 +32,8 @@ type ImageListOptions struct {
Name string `help:"Name filter"`
OsType []string `help:"Type of OS filter e.g. 'Windows, Linux, Freebsd, Android, macOS, VMWare'"`
OsTypePreciseMatch bool `help:"OS precise match"`
OsArch []string `help:"Type of OS arch filter e.g. 'x86, arm, arm64, x86_64'"`
OsArchPreciseMatch bool `help:"OS arch precise match"`
Distribution []string `help:"Distribution filter, e.g. 'CentOS, Ubuntu, Debian, Windows'"`
DistributionPreciseMatch bool `help:"Distribution precise match"`
}
@@ -75,6 +77,12 @@ func (o *ImageListOptions) Params() (jsonutils.JSONObject, error) {
if o.OsTypePreciseMatch {
params.Add(jsonutils.JSONTrue, "os_type_precise_match")
}
if len(o.OsArch) > 0 {
params.Add(jsonutils.NewStringArray(o.OsArch), "os_archs")
}
if o.OsArchPreciseMatch {
params.Add(jsonutils.JSONTrue, "os_arch_precise_match")
}
if len(o.Distribution) > 0 {
params.Add(jsonutils.NewStringArray(o.Distribution), "distributions")
}