From 6d531ef2ae6bd2dd6b11528ed87dd627eed9421b Mon Sep 17 00:00:00 2001 From: innodreamer Date: Thu, 18 Jul 2024 18:06:51 +0900 Subject: [PATCH] Apply NCP's Updated Parameter Return Values about VMImage/MyImage --- .../drivers/ncp/resources/ImageHandler.go | 32 +++++++++++++++---- .../drivers/ncp/resources/MyImageHandler.go | 17 ++++++---- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/ncp/resources/ImageHandler.go b/cloud-control-manager/cloud-driver/drivers/ncp/resources/ImageHandler.go index bffd56e40..f533af4b5 100644 --- a/cloud-control-manager/cloud-driver/drivers/ncp/resources/ImageHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/ncp/resources/ImageHandler.go @@ -12,6 +12,7 @@ import ( "fmt" "strconv" "strings" + // "github.com/davecgh/go-spew/spew" ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud" server "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/server" @@ -117,7 +118,7 @@ func MappingImageInfo(serverImage server.Product) irs.ImageInfo { NameId: *serverImage.ProductCode, SystemId: *serverImage.ProductCode, }, - GuestOS: *serverImage.ProductDescription, + GuestOS: *serverImage.OsInformation, Status: "available", } @@ -126,9 +127,9 @@ func MappingImageInfo(serverImage server.Product) irs.ImageInfo { {Key: "PlatformType", Value: *serverImage.PlatformType.CodeName}, {Key: "InfraResourceType", Value: *serverImage.InfraResourceType.CodeName}, {Key: "BaseBlockStorageSize(GB)", Value: strconv.FormatFloat(float64(*serverImage.BaseBlockStorageSize)/(1024*1024*1024), 'f', 0, 64)}, - //{Key: "OsInformation", Value: *serverImage.OsInformation}, - //{Key: "DB Type", Value: *serverImage.DbKindCode}, - //{Key: "NCP GenerationCode", Value: *serverImage.GenerationCode}, + // {Key: "OsInformation", Value: *serverImage.OsInformation}, + // {Key: "DB Type", Value: *serverImage.DbKindCode}, + // {Key: "NCP GenerationCode", Value: *serverImage.GenerationCode}, } keyValueList = append(keyValueList, irs.KeyValue{Key: "Description", Value: *serverImage.ProductDescription}) imageInfo.KeyValueList = keyValueList @@ -192,11 +193,30 @@ func (imageHandler *NcpImageHandler) GetNcpImageInfo(imageIID irs.IID) (*server. return nil, createErr } - imageReq := server.GetServerImageProductListRequest{ProductCode: ncloud.String(imageIID.SystemId)} + // cblogger.Info("\n\n### imageIID : ") + // spew.Dump(imageIID) + // cblogger.Info("\n") + + vmHandler := NcpVMHandler{ + RegionInfo: imageHandler.RegionInfo, + VMClient: imageHandler.VMClient, + } + regionNo, err := vmHandler.GetRegionNo(imageHandler.RegionInfo.Region) + if err != nil { + newErr := fmt.Errorf("Failed to Get NCP Region No of the Region Code : [%v]", err) + cblogger.Error(newErr.Error()) + LoggingError(callLogInfo, newErr) + return nil, newErr + } + + imageReq := server.GetServerImageProductListRequest{ + ProductCode: ncloud.String(imageIID.SystemId), + RegionNo: regionNo, + } callLogStart := call.Start() result, err := imageHandler.VMClient.V2Api.GetServerImageProductList(&imageReq) if err != nil { - newErr := fmt.Errorf("Failed to Find Image list from NCP : [%v]", err) + newErr := fmt.Errorf("Failed to Get Image list from NCP : [%v]", err) cblogger.Error(newErr.Error()) LoggingError(callLogInfo, newErr) return nil, newErr diff --git a/cloud-control-manager/cloud-driver/drivers/ncp/resources/MyImageHandler.go b/cloud-control-manager/cloud-driver/drivers/ncp/resources/MyImageHandler.go index 80537b76a..c1f969f34 100644 --- a/cloud-control-manager/cloud-driver/drivers/ncp/resources/MyImageHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/ncp/resources/MyImageHandler.go @@ -338,6 +338,7 @@ func (myImageHandler *NcpMyImageHandler) MappingMyImageInfo(myImage *server.Memb {Key: "Region", Value: myImageHandler.RegionInfo.Region}, {Key: "OriginalImageProductCode", Value: *myImage.OriginalServerImageProductCode}, {Key: "MyImagePlatformType", Value: *myImage.MemberServerImagePlatformType.CodeName}, + {Key: "OriginalOsInformation", Value: *myImage.OriginalOsInformation}, {Key: "CreateDate", Value: *myImage.CreateDate}, } myImageInfo.KeyValueList = keyValueList @@ -383,8 +384,8 @@ func (myImageHandler *NcpMyImageHandler) GetNcpMemberServerImageInfo(myImageIID LoggingInfo(callLogInfo, callLogStart) if len(result.MemberServerImageList) < 1 { - newErr := fmt.Errorf("Failed to Get the Member Server Image List from NCP. Member Server Image does Not Exist!!") - cblogger.Error(newErr.Error()) + newErr := fmt.Errorf("The Member Server Image does Not Exist!!") + cblogger.Debug(newErr.Error()) LoggingError(callLogInfo, newErr) return server.MemberServerImage{}, newErr } else { @@ -424,7 +425,9 @@ func (myImageHandler *NcpMyImageHandler) GetOriginImageOSPlatform(imageIID irs.I LoggingError(callLogInfo, newErr) return "", newErr } else { - imagePlatformType := strings.ToUpper(*ncpImageInfo.PlatformType.CodeName) + // cblogger.Infof("### ImageOsInformation : [%s]", *ncpImageInfo.OsInformation) + imagePlatformType := strings.ToUpper(*ncpImageInfo.OsInformation) + var originImagePlatform string if strings.Contains(imagePlatformType, "UBUNTU") { originImagePlatform = "UBUNTU" @@ -444,13 +447,13 @@ func (myImageHandler *NcpMyImageHandler) GetOriginImageOSPlatform(imageIID irs.I memberServerImageInfo, err := myImageHandler.GetNcpMemberServerImageInfo(imageIID) if err != nil { newErr := fmt.Errorf("Failed to Get NCP Member Server Image Info. [%v]", err.Error()) - cblogger.Error(newErr.Error()) + cblogger.Debug(newErr.Error()) LoggingError(callLogInfo, newErr) return "", newErr } - cblogger.Infof("### MyImagePlatformType : [%s]", *memberServerImageInfo.MemberServerImagePlatformType.CodeName) - - imagePlatformType := strings.ToUpper(*memberServerImageInfo.MemberServerImagePlatformType.CodeName) + // cblogger.Infof("### MyImageOriginalOsInformation : [%s]", *memberServerImageInfo.OriginalOsInformation) + imagePlatformType := strings.ToUpper(*memberServerImageInfo.OriginalOsInformation) + var originImagePlatform string if strings.Contains(imagePlatformType, "UBUNTU") { originImagePlatform = "UBUNTU"