mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix(region): huawei cloud sync vm os arch
This commit is contained in:
@@ -308,6 +308,7 @@ type ICloudVM interface {
|
||||
GetBootOrder() string
|
||||
GetVga() string
|
||||
GetVdi() string
|
||||
GetOSArch() string
|
||||
GetOSType() string
|
||||
GetOSName() string
|
||||
GetBios() string
|
||||
|
||||
@@ -2532,6 +2532,7 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
|
||||
self.BootOrder = extVM.GetBootOrder()
|
||||
self.Vga = extVM.GetVga()
|
||||
self.Vdi = extVM.GetVdi()
|
||||
self.OsArch = extVM.GetOSArch()
|
||||
self.OsType = extVM.GetOSType()
|
||||
self.Bios = extVM.GetBios()
|
||||
self.Machine = extVM.GetMachine()
|
||||
@@ -2620,6 +2621,7 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient.
|
||||
guest.BootOrder = extVM.GetBootOrder()
|
||||
guest.Vga = extVM.GetVga()
|
||||
guest.Vdi = extVM.GetVdi()
|
||||
guest.OsArch = extVM.GetOSArch()
|
||||
guest.OsType = extVM.GetOSType()
|
||||
guest.Bios = extVM.GetBios()
|
||||
guest.Machine = extVM.GetMachine()
|
||||
|
||||
@@ -167,7 +167,11 @@ func (self *SImage) GetSizeByte() int64 {
|
||||
|
||||
func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
|
||||
if self.imgInfo == nil {
|
||||
imgInfo := imagetools.NormalizeImageInfo(self.ImageSourceType, self.OSType, self.OSType, self.Platform, "")
|
||||
arch := "x86"
|
||||
if strings.ToLower(self.SupportArm) == "true" {
|
||||
arch = "arm"
|
||||
}
|
||||
imgInfo := imagetools.NormalizeImageInfo(self.ImageSourceType, arch, self.OSType, self.Platform, "")
|
||||
self.imgInfo = &imgInfo
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"yunion.io/x/pkg/util/osprofile"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -113,6 +114,7 @@ type SInstance struct {
|
||||
Status string `json:"status"`
|
||||
Progress string `json:"progress"`
|
||||
HostID string `json:"hostId"`
|
||||
Image Image `json:"image"`
|
||||
Updated string `json:"updated"`
|
||||
Created time.Time `json:"created"`
|
||||
Metadata VMMetadata `json:"metadata"`
|
||||
@@ -476,6 +478,26 @@ func (self *SInstance) GetVdi() string {
|
||||
return "vnc"
|
||||
}
|
||||
|
||||
func (self *SInstance) GetOSArch() string {
|
||||
if len(self.Image.ID) > 0 {
|
||||
image, err := self.host.zone.region.GetImage(self.Image.ID)
|
||||
if err == nil {
|
||||
return image.GetOsArch()
|
||||
}
|
||||
|
||||
log.Debugf("GetOSArch.GetImage %s: %s", self.Image.ID, err)
|
||||
}
|
||||
|
||||
t := self.GetInstanceType()
|
||||
if len(t) > 0 {
|
||||
if strings.HasPrefix(t, "k") {
|
||||
return apis.OS_ARCH_AARCH64
|
||||
}
|
||||
}
|
||||
|
||||
return apis.OS_ARCH_X86
|
||||
}
|
||||
|
||||
func (self *SInstance) GetOSType() string {
|
||||
return osprofile.NormalizeOSType(self.Metadata.OSType)
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"yunion.io/x/pkg/util/osprofile"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -467,6 +468,23 @@ func (self *SInstance) GetVdi() string {
|
||||
return "vnc"
|
||||
}
|
||||
|
||||
func (self *SInstance) GetOSArch() string {
|
||||
if flavor, err := self.host.zone.region.GetICloudSku(self.Flavor.ID); err == nil {
|
||||
return flavor.GetCpuArch()
|
||||
} else {
|
||||
log.Debugf("GetOSArch.GetICloudSku %s: %s", self.Flavor.ID, err)
|
||||
}
|
||||
|
||||
t := self.GetInstanceType()
|
||||
if len(t) > 0 {
|
||||
if strings.HasPrefix(t, "k") {
|
||||
return apis.OS_ARCH_AARCH64
|
||||
}
|
||||
}
|
||||
|
||||
return apis.OS_ARCH_X86
|
||||
}
|
||||
|
||||
func (self *SInstance) GetOSType() string {
|
||||
return osprofile.NormalizeOSType(self.Metadata.OSType)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package huaweistack
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
// https://support.huaweicloud.com/api-ecs/zh-cn_topic_0020212656.html
|
||||
@@ -35,8 +37,9 @@ type SInstanceType struct {
|
||||
}
|
||||
|
||||
type OSExtraSpecs struct {
|
||||
EcsPerformancetype string `json:"ecs:performancetype"`
|
||||
EcsGeneration string `json:"ecs:generation"`
|
||||
EcsPerformancetype string `json:"ecs:performancetype"`
|
||||
EcsGeneration string `json:"ecs:generation"`
|
||||
EcsInstanceArchitecture string `json:"ecs:instance_architecture"`
|
||||
}
|
||||
|
||||
var FLAVOR_FAMILY_CATEGORY_MAP = map[string]string{
|
||||
@@ -170,11 +173,21 @@ func (self *SInstanceType) GetPostpaidStatus() string {
|
||||
// https://support.huaweicloud.com/productdesc-ecs/ecs_01_0066.html
|
||||
// https://support.huaweicloud.com/ecs_faq/ecs_faq_0105.html
|
||||
func (self *SInstanceType) GetCpuArch() string {
|
||||
if strings.HasPrefix(self.ID, "k") {
|
||||
return "aarch64"
|
||||
if len(self.OSExtraSpecs.EcsInstanceArchitecture) > 0 {
|
||||
if strings.ToLower(self.OSExtraSpecs.EcsInstanceArchitecture) == "arm64" {
|
||||
return apis.OS_ARCH_AARCH64
|
||||
}
|
||||
|
||||
if strings.HasPrefix(self.OSExtraSpecs.EcsInstanceArchitecture, "arm") {
|
||||
return apis.OS_ARCH_AARCH64
|
||||
}
|
||||
}
|
||||
|
||||
return "x86"
|
||||
if strings.HasPrefix(self.ID, "k") {
|
||||
return apis.OS_ARCH_AARCH64
|
||||
}
|
||||
|
||||
return apis.OS_ARCH_X86
|
||||
}
|
||||
|
||||
func (self *SInstanceType) GetCpuCoreCount() int {
|
||||
|
||||
@@ -52,6 +52,7 @@ type SRegion struct {
|
||||
|
||||
izones []cloudprovider.ICloudZone
|
||||
ivpcs []cloudprovider.ICloudVpc
|
||||
iskus []cloudprovider.ICloudSku
|
||||
|
||||
storageCache *SStoragecache
|
||||
}
|
||||
@@ -979,6 +980,10 @@ func (region *SRegion) GetIBucketByName(name string) (cloudprovider.ICloudBucket
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSkus(zoneId string) ([]cloudprovider.ICloudSku, error) {
|
||||
if self.iskus != nil {
|
||||
return self.iskus, nil
|
||||
}
|
||||
|
||||
ret := make([]cloudprovider.ICloudSku, 0)
|
||||
flavors, err := self.fetchInstanceTypes(zoneId)
|
||||
if err != nil {
|
||||
@@ -989,9 +994,25 @@ func (self *SRegion) GetSkus(zoneId string) ([]cloudprovider.ICloudSku, error) {
|
||||
ret = append(ret, &flavors[i])
|
||||
}
|
||||
|
||||
self.iskus = ret
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetICloudSku(skuId string) (cloudprovider.ICloudSku, error) {
|
||||
skus, err := self.GetSkus("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range skus {
|
||||
if skus[i].GetId() == skuId {
|
||||
return skus[i], nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.Wrap(cloudprovider.ErrNotFound, "GetICloudSku")
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIElasticcaches() ([]cloudprovider.ICloudElasticcache, error) {
|
||||
caches, err := self.GetElasticCaches()
|
||||
if err != nil {
|
||||
|
||||
@@ -70,3 +70,7 @@ func (self *SInstanceBase) SaveImage(opts *cloudprovider.SaveImageOptions) (clou
|
||||
func (self *SInstanceBase) AllocatePublicIpAddress() (string, error) {
|
||||
return "", errors.Wrapf(cloudprovider.ErrNotImplemented, "AllocatePublicIpAddress")
|
||||
}
|
||||
|
||||
func (self *SInstanceBase) GetOSArch() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user