Skip to content

Commit

Permalink
Merge pull request #1409 from ish-hcc/nhn_vmimage
Browse files Browse the repository at this point in the history
NHN: Add more VM image info
  • Loading branch information
powerkimhub authored Dec 27, 2024
2 parents 8c6cae8 + 9aaa13e commit 4c49c1e
Showing 1 changed file with 54 additions and 11 deletions.
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

0 comments on commit 4c49c1e

Please sign in to comment.