Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify vmImage metadata for Alibaba with remove code deduplication #1450

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package resources

import (
"strconv"
"strings"

"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
Expand Down Expand Up @@ -187,6 +188,40 @@ func (imageHandler *AlibabaImageHandler) ListImage() ([]*irs.ImageInfo, error) {
return imageInfoList, nil
}

func extractOsPlatform(image *ecs.Image) irs.OSPlatform {
// Ubuntu
// Rocky Linux
// Debian
// Aliyun
// AlmaLinux
// CentOS Stream
// Windows Server 2025
// Freebsd
// Anolis
// openSUSE
// Gentoo
platformInfo := image.Platform
osPlatform := irs.PlatformNA

lowerCasePlatformInfo := strings.ToLower(platformInfo)

if strings.Contains(lowerCasePlatformInfo, "windows") {
osPlatform = irs.Windows
} else if strings.Contains(lowerCasePlatformInfo, "ubuntu") ||
strings.Contains(lowerCasePlatformInfo, "rocky") ||
strings.Contains(lowerCasePlatformInfo, "debian") ||
strings.Contains(lowerCasePlatformInfo, "aliyun") ||
strings.Contains(lowerCasePlatformInfo, "almalinux") ||
strings.Contains(lowerCasePlatformInfo, "centos") ||
strings.Contains(lowerCasePlatformInfo, "freebsd") ||
strings.Contains(lowerCasePlatformInfo, "anolis") ||
strings.Contains(lowerCasePlatformInfo, "opensuse") ||
strings.Contains(lowerCasePlatformInfo, "gentoo") {
osPlatform = irs.Linux_UNIX
}
return osPlatform
}

// https://pkg.go.dev/github.com/aliyun/alibaba-cloud-sdk-go/services/ecs?tab=doc#Image
// package ecs v1.61.170 Latest Published: Apr 30, 2020
// Image 정보를 추출함
Expand All @@ -206,7 +241,7 @@ func ExtractImageDescribeInfo(image *ecs.Image) irs.ImageInfo {
// GuestOS: image.OSNameEn,
Name: image.ImageName,
OSArchitecture: irs.OSArchitecture(image.Architecture),
OSPlatform: irs.OSPlatform(image.Platform),
OSPlatform: extractOsPlatform(image),
OSDistribution: image.Description,
OSDiskType: "NA",
OSDiskSizeInGB: "-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,19 @@ func extractOsPlatform(orgImage *compute.Image) irs.OSPlatform {
platformInfo := orgImage.Name

osPlatform := irs.PlatformNA
if strings.Contains(strings.ToLower(platformInfo), "windows") {

lowerCasePlatformInfo := strings.ToLower(platformInfo)

if strings.Contains(lowerCasePlatformInfo, "windows") {
osPlatform = irs.Windows
} else if strings.Contains(strings.ToLower(platformInfo), "ubuntu") ||
strings.Contains(strings.ToLower(platformInfo), "linux") ||
strings.Contains(strings.ToLower(platformInfo), "centos") ||
strings.Contains(strings.ToLower(platformInfo), "debian") ||
strings.Contains(strings.ToLower(platformInfo), "fedora") ||
strings.Contains(strings.ToLower(platformInfo), "rhel") ||
strings.Contains(strings.ToLower(platformInfo), "rocky") ||
strings.Contains(strings.ToLower(platformInfo), "unix") {
} else if strings.Contains(lowerCasePlatformInfo, "ubuntu") ||
strings.Contains(lowerCasePlatformInfo, "linux") ||
strings.Contains(lowerCasePlatformInfo, "centos") ||
strings.Contains(lowerCasePlatformInfo, "debian") ||
strings.Contains(lowerCasePlatformInfo, "fedora") ||
strings.Contains(lowerCasePlatformInfo, "rhel") ||
strings.Contains(lowerCasePlatformInfo, "rocky") ||
strings.Contains(lowerCasePlatformInfo, "unix") {
osPlatform = irs.Linux_UNIX
}

Expand Down