mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
feat(glance): precise_match option of image list input (#15341)
This commit is contained in:
@@ -46,9 +46,13 @@ type ImageListInput struct {
|
||||
|
||||
// 操作系统类型,可能值为: Linux, Windows, FreeBSD 等
|
||||
OsTypes []string `json:"os_types"`
|
||||
// 操作系统精确匹配
|
||||
OsTypePreciseMatch bool `json:"os_type_precise_match"`
|
||||
|
||||
// 发行版本,可能值为: CentOS, Ubuntu, Debian, ArchLinux, OpenEuler 等
|
||||
Distributions []string `json:"distributions"`
|
||||
// 发行版精确匹配
|
||||
DistributionPreciseMatch bool `json:"distribution_precise_match`
|
||||
}
|
||||
|
||||
type GuestImageListInput struct {
|
||||
|
||||
@@ -1300,7 +1300,7 @@ func (manager *SImageManager) ListItemFilter(
|
||||
}
|
||||
}
|
||||
|
||||
propFilter := func(nameKeys []string, vals []string) {
|
||||
propFilter := func(nameKeys []string, vals []string, presiceMatch bool) {
|
||||
if len(vals) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -1308,16 +1308,20 @@ func (manager *SImageManager) ListItemFilter(
|
||||
conds := make([]sqlchemy.ICondition, 0)
|
||||
for _, val := range vals {
|
||||
field := propQ.Field("value")
|
||||
conds = append(conds,
|
||||
sqlchemy.Like(field, val),
|
||||
sqlchemy.Contains(field, val))
|
||||
if presiceMatch {
|
||||
conds = append(conds, sqlchemy.Equals(field, val))
|
||||
} else {
|
||||
conds = append(conds,
|
||||
sqlchemy.Like(field, val),
|
||||
sqlchemy.Contains(field, val))
|
||||
}
|
||||
}
|
||||
propQ.Filter(sqlchemy.OR(conds...))
|
||||
propSq := propQ.SubQuery()
|
||||
q = q.Join(propSq, sqlchemy.Equals(q.Field("id"), propSq.Field("image_id"))).Distinct()
|
||||
}
|
||||
propFilter([]string{api.IMAGE_OS_TYPE}, query.OsTypes)
|
||||
propFilter([]string{api.IMAGE_OS_DISTRO, "distro"}, query.Distributions)
|
||||
propFilter([]string{api.IMAGE_OS_TYPE}, query.OsTypes, query.OsTypePreciseMatch)
|
||||
propFilter([]string{api.IMAGE_OS_DISTRO, "distro"}, query.Distributions, query.DistributionPreciseMatch)
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -23,15 +23,17 @@ import (
|
||||
type ImageListOptions struct {
|
||||
options.BaseListOptions
|
||||
|
||||
IsPublic string `help:"filter images public or not(True, False or None)" choices:"true|false"`
|
||||
IsStandard string `help:"filter images standard or non-standard" choices:"true|false"`
|
||||
Protected string `help:"filter images by protected" choices:"true|false"`
|
||||
IsUefi bool `help:"list uefi image"`
|
||||
Format []string `help:"Disk formats"`
|
||||
SubFormats []string `help:"Sub formats"`
|
||||
Name string `help:"Name filter"`
|
||||
OsType []string `help:"Type of OS filter e.g. 'Windows, Linux, Freebsd, Android, macOS, VMWare'"`
|
||||
Distribution []string `help:"Distribution filter, e.g. 'CentOS, Ubuntu, Debian, Windows'"`
|
||||
IsPublic string `help:"filter images public or not(True, False or None)" choices:"true|false"`
|
||||
IsStandard string `help:"filter images standard or non-standard" choices:"true|false"`
|
||||
Protected string `help:"filter images by protected" choices:"true|false"`
|
||||
IsUefi bool `help:"list uefi image"`
|
||||
Format []string `help:"Disk formats"`
|
||||
SubFormats []string `help:"Sub formats"`
|
||||
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"`
|
||||
Distribution []string `help:"Distribution filter, e.g. 'CentOS, Ubuntu, Debian, Windows'"`
|
||||
DistributionPreciseMatch bool `help:"Distribution precise match"`
|
||||
}
|
||||
|
||||
func (o *ImageListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
@@ -70,9 +72,15 @@ func (o *ImageListOptions) Params() (jsonutils.JSONObject, error) {
|
||||
if len(o.OsType) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(o.OsType), "os_types")
|
||||
}
|
||||
if o.OsTypePreciseMatch {
|
||||
params.Add(jsonutils.JSONTrue, "os_type_precise_match")
|
||||
}
|
||||
if len(o.Distribution) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(o.Distribution), "distributions")
|
||||
}
|
||||
if o.DistributionPreciseMatch {
|
||||
params.Add(jsonutils.JSONTrue, "distribution_precise_match")
|
||||
}
|
||||
return params, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user