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

NHN: Add more VM image info #1409

Merged
merged 1 commit into from
Dec 27, 2024
Merged
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 @@ -14,6 +14,7 @@ package resources
import (
// "errors"
"fmt"
"strconv"
"strings"
// "github.com/davecgh/go-spew/spew"

Expand Down Expand Up @@ -94,6 +95,31 @@ func (imageHandler *NhnCloudImageHandler) GetImage(imageIID irs.IID) (irs.ImageI
return *imageInfo, nil
}

func (imageHandler *NhnCloudImageHandler) GetImageN(name string) (irs.ImageInfo, error) {
cblogger.Info("NHN Cloud Driver: called GetImage()")
callLogInfo := getCallLogScheme(imageHandler.RegionInfo.Region, call.VMIMAGE, name, "GetImage()")

if strings.EqualFold(name, "") {
newErr := fmt.Errorf("Invalid SystemId!!")
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return irs.ImageInfo{}, newErr
}

start := call.Start()
nhnImage, err := images.Get(imageHandler.ImageClient, name).Extract()
if err != nil {
newErr := fmt.Errorf("Failed to Get NHN Cloud Image Info. [%v]", err.Error())
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return irs.ImageInfo{}, newErr
}
LoggingInfo(callLogInfo, start)

imageInfo := imageHandler.mappingImageInfo(*nhnImage)
return *imageInfo, nil
}

func (imageHandler *NhnCloudImageHandler) CreateImage(imageReqInfo irs.ImageReqInfo) (irs.ImageInfo, error) {
cblogger.Info("NHN Cloud Driver: called CreateImage()!")

Expand Down Expand Up @@ -138,29 +164,46 @@ func (imageHandler *NhnCloudImageHandler) DeleteImage(imageIID irs.IID) (bool, e
func (imageHandler *NhnCloudImageHandler) mappingImageInfo(image images.Image) *irs.ImageInfo {
cblogger.Info("NHN Cloud Driver: called mappingImagInfo()!")

var imgAvailability string
var imgAvailability irs.ImageStatus
if strings.EqualFold(string(image.Status), "active") {
imgAvailability = "available"
imgAvailability = irs.ImageAvailable
} else {
imgAvailability = "unavailable"
imgAvailability = irs.ImageUnavailable
}

arch := irs.ArchitectureNA
osArch := strings.ToLower(image.Properties["os_architecture"].(string))
if osArch == "amd64" {
arch = irs.X86_64
} else if osArch == "arm64" {
arch = irs.ARM64
}

platform := irs.PlatformNA
osPlatform := strings.ToLower(image.Properties["os_type"].(string))
if osPlatform == "linux" {
platform = irs.Linux_UNIX
} else if osPlatform == "windows" {
platform = irs.Windows
}

imageInfo := &irs.ImageInfo{
IId: irs.IID{
NameId: image.ID, // Caution!!
SystemId: image.ID,
},
GuestOS: image.Name, // Caution!!
Status: imgAvailability,
Name: image.ID,
OSArchitecture: arch,
OSPlatform: platform,
OSDistribution: image.Properties["os_distro"].(string),
OSDiskType: image.DiskFormat,
OSDiskSizeInGB: strconv.Itoa(image.MinDiskGigabytes),
ImageStatus: imgAvailability,
}

keyValueList := []irs.KeyValue{
{Key: "Region", Value: imageHandler.RegionInfo.Region},
{Key: "Visibility:", Value: string(image.Visibility)},
{Key: "Visibility", Value: string(image.Visibility)},
}

for key, val := range image.Properties {
if key == "os_architecture" || key == "hypervisor_type" || key == "release_date" || key == "description" || key == "os_distro" || key == "os_version" || key == "nhncloud_product" {
if key == "hypervisor_type" || key == "release_date" || key == "description" || key == "os_version" || key == "nhncloud_product" {
metadata := irs.KeyValue{
Key: strings.ToUpper(key),
Value: fmt.Sprintf("%v", val),
Expand Down
Loading