Merge pull request #1050 from tb365/bugfix/tb-ucloud-fix-0531

ucloud image upload bugfix & storage type fix
This commit is contained in:
yunion-ci-robot
2019-06-06 19:52:51 +08:00
committed by GitHub
6 changed files with 68 additions and 19 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ const (
var (
DISK_TYPES = []string{DISK_TYPE_ROTATE, DISK_TYPE_SSD, DISK_TYPE_HYBRID}
STORAGE_LOCAL_TYPES = []string{STORAGE_LOCAL, STORAGE_BAREMETAL}
STORAGE_LOCAL_TYPES = []string{STORAGE_LOCAL, STORAGE_BAREMETAL, STORAGE_UCLOUD_LOCAL_NORMAL, STORAGE_UCLOUD_LOCAL_SSD, STORAGE_UCLOUD_EXCLUSIVE_LOCAL_DISK}
STORAGE_SUPPORT_TYPES = STORAGE_LOCAL_TYPES
STORAGE_ALL_TYPES = []string{
STORAGE_LOCAL, STORAGE_BAREMETAL, STORAGE_SHEEPDOG,
+12
View File
@@ -47,6 +47,18 @@ func (self *SUCloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb
if sizeGb < 20 || sizeGb > 4000 {
return fmt.Errorf("The %s disk size must be in the range of 20G ~ 4000GB", storage.StorageType)
}
} else if storage.StorageType == api.STORAGE_UCLOUD_LOCAL_SSD {
if sizeGb < 20 || sizeGb > 1000 {
return fmt.Errorf("The %s disk size must be in the range of 20G ~ 1000GB", storage.StorageType)
}
return fmt.Errorf("Not support create/resize %s disk", storage.StorageType)
} else if storage.StorageType == api.STORAGE_UCLOUD_LOCAL_NORMAL {
if sizeGb < 20 || sizeGb > 2000 {
return fmt.Errorf("The %s disk size must be in the range of 20G ~ 2000GB", storage.StorageType)
}
return fmt.Errorf("Not support create/resize %s disk", storage.StorageType)
} else {
return fmt.Errorf("Not support create %s disk", storage.StorageType)
}
+2 -2
View File
@@ -257,8 +257,8 @@ func (self *SHost) _createVM(name, imgId string, sysDisk cloudprovider.SDiskInfo
log.Errorf("GetImage %s fail %s", imgId, err)
return "", err
}
if img.GetStatus() != cloudprovider.IMAGE_STATUS_ACTIVE {
log.Errorf("image %s status %s, expect %s", imgId, img.GetStatus(), cloudprovider.IMAGE_STATUS_ACTIVE)
if img.GetStatus() != api.CACHED_IMAGE_STATUS_READY {
log.Errorf("image %s status %s, expect %s", imgId, img.GetStatus(), api.CACHED_IMAGE_STATUS_READY)
return "", fmt.Errorf("image not ready")
}
+46 -11
View File
@@ -20,6 +20,7 @@ import (
"fmt"
"strings"
"time"
"yunion.io/x/pkg/utils"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
@@ -27,6 +28,7 @@ import (
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/multicloud"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/util/billing"
)
@@ -93,7 +95,9 @@ func (self *SInstance) GetError() error {
type DiskSet struct {
DiskID string `json:"DiskId"`
DiskType string `json:"DiskType"`
Drive string `json:"Drive"`
IsBoot bool `json:"IsBoot"`
Size int `json:"Size"`
Encrypted string `json:"Encrypted"`
Type string `json:"Type"`
@@ -220,10 +224,38 @@ func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
return self.host
}
func (self *SInstance) GetLocalDisk(diskId, storageType string, sizeGB int, isBoot bool) SDisk {
diskType := ""
if isBoot {
diskType = "SystemDisk"
}
disk := SDisk{
SDisk: multicloud.SDisk{},
Status: "Available",
UHostID: self.GetId(),
Name: diskId,
Zone: self.host.zone.GetId(),
DiskType: diskType,
UDiskID: diskId,
UHostName: self.GetName(),
CreateTime: self.CreateTime,
SizeGB: sizeGB,
}
disk.storage = &SStorage{zone: self.host.zone, storageType: storageType}
return disk
}
func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
localDisks := make([]SDisk, 0)
diskIds := make([]string, 0)
for _, disk := range self.DiskSet {
diskIds = append(diskIds, disk.DiskID)
if utils.IsInStringArray(disk.DiskType, []string{api.STORAGE_UCLOUD_LOCAL_NORMAL, api.STORAGE_UCLOUD_LOCAL_SSD}) {
localDisks = append(localDisks, self.GetLocalDisk(disk.DiskID, disk.DiskType, disk.Size, disk.IsBoot))
} else {
diskIds = append(diskIds, disk.DiskID)
}
}
disks, err := self.host.zone.region.GetDisks("", "", diskIds)
@@ -231,19 +263,22 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
return nil, err
}
disks = append(disks, localDisks...)
idisks := make([]cloudprovider.ICloudDisk, len(disks))
for i := 0; i < len(disks); i += 1 {
var category string
if strings.Contains(disks[i].DiskType, "SSD") {
category = api.STORAGE_UCLOUD_CLOUD_SSD
} else {
category = api.STORAGE_UCLOUD_CLOUD_NORMAL
if disks[i].storage == nil {
var category string
if strings.Contains(disks[i].DiskType, "SSD") {
category = api.STORAGE_UCLOUD_CLOUD_SSD
} else {
category = api.STORAGE_UCLOUD_CLOUD_NORMAL
}
storage, err := self.host.zone.getStorageByCategory(category)
if err != nil {
return nil, err
}
disks[i].storage = storage
}
storage, err := self.host.zone.getStorageByCategory(category)
if err != nil {
return nil, err
}
disks[i].storage = storage
idisks[i] = &disks[i]
// 将系统盘放到第0个位置
if disks[i].GetDiskType() == api.DISK_TYPE_SYS {
+5 -5
View File
@@ -22,14 +22,14 @@ import (
"time"
"yunion.io/x/log"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/util/qemuimg"
"yunion.io/x/pkg/utils"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/mcclient"
)
@@ -124,7 +124,7 @@ func (self *SStoragecache) UploadImage(ctx context.Context, userCred mcclient.To
if err != nil {
log.Errorf("GetImageStatus error %s", err)
}
if img.GetStatus() == cloudprovider.IMAGE_STATUS_ACTIVE && !isForce {
if img.GetStatus() == api.CACHED_IMAGE_STATUS_READY && !isForce {
return image.ExternalId, nil
}
} else {
+2
View File
@@ -28,6 +28,8 @@ import (
var StorageTypes = []string{
api.STORAGE_UCLOUD_CLOUD_NORMAL,
api.STORAGE_UCLOUD_CLOUD_SSD,
api.STORAGE_UCLOUD_LOCAL_NORMAL, // 本地盘
api.STORAGE_UCLOUD_LOCAL_SSD, // 本地SSD盘
}
type SZone struct {