fix: unify image.min_disk unit to MB

This commit is contained in:
Qiu Jian
2019-02-25 17:04:51 +08:00
parent f878b57fab
commit 92bfe69de1
4 changed files with 15 additions and 16 deletions
+6 -6
View File
@@ -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(),
}
}
+1 -1
View File
@@ -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
+7 -8
View File
@@ -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
})
+1 -1
View File
@@ -161,7 +161,7 @@ func (image *SImage) GetOsArch() string {
}
func (image *SImage) GetMinOsDiskSizeGb() int {
return 50
return image.MinDisk
}
func (image *SImage) GetImageFormat() string {