mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix: unify image.min_disk unit to MB
This commit is contained in:
@@ -25,13 +25,13 @@ type SImage struct {
|
||||
DiskFormat string
|
||||
Id string
|
||||
IsPublic bool
|
||||
MinDisk int
|
||||
MinRam int
|
||||
MinDiskMB int `json:"min_disk"`
|
||||
MinRamMB int `json:"min_ram"`
|
||||
Name string
|
||||
Owner string
|
||||
Properties map[string]string
|
||||
Protected bool
|
||||
Size int64
|
||||
SizeBytes int64 `json:"size"`
|
||||
Status string
|
||||
// UpdatedAt time.Time
|
||||
}
|
||||
@@ -43,8 +43,8 @@ func CloudImage2Image(image ICloudImage) SImage {
|
||||
DiskFormat: image.GetImageFormat(),
|
||||
Id: image.GetId(),
|
||||
IsPublic: image.GetImageType() != CachedImageTypeCustomized,
|
||||
MinDisk: image.GetMinOsDiskSizeGb(),
|
||||
MinRam: 0,
|
||||
MinDiskMB: image.GetMinOsDiskSizeGb() * 1024,
|
||||
MinRamMB: 0,
|
||||
Name: image.GetName(),
|
||||
Properties: map[string]string{
|
||||
"os_type": image.GetOsType(),
|
||||
@@ -53,7 +53,7 @@ func CloudImage2Image(image ICloudImage) SImage {
|
||||
"os_arch": image.GetOsArch(),
|
||||
},
|
||||
Protected: true,
|
||||
Size: image.GetSize(),
|
||||
SizeBytes: image.GetSize(),
|
||||
Status: image.GetImageStatus(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1274,7 +1274,7 @@ func fillDiskConfigByImage(ctx context.Context, userCred mcclient.TokenCredentia
|
||||
// diskConfig.ImageDiskFormat = image.DiskFormat
|
||||
CachedimageManager.ImageAddRefCount(image.Id)
|
||||
if diskConfig.SizeMb == 0 {
|
||||
diskConfig.SizeMb = image.MinDisk * 1024 // MB
|
||||
diskConfig.SizeMb = image.MinDiskMB // MB
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -114,8 +114,8 @@ type SImage struct {
|
||||
Checksum string `width:"32" charset:"ascii" nullable:"true" get:"user" list:"user"`
|
||||
FastHash string `width:"32" charset:"ascii" nullable:"true" get:"user"`
|
||||
Owner string `width:"255" charset:"ascii" nullable:"true" get:"user"`
|
||||
MinDisk int32 `nullable:"false" default:"0" get:"user" create:"optional" update:"user"`
|
||||
MinRam int32 `nullable:"false" default:"0" get:"user" create:"optional" update:"user"`
|
||||
MinDiskMB int32 `name:"min_disk" nullable:"false" default:"0" get:"user" create:"optional" update:"user"`
|
||||
MinRamMB int32 `name:"min_ram" nullable:"false" default:"0" get:"user" create:"optional" update:"user"`
|
||||
Protected *bool `nullable:"true" list:"user" get:"user" create:"optional" update:"user"`
|
||||
}
|
||||
|
||||
@@ -392,15 +392,14 @@ func (self *SImage) SaveImageFromStream(reader io.Reader) error {
|
||||
|
||||
sp, err := self.saveImageFromStream(localPath, reader)
|
||||
|
||||
virtualSize := int64(0)
|
||||
virtualSizeBytes := int64(0)
|
||||
format := ""
|
||||
img, err := qemuimg.NewQemuImage(localPath)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
format = string(img.Format)
|
||||
virtualSize = img.SizeBytes
|
||||
}
|
||||
format = string(img.Format)
|
||||
virtualSizeBytes = img.SizeBytes
|
||||
|
||||
fastChksum, err := fileutils2.FastCheckSum(localPath)
|
||||
if err != nil {
|
||||
@@ -415,8 +414,8 @@ func (self *SImage) SaveImageFromStream(reader io.Reader) error {
|
||||
if len(format) > 0 {
|
||||
self.DiskFormat = format
|
||||
}
|
||||
if virtualSize > 0 {
|
||||
self.VirtualSize = virtualSize
|
||||
if virtualSizeBytes > 0 {
|
||||
self.MinDiskMB = int32(virtualSizeBytes / 1024 / 1024)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -161,7 +161,7 @@ func (image *SImage) GetOsArch() string {
|
||||
}
|
||||
|
||||
func (image *SImage) GetMinOsDiskSizeGb() int {
|
||||
return 50
|
||||
return image.MinDisk
|
||||
}
|
||||
|
||||
func (image *SImage) GetImageFormat() string {
|
||||
|
||||
Reference in New Issue
Block a user