diff --git a/pkg/cloudprovider/images.go b/pkg/cloudprovider/images.go index c26e6d2ea4..04b635ccad 100644 --- a/pkg/cloudprovider/images.go +++ b/pkg/cloudprovider/images.go @@ -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(), diff --git a/pkg/cloudprovider/instance.go b/pkg/cloudprovider/instance.go index d0249a3190..549cbc5dd3 100644 --- a/pkg/cloudprovider/instance.go +++ b/pkg/cloudprovider/instance.go @@ -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 diff --git a/pkg/cloudprovider/resources.go b/pkg/cloudprovider/resources.go index 7a493fc561..5fbbddabd4 100644 --- a/pkg/cloudprovider/resources.go +++ b/pkg/cloudprovider/resources.go @@ -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 { diff --git a/pkg/compute/guestdrivers/utils.go b/pkg/compute/guestdrivers/utils.go index 03635b0931..7a64e9d285 100644 --- a/pkg/compute/guestdrivers/utils.go +++ b/pkg/compute/guestdrivers/utils.go @@ -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") diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 906fae0717..f911e1fee2 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -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() diff --git a/pkg/multicloud/aliyun/image.go b/pkg/multicloud/aliyun/image.go index 54b1ccc877..9266745153 100644 --- a/pkg/multicloud/aliyun/image.go +++ b/pkg/multicloud/aliyun/image.go @@ -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 { diff --git a/pkg/multicloud/aliyun/instance.go b/pkg/multicloud/aliyun/instance.go index c506e8fef5..e12ac6c6d3 100644 --- a/pkg/multicloud/aliyun/instance.go +++ b/pkg/multicloud/aliyun/instance.go @@ -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 { diff --git a/pkg/multicloud/apsara/image.go b/pkg/multicloud/apsara/image.go index b6c31deffd..11177ac5e4 100644 --- a/pkg/multicloud/apsara/image.go +++ b/pkg/multicloud/apsara/image.go @@ -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 { diff --git a/pkg/multicloud/apsara/instance.go b/pkg/multicloud/apsara/instance.go index ebfdab3a54..44226cb475 100644 --- a/pkg/multicloud/apsara/instance.go +++ b/pkg/multicloud/apsara/instance.go @@ -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 { diff --git a/pkg/multicloud/aws/image.go b/pkg/multicloud/aws/image.go index ec58ab91ca..11f8cc98fc 100644 --- a/pkg/multicloud/aws/image.go +++ b/pkg/multicloud/aws/image.go @@ -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) diff --git a/pkg/multicloud/aws/instance.go b/pkg/multicloud/aws/instance.go index ae1fbbf986..6571b01ae6 100644 --- a/pkg/multicloud/aws/instance.go +++ b/pkg/multicloud/aws/instance.go @@ -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{} diff --git a/pkg/multicloud/azure/classic_instance.go b/pkg/multicloud/azure/classic_instance.go index cc58f1885b..5108038f85 100644 --- a/pkg/multicloud/azure/classic_instance.go +++ b/pkg/multicloud/azure/classic_instance.go @@ -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) { diff --git a/pkg/multicloud/azure/host.go b/pkg/multicloud/azure/host.go index 6ba08a9116..7921cd0a70 100644 --- a/pkg/multicloud/azure/host.go +++ b/pkg/multicloud/azure/host.go @@ -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 "`~!@#$%^&*()=+_[]{}\\|;:.'\",<>/?" { diff --git a/pkg/multicloud/azure/image.go b/pkg/multicloud/azure/image.go index 88f2af8382..e81958af08 100644 --- a/pkg/multicloud/azure/image.go +++ b/pkg/multicloud/azure/image.go @@ -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 { diff --git a/pkg/multicloud/azure/instance.go b/pkg/multicloud/azure/instance.go index 7919d647dd..151e19fed6 100644 --- a/pkg/multicloud/azure/instance.go +++ b/pkg/multicloud/azure/instance.go @@ -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") } diff --git a/pkg/multicloud/azure/web_app.go b/pkg/multicloud/azure/web_app.go index 0802ede373..a31e6ab766 100644 --- a/pkg/multicloud/azure/web_app.go +++ b/pkg/multicloud/azure/web_app.go @@ -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 } diff --git a/pkg/multicloud/cloudpods/image.go b/pkg/multicloud/cloudpods/image.go index cc219c7089..e3f5a78108 100644 --- a/pkg/multicloud/cloudpods/image.go +++ b/pkg/multicloud/cloudpods/image.go @@ -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 { diff --git a/pkg/multicloud/cloudpods/instance.go b/pkg/multicloud/cloudpods/instance.go index 355b6e22e3..2ec91299f4 100644 --- a/pkg/multicloud/cloudpods/instance.go +++ b/pkg/multicloud/cloudpods/instance.go @@ -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 { diff --git a/pkg/multicloud/ctyun/image.go b/pkg/multicloud/ctyun/image.go index 10c9f65575..af138a42af 100644 --- a/pkg/multicloud/ctyun/image.go +++ b/pkg/multicloud/ctyun/image.go @@ -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 { diff --git a/pkg/multicloud/ctyun/instance.go b/pkg/multicloud/ctyun/instance.go index 5adbcf6953..f69dd7a74b 100644 --- a/pkg/multicloud/ctyun/instance.go +++ b/pkg/multicloud/ctyun/instance.go @@ -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 { diff --git a/pkg/multicloud/ecloud/image.go b/pkg/multicloud/ecloud/image.go index 5fc8bbf334..0f4e03fedd 100644 --- a/pkg/multicloud/ecloud/image.go +++ b/pkg/multicloud/ecloud/image.go @@ -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 { diff --git a/pkg/multicloud/ecloud/instance.go b/pkg/multicloud/ecloud/instance.go index e7b688a9e9..24fa87f0e6 100644 --- a/pkg/multicloud/ecloud/instance.go +++ b/pkg/multicloud/ecloud/instance.go @@ -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 "" } diff --git a/pkg/multicloud/esxi/image.go b/pkg/multicloud/esxi/image.go index 4fda6168e8..ffa089372c 100644 --- a/pkg/multicloud/esxi/image.go +++ b/pkg/multicloud/esxi/image.go @@ -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 { diff --git a/pkg/multicloud/esxi/template.go b/pkg/multicloud/esxi/template.go index 0b1acead9d..262c97d3bb 100644 --- a/pkg/multicloud/esxi/template.go +++ b/pkg/multicloud/esxi/template.go @@ -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 { diff --git a/pkg/multicloud/esxi/virtualmachine.go b/pkg/multicloud/esxi/virtualmachine.go index 39abc37068..4c3cc270eb 100644 --- a/pkg/multicloud/esxi/virtualmachine.go +++ b/pkg/multicloud/esxi/virtualmachine.go @@ -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 { diff --git a/pkg/multicloud/google/image.go b/pkg/multicloud/google/image.go index bab9294f3e..14b2457bfe 100644 --- a/pkg/multicloud/google/image.go +++ b/pkg/multicloud/google/image.go @@ -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 { diff --git a/pkg/multicloud/google/instance.go b/pkg/multicloud/google/instance.go index eb652a94bd..9cb577f459 100644 --- a/pkg/multicloud/google/instance.go +++ b/pkg/multicloud/google/instance.go @@ -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 { diff --git a/pkg/multicloud/huawei/image.go b/pkg/multicloud/huawei/image.go index 5b985608e2..e1c134a8a3 100644 --- a/pkg/multicloud/huawei/image.go +++ b/pkg/multicloud/huawei/image.go @@ -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()) } diff --git a/pkg/multicloud/huawei/instance.go b/pkg/multicloud/huawei/instance.go index 89622945ab..acf5fefe53 100644 --- a/pkg/multicloud/huawei/instance.go +++ b/pkg/multicloud/huawei/instance.go @@ -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 { diff --git a/pkg/multicloud/huaweistack/image.go b/pkg/multicloud/huaweistack/image.go index 60348ff0a5..84ad7c8a1b 100644 --- a/pkg/multicloud/huaweistack/image.go +++ b/pkg/multicloud/huaweistack/image.go @@ -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()) } diff --git a/pkg/multicloud/huaweistack/instance.go b/pkg/multicloud/huaweistack/instance.go index 2c57b2eea2..b846bc6b0e 100644 --- a/pkg/multicloud/huaweistack/instance.go +++ b/pkg/multicloud/huaweistack/instance.go @@ -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 { diff --git a/pkg/multicloud/jdcloud/image.go b/pkg/multicloud/jdcloud/image.go index e74fdfaac1..795077423c 100644 --- a/pkg/multicloud/jdcloud/image.go +++ b/pkg/multicloud/jdcloud/image.go @@ -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 { diff --git a/pkg/multicloud/jdcloud/instance.go b/pkg/multicloud/jdcloud/instance.go index 2be22a192c..eab43a6f2f 100644 --- a/pkg/multicloud/jdcloud/instance.go +++ b/pkg/multicloud/jdcloud/instance.go @@ -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 "" } diff --git a/pkg/multicloud/openstack/image.go b/pkg/multicloud/openstack/image.go index 8b35a25f0d..80ff4cbb48 100644 --- a/pkg/multicloud/openstack/image.go +++ b/pkg/multicloud/openstack/image.go @@ -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 { diff --git a/pkg/multicloud/openstack/instance.go b/pkg/multicloud/openstack/instance.go index a980582a1c..2a46c59195 100644 --- a/pkg/multicloud/openstack/instance.go +++ b/pkg/multicloud/openstack/instance.go @@ -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 { diff --git a/pkg/multicloud/qcloud/image.go b/pkg/multicloud/qcloud/image.go index 107e08bfbe..8705aee5d5 100644 --- a/pkg/multicloud/qcloud/image.go +++ b/pkg/multicloud/qcloud/image.go @@ -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 { diff --git a/pkg/multicloud/qcloud/instance.go b/pkg/multicloud/qcloud/instance.go index 2445ed3f86..eb4f07e1c5 100644 --- a/pkg/multicloud/qcloud/instance.go +++ b/pkg/multicloud/qcloud/instance.go @@ -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) diff --git a/pkg/multicloud/ucloud/image.go b/pkg/multicloud/ucloud/image.go index 319a59e0e9..0afb93c871 100644 --- a/pkg/multicloud/ucloud/image.go +++ b/pkg/multicloud/ucloud/image.go @@ -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 { diff --git a/pkg/multicloud/ucloud/instance.go b/pkg/multicloud/ucloud/instance.go index 3a03884eeb..62b3725ead 100644 --- a/pkg/multicloud/ucloud/instance.go +++ b/pkg/multicloud/ucloud/instance.go @@ -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 { diff --git a/pkg/multicloud/zstack/image.go b/pkg/multicloud/zstack/image.go index c72666186f..8bad785a22 100644 --- a/pkg/multicloud/zstack/image.go +++ b/pkg/multicloud/zstack/image.go @@ -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 { diff --git a/pkg/multicloud/zstack/instance.go b/pkg/multicloud/zstack/instance.go index 455735306e..8a1c10b8fe 100644 --- a/pkg/multicloud/zstack/instance.go +++ b/pkg/multicloud/zstack/instance.go @@ -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 {