From 9aaa13eb25b3aa1402a0e6ca5f824bdb9b320031 Mon Sep 17 00:00:00 2001 From: ish Date: Thu, 26 Dec 2024 20:20:13 +0900 Subject: [PATCH] NHN: Add more VM image info --- .../nhncloud/resources/ImageHandler.go | 65 +++++++++++++++---- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/nhncloud/resources/ImageHandler.go b/cloud-control-manager/cloud-driver/drivers/nhncloud/resources/ImageHandler.go index 0aafdf423..d6ad501d9 100644 --- a/cloud-control-manager/cloud-driver/drivers/nhncloud/resources/ImageHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/nhncloud/resources/ImageHandler.go @@ -14,6 +14,7 @@ package resources import ( // "errors" "fmt" + "strconv" "strings" // "github.com/davecgh/go-spew/spew" @@ -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()!") @@ -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),