Merge pull request #12054 from ioito/automated-cherry-pick-of-#12053-upstream-release-3.8

Automated cherry pick of #12053: fix(region): sync vm os type
This commit is contained in:
Zexi Li
2021-08-30 15:04:25 +08:00
committed by GitHub
41 changed files with 104 additions and 468 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ func CloudImage2Image(image ICloudImage) SImage {
MinRamMB: image.GetMinRamSizeMb(),
Name: image.GetName(),
Properties: map[string]string{
"os_type": image.GetOsType(),
"os_type": string(image.GetOsType()),
"os_distribution": image.GetOsDist(),
"os_version": image.GetOsVersion(),
"os_arch": image.GetOsArch(),
+7
View File
@@ -26,6 +26,13 @@ import (
"yunion.io/x/onecloud/pkg/util/seclib2"
)
type TOsType string
var (
OsTypeLinux = TOsType(osprofile.OS_TYPE_LINUX)
OsTypeWindows = TOsType(osprofile.OS_TYPE_WINDOWS)
)
type SDistDefaultAccount struct {
// 操作系统发行版
OsDistribution string
+3 -3
View File
@@ -213,7 +213,7 @@ type ICloudImage interface {
GetSizeByte() int64
GetImageType() TImageType
GetImageStatus() string
GetOsType() string
GetOsType() TOsType
GetOsDist() string
GetOsVersion() string
GetOsArch() string
@@ -333,7 +333,7 @@ type ICloudVM interface {
GetVga() string
GetVdi() string
GetOSArch() string
GetOSType() string
GetOsType() TOsType
GetOSName() string
GetBios() string
GetMachine() string
@@ -1458,7 +1458,7 @@ type ICloudApp interface {
GetTechStack() string
GetType() string
GetKind() string
GetOsType() string
GetOsType() TOsType
}
type ICloudAppEnvironment interface {
+1 -1
View File
@@ -48,7 +48,7 @@ type SDiskInfo struct {
func fetchIVMinfo(desc cloudprovider.SManagedVMCreateConfig, iVM cloudprovider.ICloudVM, guestId string, account, passwd string, publicKey string, action string) *jsonutils.JSONDict {
data := jsonutils.NewDict()
data.Add(jsonutils.NewString(iVM.GetOSType()), "os")
data.Add(jsonutils.NewString(string(iVM.GetOsType())), "os")
//避免在rebuild_root时绑定秘钥,没有account信息
data.Add(jsonutils.NewString(account), "account")
+2 -2
View File
@@ -2427,7 +2427,7 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
self.Vga = extVM.GetVga()
self.Vdi = extVM.GetVdi()
self.OsArch = extVM.GetOSArch()
self.OsType = extVM.GetOSType()
self.OsType = string(extVM.GetOsType())
self.Bios = extVM.GetBios()
self.Machine = extVM.GetMachine()
if !recycle {
@@ -2507,7 +2507,7 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient.
guest.Vga = extVM.GetVga()
guest.Vdi = extVM.GetVdi()
guest.OsArch = extVM.GetOSArch()
guest.OsType = extVM.GetOSType()
guest.OsType = string(extVM.GetOsType())
guest.Bios = extVM.GetBios()
guest.Machine = extVM.GetMachine()
guest.Hypervisor = extVM.GetHypervisor()
+2 -11
View File
@@ -84,15 +84,6 @@ func (self *SImage) GetMinRamSizeMb() int {
return 0
}
func (self *SImage) GetSysTags() map[string]string {
data := map[string]string{}
data["os_arch"] = self.Architecture
data["os_name"] = self.GetOsType()
data["os_distribution"] = self.Platform
data["os_version"] = self.OSName
return data
}
func (self *SImage) GetId() string {
return self.ImageId
}
@@ -178,8 +169,8 @@ func (self *SImage) GetSizeByte() int64 {
return int64(self.Size) * 1024 * 1024 * 1024
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
+2 -21
View File
@@ -179,25 +179,6 @@ func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
return self.SecurityGroupIds.SecurityGroupId, nil
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
if len(self.ImageId) > 0 {
if image, err := self.host.zone.region.GetImage(self.ImageId); err != nil {
log.Errorf("Failed to find image %s for instance %s", self.ImageId, self.GetName())
} else {
imageSysTags := image.GetSysTags()
for k, v := range imageSysTags {
data[k] = v
}
}
}
sys := self.AliyunTags.GetSysTags()
for k, v := range sys {
data[k] = v
}
return data
}
func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
return self.host
}
@@ -327,8 +308,8 @@ func (self *SInstance) GetVdi() string {
return "vnc"
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.OSType)
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.OSType))
}
func (self *SInstance) GetOSName() string {
+2 -11
View File
@@ -84,15 +84,6 @@ func (self *SImage) GetMinRamSizeMb() int {
return 0
}
func (self *SImage) GetSysTags() map[string]string {
data := map[string]string{}
data["os_arch"] = self.Architecture
data["os_name"] = self.GetOsType()
data["os_distribution"] = self.Platform
data["os_version"] = self.OSName
return data
}
func (self *SImage) GetId() string {
return self.ImageId
}
@@ -187,8 +178,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
+2 -90
View File
@@ -167,98 +167,10 @@ func (self *SRegion) GetInstances(zoneId string, ids []string, offset int, limit
return instances, int(total), nil
}
func (self *SRegion) fetchTags(resourceType string, resourceId string) (*jsonutils.JSONDict, error) {
// 资源类型。取值范围:
// disk
// instance
// image
// securitygroup
// snapshot
var page int64 = 1
var pageSize int64 = 50
params := make(map[string]string)
params["RegionId"] = self.RegionId
params["ResourceType"] = resourceType
params["ResourceId"] = resourceId
params["PageSize"] = fmt.Sprintf("%d", pageSize)
params["PageNumber"] = fmt.Sprintf("%d", page)
ret, err := self.ecsRequest("DescribeTags", params)
if err != nil {
return nil, err
}
tags := jsonutils.NewDict()
result, _ := ret.GetArray("Tags", "Tag")
for _, item := range result {
k, _ := item.GetString("TagKey")
v, _ := item.Get("TagValue")
if len(k) > 0 {
tags.Set(k, v)
}
}
total, _ := ret.Int("TotalCount")
for ; total > page*pageSize; page++ {
params["PageSize"] = fmt.Sprintf("%d", pageSize)
params["PageNumber"] = fmt.Sprintf("%d", page)
ret, err := self.ecsRequest("DescribeTags", params)
if err != nil {
return nil, err
}
result, _ := ret.GetArray("Tags", "Tag")
for _, item := range result {
k, _ := item.GetString("TagKey")
v, _ := item.Get("TagValue")
if len(k) > 0 {
tags.Set(k, v)
}
}
}
return tags, nil
}
func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
return self.SecurityGroupIds.SecurityGroupId, nil
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
// The pricingInfo key structure is 'RegionId::InstanceType::NetworkType::OSType::IoOptimized'
optimized := "optimized"
if !self.IoOptimized {
optimized = "none"
}
priceKey := fmt.Sprintf("%s::%s::%s::%s::%s", self.RegionId, self.InstanceType, self.InstanceNetworkType, self.OSType, optimized)
data["price_key"] = priceKey
data["zone_ext_id"] = self.host.zone.GetGlobalId()
if len(self.ImageId) > 0 {
if image, err := self.host.zone.region.GetImage(self.ImageId); err != nil {
log.Errorf("Failed to find image %s for instance %s", self.ImageId, self.GetName())
} else {
imageSysTags := image.GetSysTags()
for k, v := range imageSysTags {
data[k] = v
}
}
}
return data
}
func (self *SInstance) GetTags() (map[string]string, error) {
tags, err := self.host.zone.region.fetchTags("instance", self.InstanceId)
if err != nil {
return nil, errors.Wrap(err, "self.host.zone.region.fetchTags")
}
data := map[string]string{}
err = tags.Unmarshal(&data)
if err != nil {
return nil, errors.Wrap(err, "tags.Unmarshal")
}
return data, nil
}
func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
return self.host
}
@@ -379,8 +291,8 @@ func (self *SInstance) GetVdi() string {
return "vnc"
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.OSType)
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.OSType))
}
func (self *SInstance) GetOSName() string {
+2 -11
View File
@@ -242,8 +242,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsArch() string {
@@ -274,15 +274,6 @@ func (self *SImage) IsEmulated() bool {
return false
}
func (self *SImage) GetSysTags() map[string]string {
data := map[string]string{}
data["os_arch"] = self.Architecture
data["os_name"] = self.OSType
data["os_distribution"] = self.OSDist
data["os_version"] = self.OSVersion
return data
}
func (self *SImage) Delete(ctx context.Context) error {
// todo: implement me
return self.storageCache.region.DeleteImage(self.ImageId)
+8 -29
View File
@@ -212,35 +212,14 @@ func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
return self.SecurityGroupIds.SecurityGroupId, nil
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
priceKey := fmt.Sprintf("%s::%s::%s::NA::NA::shared::boxusage", self.RegionId, self.InstanceType, strings.ToLower(self.OSType))
data["price_key"] = priceKey
data["zone_ext_id"] = self.host.zone.GetGlobalId()
if strings.Contains(strings.ToLower(self.OSType), "window") {
if loginKey, err := self.host.zone.region.getPasswordData(self.GetId()); err == nil {
data["login_key"] = loginKey
}
}
ec2Client, err := self.host.zone.region.getEc2Client()
if err != nil {
return data
}
// Name tag
tags, err := FetchTags(ec2Client, self.InstanceId)
if err == nil {
name, err := tags.GetString("Name")
if err == nil {
data["Name"] = name
}
}
return data
}
func (self *SInstance) GetTags() (map[string]string, error) {
return self.TagSpec.GetTags()
}
func (self *SInstance) GetSysTags() map[string]string {
return map[string]string{}
}
func (self *SInstance) GetBillingType() string {
// todo: implement me
return billing_api.BILLING_TYPE_POSTPAID
@@ -331,8 +310,8 @@ func (self *SInstance) GetVdi() string {
return "vnc"
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.OSType)
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.OSType))
}
func (self *SInstance) GetOSName() string {
@@ -452,8 +431,8 @@ func (self *SInstance) RebuildRoot(ctx context.Context, desc *cloudprovider.SMan
}
userdata := ""
srcOsType := strings.ToLower(self.GetOSType())
destOsType := strings.ToLower(image.GetOsType())
srcOsType := strings.ToLower(string(self.GetOsType()))
destOsType := strings.ToLower(string(image.GetOsType()))
winOS := strings.ToLower(osprofile.OS_TYPE_WINDOWS)
cloudconfig := &cloudinit.SCloudConfig{}
+2 -2
View File
@@ -337,8 +337,8 @@ func (self *SClassicInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
return ret, nil
}
func (self *SClassicInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.Properties.StorageProfile.OperatingSystemDisk.OperatingSystem)
func (self *SClassicInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.Properties.StorageProfile.OperatingSystemDisk.OperatingSystem))
}
func (self *SClassicInstance) GetINics() ([]cloudprovider.ICloudNic, error) {
+1 -1
View File
@@ -90,7 +90,7 @@ func (self *SRegion) _createVM(desc *cloudprovider.SManagedVMCreateConfig, nicId
return nil, fmt.Errorf("image %s not ready status: %s", desc.ExternalImageId, image.Properties.ProvisioningState)
}
if !utils.IsInStringArray(desc.OsType, []string{osprofile.OS_TYPE_LINUX, osprofile.OS_TYPE_WINDOWS}) {
desc.OsType = image.GetOsType()
desc.OsType = string(image.GetOsType())
}
computeName := desc.Name
for _, k := range "`~!@#$%^&*()=+_[]{}\\|;:.'\",<>/?" {
+2 -2
View File
@@ -166,12 +166,12 @@ func (self *SImage) GetSizeByte() int64 {
return int64(self.Properties.StorageProfile.OsDisk.DiskSizeGB) * 1024 * 1024 * 1024
}
func (self *SImage) GetOsType() string {
func (self *SImage) GetOsType() cloudprovider.TOsType {
osType := self.Properties.StorageProfile.OsDisk.OsType
if len(osType) == 0 {
osType = publisherGetOsType(self.Publisher)
}
return osType
return cloudprovider.TOsType(osType)
}
func (self *SImage) GetOsArch() string {
+4 -4
View File
@@ -494,7 +494,7 @@ func (self *SInstance) DeployVM(ctx context.Context, name string, username strin
return err
}
}
return self.host.zone.region.DeployVM(ctx, self.ID, self.GetOSType(), name, password, publicKey, deleteKeypair, description)
return self.host.zone.region.DeployVM(ctx, self.ID, string(self.GetOsType()), name, password, publicKey, deleteKeypair, description)
}
type VirtualMachineExtensionProperties struct {
@@ -839,8 +839,8 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) {
return disks, nil
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(string(self.Properties.StorageProfile.OsDisk.OsType))
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(string(self.Properties.StorageProfile.OsDisk.OsType)))
}
func (self *SRegion) getOvsEnv(instanceId string) (string, error) {
@@ -1083,7 +1083,7 @@ func (self *SInstance) SaveImage(opts *cloudprovider.SaveImageOptions) (cloudpro
if self.Properties.StorageProfile.OsDisk.ManagedDisk == nil {
return nil, fmt.Errorf("invalid os disk for save image")
}
image, err := self.host.zone.region.SaveImage(self.GetOSType(), self.Properties.StorageProfile.OsDisk.ManagedDisk.ID, opts)
image, err := self.host.zone.region.SaveImage(string(self.GetOsType()), self.Properties.StorageProfile.OsDisk.ManagedDisk.ID, opts)
if err != nil {
return nil, errors.Wrapf(err, "SaveImage")
}
+3 -3
View File
@@ -294,9 +294,9 @@ func (a *SApp) GetKind() string {
return a.Kind
}
func (a *SApp) GetOsType() string {
func (a *SApp) GetOsType() cloudprovider.TOsType {
if strings.Contains(a.Kind, "linux") {
return "Linux"
return cloudprovider.OsTypeLinux
}
return "Windows"
return cloudprovider.OsTypeWindows
}
+3 -3
View File
@@ -82,12 +82,12 @@ func (self *SImage) GetImageStatus() string {
return self.Status
}
func (self *SImage) GetOsType() string {
func (self *SImage) GetOsType() cloudprovider.TOsType {
osType, ok := self.Properties["os_type"]
if ok {
return osType
return cloudprovider.TOsType(osType)
}
return "linux"
return cloudprovider.OsTypeLinux
}
func (self *SImage) GetOsDist() string {
+2 -2
View File
@@ -127,8 +127,8 @@ func (self *SInstance) GetVdi() string {
return self.Vdi
}
func (self *SInstance) GetOSType() string {
return self.OsType
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.OsType)
}
func (self *SInstance) GetOSName() string {
+2 -19
View File
@@ -87,23 +87,6 @@ func (self *SImage) IsEmulated() bool {
return false
}
func (self *SImage) GetSysTags() map[string]string {
data := map[string]string{}
if self.OSBit > 0 {
data["os_arch"] = self.GetOsArch()
}
if len(self.OSType) > 0 {
data["os_name"] = self.GetOsType()
}
if len(self.Platform) > 0 {
data["os_distribution"] = self.GetOsDist()
}
data["os_version"] = self.GetOsVersion()
return data
}
func (self *SImage) Delete(ctx context.Context) error {
return cloudprovider.ErrNotSupported
}
@@ -142,8 +125,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
+3 -25
View File
@@ -182,27 +182,6 @@ func (self *SInstance) IsEmulated() bool {
return false
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
lowerOs := self.GetOSType()
if strings.HasPrefix(lowerOs, "win") {
lowerOs = "win"
}
priceKey := fmt.Sprintf("%s::%s::%s", self.host.zone.region.GetId(), self.GetInstanceType(), lowerOs)
data["price_key"] = priceKey
data["zone_ext_id"] = self.host.zone.GetGlobalId()
image, _ := self.GetImage()
if image != nil {
meta := image.GetSysTags()
for k, v := range meta {
data[k] = v
}
}
return data
}
func (self *SInstance) GetProjectId() string {
return ""
}
@@ -333,14 +312,13 @@ func (self *SInstance) GetImage() (*SImage, error) {
return self.image, nil
}
func (self *SInstance) GetOSType() string {
func (self *SInstance) GetOsType() cloudprovider.TOsType {
image, err := self.GetImage()
if err != nil {
log.Errorf("SInstance.GetOSType %s", err)
return ""
return cloudprovider.OsTypeLinux
}
return image.OSType
return cloudprovider.TOsType(image.OSType)
}
func (self *SInstance) GetOSName() string {
+2 -17
View File
@@ -124,23 +124,8 @@ func (i *SImage) IsEmulated() bool {
return false
}
func (i *SImage) GetSysTags() map[string]string {
data := map[string]string{}
if osType := i.GetOsType(); len(osType) > 0 {
data["os_type"] = osType
}
if len(i.OsName) > 0 {
data["os_name"] = i.OsName
}
if osDis := i.GetOsDist(); len(osDis) > 0 {
data["os_distribution"] = osDis
}
return data
}
func (i *SImage) GetOsType() string {
return i.OsType
func (i *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(i.OsType)
}
func (i *SImage) GetOsDist() string {
+2 -21
View File
@@ -156,8 +156,8 @@ func (i *SInstance) GetImage() (*SImage, error) {
return i.image, nil
}
func (i *SInstance) GetOSType() string {
return i.ImageOsType
func (i *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(i.ImageOsType)
}
func (i *SInstance) GetOSName() string {
@@ -180,25 +180,6 @@ func (i *SInstance) GetInstanceType() string {
return i.FlavorRef
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
// TODO
lowerOs := self.GetOSType()
priceKey := fmt.Sprintf("%s::%s::%s", self.host.zone.region.GetId(), self.GetInstanceType(), lowerOs)
data["price_key"] = priceKey
data["zone_ext_id"] = self.host.zone.GetGlobalId()
image, _ := self.GetImage()
if image != nil {
meta := image.GetSysTags()
for k, v := range meta {
data[k] = v
}
}
return data
}
func (in *SInstance) GetProjectId() string {
return ""
}
+2 -2
View File
@@ -110,8 +110,8 @@ func (self *SImage) GetSizeByte() int64 {
return self.size
}
func (self *SImage) GetOsType() string {
return ""
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.OsTypeLinux
}
func (self *SImage) GetOsDist() string {
+2 -2
View File
@@ -146,8 +146,8 @@ func (t *SVMTemplate) GetImageStatus() string {
return cloudprovider.IMAGE_STATUS_DELETED
}
func (t *SVMTemplate) GetOsType() string {
return t.vm.GetOSType()
func (t *SVMTemplate) GetOsType() cloudprovider.TOsType {
return t.vm.GetOsType()
}
func (t *SVMTemplate) GetOsDist() string {
+3 -3
View File
@@ -355,11 +355,11 @@ func (self *SVirtualMachine) GetGuestToolsRunningStatus() string {
return string(moVM.Guest.ToolsRunningStatus)
}
func (self *SVirtualMachine) GetOSType() string {
func (self *SVirtualMachine) GetOsType() cloudprovider.TOsType {
if osInfo, ok := GuestOsInfo[self.GetGuestId()]; ok {
return string(osInfo.OsType)
return cloudprovider.TOsType(osInfo.OsType)
}
return ""
return cloudprovider.OsTypeLinux
}
func (self *SVirtualMachine) GetOSName() string {
+2 -2
View File
@@ -174,8 +174,8 @@ func (image *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return image.imgInfo
}
func (image *SImage) GetOsType() string {
return image.getNormalizedImageInfo().OsType
func (image *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(image.getNormalizedImageInfo().OsType)
}
func (image *SImage) GetOsDist() string {
+4 -5
View File
@@ -24,7 +24,6 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/fileutils"
"yunion.io/x/pkg/util/osprofile"
"yunion.io/x/pkg/utils"
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
@@ -287,19 +286,19 @@ func (instance *SInstance) GetVdi() string {
return "vnc"
}
func (instance *SInstance) GetOSType() string {
func (instance *SInstance) GetOsType() cloudprovider.TOsType {
for _, disk := range instance.Disks {
if disk.Index == 0 {
for _, license := range disk.Licenses {
if strings.Index(strings.ToLower(license), "windows") < 0 {
return osprofile.OS_TYPE_LINUX
return cloudprovider.OsTypeWindows
} else {
return osprofile.OS_TYPE_WINDOWS
return cloudprovider.OsTypeLinux
}
}
}
}
return osprofile.OS_TYPE_LINUX
return cloudprovider.OsTypeLinux
}
func (instance *SInstance) GetOSName() string {
+2 -19
View File
@@ -178,8 +178,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
@@ -210,23 +210,6 @@ func (self *SImage) IsEmulated() bool {
return false
}
func (self *SImage) GetSysTags() map[string]string {
data := map[string]string{}
if len(self.OSBit) > 0 {
data["os_arch"] = self.GetOsArch()
}
if len(self.OSType) > 0 {
data["os_name"] = self.GetOsType()
}
if len(self.Platform) > 0 {
data["os_distribution"] = self.GetOsDist()
}
if len(self.OSVersion) > 0 {
data["os_version"] = self.GetOsVersion()
}
return data
}
func (self *SImage) Delete(ctx context.Context) error {
return self.storageCache.region.DeleteImage(self.GetId())
}
+2 -25
View File
@@ -254,29 +254,6 @@ func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
return self.host.zone.region.GetInstanceSecrityGroupIds(self.GetId())
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
// cn-north-1::et2.2xlarge.16::win
lowerOs := self.GetOSType()
if strings.HasPrefix(lowerOs, "win") {
lowerOs = "win"
}
priceKey := fmt.Sprintf("%s::%s::%s", self.host.zone.region.GetId(), self.GetInstanceType(), lowerOs)
data["price_key"] = priceKey
data["zone_ext_id"] = self.host.zone.GetGlobalId()
if len(self.Metadata.MeteringImageID) > 0 {
if image, err := self.host.zone.region.GetImage(self.Metadata.MeteringImageID); err != nil {
log.Errorf("Failed to find image %s for instance %s zone %s", self.Metadata.MeteringImageID, self.GetId(), self.OSEXTAZAvailabilityZone)
} else {
meta := image.GetSysTags()
for k, v := range meta {
data[k] = v
}
}
}
return data
}
// https://support.huaweicloud.com/api-ecs/ecs_02_1002.html
// key 相同时value不会替换
func (self *SRegion) CreateServerTags(instanceId string, tags map[string]string) error {
@@ -498,8 +475,8 @@ func (self *SInstance) GetOSArch() string {
return apis.OS_ARCH_X86
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.Metadata.OSType)
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.Metadata.OSType))
}
func (self *SInstance) GetOSName() string {
+2 -19
View File
@@ -178,8 +178,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
@@ -210,23 +210,6 @@ func (self *SImage) IsEmulated() bool {
return false
}
func (self *SImage) GetSysTags() map[string]string {
data := map[string]string{}
if len(self.OSBit) > 0 {
data["os_arch"] = self.GetOsArch()
}
if len(self.OSType) > 0 {
data["os_name"] = self.GetOsType()
}
if len(self.Platform) > 0 {
data["os_distribution"] = self.GetOsDist()
}
if len(self.OSVersion) > 0 {
data["os_version"] = self.GetOsVersion()
}
return data
}
func (self *SImage) Delete(ctx context.Context) error {
return self.storageCache.region.DeleteImage(self.GetId())
}
+2 -25
View File
@@ -253,29 +253,6 @@ func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
return self.host.zone.region.GetInstanceSecrityGroupIds(self.GetId())
}
func (self *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
// cn-north-1::et2.2xlarge.16::win
lowerOs := self.GetOSType()
if strings.HasPrefix(lowerOs, "win") {
lowerOs = "win"
}
priceKey := fmt.Sprintf("%s::%s::%s", self.host.zone.region.GetId(), self.GetInstanceType(), lowerOs)
data["price_key"] = priceKey
data["zone_ext_id"] = self.host.zone.GetGlobalId()
if len(self.Metadata.MeteringImageID) > 0 {
if image, err := self.host.zone.region.GetImage(self.Metadata.MeteringImageID); err != nil {
log.Errorf("Failed to find image %s for instance %s zone %s", self.Metadata.MeteringImageID, self.GetId(), self.OSEXTAZAvailabilityZone)
} else {
meta := image.GetSysTags()
for k, v := range meta {
data[k] = v
}
}
}
return data
}
// https://support.huaweicloud.com/api-ecs/ecs_02_1002.html
// key 相同时value不会替换
func (self *SRegion) CreateServerTags(instanceId string, tags map[string]string) error {
@@ -489,8 +466,8 @@ func (self *SInstance) GetOSArch() string {
return apis.OS_ARCH_X86
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.Metadata.OSType)
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.Metadata.OSType))
}
func (self *SInstance) GetOSName() string {
+2 -11
View File
@@ -84,17 +84,8 @@ func (i *SImage) IsEmulated() bool {
return false
}
func (i *SImage) GetSysTags() map[string]string {
return map[string]string{
"os_arch": i.Architecture,
"os_name": i.OsType,
"os_distribution": i.Platform,
"os_version": i.OsVersion,
}
}
func (i *SImage) GetOsType() string {
return i.OsType
func (i *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(i.OsType)
}
func (i *SImage) GetOsDist() string {
+2 -21
View File
@@ -125,10 +125,10 @@ func (i *SInstance) GetImage() (*SImage, error) {
return i.image, nil
}
func (i *SInstance) GetOSType() string {
func (i *SInstance) GetOsType() cloudprovider.TOsType {
image, err := i.GetImage()
if err != nil {
return ""
return cloudprovider.OsTypeLinux
}
return image.GetOsType()
}
@@ -153,25 +153,6 @@ func (i *SInstance) GetInstanceType() string {
return i.InstanceType
}
func (i *SInstance) GetSysTags() map[string]string {
data := map[string]string{}
// TODO
lowerOs := i.GetOSType()
priceKey := fmt.Sprintf("%s::%s::%s", i.host.zone.region.GetId(), i.GetInstanceType(), lowerOs)
data["price_key"] = priceKey
data["zone_ext_id"] = i.host.zone.GetGlobalId()
image, _ := i.GetImage()
if image != nil {
meta := image.GetSysTags()
for k, v := range meta {
data[k] = v
}
}
return data
}
func (in *SInstance) GetProjectId() string {
return ""
}
+2 -2
View File
@@ -221,8 +221,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (image *SImage) GetOsType() string {
return image.getNormalizedImageInfo().OsType
func (image *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(image.getNormalizedImageInfo().OsType)
}
func (image *SImage) GetOsDist() string {
+3 -5
View File
@@ -25,7 +25,6 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/osprofile"
billing_api "yunion.io/x/onecloud/pkg/apis/billing"
api "yunion.io/x/onecloud/pkg/apis/compute"
@@ -324,19 +323,18 @@ func (instance *SInstance) GetVdi() string {
return "vnc"
}
func (instance *SInstance) GetOSType() string {
func (instance *SInstance) GetOsType() cloudprovider.TOsType {
if instance.Image != nil {
imageId, _ := instance.Image.GetString("id")
if len(imageId) > 0 {
image, err := instance.host.zone.region.GetImage(imageId)
if err != nil {
log.Errorf("GetImage %s", imageId)
return osprofile.OS_TYPE_LINUX
return cloudprovider.OsTypeLinux
}
return image.GetOsType()
}
}
return osprofile.OS_TYPE_LINUX
return cloudprovider.OsTypeLinux
}
func (instance *SInstance) GetOSName() string {
+2 -2
View File
@@ -196,8 +196,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
+6 -20
View File
@@ -355,25 +355,11 @@ func (self *SInstance) GetVdi() string {
return "vnc"
}
func (self *SInstance) GetOSType() string {
if self.image == nil {
image, err := self.host.zone.region.GetImage(self.ImageId)
if err != nil {
return self.OsName
}
self.image = image
func (self *SInstance) GetOsType() cloudprovider.TOsType {
if strings.Contains(strings.ToLower(self.OsName), "win") {
return cloudprovider.OsTypeWindows
}
if self.image != nil {
switch self.image.Platform {
case "Windows":
return "Windows"
case "CentOS", "Debian", "FreeBSD", "SUSE", "openSUSE":
return "Linux"
default:
return "Linux"
}
}
return self.OsName
return cloudprovider.OsTypeLinux
}
func (self *SInstance) GetOSName() string {
@@ -473,7 +459,7 @@ func (self *SInstance) GetVNCInfo() (jsonutils.JSONObject, error) {
}
func (self *SInstance) UpdateVM(ctx context.Context, name string) error {
return self.host.zone.region.UpdateVM(self.InstanceId, name, self.GetOSType())
return self.host.zone.region.UpdateVM(self.InstanceId, name)
}
func (self *SInstance) DeployVM(ctx context.Context, name string, username string, password string, publicKey string, deleteKeypair bool, description string) error {
@@ -842,7 +828,7 @@ func (self *SInstance) DeleteVM(ctx context.Context) error {
return cloudprovider.WaitDeleted(self, 10*time.Second, 5*time.Minute) // 5minutes
}
func (self *SRegion) UpdateVM(instanceId string, name, osType string) error {
func (self *SRegion) UpdateVM(instanceId string, name string) error {
params := make(map[string]string)
params["InstanceName"] = name
return self.modifyInstanceAttribute(instanceId, params)
+2 -20
View File
@@ -93,24 +93,6 @@ func (self *SImage) IsEmulated() bool {
return false
}
func (self *SImage) GetSysTags() map[string]string {
imageInfo := imagetools.NormalizeImageInfo(self.ImageName, "", "", "", "")
data := map[string]string{}
if len(imageInfo.OsArch) > 0 {
data["os_arch"] = imageInfo.OsArch
}
if len(imageInfo.OsType) > 0 {
data["os_name"] = imageInfo.OsType
}
if len(imageInfo.OsDistro) > 0 {
data["os_distribution"] = imageInfo.OsDistro
}
if len(imageInfo.OsVersion) > 0 {
data["os_version"] = imageInfo.OsVersion
}
return data
}
func (self *SImage) Delete(ctx context.Context) error {
return self.storageCache.region.DeleteImage(self.GetId())
}
@@ -159,8 +141,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (self *SImage) GetOsType() string {
return self.getNormalizedImageInfo().OsType
func (self *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(self.getNormalizedImageInfo().OsType)
}
func (self *SImage) GetOsDist() string {
+2 -2
View File
@@ -351,8 +351,8 @@ func (self *SInstance) GetVdi() string {
return "vnc"
}
func (self *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(self.OSType)
func (self *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(self.OSType))
}
func (self *SInstance) GetOSName() string {
+2 -2
View File
@@ -164,8 +164,8 @@ func (self *SImage) getNormalizedImageInfo() *imagetools.ImageInfo {
return self.imgInfo
}
func (image *SImage) GetOsType() string {
return image.getNormalizedImageInfo().OsType
func (image *SImage) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(image.getNormalizedImageInfo().OsType)
}
func (image *SImage) GetOsDist() string {
+2 -2
View File
@@ -218,8 +218,8 @@ func (instance *SInstance) GetVdi() string {
return "vnc"
}
func (instance *SInstance) GetOSType() string {
return osprofile.NormalizeOSType(instance.Platform)
func (instance *SInstance) GetOsType() cloudprovider.TOsType {
return cloudprovider.TOsType(osprofile.NormalizeOSType(instance.Platform))
}
func (instance *SInstance) GetOSName() string {