mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(glance): Structured subimage info and add 'created_at' field
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
@@ -27,13 +29,23 @@ type GuestImageDetails struct {
|
||||
ImageIds jsonutils.JSONObject `json:"image_ids"`
|
||||
|
||||
//Status string `json:"status"`
|
||||
Size int64 `json:"size"`
|
||||
MinRamMb int32 `json:"min_ram_mb"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
RootImage jsonutils.JSONObject `json:"root_image"`
|
||||
DataImages jsonutils.JSONObject `json:"data_images"`
|
||||
Size int64 `json:"size"`
|
||||
MinRamMb int32 `json:"min_ram_mb"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
RootImage SubImageInfo `json:"root_image"`
|
||||
DataImages []SubImageInfo `json:"data_images"`
|
||||
|
||||
Properties *jsonutils.JSONDict `json:"properties"`
|
||||
|
||||
DisableDelete bool `json:"disable_delete"`
|
||||
}
|
||||
|
||||
type SubImageInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
MinDiskMB int32 `json:"min_disk_mb"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
Size int64 `json:"size"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
@@ -269,15 +269,6 @@ func (gi *SGuestImage) DoCancelPendingDelete(ctx context.Context, userCred mccli
|
||||
return errors.Wrap(err, "guest image cancel delete error")
|
||||
}
|
||||
|
||||
type sPair struct {
|
||||
ID string
|
||||
Name string
|
||||
MinDiskMB int32
|
||||
DiskFormat string
|
||||
Size int64
|
||||
Status string
|
||||
}
|
||||
|
||||
func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject,
|
||||
out api.GuestImageDetails) api.GuestImageDetails {
|
||||
|
||||
@@ -294,27 +285,42 @@ func (self *SGuestImage) getMoreDetails(ctx context.Context, userCred mcclient.T
|
||||
out.Size = size
|
||||
return out
|
||||
}
|
||||
dataImages := make([]sPair, 0, len(images)-1)
|
||||
var rootImage sPair
|
||||
dataImages := make([]api.SubImageInfo, 0, len(images)-1)
|
||||
var rootImage api.SubImageInfo
|
||||
for i := range images {
|
||||
image := images[i]
|
||||
size += image.Size
|
||||
if !image.IsData.IsTrue() {
|
||||
rootImage = sPair{image.Id, images[i].Name, image.MinDiskMB, image.DiskFormat, image.Size, image.Status}
|
||||
rootImage = api.SubImageInfo{
|
||||
ID: image.Id,
|
||||
Name: image.Name,
|
||||
MinDiskMB: image.MinDiskMB,
|
||||
DiskFormat: image.DiskFormat,
|
||||
Size: image.Size,
|
||||
Status: image.Status,
|
||||
CreatedAt: image.CreatedAt,
|
||||
}
|
||||
out.MinRamMb = image.MinRamMB
|
||||
out.DiskFormat = image.DiskFormat
|
||||
continue
|
||||
}
|
||||
dataImages = append(dataImages, sPair{image.Id, image.Name, image.MinDiskMB, image.DiskFormat, image.Size,
|
||||
image.Status})
|
||||
dataImages = append(dataImages, api.SubImageInfo{
|
||||
ID: image.Id,
|
||||
Name: image.Name,
|
||||
MinDiskMB: image.MinDiskMB,
|
||||
DiskFormat: image.DiskFormat,
|
||||
Size: image.Size,
|
||||
Status: image.Status,
|
||||
CreatedAt: image.CreatedAt,
|
||||
})
|
||||
}
|
||||
// make sure that the sort of dataimage is fixed
|
||||
sort.Slice(dataImages, func(i, j int) bool {
|
||||
return dataImages[i].Name < dataImages[j].Name
|
||||
})
|
||||
out.Size = size
|
||||
out.RootImage = jsonutils.Marshal(rootImage)
|
||||
out.DataImages = jsonutils.Marshal(dataImages)
|
||||
out.RootImage = rootImage
|
||||
out.DataImages = dataImages
|
||||
// properties of root image
|
||||
properties, err := ImagePropertyManager.GetProperties(rootImage.ID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user