mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: image-list --sub-format support
This commit is contained in:
@@ -143,6 +143,7 @@ func init() {
|
||||
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"`
|
||||
}
|
||||
R(&ImageListOptions{}, "image-list", "List images", func(s *mcclient.ClientSession, args *ImageListOptions) error {
|
||||
@@ -173,15 +174,14 @@ func init() {
|
||||
params.Add(jsonutils.NewString(args.Name), "name")
|
||||
}
|
||||
if len(args.Format) > 0 {
|
||||
if len(args.Format) == 1 {
|
||||
params.Add(jsonutils.NewString(args.Format[0]), "disk_format")
|
||||
} else {
|
||||
fs := jsonutils.NewArray()
|
||||
for _, f := range args.Format {
|
||||
fs.Add(jsonutils.NewString(f))
|
||||
}
|
||||
params.Add(fs, "disk_formats")
|
||||
fs := jsonutils.NewArray()
|
||||
for _, f := range args.Format {
|
||||
fs.Add(jsonutils.NewString(f))
|
||||
}
|
||||
params.Add(fs, "disk_formats")
|
||||
}
|
||||
if len(args.SubFormats) > 0 {
|
||||
params.Add(jsonutils.Marshal(args.SubFormats), "sub_formats")
|
||||
}
|
||||
result, err := modules.Images.List(s, params)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,6 +28,9 @@ type ImageListInput struct {
|
||||
// 列出是否支持UEFI启动的镜像
|
||||
Uefi *bool `json:"uefi"`
|
||||
|
||||
// 根据已转换格式过滤, 可能值为: qcow2, vmdk, vhd, raw等
|
||||
SubFormats []string `json:"subFormats"`
|
||||
|
||||
// 是否为标准镜像
|
||||
IsStandard *bool `json:"is_standard"`
|
||||
|
||||
|
||||
@@ -1156,6 +1156,10 @@ func (manager *SImageManager) ListItemFilter(
|
||||
if len(query.DiskFormats) > 0 {
|
||||
q = q.In("disk_format", query.DiskFormats)
|
||||
}
|
||||
if len(query.SubFormats) > 0 {
|
||||
sq := ImageSubformatManager.Query().SubQuery()
|
||||
q = q.Join(sq, sqlchemy.Equals(sq.Field("image_id"), q.Field("id"))).Filter(sqlchemy.In(sq.Field("format"), query.SubFormats))
|
||||
}
|
||||
if query.Uefi != nil && *query.Uefi {
|
||||
imagePropertyQ := ImagePropertyManager.Query().
|
||||
Equals("name", api.IMAGE_UEFI_SUPPORT).Equals("value", "true").SubQuery()
|
||||
|
||||
Reference in New Issue
Block a user